Shortened the long editor context menu. eric7

Thu, 19 Aug 2021 18:37:26 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 19 Aug 2021 18:37:26 +0200
branch
eric7
changeset 8519
fd4722a8f782
parent 8518
6a3eadfc3fb6
child 8520
48e1237aaef7

Shortened the long editor context menu.

eric7/Plugins/ViewManagerPlugins/Listspace/Listspace.py file | annotate | diff | comparison | revisions
eric7/Plugins/ViewManagerPlugins/Tabview/Tabview.py file | annotate | diff | comparison | revisions
eric7/QScintilla/Editor.py file | annotate | diff | comparison | revisions
eric7/ViewManager/ViewManager.py file | annotate | diff | comparison | revisions
--- a/eric7/Plugins/ViewManagerPlugins/Listspace/Listspace.py	Thu Aug 19 18:36:06 2021 +0200
+++ b/eric7/Plugins/ViewManagerPlugins/Listspace/Listspace.py	Thu Aug 19 18:37:26 2021 +0200
@@ -280,6 +280,9 @@
             self.__contextMenuOpenRejections)
         self.__menu.addSeparator()
         self.__menu.addAction(
+            UI.PixmapCache.getIcon("printPreview"),
+            self.tr("Print Preview"), self.__contextMenuPrintPreviewFile)
+        self.__menu.addAction(
             UI.PixmapCache.getIcon("print"),
             self.tr('Print'), self.__contextMenuPrintFile)
         self.__menu.addSeparator()
@@ -851,7 +854,14 @@
         """
         if self.contextMenuEditor:
             self.printEditor(self.contextMenuEditor)
-        
+    
+    def __contextMenuPrintPreviewFile(self):
+        """
+        Private method to show a print preview of the selected editor.
+        """
+        if self.contextMenuEditor:
+            self.printPreviewEditor(self.contextMenuEditor)
+    
     def __contextMenuCopyPathToClipboard(self):
         """
         Private method to copy the file name of the selected editor to the
--- a/eric7/Plugins/ViewManagerPlugins/Tabview/Tabview.py	Thu Aug 19 18:36:06 2021 +0200
+++ b/eric7/Plugins/ViewManagerPlugins/Tabview/Tabview.py	Thu Aug 19 18:37:26 2021 +0200
@@ -279,6 +279,9 @@
             self.__contextMenuOpenRejections)
         self.__menu.addSeparator()
         self.__menu.addAction(
+            UI.PixmapCache.getIcon("printPreview"),
+            self.tr("Print Preview"), self.__contextMenuPrintPreviewFile)
+        self.__menu.addAction(
             UI.PixmapCache.getIcon("print"),
             self.tr('Print'), self.__contextMenuPrintFile)
         self.__menu.addSeparator()
@@ -670,6 +673,13 @@
         if self.contextMenuEditor:
             self.vm.printEditor(self.contextMenuEditor)
     
+    def __contextMenuPrintPreviewFile(self):
+        """
+        Private method to show a print preview of the selected tab.
+        """
+        if self.contextMenuEditor:
+            self.vm.printPreviewEditor(self.contextMenuEditor)
+    
     def __contextMenuCopyPathToClipboard(self):
         """
         Private method to copy the file name of the selected tab to the
--- a/eric7/QScintilla/Editor.py	Thu Aug 19 18:36:06 2021 +0200
+++ b/eric7/QScintilla/Editor.py	Thu Aug 19 18:37:26 2021 +0200
@@ -50,7 +50,6 @@
     "ReferenceItem", ["modulePath", "codeLine", "line", "column"])
 
 
-# TODO: Make 'long' context menu shorter
 class Editor(QsciScintillaCompat):
     """
     Class implementing the editor component of the eric IDE.
@@ -810,14 +809,12 @@
             self.__menus["Autocompletion"] = self.autocompletionMenu
         self.toolsMenu = self.__initContextMenuTools()
         self.__menus["Tools"] = self.toolsMenu
-        self.exportersMenu = self.__initContextMenuExporters()
-        self.__menus["Exporters"] = self.exportersMenu
         self.eolMenu = self.__initContextMenuEol()
         self.__menus["Eol"] = self.eolMenu
         self.encodingsMenu = self.__initContextMenuEncodings()
         self.__menus["Encodings"] = self.encodingsMenu
-        self.spellLanguagesMenu = self.__initContextMenuSpellLanguages()
-        self.__menus["SpellLanguages"] = self.spellLanguagesMenu
+        self.spellCheckMenu = self.__initContextMenuSpellCheck()
+        self.__menus["SpellCheck"] = self.spellCheckMenu
         
         self.menuActs["Undo"] = self.menu.addAction(
             UI.PixmapCache.getIcon("editUndo"),
@@ -839,9 +836,6 @@
             UI.PixmapCache.getIcon("editPaste"),
             self.tr('Paste'), self.paste)
         if not self.miniMenu:
