Detecting when new document is opened in Gedit plugin

20 views Asked by At

I'm working on a plugin for the text editor Gedit in which I need to know when a new document is opened. Is there a signal which is emitted when that happens? The method do_activate in the ViewActivatable extension point is called when a new view (tab) is created but when a document is opened in an empty Gedit session the tab "Unsaved Document 1" is reused so no new view is created.

1

There are 1 answers

0
Kripto On

Gedit changes the window title to the title of the open document. This happens whenever you open or rename a document or switch between document tabs. I don't know exactly how a plugin is executed, but I believe it is possible to use Gtk.Label.connect("notify::label", your_callback_function) in Gtk.Label responsible for the title to detect this change and thus know if a new document has been open.

Of course, you will need to filter changes that occur due to switching tabs or renaming the file, but that doesn't seem like a big problem to me.