【问题标题】:Can Gedit plugins bind to the OnSave event?Gedit 插件可以绑定到 OnSave 事件吗?
【发布时间】:2012-02-18 10:15:37
【问题描述】:
我正在写一个gedit 3 plugin,类似于phsilva's PyLint plugin,它调用外部lint 程序并突出显示当前文档中的代码行。我的问题是,如果我的插件有 run_lint 动作,是否可以将其绑定到 gedit 中的 OnSave 事件?我在上面链接的文档中的可用信号列表仍然有一个 FIXME 通知反对它,我正在努力找出在 API 文档汤中可以找到完整列表的位置。
【问题讨论】:
标签:
python
plugins
gedit
gnome-3
【解决方案1】:
嗯,没有人回答这个问题,但我最终想通了。这有两个步骤,当在该选项卡包含文档的窗口中创建一个新选项卡时。该文档具有可以连接到操作的loaded 和saved 信号。请务必记住,每个选项卡都有一个单独的文档,每个选项卡都需要自己的一组信号和处理程序。
这是一个大纲解决方案,以防对其他人有用:
class FooPlugin(GObject.Object, Gedit.WindowActivatable):
__gtype_name__ = 'Foo'
...
def do_activate(self):
self._add_ui()
self.window.connect('tab-added', self.on_tab_added)
...
return
def on_tab_added(self, window, tab, data=None):
doc = tab.get_document()
doc.connect('saved', self.on_document_saved)
doc.connect('loaded', self.on_document_loaded)
return
def on_document_loaded(self, document, data=None):
# do something here...
return
def on_document_saved(self, document, data=None):
# do something here...
return