Sun, 04 Oct 2020 16:24:23 +0200
Editor Outline Viewer: made the width step size configurable and optimized the context menu handling.
--- a/eric6/Preferences/ConfigurationPages/EditorGeneralPage.py Sun Oct 04 15:25:17 2020 +0200 +++ b/eric6/Preferences/ConfigurationPages/EditorGeneralPage.py Sun Oct 04 16:24:23 2020 +0200 @@ -59,6 +59,8 @@ Preferences.getEditor("ShowSourceOutline")) self.sourceOutlineWidthSpinBox.setValue( Preferences.getEditor("SourceOutlineWidth")) + self.sourceOutlineWidthStepSpinBox.setValue( + Preferences.getEditor("SourceOutlineStepSize")) virtualSpaceOptions = Preferences.getEditor("VirtualSpaceOptions") self.vsSelectionCheckBox.setChecked( @@ -100,6 +102,9 @@ Preferences.setEditor( "SourceOutlineWidth", self.sourceOutlineWidthSpinBox.value()) + Preferences.setEditor( + "SourceOutlineStepSize", + self.sourceOutlineWidthStepSpinBox.value()) virtualSpaceOptions = QsciScintillaBase.SCVS_NONE if self.vsSelectionCheckBox.isChecked():
--- a/eric6/Preferences/ConfigurationPages/EditorGeneralPage.ui Sun Oct 04 15:25:17 2020 +0200 +++ b/eric6/Preferences/ConfigurationPages/EditorGeneralPage.ui Sun Oct 04 16:24:23 2020 +0200 @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>559</width> - <height>664</height> + <width>550</width> + <height>700</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout_4"> @@ -286,15 +286,15 @@ <property name="checkable"> <bool>true</bool> </property> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> + <layout class="QGridLayout" name="gridLayout_3"> + <item row="0" column="0"> <widget class="QLabel" name="label_2"> <property name="text"> <string>Default Width:</string> </property> </widget> </item> - <item> + <item row="0" column="1"> <widget class="QSpinBox" name="sourceOutlineWidthSpinBox"> <property name="toolTip"> <string>Enter the default width of the source code outline view</string> @@ -313,19 +313,45 @@ </property> </widget> </item> - <item> + <item row="0" column="2"> <spacer name="horizontalSpacer"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> <property name="sizeHint" stdset="0"> <size> - <width>397</width> - <height>20</height> + <width>345</width> + <height>17</height> </size> </property> </spacer> </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Width Step Size:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QSpinBox" name="sourceOutlineWidthStepSpinBox"> + <property name="toolTip"> + <string>Enter the amount of pixels the width of the outline should be increased or decreased</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <property name="minimum"> + <number>10</number> + </property> + <property name="maximum"> + <number>100</number> + </property> + <property name="singleStep"> + <number>10</number> + </property> + </widget> + </item> </layout> </widget> </item> @@ -405,6 +431,7 @@ <tabstop>converttabsCheckBox</tabstop> <tabstop>sourceOutlineGroupBox</tabstop> <tabstop>sourceOutlineWidthSpinBox</tabstop> + <tabstop>sourceOutlineWidthStepSpinBox</tabstop> <tabstop>comment0CheckBox</tabstop> <tabstop>vsSelectionCheckBox</tabstop> <tabstop>vsUserCheckBox</tabstop>
--- a/eric6/Preferences/__init__.py Sun Oct 04 15:25:17 2020 +0200 +++ b/eric6/Preferences/__init__.py Sun Oct 04 16:24:23 2020 +0200 @@ -496,6 +496,7 @@ "ShowSourceOutline": True, "SourceOutlineWidth": 200, + "SourceOutlineStepSize": 50, # All (most) lexers "AllFoldCompact": True, @@ -2097,7 +2098,8 @@ "OnlineSyntaxCheckInterval", "OnlineChangeTraceInterval", "WrapLongLinesMode", "WrapVisualFlag", "WrapIndentMode", "WrapStartIndent", "CallTipsPosition", "VirtualSpaceOptions", - "PreviewRefreshWaitTimer", "SourceOutlineWidth"]: + "PreviewRefreshWaitTimer", "SourceOutlineWidth", + "SourceOutlineStepSize"]: return int(prefClass.settings.value( "Editor/" + key, prefClass.editorDefaults[key])) elif key in ["AdditionalOpenFilters", "AdditionalSaveFilters",
--- 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() #######################################################################