-            self.menuActs["ExecuteSelection"] = self.menu.addAction(
-                self.tr("Execute Selection In Console"),
-                self.__executeSelection)
             self.menu.addSeparator()
             self.menu.addAction(
                 UI.PixmapCache.getIcon("editIndent"),
@@ -855,12 +849,6 @@
             self.menuActs["Uncomment"] = self.menu.addAction(
                 UI.PixmapCache.getIcon("editUncomment"),
                 self.tr('Uncomment'), self.uncommentLineOrSelection)
-            self.menuActs["StreamComment"] = self.menu.addAction(
-                self.tr('Stream Comment'),
-                self.streamCommentLineOrSelection)
-            self.menuActs["BoxComment"] = self.menu.addAction(
-                self.tr('Box Comment'),
-                self.boxCommentLineOrSelection)
             self.menu.addSeparator()
             self.menuActs["Docstring"] = self.menu.addAction(
                 self.tr("Generate Docstring"),
@@ -871,24 +859,13 @@
             self.menu.addAction(self.tr('Select all'), self.__selectAll)
             self.menu.addAction(
                 self.tr('Deselect all'), self.__deselectAll)
+            self.menuActs["ExecuteSelection"] = self.menu.addAction(
+                self.tr("Execute Selection In Console"),
+                self.__executeSelection)
         else:
             self.menuActs["ExecuteSelection"] = None
         self.menu.addSeparator()
-        self.menuActs["SpellCheck"] = self.menu.addAction(
-            UI.PixmapCache.getIcon("spellchecking"),
-            self.tr('Check spelling...'), self.checkSpelling)
-        self.menuActs["SpellCheckSelection"] = self.menu.addAction(
-            UI.PixmapCache.getIcon("spellchecking"),
-            self.tr('Check spelling of selection...'),
-            self.__checkSpellingSelection)
-        self.menuActs["SpellCheckRemove"] = self.menu.addAction(
-            self.tr("Remove from dictionary"),
-            self.__removeFromSpellingDictionary)
-        self.menuActs["SpellCheckLanguages"] = self.menu.addMenu(
-            self.spellLanguagesMenu)
-        self.menu.addSeparator()
-        self.menu.addAction(
-            self.tr('Shorten empty lines'), self.shortenEmptyLines)
+        self.menu.addMenu(self.spellCheckMenu)
         self.menu.addSeparator()
         self.menuActs["Languages"] = self.menu.addMenu(self.languagesMenu)
         self.menuActs["Encodings"] = self.menu.addMenu(self.encodingsMenu)
@@ -942,9 +919,6 @@
             self.tr('New Document View (with new split)'),
             self.__newViewNewSplit)
         self.menuActs["NewSplit"].setEnabled(self.vm.canSplit())
-        self.menu.addAction(
-            UI.PixmapCache.getIcon("close"),
-            self.tr('Close'), self.__contextClose)
         self.menu.addSeparator()
         self.reopenEncodingMenu = self.__initContextMenuReopenWithEncoding()
         self.menuActs["Reopen"] = self.menu.addMenu(self.reopenEncodingMenu)
@@ -957,21 +931,6 @@
         self.menu.addAction(
             UI.PixmapCache.getIcon("fileSaveCopy"),
             self.tr('Save Copy...'), self.__contextSaveCopy)
-        if not self.miniMenu:
-            self.menu.addMenu(self.exportersMenu)
-            self.menu.addSeparator()
-            self.menuActs["OpenRejections"] = self.menu.addAction(
-                self.tr("Open 'rejection' file"),
-                self.__contextOpenRejections)
-            self.menu.addSeparator()
-            self.menu.addAction(
-                UI.PixmapCache.getIcon("printPreview"),
-                self.tr("Print Preview"), self.printPreviewFile)
-            self.menu.addAction(
-                UI.PixmapCache.getIcon("print"),
-                self.tr('Print'), self.printFile)
-        else:
-            self.menuActs["OpenRejections"] = None
         
         self.menu.aboutToShow.connect(self.__showContextMenu)
         
@@ -986,7 +945,8 @@
         """
         Private method used to setup the Checks context sub menu.
         
-        @return reference to the generated menu (QMenu)
+        @return reference to the generated menu
+        @rtype QMenu
         """
         menu = QMenu(self.tr('Complete'))
         
@@ -1007,12 +967,13 @@
         menu.aboutToShow.connect(self.__showContextMenuAutocompletion)
         
         return menu
-
+    
     def __initContextMenuChecks(self):
         """
         Private method used to setup the Checks context sub menu.
         
-        @return reference to the generated menu (QMenu)
+        @return reference to the generated menu
+        @rtype QMenu
         """
         menu = QMenu(self.tr('Check'))
         menu.aboutToShow.connect(self.__showContextMenuChecks)
@@ -1022,7 +983,8 @@
         """
         Private method used to setup the Tools context sub menu.
         
-        @return reference to the generated menu (QMenu)
+        @return reference to the generated menu
+        @rtype QMenu
         """
         menu = QMenu(self.tr('Tools'))
         menu.aboutToShow.connect(self.__showContextMenuTools)
@@ -1032,7 +994,8 @@
         """
         Private method used to setup the Show context sub menu.
         
-        @return reference to the generated menu (QMenu)
+        @return reference to the generated menu
+        @rtype QMenu
         """
         menu = QMenu(self.tr('Show'))
         
@@ -1056,7 +1019,8 @@
         """
         Private method used to setup the diagrams context sub menu.
         
-        @return reference to the generated menu (QMenu)
+        @return reference to the generated menu
+        @rtype QMenu
         """
         menu = QMenu(self.tr('Diagrams'))
         
@@ -1082,7 +1046,8 @@
         """
         Private method used to setup the Languages context sub menu.
         
-        @return reference to the generated menu (QMenu)
+        @return reference to the generated menu
+        @rtype QMenu
         """
         menu = QMenu(self.tr("Languages"))
         
@@ -1129,7 +1094,8 @@
         """
         Private method used to setup the Encodings context sub menu.
         
-        @return reference to the generated menu (QMenu)
+        @return reference to the generated menu
+        @rtype QMenu
         """
         self.supportedEncodings = {}
         
@@ -1153,7 +1119,8 @@
         """
         Private method used to setup the Reopen With Encoding context sub menu.
         
-        @return reference to the generated menu (QMenu)
+        @return reference to the generated menu
+        @rtype QMenu
         """
         menu = QMenu(self.tr("Re-Open With Encoding"))
         menu.setIcon(UI.PixmapCache.getIcon("open"))
@@ -1170,7 +1137,8 @@
         """
         Private method to setup the eol context sub menu.
         
-        @return reference to the generated menu (QMenu)
+        @return reference to the generated menu
+        @rtype QMenu
         """
         self.supportedEols = {}
         
@@ -1204,6 +1172,36 @@
         
         return menu
     
+    def __initContextMenuSpellCheck(self):
+        """
+        Private method used to setup the spell checking context sub menu.
+        
+        @return reference to the generated menu
+        @rtype QMenu
+        """
+        menu = QMenu(self.tr("Spelling"))
+        menu.setIcon(UI.PixmapCache.getIcon("spellchecking"))
+        
+        self.spellLanguagesMenu = self.__initContextMenuSpellLanguages()
+        self.__menus["SpellLanguages"] = self.spellLanguagesMenu
+        
+        self.menuActs["SpellCheck"] = menu.addAction(
+            UI.PixmapCache.getIcon("spellchecking"),
+            self.tr('Check spelling...'), self.checkSpelling)
+        self.menuActs["SpellCheckSelection"] = menu.addAction(
+            UI.PixmapCache.getIcon("spellchecking"),
+            self.tr('Check spelling of selection...'),
+            self.__checkSpellingSelection)
+        self.menuActs["SpellCheckRemove"] = menu.addAction(
+            self.tr("Remove from dictionary"),
+            self.__removeFromSpellingDictionary)
+        self.menuActs["SpellCheckLanguages"] = menu.addMenu(
+            self.spellLanguagesMenu)
+        
+        menu.aboutToShow.connect(self.__showContextMenuSpellCheck)
+        
+        return menu
+    
     def __initContextMenuSpellLanguages(self):
         """
         Private method to setup the spell checking languages context sub menu.
@@ -1236,25 +1234,6 @@
         
         return menu
     
-    def __initContextMenuExporters(self):
-        """
-        Private method used to setup the Exporters context sub menu.
-        
-        @return reference to the generated menu (QMenu)
-        """
-        menu = QMenu(self.tr("Export as"))
-        
-        from . import Exporters
-        supportedExporters = Exporters.getSupportedFormats()
-        exporters = sorted(list(supportedExporters.keys()))
-        for exporter in exporters:
-            act = menu.addAction(supportedExporters[exporter])
-            act.setData(exporter)
-        
-        menu.triggered.connect(self.__exportMenuTriggered)
-        
-        return menu
-        
     def __initContextMenuMargins(self):
         """
         Private method used to setup the context menu for the margins.
@@ -1409,15 +1388,6 @@
         self.indicMarginMenu.aboutToShow.connect(
             lambda: self.__showContextMenuMargin(self.indicMarginMenu))
         
-    def __exportMenuTriggered(self, act):
-        """
-        Private method to handle the selection of an export format.
-        
-        @param act reference to the action that was triggered (QAction)
-        """
-        exporterFormat = act.data()
-        self.exportFile(exporterFormat)
-        
     def exportFile(self, exporterFormat):
         """
         Public method to export the file.
@@ -1714,6 +1684,21 @@
             self.eolChanged.emit(eol)
             self.inEolChanged = False
     
+    def __showContextMenuSpellCheck(self):
+        """
+        Private slot handling the aboutToShow signal of the spell check
+        context menu.
+        """
+        spellingAvailable = SpellChecker.isAvailable()
+        self.menuActs["SpellCheck"].setEnabled(spellingAvailable)
+        self.menuActs["SpellCheckSelection"].setEnabled(
+            spellingAvailable and self.hasSelectedText())
+        self.menuActs["SpellCheckRemove"].setEnabled(
+            spellingAvailable and self.spellingMenuPos >= 0)
+        self.menuActs["SpellCheckLanguages"].setEnabled(spellingAvailable)
+        
+        self.showMenu.emit("SpellCheck", self.spellCheckMenu, self)
+    
     def __showContextMenuSpellLanguages(self):
         """
         Private slot handling the aboutToShow signal of the spell check
@@ -5541,15 +5526,9 @@
                     self.lexer_.canBlockComment())
                 self.menuActs["Uncomment"].setEnabled(
                     self.lexer_.canBlockComment())
