[gedit-latex] Use GtkActions to build the tools toolbar menu



commit 2813dd3be782c96b2657bd7d557bd21f21438fb6
Author: John Stowers <john stowers gmail com>
Date:   Wed Jun 29 15:16:42 2011 +1200

    Use GtkActions to build the tools toolbar menu
    
    	* Use a placeholder in the custom toolbar
    	  and merge the tools into that

 latex/base/config.py            |   11 ++++++++-
 latex/base/windowactivatable.py |   42 +++++++++++++--------------------------
 latex/latex/actions.py          |   20 ++++++++++++++++++
 3 files changed, 43 insertions(+), 30 deletions(-)
---
diff --git a/latex/base/config.py b/latex/base/config.py
index dd5954a..ce7f614 100644
--- a/latex/base/config.py
+++ b/latex/base/config.py
@@ -105,7 +105,12 @@ UI = """
             <toolitem action="LaTeXListingAction" />
             <toolitem action="LaTeXUseBibliographyAction" />
             <separator />
-            <toolitem action="LaTeXBuildImageAction" />
+            <toolitem action="LaTeXBuildAction">
+                <menu action="LaTeXBuildMenuAction">
+					<menuitem action="LaTeXBuildImageAction" />
+					<placeholder name="LaTeXBuildPlaceholder_1" />
+                </menu>
+            </toolitem>				
         </toolbar>
     </ui>"""
 
@@ -119,7 +124,8 @@ from ..latex.actions import LaTeXMenuAction, LaTeXNewAction, LaTeXChooseMasterAc
         LaTeXJustifyCenterAction, LaTeXJustifyRightAction, LaTeXMathMenuAction, LaTeXMathAction, LaTeXDisplayMathAction, \
         LaTeXEquationAction, LaTeXUnEqnArrayAction, LaTeXEqnArrayAction, LaTeXUnderlineAction, LaTeXSmallCapitalsAction, \
         LaTeXRomanAction, LaTeXSansSerifAction, LaTeXTypewriterAction, LaTeXCloseEnvironmentAction, LaTeXBlackboardBoldAction, \
-        LaTeXCaligraphyAction, LaTeXFrakturAction, LaTeXBuildImageAction, LaTeXSaveAsTemplateAction
+        LaTeXCaligraphyAction, LaTeXFrakturAction, LaTeXBuildImageAction, LaTeXSaveAsTemplateAction, \
+        LaTeXBuildAction, LaTeXBuildMenuAction
 
 from ..bibtex.actions import BibTeXMenuAction, BibTeXNewEntryAction
 
@@ -132,6 +138,7 @@ ACTIONS = [LaTeXMenuAction, LaTeXNewAction, LaTeXChooseMasterAction,
         LaTeXEquationAction, LaTeXUnEqnArrayAction, LaTeXEqnArrayAction, LaTeXUnderlineAction, LaTeXSmallCapitalsAction,
         LaTeXRomanAction, LaTeXSansSerifAction, LaTeXTypewriterAction, LaTeXCloseEnvironmentAction, LaTeXBlackboardBoldAction,
         LaTeXCaligraphyAction, LaTeXFrakturAction, LaTeXBuildImageAction, LaTeXSaveAsTemplateAction,
+        LaTeXBuildAction, LaTeXBuildMenuAction,
         BibTeXMenuAction, BibTeXNewEntryAction]
 
 # views
