Detect when documents (context) change?

Is there a way to detect when a document changes?

I a working on a context manager that basically caches the current document ( XComponent ) When the document changes I want to invalidate the cache. The manager also does a few other things so its not just about cache.

I am getting the desktop from the the LO Service Manager.

self.desktop = self._mc_factory.DefaultContext.getByName("/singletons/com.sun.star.frame.theDesktop")

Then I am adding a listener to the deskop

self.desktop.addFrameActionListener(mylistener)

Next I open a LibreOffice Writer and run the APSO console. From there I load my context manager, Which is a static class. Loading creates the deskop and adds the listener.

Next I open Calc from the Writer File Menu. This creates a Calc document that is open at the same time as the Write Document.

I expect my Context Manager to get notification when I switch from Write to Calc and back again.
The frame action event is not firing. Am I missing something?

I missing some more relevant LOC instead prose!

I don’t know what this means?

LOC = »Lines Of Code«

I have been working on the Loader for OOO Development Tools (OooDev).

in the _load_from_context() methood I capture theDesktop singleton.
Next I Add an Event Listener on Line 535.
In my thinking this should fire on_context_changed() when switching from a Calc Document to a Write document and back again. It currently does not work at all.
I would like to detect when a the desktop current component has changed, when desktop.getCurrentComponent() has a differnet document then it previous call.

I think you’ll get a lot more information using the addDocumentEventListener method of document or theGlobalEventBroadcaster.

1 Like

Hmm… Looks promising. I will take a closer look at this when I get a chance.

Hi Paul,

Regardless of your Python scripting idiosyncrasies you should have a look at document events. The events you may be interested in are OnFocus and OnUnfocus. Online help describes the Monitoring of document events with Python or Basic. TDF wiki holds an .ODS file with such a document listener Python example.

I ended up baking in a Global Event Broadcaster and subscribing to the OnUnfocus Event. It seem to be doing the trick.

Is there a list of events somewhere that the theGlobalEventBroadcaster uses?

Hi Paul

Please look at document events link in my previous reply for such a list of events

1 Like