PluginColorString.py

changeset 25
cf10856f55de
parent 23
8a7d311ecf96
child 29
cd734d353339
--- a/PluginColorString.py	Sun Mar 08 18:02:41 2015 +0100
+++ b/PluginColorString.py	Thu Aug 27 19:40:28 2015 +0200
@@ -23,7 +23,7 @@
 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
 autoactivate = True
 deactivateable = True
-version = "2.1.1"
+version = "2.2.0"
 className = "ColorStringPlugin"
 packageName = "ColorString"
 shortDescription = "Insert color as string"
@@ -59,6 +59,7 @@
         self.__initMenu()
         
         self.__editors = {}
+        self.__mainActions = []
     
     def activate(self):
         """
@@ -71,6 +72,14 @@
         
         self.__ui.showMenu.connect(self.__populateMenu)
         
+        menu = self.__ui.getMenu("plugin_tools")
+        if menu is not None:
+            if not menu.isEmpty():
+                act = menu.addSeparator()
+                self.__mainActions.append(act)
+            act = menu.addMenu(self.__menu)
+            self.__mainActions.append(act)
+        
         e5App().getObject("ViewManager").editorOpenedEd.connect(
             self.__editorOpened)
         e5App().getObject("ViewManager").editorClosedEd.connect(
@@ -87,6 +96,12 @@
         """
         self.__ui.showMenu.disconnect(self.__populateMenu)
         
+        menu = self.__ui.getMenu("plugin_tools")
+        if menu is not None:
+            for act in self.__mainActions:
+                menu.removeAction(act)
+        self.__mainActions = []
+
         e5App().getObject("ViewManager").editorOpenedEd.disconnect(
             self.__editorOpened)
         e5App().getObject("ViewManager").editorClosedEd.disconnect(
@@ -137,12 +152,18 @@
         @param name name of the menu (string)
         @param menu reference to the menu to be populated (QMenu)
         """
-        if name != "Tools":
+        if name not in ["Tools", "PluginTools"]:
             return
         
-        if not menu.isEmpty():
-            menu.addSeparator()
-        menu.addMenu(self.__menu)
+        editor = e5App().getObject("ViewManager").activeWindow()
+        
+        if name == "Tools":
+            if not menu.isEmpty():
+                menu.addSeparator()
+            act = menu.addMenu(self.__menu)
+            act.setEnabled(editor is not None)
+        elif name == "PluginTools" and self.__mainActions:
+            self.__mainActions[-1].setEnabled(editor is not None)
     
     def __editorOpened(self, editor):
         """

eric ide

mercurial