diff --git a/latex/base/windowactivatable.py b/latex/base/windowactivatable.py
index ef1c7ba..0336a7a 100644
--- a/latex/base/windowactivatable.py
+++ b/latex/base/windowactivatable.py
@@ -52,13 +52,20 @@ class LaTeXWindowActivatable(GObject.Object, Gedit.WindowActivatable, PeasGtk.Co
 
     _log = logging.getLogger("LaTeXWindowActivatable")
 
-    # ui definition template for hooking tools in Gedit's ui
+    # ui definition template for hooking tools in Gedit's ui.
     _tool_ui_template = string.Template("""<ui>
             <menubar name="MenuBar">
                 <menu name="ToolsMenu" action="Tools">
                     <placeholder name="ToolsOps_1">$items</placeholder>
                 </menu>
             </menubar>
+			<toolbar name="LaTeXToolbar">
+				<toolitem action="LaTeXBuildAction">
+					<menu action="LaTeXBuildMenuAction">
+						<placeholder name="LaTeXBuildPlaceholder_1">$items</placeholder>
+					</menu>
+				</toolitem>
+            </toolbar>
         </ui>""")
 
     def __init__(self):
@@ -214,6 +221,7 @@ class LaTeXWindowActivatable(GObject.Object, Gedit.WindowActivatable, PeasGtk.Co
         self._toolbar = self._ui_manager.get_widget("/LaTeXToolbar")
         self._toolbar.set_style(Gtk.ToolbarStyle.BOTH_HORIZ)
 
+        # FIXME: Adding a new toolbar to gedit is not really public API
         self._main_box = self.window.get_children()[0]
         self._main_box.pack_start(self._toolbar, False, True, 0)
         self._main_box.reorder_child(self._toolbar, 2)
@@ -245,21 +253,13 @@ class LaTeXWindowActivatable(GObject.Object, Gedit.WindowActivatable, PeasGtk.Co
          - hook them in the window UI
          - create a map from extensions to lists of ToolActions
         """
+        items_ui = ""
+        self._action_handlers = {}
 
-        # add a MenuToolButton with the tools menu to the toolbar afterwards
-        # FIXME: this is quite hacky
-        menu = Gtk.Menu()
-
-        # this is used for enable/disable actions by name
-        # None stands for every extension
+        # this is used for enable/disable actions by name (None = every extension)
         self._tool_action_extensions = {None: []}
-
         self._tool_action_group = Gtk.ActionGroup("LaTeXPluginToolActions")
 
-        items_ui = ""
-
-        self._action_handlers = {}
-
         i = 1                    # counting tool actions
         accel_counter = 1        # counting tool actions without custom accel
         for tool in self._tool_preferences.tools:
@@ -286,26 +286,15 @@ class LaTeXWindowActivatable(GObject.Object, Gedit.WindowActivatable, PeasGtk.Co
                 self._tool_action_group.add_action_with_accel(gtk_action, "<Ctrl><Alt>%s" % accel_counter)
                 accel_counter += 1
 
-            # add to MenuToolBar menu
-            # FIXME: GtkWarning: gtk_accel_label_set_accel_closure: assertion `gtk_accel_group_from_accel_closure (accel_closure) != NULL' failed
-            menu.add(gtk_action.create_menu_item())
-
             # add UI definition
             items_ui += """<menuitem action="%s" />""" % name
-
             i += 1
 
         tool_ui = self._tool_ui_template.substitute({"items": items_ui})
-
+        
         self._ui_manager.insert_action_group(self._tool_action_group, -1)
         self._tool_ui_id = self._ui_manager.add_ui_from_string(tool_ui)
-
-        # add a MenuToolButton with the tools menu to the toolbar
-        self._menu_tool_button = Gtk.MenuToolButton.new_from_stock(Gtk.STOCK_CONVERT)
-        self._menu_tool_button.set_menu(menu)
-        self._menu_tool_button.show_all()
-        self._toolbar.insert(self._menu_tool_button, -1)
-
+        
     def save_file(self):
         """
         Trigger the 'Save' action
@@ -324,9 +313,6 @@ class LaTeXWindowActivatable(GObject.Object, Gedit.WindowActivatable, PeasGtk.Co
             self._tool_action_group.remove_action(gtk_action)
         self._ui_manager.remove_action_group(self._tool_action_group)
 
-        # remove MenuToolButton
-        self._toolbar.remove(self._menu_tool_button)
-
         # re-init tool actions
         self._init_tool_actions()
 
diff --git a/latex/latex/actions.py b/latex/latex/actions.py
index 1e7f86a..4757181 100644
--- a/latex/latex/actions.py
+++ b/latex/latex/actions.py
@@ -433,6 +433,26 @@ class LaTeXListingAction(LaTeXIconAction):
         if source:
             context.active_editor.insert(source)
 
+class LaTeXBuildAction(LaTeXIconAction):
+    menu_tool_action = True
+
+    label = "Build"
+    accelerator = None
+    tooltip = "Build"
+    stock_id = Gtk.STOCK_CONVERT
+
+    def activate(self, context):
+        pass
+
+
+class LaTeXBuildMenuAction(LaTeXAction):
+    label = "Build"
+    accelerator = None
+    tooltip = "Build"
+    stock_id = None
+
+    def activate(self, context):
+        pass
 
 class LaTeXBuildImageAction(LaTeXIconAction):
     label = "Build Image"



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