1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
From 0c4ef746e91cb8987430b89f22cb4699e06410fe Mon Sep 17 00:00:00 2001
From: Jesse van den Kieboom <jesse.vandenkieboom@epfl.ch>
Date: Mon, 03 May 2010 11:48:21 +0000
Subject: Make multi edit menu item proper toggle item
---
diff --git a/plugins/multiedit/multiedit/documenthelper.py b/plugins/multiedit/multiedit/documenthelper.py
index 58ccac7..df08c7f 100644
--- a/plugins/multiedit/multiedit/documenthelper.py
+++ b/plugins/multiedit/multiedit/documenthelper.py
@@ -69,6 +69,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()
@@ -147,12 +157,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 d9941ae..adae3af 100644
--- a/plugins/multiedit/multiedit/windowhelper.py
+++ b/plugins/multiedit/multiedit/windowhelper.py
@@ -58,14 +58,15 @@ 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()
def install_ui(self):
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)
@@ -95,26 +96,40 @@ class WindowHelper(Signals):
def add_document_helper(self, view):
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)
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:
--
cgit v0.8.3.1
|