Source code for ooodev.adapter.document.storage_change_listener

from __future__ import annotations
from typing import TYPE_CHECKING

import uno
from import XStorageChangeListener

from import EventArgs
from import GenericArgs
from ooodev.adapter.adapter_base import AdapterBase

    from import XInterface
    from import XStorage
    from import XStorageBasedDocument

[docs]class StorageChangeListener(AdapterBase, XStorageChangeListener): """ allows to be notified when a document is switched to a new storage. See Also: `API XStorageChangeListener <>`_ """
[docs] def __init__( self, trigger_args: GenericArgs | None = None, subscriber: XStorageBasedDocument | None = None ) -> None: """ Constructor Args: trigger_args (GenericArgs, Optional): Args that are passed to events when they are triggered. subscriber (XStorageBasedDocument, optional): An UNO object that implements the ``XStorageBasedDocument`` interface. If passed in then this listener instance is automatically added to it. """ super().__init__(trigger_args=trigger_args) if subscriber: subscriber.addStorageChangeListener(self)
[docs] def notifyStorageChange(self, document: XInterface, storage: XStorage) -> None: """ Event is invoked when document switches to another storage. When this method is triggered it raises the ``notifyStorageChange`` event. The event data is a dictionary with the following keys: - ``document``: The document that is being switched to another storage. - ``storage``: The new storage that the document is being switched to. """ args = EventArgs(self) args.event_data = {"document": document, "storage": storage} self._trigger_event("notifyStorageChange", args)