--- a/eric6/ViewManager/ViewManager.py Mon Feb 22 19:15:06 2021 +0100 +++ b/eric6/ViewManager/ViewManager.py Mon Feb 22 19:30:16 2021 +0100 @@ -14,10 +14,9 @@ pyqtSignal, pyqtSlot, Qt, QSignalMapper, QTimer, QFileInfo, QPoint, QCoreApplication ) -from PyQt5.QtGui import QColor, QKeySequence, QPalette, QPixmap +from PyQt5.QtGui import QKeySequence, QPixmap from PyQt5.QtWidgets import ( - QLineEdit, QToolBar, QWidgetAction, QDialog, QApplication, QMenu, - QComboBox, QWidget + QToolBar, QDialog, QApplication, QMenu, QWidget ) from PyQt5.Qsci import QsciScintilla @@ -38,55 +37,6 @@ from E5Gui.E5Action import E5Action, createActionGroup -class QuickSearchLineEdit(QLineEdit): - """ - Class implementing a line edit that reacts to newline and cancel commands. - - @signal escPressed() emitted after the cancel command was activated - @signal gotFocus() emitted when the focus is changed to this widget - """ - escPressed = pyqtSignal() - gotFocus = pyqtSignal() - - def editorCommand(self, cmd): - """ - Public method to perform an editor command. - - @param cmd the scintilla command to be performed - """ - if cmd == QsciScintilla.SCI_NEWLINE: - cb = self.parent() - hasEntry = cb.findText(self.text()) != -1 - if not hasEntry: - if cb.insertPolicy() == QComboBox.InsertAtTop: - cb.insertItem(0, self.text()) - else: - cb.addItem(self.text()) - self.returnPressed.emit() - elif cmd == QsciScintilla.SCI_CANCEL: - self.escPressed.emit() - - def keyPressEvent(self, evt): - """ - Protected method to handle the press of the ESC key. - - @param evt key event (QKeyPressEvent) - """ - if evt.key() == Qt.Key_Escape: - self.escPressed.emit() - else: - super(QuickSearchLineEdit, self).keyPressEvent(evt) # pass it on - - def focusInEvent(self, evt): - """ - Protected method to record the current editor widget. - - @param evt focus event (QFocusEvent) - """ - self.gotFocus.emit() - super(QuickSearchLineEdit, self).focusInEvent(evt) # pass it on - - class ViewManager(QWidget): """ Base class inherited by all specific view manager classes. @@ -3109,70 +3059,6 @@ self.__replaceWidget.replaceAll) self.searchActions.append(self.replaceAllAct) - self.quickSearchAct = E5Action( - QCoreApplication.translate('ViewManager', 'Quicksearch'), - UI.PixmapCache.getIcon("quickFindNext"), - QCoreApplication.translate('ViewManager', '&Quicksearch'), - QKeySequence(QCoreApplication.translate( - 'ViewManager', "Ctrl+Shift+K", "Search|Quicksearch")), - 0, - self.searchActGrp, 'vm_quicksearch') - self.quickSearchAct.setStatusTip(QCoreApplication.translate( - 'ViewManager', 'Perform a quicksearch')) - self.quickSearchAct.setWhatsThis(QCoreApplication.translate( - 'ViewManager', - """<b>Quicksearch</b>""" - """<p>This activates the quicksearch function of the IDE by""" - """ giving focus to the quicksearch entry field. If this field""" - """ is already active and contains text, it searches for the""" - """ next occurrence of this text.</p>""" - )) - self.quickSearchAct.triggered.connect(self.__quickSearch) - self.searchActions.append(self.quickSearchAct) - - self.quickSearchBackAct = E5Action( - QCoreApplication.translate( - 'ViewManager', 'Quicksearch backwards'), - UI.PixmapCache.getIcon("quickFindPrev"), - QCoreApplication.translate( - 'ViewManager', 'Quicksearch &backwards'), - QKeySequence(QCoreApplication.translate( - 'ViewManager', - "Ctrl+Shift+J", "Search|Quicksearch backwards")), - 0, self.searchActGrp, 'vm_quicksearch_backwards') - self.quickSearchBackAct.setStatusTip(QCoreApplication.translate( - 'ViewManager', - 'Perform a quicksearch backwards')) - self.quickSearchBackAct.setWhatsThis(QCoreApplication.translate( - 'ViewManager', - """<b>Quicksearch backwards</b>""" - """<p>This searches the previous occurrence of the quicksearch""" - """ text.</p>""" - )) - self.quickSearchBackAct.triggered.connect(self.__quickSearchPrev) - self.searchActions.append(self.quickSearchBackAct) - - self.quickSearchExtendAct = E5Action( - QCoreApplication.translate('ViewManager', 'Quicksearch extend'), - UI.PixmapCache.getIcon("quickFindExtend"), - QCoreApplication.translate('ViewManager', 'Quicksearch e&xtend'), - QKeySequence(QCoreApplication.translate( - 'ViewManager', "Ctrl+Shift+H", "Search|Quicksearch extend")), - 0, - self.searchActGrp, 'vm_quicksearch_extend') - self.quickSearchExtendAct.setStatusTip(QCoreApplication.translate( - 'ViewManager', - 'Extend the quicksearch to the end of the current word')) - self.quickSearchExtendAct.setWhatsThis(QCoreApplication.translate( - 'ViewManager', - """<b>Quicksearch extend</b>""" - """<p>This extends the quicksearch text to the end of the word""" - """ currently found.</p>""" - )) - self.quickSearchExtendAct.triggered.connect( - self.__quickSearchExtend) - self.searchActions.append(self.quickSearchExtendAct) - self.gotoAct = E5Action( QCoreApplication.translate('ViewManager', 'Goto Line'), UI.PixmapCache.getIcon("goto"), @@ -3377,8 +3263,6 @@ QCoreApplication.translate('ViewManager', '&Search'), self.ui) menu.setTearOffEnabled(True) - menu.addAction(self.quickSearchAct) - menu.addAction(self.quickSearchBackAct) menu.addAction(self.searchAct) menu.addAction(self.searchNextAct) menu.addAction(self.searchPrevAct) @@ -3396,74 +3280,15 @@ return menu - def initSearchToolbars(self, toolbarManager): - """ - Public method to create the Search toolbars. + def initSearchToolbar(self, toolbarManager): + """ + Public method to create the Search toolbar. @param toolbarManager reference to a toolbar manager object - (E5ToolBarManager) - @return a tuple of the generated toolbar (search, quicksearch) - """ - qtb = QToolBar(QCoreApplication.translate( - 'ViewManager', 'Quicksearch'), self.ui) - qtb.setIconSize(UI.Config.ToolBarIconSize) - qtb.setObjectName("QuicksearchToolbar") - qtb.setToolTip(QCoreApplication.translate( - 'ViewManager', 'Quicksearch')) - - self.quickFindLineEdit = QuickSearchLineEdit(self) - self.quickFindtextCombo = QComboBox(self) - self.quickFindtextCombo.setEditable(True) - self.quickFindtextCombo.setLineEdit(self.quickFindLineEdit) - self.quickFindtextCombo.setDuplicatesEnabled(False) - self.quickFindtextCombo.setInsertPolicy(QComboBox.InsertAtTop) - self.quickFindtextCombo.lastActive = None - self.quickFindtextCombo.lastCursorPos = None - self.quickFindtextCombo.lastSearchText = "" - self.quickFindtextCombo._editor = self.quickFindtextCombo.lineEdit() - # this allows us not to jump across searched text - # just because of autocompletion enabled - self.quickFindtextCombo.setMinimumWidth(250) - self.quickFindtextCombo.setSizeAdjustPolicy( - QComboBox.AdjustToMinimumContentsLengthWithIcon) - self.quickFindtextCombo.addItem("") - self.quickFindtextCombo.setWhatsThis(QCoreApplication.translate( - 'ViewManager', - """<p>Enter the searchtext directly into this field.""" - """ The search will be performed case insensitive.""" - """ The quicksearch function is activated upon activation""" - """ of the quicksearch next action (default key Ctrl+Shift+K),""" - """ if this entry field does not have the input focus.""" - """ Otherwise it searches for the next occurrence of the""" - """ text entered. The quicksearch backwards action""" - """ (default key Ctrl+Shift+J) searches backward.""" - """ Activating the 'quicksearch extend' action""" - """ (default key Ctrl+Shift+H) extends the current""" - """ searchtext to the end of the currently found word.""" - """ The quicksearch can be ended by pressing the Return key""" - """ while the quicksearch entry has the the input focus.</p>""" - )) - self.quickFindtextCombo._editor.returnPressed.connect( - self.__quickSearchEnter) - self.quickFindtextCombo._editor.textChanged.connect( - self.__quickSearchText) - self.quickFindtextCombo._editor.escPressed.connect( - self.__quickSearchEscape) - self.quickFindtextCombo._editor.gotFocus.connect( - self.__quickSearchFocusIn) - self.quickFindtextAction = QWidgetAction(self) - self.quickFindtextAction.setDefaultWidget(self.quickFindtextCombo) - self.quickFindtextAction.setObjectName("vm_quickfindtext_action") - self.quickFindtextAction.setText(QCoreApplication.translate( - 'ViewManager', "Quicksearch Textedit")) - qtb.addAction(self.quickFindtextAction) - qtb.addAction(self.quickSearchAct) - qtb.addAction(self.quickSearchBackAct) - qtb.addAction(self.quickSearchExtendAct) - self.quickFindtextCombo.setEnabled(False) - self.__quickSearchToolbar = qtb - self.__quickSearchToolbarVisibility = None - + @type E5ToolBarManager + @return generated toolbar + @rtype QToolBar + """ tb = QToolBar(QCoreApplication.translate('ViewManager', 'Search'), self.ui) tb.setIconSize(UI.Config.ToolBarIconSize) @@ -3486,7 +3311,6 @@ tb.setAllowedAreas( Qt.ToolBarAreas(Qt.TopToolBarArea | Qt.BottomToolBarArea)) - toolbarManager.addToolBar(qtb, qtb.windowTitle()) toolbarManager.addToolBar(tb, tb.windowTitle()) toolbarManager.addAction(self.gotoAct, tb.windowTitle()) toolbarManager.addAction(self.gotoBraceAct, tb.windowTitle()) @@ -3494,7 +3318,7 @@ toolbarManager.addAction(self.replaceAllAct, tb.windowTitle()) toolbarManager.addAction(self.replaceAndSearchAct, tb.windowTitle()) - return tb, qtb + return tb ################################################################## ## Initialize the view related actions, view menu and toolbar @@ -5506,15 +5330,9 @@ self.sbZoom.setEnabled(True) self.sbZoom.setValue(now.getZoom()) - if ( - not isinstance(now, (Editor, Shell)) and - now is not self.quickFindtextCombo - ): + if not isinstance(now, (Editor, Shell)): self.searchActGrp.setEnabled(False) - if now is self.quickFindtextCombo: - self.searchActGrp.setEnabled(True) - if not isinstance(now, (Editor, Shell)): self.__lastFocusWidget = old @@ -5741,223 +5559,6 @@ """ return self.srHistory[key] - def __quickSearch(self): - """ - Private slot to handle the incremental quick search. - """ - # first we have to check if quick search is active - # and try to activate it if not - if self.__quickSearchToolbarVisibility is None: - self.__quickSearchToolbarVisibility = ( - self.__quickSearchToolbar.isVisible() - ) - if not self.__quickSearchToolbar.isVisible(): - self.__quickSearchToolbar.show() - if not self.quickFindtextCombo.lineEdit().hasFocus(): - aw = self.activeWindow() - self.quickFindtextCombo.lastActive = aw - if aw: - self.quickFindtextCombo.lastCursorPos = aw.getCursorPosition() - else: - self.quickFindtextCombo.lastCursorPos = None - tff = self.textForFind(False) - if tff: - self.quickFindtextCombo.lineEdit().setText(tff) - self.quickFindtextCombo.lineEdit().setFocus() - self.quickFindtextCombo.lineEdit().selectAll() - self.__quickSearchSetEditColors(False) - else: - self.__quickSearchInEditor(True, False) - - def __quickSearchFocusIn(self): - """ - Private method to handle a focus in signal of the quicksearch lineedit. - """ - self.quickFindtextCombo.lastActive = self.activeWindow() - - def __quickSearchEnter(self): - """ - Private slot to handle the incremental quick search return pressed - (jump back to text). - """ - if self.quickFindtextCombo.lastActive: - self.quickFindtextCombo.lastActive.setFocus() - if self.__quickSearchToolbarVisibility is not None: - self.__quickSearchToolbar.setVisible( - self.__quickSearchToolbarVisibility) - self.__quickSearchToolbarVisibility = None - - def __quickSearchEscape(self): - """ - Private slot to handle the incremental quick search escape pressed - (jump back to text). - """ - if self.quickFindtextCombo.lastActive: - self.quickFindtextCombo.lastActive.setFocus() - aw = self.activeWindow() - if aw: - aw.hideFindIndicator() - if self.quickFindtextCombo.lastCursorPos: - aw.setCursorPosition( - self.quickFindtextCombo.lastCursorPos[0], - self.quickFindtextCombo.lastCursorPos[1]) - - if self.__quickSearchToolbarVisibility is not None: - self.__quickSearchToolbar.setVisible( - self.__quickSearchToolbarVisibility) - self.__quickSearchToolbarVisibility = None - - def __quickSearchText(self): - """ - Private slot to handle the textChanged signal of the quicksearch edit. - """ - self.__quickSearchInEditor(False, False) - - def __quickSearchPrev(self): - """ - Private slot to handle the quickFindPrev toolbutton action. - """ - # first we have to check if quick search is active - # and try to activate it if not - if self.__quickSearchToolbarVisibility is None: - self.__quickSearchToolbarVisibility = ( - self.__quickSearchToolbar.isVisible() - ) - if not self.__quickSearchToolbar.isVisible(): - self.__quickSearchToolbar.show() - if not self.quickFindtextCombo.lineEdit().hasFocus(): - aw = self.activeWindow() - self.quickFindtextCombo.lastActive = aw - if aw: - self.quickFindtextCombo.lastCursorPos = aw.getCursorPosition() - else: - self.quickFindtextCombo.lastCursorPos = None - tff = self.textForFind(False) - if tff: - self.quickFindtextCombo.lineEdit().setText(tff) - self.quickFindtextCombo.lineEdit().setFocus() - self.quickFindtextCombo.lineEdit().selectAll() - self.__quickSearchSetEditColors(False) - else: - self.__quickSearchInEditor(True, True) - - def __quickSearchMarkOccurrences(self, txt): - """ - Private method to mark all occurrences of the search text. - - @param txt text to search for (string) - """ - aw = self.activeWindow() - - lineFrom = 0 - indexFrom = 0 - lineTo = -1 - indexTo = -1 - - aw.clearSearchIndicators() - ok = aw.findFirstTarget(txt, False, False, False, - lineFrom, indexFrom, lineTo, indexTo) - while ok: - tgtPos, tgtLen = aw.getFoundTarget() - aw.setSearchIndicator(tgtPos, tgtLen) - ok = aw.findNextTarget() - - def __quickSearchInEditor(self, again, back): - """ - Private slot to perform a quick search. - - @param again flag indicating a repeat of the last search (boolean) - @param back flag indicating a backwards search operation (boolean) - """ - aw = self.activeWindow() - if not aw: - return - - aw.hideFindIndicator() - - text = self.quickFindtextCombo.lineEdit().text() - if not text and again: - text = self.quickFindtextCombo.lastSearchText - if not text: - if Preferences.getEditor("QuickSearchMarkersEnabled"): - aw.clearSearchIndicators() - return - else: - self.quickFindtextCombo.lastSearchText = text - - if Preferences.getEditor("QuickSearchMarkersEnabled"): - self.__quickSearchMarkOccurrences(text) - - lineFrom, indexFrom, lineTo, indexTo = aw.getSelection() - cline, cindex = aw.getCursorPosition() - if again: - if back: - if indexFrom != 0: - index = indexFrom - 1 - line = lineFrom - elif lineFrom == 0: - return - else: - line = lineFrom - 1 - index = aw.lineLength(line) - ok = aw.findFirst(text, False, False, False, True, False, - line, index) - else: - ok = aw.findFirst(text, False, False, False, True, not back, - cline, cindex) - else: - ok = aw.findFirst(text, False, False, False, True, not back, - lineFrom, indexFrom) - if ok: - sline, sindex, eline, eindex = aw.getSelection() - aw.showFindIndicator(sline, sindex, eline, eindex) - self.__quickSearchSetEditColors(not ok) - - def __quickSearchSetEditColors(self, error): - """ - Private method to set the quick search edit colors. - - @param error flag indicating an error (boolean) - """ - if error: - palette = self.quickFindtextCombo.lineEdit().palette() - palette.setColor(QPalette.Base, QColor("red")) - palette.setColor(QPalette.Text, QColor("white")) - self.quickFindtextCombo.lineEdit().setPalette(palette) - else: - palette = self.quickFindtextCombo.lineEdit().palette() - palette.setColor( - QPalette.Base, - self.quickFindtextCombo.palette().color(QPalette.Base)) - palette.setColor( - QPalette.Text, - self.quickFindtextCombo.palette().color(QPalette.Text)) - self.quickFindtextCombo.lineEdit().setPalette(palette) - - def __quickSearchExtend(self): - """ - Private method to handle the quicksearch extend action. - """ - aw = self.activeWindow() - if aw is None: - return - - txt = self.quickFindtextCombo.lineEdit().text() - if not txt: - return - - line, index = aw.getCursorPosition() - text = aw.text(line) - - rx = re.compile(r'[^\w_]') - match = rx.search(text, index) - if match: - end = match.start() - if end > index: - ext = text[index:end] - txt += ext - self.quickFindtextCombo.lineEdit().setText(txt) - def showSearchWidget(self): """ Public method to show the search widget. @@ -6724,7 +6325,6 @@ self.printPreviewAct.setEnabled(False) self.editActGrp.setEnabled(False) self.searchActGrp.setEnabled(False) - self.quickFindtextCombo.setEnabled(False) self.viewActGrp.setEnabled(False) self.viewFoldActGrp.setEnabled(False) self.unhighlightAct.setEnabled(False) @@ -6771,7 +6371,6 @@ self.printPreviewAct.setEnabled(True) self.editActGrp.setEnabled(True) self.searchActGrp.setEnabled(True) - self.quickFindtextCombo.setEnabled(True) self.viewActGrp.setEnabled(True) self.viewFoldActGrp.setEnabled(True) self.unhighlightAct.setEnabled(True) @@ -7061,8 +6660,6 @@ focusWidget = QApplication.focusWidget() if focusWidget == e5App().getObject("Shell"): e5App().getObject("Shell").editorCommand(cmd) - elif focusWidget == self.quickFindtextCombo: - self.quickFindtextCombo._editor.editorCommand(cmd) else: aw = self.activeWindow() if aw: @@ -7074,10 +6671,7 @@ cursor is not at the end of the line. """ focusWidget = QApplication.focusWidget() - if ( - focusWidget == e5App().getObject("Shell") or - focusWidget == self.quickFindtextCombo - ): + if focusWidget == e5App().getObject("Shell"): return else: aw = self.activeWindow()