from __future__ import annotations
from typing import Any, Dict, TYPE_CHECKING
from ooodev.events.args.generic_args import GenericArgs
from ooodev.events.args.listener_event_args import ListenerEventArgs
from ooodev.utils import gen_util as gUtil
from ooodev.adapter.ui.context_menu_interceptor import ContextMenuInterceptor
if TYPE_CHECKING:
from com.sun.star.ui import XContextMenuInterception
from ooodev.utils.type_var import EventArgsCallbackT, ListenerEventCallbackT
# https://wiki.documentfoundation.org/Framework/Tutorial/Context_Menu_Interception
# endregion Manage Events
[docs]def on_lazy_cb(source: Any, event: ListenerEventArgs) -> None:
"""
Callback that is invoked when an event is added or removed.
This method is generally used to add the listener to the component in a lazy manner.
This means this callback will only be called once in the lifetime of the component.
Args:
source (Any): Expected to be an instance of ActivationEventEvents that is a partial class of a component based class.
event (ListenerEventArgs): Event arguments.
Returns:
None:
Warning:
This method is intended for internal use only.
"""
# will only ever fire once
if not isinstance(source, ContextMenuInterceptorEvents):
return
# if not hasattr(source, "component"):
# return
# There is not attaching events to the component for ContextMenuInterceptorEvents.
event.remove_callback = True