[gedit-plugins/gnome-2-30] Added commander toggle menu item



commit ad60cf271784d10aa6fadf9bef6254f8f1df82ad
Author: Jesse van den Kieboom <jesse vandenkieboom epfl ch>
Date:   Mon May 3 13:46:58 2010 +0200

    Added commander toggle menu item

 plugins/commander/commander/windowhelper.py |   66 +++++++++++++++++++++------
 1 files changed, 51 insertions(+), 15 deletions(-)
---
diff --git a/plugins/commander/commander/windowhelper.py b/plugins/commander/commander/windowhelper.py
index 15dc787..9c71f28 100644
--- a/plugins/commander/commander/windowhelper.py
+++ b/plugins/commander/commander/windowhelper.py
@@ -2,43 +2,79 @@ import gedit
 import gtk
 from entry import Entry
 from info import Info
+from gpdefs import *
+
+try:
+    gettext.bindtextdomain(GETTEXT_PACKAGE, GP_LOCALEDIR)
+    _ = lambda s: gettext.dgettext(GETTEXT_PACKAGE, s);
+except:
+    _ = lambda s: s
+
+ui_str = """
+<ui>
+  <menubar name="MenuBar">
+    <menu name="EditMenu" action="Edit">
+      <placeholder name="EditOps_5">
+        <menuitem name="CommanderEditMode" action="CommanderModeAction"/>
+      </placeholder>
+    </menu>
+  </menubar>
+</ui>
+"""
 
 class WindowHelper:
 	def __init__(self, plugin, window):
 		self._window = window
 		self._plugin = plugin
 		self._entry = None
-		accel_path = '<gedit>/plugins/commander/activate'
+		self._view = None
 
-		accel = gtk.accel_map_lookup_entry(accel_path)
+		self.install_ui()
 
-		if accel == None:
-			gtk.accel_map_add_entry(accel_path, gtk.keysyms.period, gtk.gdk.CONTROL_MASK)
+	def install_ui(self):
+		manager = self._window.get_ui_manager()
+
+		self._action_group = gtk.ActionGroup("GeditCommanderPluginActions")
+		self._action_group.add_toggle_actions([('CommanderModeAction', None, _('Commander Mode'), '<Ctrl>period', _('Start commander mode'), self.on_commander_mode)])
+
+		manager.insert_action_group(self._action_group, -1)
+		self._merge_id = manager.add_ui_from_string(ui_str)
+
+	def uninstall_ui(self):
+		manager = self._window.get_ui_manager()
+		manager.remove_ui(self._merge_id)
+		manager.remove_action_group(self._action_group)
+
+		manager.ensure_update()
 
-		self._accel = gtk.AccelGroup()
-		self._accel.connect_by_path(accel_path, self._do_command)
-		self._window.add_accel_group(self._accel)
-	
 	def deactivate(self):
-		self._window.remove_accel_group(self._accel)
+		self.uninstall_ui()
+
 		self._window = None
 		self._plugin = None
 
 	def update_ui(self):
 		pass
-	
-	def _do_command(self, group, obj, keyval, mod):
+
+	def on_commander_mode(self, action):
 		view = self._window.get_active_view()
 		
 		if not view:
 			return False
 
-		if not self._entry:
-			self._entry = Entry(self._window.get_active_view())
-			self._entry.connect('destroy', self.on_entry_destroy)
+		if action.get_active():
+			if not self._entry or view != self._view:
+				self._entry = Entry(view)
+				self._entry.connect('destroy', self.on_entry_destroy)
+
+			self._entry.grab_focus()
+			self._view = view
+		elif self._entry:
+			self._entry.destroy()
+			self._view = None
 
-		self._entry.grab_focus()
 		return True
 	
 	def on_entry_destroy(self, widget):
 		self._entry = None
+		self._action_group.get_action('CommanderModeAction').set_active(False)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]