Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added freshly cooked plugin files

  • Loading branch information...
commit 859c65084dd6d4fe65a57a29901f3bacfda67938 1 parent ccacad5
Intars Students authored May 24, 2010
9  toggleMenu.gedit-plugin
... ...
@@ -0,0 +1,9 @@
  1
+[Gedit Plugin]
  2
+Loader=python
  3
+Module=toggleMenu
  4
+IAge=2
  5
+Name=Toggle Menu
  6
+Description=Show or Hide Menu Bar
  7
+Authors=Intars Students <the.mobix@gmail.com>
  8
+Copyright=Copyright © 2010 Intars Students <the.mobix@gmail.com>
  9
+Website=http://www.gedit.org
91  toggleMenu.py
... ...
@@ -0,0 +1,91 @@
  1
+import gedit
  2
+import gtk
  3
+import os
  4
+
  5
+# Toggle menu item XML
  6
+ui_manager_xml = """
  7
+<ui>
  8
+  <menubar name="MenuBar">
  9
+    <menu name="ViewMenu" action="View">
  10
+      <placeholder name="ViewOps_2">
  11
+        <separator/>
  12
+        <menuitem name="toggleMenuBar" action="toggleMenuBar"/>
  13
+      </placeholder>
  14
+    </menu>
  15
+  </menubar>
  16
+</ui>
  17
+"""
  18
+
  19
+class toggleMenuInstance:
  20
+  def __init__(self, plugin, window):
  21
+    
  22
+    self._window = window
  23
+    self._plugin = plugin
  24
+    
  25
+    # Find location of Toggle Menu config file (if it's possible)
  26
+    try: self._config = os.path.expanduser('~')+"/.toggleMenu"
  27
+    except: self._config = ""
  28
+    
  29
+    # Get gEdit main menu bar object
  30
+    self._manager = self._window.get_ui_manager()
  31
+    self._menuBar = self._manager.get_widget("/ui/MenuBar")
  32
+    
  33
+    # Append custom menu item and key shortcut to toggle menu bar
  34
+    toggleMenuBar = (
  35
+      'toggleMenuBar',
  36
+      None,
  37
+      _("Toggle Menu"),
  38
+      '<Ctrl><Alt>M',
  39
+      _("Show or Hide Menu Bar"),
  40
+      self.toggle
  41
+    )
  42
+    self._action_group = gtk.ActionGroup("toggleMenuBar")
  43
+    self._action_group.add_actions([toggleMenuBar])
  44
+    self._manager.insert_action_group(self._action_group, -1)
  45
+    
  46
+    self._ui_id = self._manager.add_ui_from_string(ui_manager_xml)
  47
+    
  48
+    # Auto start with menu hidden?
  49
+    try:
  50
+      if os.path.exists(self._config):
  51
+        self._menuBar.hide()
  52
+        
  53
+    except: pass
  54
+  
  55
+  # Show menu, remove custom menu item & keyboard shortcut
  56
+  def deactivate(self):
  57
+    self._menuBar.show()
  58
+    self._manager.remove_ui(self._ui_id)
  59
+    self._manager.ensure_update()
  60
+    
  61
+    del self
  62
+  
  63
+  # Toggle menu bar and save current status in file (kinda)
  64
+  def toggle(self, action):
  65
+    if self._menuBar.flags() & gtk.VISIBLE:
  66
+      
  67
+      self._menuBar.hide()
  68
+      try: open(self._config, 'w').close()
  69
+      except: pass
  70
+    
  71
+    else:
  72
+      
  73
+      self._menuBar.show()
  74
+      try: os.unlink(self._config)
  75
+      except: pass
  76
+
  77
+# Basic gEdit plugin structure (nothing interesting)
  78
+class toggleMenuPlugin(gedit.Plugin):
  79
+  def __init__(self):
  80
+    gedit.Plugin.__init__(self)
  81
+    self._instances = {}
  82
+  
  83
+  def activate(self, window):
  84
+    self._instances[window] = toggleMenuInstance(self, window)
  85
+    
  86
+  def deactivate(self, window):
  87
+    self._instances[window].deactivate()
  88
+    del self._instances[window]
  89
+    
  90
+  def update_ui(self, window):
  91
+    pass

0 notes on commit 859c650

Please sign in to comment.
Something went wrong with that request. Please try again.