-                self.menuActs["StreamComment"].setEnabled(
-                    self.lexer_.canStreamComment())
-                self.menuActs["BoxComment"].setEnabled(
-                    self.lexer_.canBoxComment())
             else:
                 self.menuActs["Comment"].setEnabled(False)
                 self.menuActs["Uncomment"].setEnabled(False)
-                self.menuActs["StreamComment"].setEnabled(False)
-                self.menuActs["BoxComment"].setEnabled(False)
             
             cline = self.getCursorPosition()[0]
             line = self.text(cline)
@@ -5566,21 +5545,6 @@
             self.menuActs["codeInfo"].setEnabled(
                 self.vm.isEditorInfoSupported(self.getLanguage()))
         
-        spellingAvailable = SpellChecker.isAvailable()
-        self.menuActs["SpellCheck"].setEnabled(spellingAvailable)
-        self.menuActs["SpellCheckSelection"].setEnabled(
-            spellingAvailable and self.hasSelectedText())
-        self.menuActs["SpellCheckRemove"].setEnabled(
-            spellingAvailable and self.spellingMenuPos >= 0)
-        self.menuActs["SpellCheckLanguages"].setEnabled(spellingAvailable)
-        
-        if self.menuActs["OpenRejections"]:
-            if self.fileName:
-                rej = "{0}.rej".format(self.fileName)
-                self.menuActs["OpenRejections"].setEnabled(os.path.exists(rej))
-            else:
-                self.menuActs["OpenRejections"].setEnabled(False)
-        
         self.menuActs["MonospacedFont"].setEnabled(self.lexer_ is None)
         
         splitOrientation = self.vm.getSplitOrientation()
