summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthieu Gautier <starmad@pegase.localdomain>2009-03-25 20:29:18 +0100
committerMatthieu Gautier <starmad@pegase.localdomain>2009-03-25 20:29:18 +0100
commit20e5e77ebea384f7d4acfa270fd8b0a5bfb9886a (patch)
tree7c1b6dc6c34852945559a8fd2095d7f56a15bb7a
parentfdffb9c285c8235032bd910c56cd987388a740c2 (diff)
downloadg-ed-it-20e5e77ebea384f7d4acfa270fd8b0a5bfb9886a.zip
g-ed-it-20e5e77ebea384f7d4acfa270fd8b0a5bfb9886a.tar.gz
g-ed-it-20e5e77ebea384f7d4acfa270fd8b0a5bfb9886a.tar.xz
Export the management of the git menu in a nw file.
* Create g-ed-it/menuManager.py * Move creation and suppression of the git menu in menuManager Signed-off-by: Matthieu Gautier <starmad@pegase.localdomain>
-rw-r--r--g-ed-it/g_ed_it.py86
-rw-r--r--g-ed-it/menuManager.py33
2 files changed, 73 insertions, 46 deletions
diff --git a/g-ed-it/g_ed_it.py b/g-ed-it/g_ed_it.py
index 553dff4..754e3b9 100644
--- a/g-ed-it/g_ed_it.py
+++ b/g-ed-it/g_ed_it.py
@@ -8,17 +8,7 @@ import gobject
import os
import time
-ui_string = """<ui>
- <menubar name="MenuBar">
- <placeholder name="ExtraMenu_1">
- <menu action="GitMenu">
- <menuitem action="Commit"/>
- <menuitem action="Add"/>
- </menu>
- </placeholder>
- </menubar>
-</ui>
-"""
+import menuManager
GLADE_FILE = os.path.join(os.path.dirname(__file__), "commit.glade")
@@ -26,11 +16,10 @@ class PluginHelper:
def __init__(self, plugin, window):
self.window = window
self.plugin = plugin
-
- self.ui_id = None
- # Add a "toggle split view" item to the View menu
- self.insert_menu_item(window)
+ self.createActionManager()
+
+ self.menuManager = menuManager.MenuManager(window)
self.load_dialogs()
@@ -39,7 +28,8 @@ class PluginHelper:
except: self.encoding = gedit.gedit_encoding_get_current()
def deactivate(self):
- self.remove_menu_item()
+ self.menuManager.deactivate()
+ self.manager.remove_action_group(self.action_group)
self.window = None
self.plugin = None
@@ -47,9 +37,42 @@ class PluginHelper:
def update_ui(self):
return
- def commit_action(self, window):
+ def action_commit(self, window):
self._search_dialog.show()
pass
+
+ def action_add(self, window):
+ pass
+
+ def createActionManager(self):
+ self.manager = self.window.get_ui_manager()
+
+
+ self.action_group = gtk.ActionGroup("GitPluginActions")
+
+ self.git_menu_action = gtk.Action(name="GitMenu",
+ label="Git",
+ tooltip="Manage git",
+ stock_id=None)
+ self.commit_action = gtk.Action(name="Commit",
+ label="Commit",
+ tooltip="Commit current state",
+ stock_id=gtk.STOCK_GO_UP)
+ self.add_action = gtk.Action(name="Add",
+ label="Add to index",
+ tooltip="",
+ stock_id=gtk.STOCK_ADD)
+
+ self.commit_action.connect("activate", self.action_commit)
+ self.add_action.connect("activate", self.action_add)
+
+ self.action_group.add_action(self.git_menu_action)
+ self.action_group.add_action(self.commit_action)
+ self.action_group.add_action(self.add_action)
+
+ # Add the action group.
+ self.manager.insert_action_group(self.action_group, -1)
+ pass
###
# Called when the "Close" button is clicked.
@@ -64,35 +87,6 @@ class PluginHelper:
def on_commit_text_changed(self, commit_text_entry):
pass
-
- def add_action(self, window):
- pass
-
- def insert_menu_item(self, window):
- manager = self.window.get_ui_manager()
-
- self.action_group = gtk.ActionGroup("GitPluginActions")
-
- self.git_menu_action_ = gtk.Action(name="GitMenu", label="Git", tooltip="Manage git", stock_id=None)
- self.commit_action_ = gtk.Action(name="Commit", label="Commit", tooltip="Commit current state", stock_id=gtk.STOCK_GO_UP)
- self.add_action_ = gtk.Action(name="Add", label="Add to index", tooltip="", stock_id=gtk.STOCK_ADD)
- self.commit_action_.connect("activate", self.commit_action)
- self.add_action_.connect("activate", self.add_action)
-
- self.action_group.add_action(self.git_menu_action_)
- self.action_group.add_action(self.commit_action_)
- self.action_group.add_action(self.add_action_)
-
- # Add the action group.
- manager.insert_action_group(self.action_group, -1)
-
- self.ui_id = manager.add_ui_from_string(ui_string)
-
- def remove_menu_item(self):
- manager.remove_ui(self.ui_id)
- manager.remove_action_group(self.action_group)
- manager.ensure_update()
-
###
# Load commit dialog.
# - Load dialog from its Glade file
diff --git a/g-ed-it/menuManager.py b/g-ed-it/menuManager.py
new file mode 100644
index 0000000..70c4b38
--- /dev/null
+++ b/g-ed-it/menuManager.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+
+ui_string = """<ui>
+ <menubar name="MenuBar">
+ <placeholder name="ExtraMenu_1">
+ <menu action="GitMenu">
+ <menuitem action="Commit"/>
+ <menuitem action="Add"/>
+ </menu>
+ </placeholder>
+ </menubar>
+</ui>
+"""
+
+class MenuManager (object):
+
+ def __init__(self, window):
+ self.window = window
+ self.ui_id = None
+ self.insert_menu_item(window)
+
+ def insert_menu_item(self, window):
+ self.manager = self.window.get_ui_manager()
+ self.ui_id = self.manager.add_ui_from_string(ui_string)
+
+ def deactivate(self):
+ self.manager.remove_ui(self.ui_id)
+ self.manager.ensure_update()
+
+ self.window = None
+
+