eric6/QScintilla/EditorOutline.py

changeset 7750
b16930e5baa9
parent 7749
285855999b4e
child 7923
91e843545d9a
--- a/eric6/QScintilla/EditorOutline.py	Sun Oct 04 15:25:17 2020 +0200
+++ b/eric6/QScintilla/EditorOutline.py	Sun Oct 04 16:24:23 2020 +0200
@@ -7,7 +7,7 @@
 Module implementing an outline widget for source code navigation of the editor.
 """
 
-from PyQt5.QtCore import pyqtSlot, Qt, QCoreApplication, QModelIndex
+from PyQt5.QtCore import pyqtSlot, Qt, QCoreApplication, QModelIndex, QPoint
 from PyQt5.QtWidgets import QTreeView, QAbstractItemView, QMenu, QApplication
 
 from UI.BrowserSortFilterProxyModel import BrowserSortFilterProxyModel
@@ -18,16 +18,14 @@
 
 from .EditorOutlineModel import EditorOutlineModel
 
+import Preferences
 
-# TODO: save latest width in Preferences
-# TODO: config entry for default width
+
 class EditorOutlineView(QTreeView):
     """
     Class implementing an outline widget for source code navigation of the
     editor.
     """
-    WidthIncrement = 50
-    
     def __init__(self, editor, populate=True, parent=None):
         """
         Constructor
@@ -103,6 +101,7 @@
             
             self.__model.clear()
     
+    @pyqtSlot()
     def __resizeColumns(self):
         """
         Private slot to resize the view when items get expanded or collapsed.
@@ -118,6 +117,7 @@
         """
         return self.__model.isPopulated()
     
+    @pyqtSlot()
     def repopulate(self):
         """
         Public slot to repopulate the model.
@@ -127,6 +127,7 @@
             self.__model.repopulate()
             self.__completeRepopulate()
     
+    @pyqtSlot()
     def __prepareRepopulate(self):
         """
         Private slot to prepare to repopulate the outline view.
@@ -144,6 +145,7 @@
                     self.model().item(childIndex).data(0))
             childIndex = self.indexBelow(childIndex)
     
+    @pyqtSlot()
     def __completeRepopulate(self):
         """
         Private slot to complete the repopulate of the outline view.
@@ -172,6 +174,7 @@
         """
         return language in EditorOutlineModel.SupportedLanguages
     
+    @pyqtSlot(QModelIndex)
     def __gotoItem(self, index):
         """
         Private slot to set the editor cursor.
@@ -252,10 +255,14 @@
             QCoreApplication.translate(
                 'EditorOutlineView', 'Increment Width'),
             self.__incWidth)
-        self.__menu.addAction(
+        self.__decWidthAct = self.__menu.addAction(
             QCoreApplication.translate(
                 'EditorOutlineView', 'Decrement Width'),
             self.__decWidth)
+        self.__menu.addAction(
+            QCoreApplication.translate(
+                'EditorOutlineView', 'Set Default Width'),
+            self.__defaultWidth)
         
         # create the attribute/import menu
         self.__gotoMenu = QMenu(
@@ -289,10 +296,14 @@
             QCoreApplication.translate(
                 'EditorOutlineView', 'Increment Width'),
             self.__incWidth)
-        self.__attributeMenu.addAction(
+        self.__attributeDecWidthAct = self.__attributeMenu.addAction(
             QCoreApplication.translate(
                 'EditorOutlineView', 'Decrement Width'),
             self.__decWidth)
+        self.__attributeMenu.addAction(
+            QCoreApplication.translate(
+                'EditorOutlineView', 'Set Default Width'),
+            self.__defaultWidth)
         
         # create the background menu
         self.__backMenu = QMenu(self)
@@ -318,11 +329,16 @@
             QCoreApplication.translate(
                 'EditorOutlineView', 'Increment Width'),
             self.__incWidth)
-        self.__backMenu.addAction(
+        self.__backDecWidthAct = self.__backMenu.addAction(
             QCoreApplication.translate(
                 'EditorOutlineView', 'Decrement Width'),
             self.__decWidth)
+        self.__backMenu.addAction(
+            QCoreApplication.translate(
+                'EditorOutlineView', 'Set Default Width'),
+            self.__defaultWidth)
     
+    @pyqtSlot(QPoint)
     def __contextMenuRequested(self, coord):
         """
         Private slot to show the context menu.
@@ -333,6 +349,11 @@
         index = self.indexAt(coord)
         coord = self.mapToGlobal(coord)
         
+        decWidthEnable = (
+            self.maximumWidth() !=
+            2 * Preferences.getEditor("SourceOutlineStepSize")
+        )
+        
         if index.isValid():
             self.setCurrentIndex(index)
             
@@ -340,12 +361,16 @@
             if isinstance(
                 itm, (BrowserClassAttributeItem, BrowserImportItem)
             ):
+                self.__attributeDecWidthAct.setEnabled(decWidthEnable)
                 self.__attributeMenu.popup(coord)
             else:
+                self.__decWidthAct.setEnabled(decWidthEnable)
                 self.__menu.popup(coord)
         else:
+            self.__backDecWidthAct.setEnabled(decWidthEnable)
             self.__backMenu.popup(coord)
     
+    @pyqtSlot()
     def __showGotoMenu(self):
         """
         Private slot to prepare the goto submenu of the attribute menu.
@@ -371,6 +396,7 @@
     ## Context menu handlers below
     #######################################################################
     
+    @pyqtSlot()
     def __gotoAttribute(self, act):
         """
         Private slot to handle the selection of the goto menu.
@@ -380,12 +406,14 @@
         lineno = act.data()
         self.__model.editor().gotoLine(lineno)
     
+    @pyqtSlot()
     def __goto(self):
         """
         Private slot to move the editor cursor to the line of the context item.
         """
         self.__gotoItem(self.currentIndex())
     
+    @pyqtSlot()
     def __copyToClipboard(self):
         """
         Private slot to copy the file name of the editor to the clipboard.
@@ -396,20 +424,34 @@
             cb = QApplication.clipboard()
             cb.setText(fn)
     
+    @pyqtSlot()
     def __incWidth(self):
         """
-        Private method to increment the width of the outline.
+        Private slot to increment the width of the outline.
         """
         self.setMaximumWidth(
-            self.maximumWidth() + EditorOutlineView.WidthIncrement)
+            self.maximumWidth() +
+            Preferences.getEditor("SourceOutlineStepSize")
+        )
         self.updateGeometry()
     
+    @pyqtSlot()
     def __decWidth(self):
         """
-        Private method to decrement the width of the outline.
+        Private slot to decrement the width of the outline.
         """
-        self.setMaximumWidth(
-            self.maximumWidth() - EditorOutlineView.WidthIncrement)
+        stepSize = Preferences.getEditor("SourceOutlineStepSize")
+        newWidth = self.maximumWidth() - stepSize
+        
+        self.setMaximumWidth(max(newWidth, 2 * stepSize))
+        self.updateGeometry()
+    
+    @pyqtSlot()
+    def __defaultWidth(self):
+        """
+        Private slot to set the outline to the default width.
+        """
+        self.setMaximumWidth(Preferences.getEditor("SourceOutlineWidth"))
         self.updateGeometry()
     
     #######################################################################

eric ide

mercurial