PluginProjectWeb.py

changeset 6
a1600fa29542
parent 5
31bc1ef6f624
child 7
e6fbd4a7484d
diff -r 31bc1ef6f624 -r a1600fa29542 PluginProjectWeb.py
--- a/PluginProjectWeb.py	Thu Jan 01 17:14:39 2015 +0100
+++ b/PluginProjectWeb.py	Fri Jan 02 16:22:30 2015 +0100
@@ -115,7 +115,7 @@
         """
         Public method to deactivate this plugin.
         """
-        self.__e5project.unregisterProjectType("Django")
+        self.__e5project.unregisterProjectType("Web")
         
         self.__ui.showMenu.disconnect(self.__populateMenu)
         
@@ -125,7 +125,7 @@
             self.__editorClosed)
         
         for editor, acts in self.__editors.items():
-##            editor.showMenu.disconnect(self.__editorShowMenu)
+            editor.showMenu.disconnect(self.__editorShowMenu)
             menu = editor.getMenu("Tools")
             if menu is not None:
                 for act in acts:
@@ -192,7 +192,8 @@
         """
         editor = e5App().getObject("ViewManager").activeWindow()
         selectionAvailable = bool(editor and editor.selectedText() != "")
-        isHtml = editor.getLanguage().lower().startswith("html")
+        isHtml = bool(editor and
+                      editor.getLanguage().lower().startswith("html"))
         
         self.__html5ToCss3Act.setEnabled(
             selectionAvailable and BeautifulSoupAvailable and isHtml)
@@ -211,14 +212,10 @@
         if name != "Tools":
             return
         
-##        editor = e5App().getObject("ViewManager").activeWindow()
-##        
         if not menu.isEmpty():
             menu.addSeparator()
         
-        act = menu.addMenu(self.__menu)
-        # TODO: check this
-##        act.setEnabled(editor is not None and editor.selectedText() != '')
+        menu.addMenu(self.__menu)
     
     def __editorOpened(self, editor):
         """
@@ -234,7 +231,7 @@
                 self.__editors[editor].append(act)
             act = menu.addMenu(self.__menu)
             self.__editors[editor].append(act)
-##            editor.showMenu.connect(self.__editorShowMenu)
+            editor.showMenu.connect(self.__editorShowMenu)
     
     def __editorClosed(self, editor):
         """
@@ -247,19 +244,25 @@
         except KeyError:
             pass
     
-##    def __editorShowMenu(self, menuName, menu, editor):
-##        """
-##        Private slot called, when the the editor context menu or a submenu is
-##        about to be shown.
-##        
-##        @param menuName name of the menu to be shown (string)
-##        @param menu reference to the menu (QMenu)
-##        @param editor reference to the editor
-##        """
-##        if menuName == "Tools":
-##            # TODO: check this
-##            self.__menu.setEnabled(editor.selectedText() != '')
-##    
+    def __editorShowMenu(self, menuName, menu, editor):
+        """
+        Private slot called, when the the editor context menu or a submenu is
+        about to be shown.
+        
+        @param menuName name of the menu to be shown (string)
+        @param menu reference to the menu (QMenu)
+        @param editor reference to the editor
+        """
+        if menuName == "Tools":
+            if self.__menu.menuAction() not in menu.actions():
+                # Re-add our menu
+                self.__editors[editor] = []
+                if not menu.isEmpty():
+                    act = menu.addSeparator()
+                    self.__editors[editor].append(act)
+                act = menu.addMenu(self.__menu)
+                self.__editors[editor].append(act)
+    
     def __htm5ToCss3(self):
         """
         Private slot handling the HTML5 to CSS3 conversion.

eric ide

mercurial