@@ -5832,15 +5796,6 @@
         """
         self.vm.closeEditor(self)
     
-    def __contextOpenRejections(self):
-        """
-        Private slot handling the open rejections file context menu entry.
-        """
-        if self.fileName:
-            rej = "{0}.rej".format(self.fileName)
-            if os.path.exists(rej):
-                self.vm.openSourceFile(rej)
-    
     def __newView(self):
         """
         Private slot to create a new view to an open document.
--- a/eric7/ViewManager/ViewManager.py	Thu Aug 19 18:36:06 2021 +0200
+++ b/eric7/ViewManager/ViewManager.py	Thu Aug 19 18:37:26 2021 +0200
@@ -5138,12 +5138,11 @@
         Public slot to print an editor.
         
         @param editor editor to be printed
+        @type Editor
         """
         if editor:
             editor.printFile()
-        else:
-            return
-        
+    
     def printCurrentEditor(self):
         """
         Public slot to print the contents of the current editor.
@@ -5151,6 +5150,16 @@
         aw = self.activeWindow()
         self.printEditor(aw)
         
+    def printPreviewEditor(self, editor):
+        """
+        Public slot to show a print preview of an editor.
+        
+        @param editor editor to be printed
+        @type Editor
+        """
+        if editor:
+            editor.printPreviewFile()
+    
     def printPreviewCurrentEditor(self):
         """
         Public slot to show a print preview of the current editor.

eric ide

mercurial