[gedit-plugins] Make multi edit menu item proper toggle item
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-plugins] Make multi edit menu item proper toggle item
- Date: Sat, 1 May 2010 15:33:25 +0000 (UTC)
commit d49ea93d4865cf15234b6973b55e4a442bae66cd
Author: Jesse van den Kieboom <jesse icecrew nl>
Date: Sat May 1 17:32:23 2010 +0200
Make multi edit menu item proper toggle item
plugins/multiedit/multiedit/documenthelper.py | 23 +++++++++++++++++++++--
plugins/multiedit/multiedit/windowhelper.py | 21 ++++++++++++++++++---
2 files changed, 39 insertions(+), 5 deletions(-)
---
diff --git a/plugins/multiedit/multiedit/documenthelper.py b/plugins/multiedit/multiedit/documenthelper.py
index 8f107ce..82ec9da 100644
--- a/plugins/multiedit/multiedit/documenthelper.py
+++ b/plugins/multiedit/multiedit/documenthelper.py
@@ -74,6 +74,16 @@ class DocumentHelper(Signals):
self.reset_buffer(self._view.get_buffer())
self.initialize_event_handlers()
+ self.toggle_callback = None
+
+ def get_view(self):
+ return self._view
+
+ def set_toggle_callback(self, callback, data):
+ self.toggle_callback = lambda: callback(data)
+
+ def enabled(self):
+ return self._in_mode
def _update_selection_tag(self):
style = self._view.get_style()
@@ -155,12 +165,21 @@ class DocumentHelper(Signals):
self._view.set_border_window_size(gtk.TEXT_WINDOW_TOP, 0)
self.remove_edit_points()
+ if self.toggle_callback:
+ self.toggle_callback()
+
def enable_multi_edit(self):
self._view.set_border_window_size(gtk.TEXT_WINDOW_TOP, 20)
self._in_mode = True
- def toggle_multi_edit(self):
- if self._in_mode:
+ if self.toggle_callback:
+ self.toggle_callback()
+
+ def toggle_multi_edit(self, enabled):
+ if self.enabled() == enabled:
+ return
+
+ if self.enabled():
self.disable_multi_edit()
else:
self.enable_multi_edit()
diff --git a/plugins/multiedit/multiedit/windowhelper.py b/plugins/multiedit/multiedit/windowhelper.py
index bb80132..9dc7969 100644
--- a/plugins/multiedit/multiedit/windowhelper.py
+++ b/plugins/multiedit/multiedit/windowhelper.py
@@ -58,6 +58,7 @@ class WindowHelper(Signals):
self.connect_signal(window, 'tab-added', self.on_tab_added)
self.connect_signal(window, 'tab-removed', self.on_tab_removed)
+ self.connect_signal(window, 'active-tab-changed', self.on_active_tab_changed)
self.install_ui()
@@ -65,7 +66,7 @@ class WindowHelper(Signals):
manager = self._window.get_ui_manager()
self._action_group = gtk.ActionGroup("GeditMultiEditPluginActions")
- self._action_group.add_actions(
+ self._action_group.add_toggle_actions(
[('MultiEditModeAction', None, _('Multi Edit Mode'), '<Ctrl><Shift>C', _('Start multi edit mode'), self.on_multi_edit_mode)])
manager.insert_action_group(self._action_group, -1)
@@ -96,7 +97,8 @@ class WindowHelper(Signals):
if view.get_data(constants.DOCUMENT_HELPER_KEY) != None:
return
- DocumentHelper(view)
+ helper = DocumentHelper(view)
+ helper.set_toggle_callback(self.on_multi_edit_toggled, helper)
def remove_document_helper(self, view):
helper = view.get_data(constants.DOCUMENT_HELPER_KEY)
@@ -104,17 +106,30 @@ class WindowHelper(Signals):
if helper != None:
helper.stop()
+ def get_action(self):
+ return self._action_group.get_action('MultiEditModeAction')
+
+ def on_multi_edit_toggled(self, helper):
+ if helper.get_view() == self._window.get_active_view():
+ self.get_action().set_active(helper.enabled())
+
def on_tab_added(self, window, tab):
self.add_document_helper(tab.get_view())
def on_tab_removed(self, window, tab):
self.remove_document_helper(tab.get_view())
+ def on_active_tab_changed(self, window, tab):
+ view = tab.get_view()
+ helper = view.get_data(constants.DOCUMENT_HELPER_KEY)
+
+ self.get_action().set_active(helper != None and helper.enabled())
+
def on_multi_edit_mode(self, action):
view = self._window.get_active_view()
helper = view.get_data(constants.DOCUMENT_HELPER_KEY)
if helper != None:
- helper.toggle_multi_edit()
+ helper.toggle_multi_edit(self.get_action().get_active())
# ex:ts=4:et:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]