From a601b909daabe84c1a3c31ba13456e48c3871e46 Mon Sep 17 00:00:00 2001
From: Sebastian Koslowski <koslowski@kit.edu>
Date: Thu, 2 Apr 2015 13:20:19 +0200
Subject: grc: move context def into Bars.py and add submenu

---
 grc/gui/Bars.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 50 insertions(+), 3 deletions(-)

(limited to 'grc/gui/Bars.py')

diff --git a/grc/gui/Bars.py b/grc/gui/Bars.py
index 5041a28f14..6ce614bc99 100644
--- a/grc/gui/Bars.py
+++ b/grc/gui/Bars.py
@@ -121,6 +121,30 @@ MENU_BAR_LIST = (
         Actions.ABOUT_WINDOW_DISPLAY,
     ]),
 )
+
+
+CONTEXT_MENU_LIST = [
+    Actions.BLOCK_CUT,
+    Actions.BLOCK_COPY,
+    Actions.BLOCK_PASTE,
+    Actions.ELEMENT_DELETE,
+    None,
+    Actions.BLOCK_ROTATE_CCW,
+    Actions.BLOCK_ROTATE_CW,
+    Actions.BLOCK_ENABLE,
+    Actions.BLOCK_DISABLE,
+    None,
+    (gtk.Action('More', '_More', None, None), [
+        Actions.BLOCK_CREATE_HIER,
+        Actions.OPEN_HIER,
+        None,
+        Actions.BUSSIFY_SOURCES,
+        Actions.BUSSIFY_SINKS,
+    ]),
+    Actions.BLOCK_PARAM_MODIFY
+]
+
+
 class Toolbar(gtk.Toolbar):
     """The gtk toolbar with actions added from the toolbar list."""
 
@@ -138,6 +162,7 @@ class Toolbar(gtk.Toolbar):
                 action.set_property('tooltip', action.get_property('tooltip'))
             else: self.add(gtk.SeparatorToolItem())
 
+
 class MenuBar(gtk.MenuBar):
     """The gtk menu bar with actions added from the menu bar list."""
 
@@ -157,7 +182,29 @@ class MenuBar(gtk.MenuBar):
             main_menu = gtk.Menu()
             main_menu_item.set_submenu(main_menu)
             for action in actions:
-                if action: #append a menu item
-                    main_menu.append(action.create_menu_item())
-                else: main_menu.append(gtk.SeparatorMenuItem())
+                main_menu.append(action.create_menu_item() if action else
+                                 gtk.SeparatorMenuItem())
             main_menu.show_all() #this show all is required for the separators to show
+
+
+class ContextMenu(gtk.Menu):
+    """The gtk menu with actions added from the context menu list."""
+
+    def __init__(self):
+        gtk.Menu.__init__(self)
+        for action in CONTEXT_MENU_LIST:
+            if isinstance(action, tuple):
+                action, sub_menu_action_list = action
+                item = action.create_menu_item()
+                self.append(item)
+                sub_menu = gtk.Menu()
+                item.set_submenu(sub_menu)
+                for action in sub_menu_action_list:
+                    sub_menu.append(action.create_menu_item() if action else
+                                    gtk.SeparatorMenuItem())
+                sub_menu.show_all()
+
+            else:
+                self.append(action.create_menu_item() if action else
+                            gtk.SeparatorMenuItem())
+        self.show_all()
-- 
cgit v1.2.3