From 5016c21ed3046d049d614ccba6aabaa2a85802bb Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Fri, 15 Dec 2017 11:07:15 +0200 Subject: [PATCH] [FEATURE][processing][needs-docs] add find and replace functionality to Processing script editor (forward-port from 2.18 branch) --- images/images.qrc | 1 + .../default/mActionAddAllToOverview.svg | 64 +++++++++++--- images/themes/default/mActionFindReplace.svg | 55 ++++++++++++ .../processing/gui/ScriptEditorDialog.py | 25 ++++++ .../plugins/processing/ui/DlgScriptEditor.ui | 83 +++++++++++++++++++ 5 files changed, 217 insertions(+), 11 deletions(-) create mode 100644 images/themes/default/mActionFindReplace.svg diff --git a/images/images.qrc b/images/images.qrc index 6864c5d3cc8..91d4afc4eca 100644 --- a/images/images.qrc +++ b/images/images.qrc @@ -599,6 +599,7 @@ themes/default/mActionRegularPolygon2Points.svg themes/default/mActionCircle3Tangents.svg themes/default/mActionAddGeoPackageLayer.svg + themes/default/mActionFindReplace.svg icons/qgis_icon.svg themes/default/mActionCircle2TangentsPoint.svg themes/default/mActionRegularPolygonCenterPoint.svg diff --git a/images/themes/default/mActionAddAllToOverview.svg b/images/themes/default/mActionAddAllToOverview.svg index 20b2289b955..4916a84ded5 100644 --- a/images/themes/default/mActionAddAllToOverview.svg +++ b/images/themes/default/mActionAddAllToOverview.svg @@ -1,12 +1,54 @@ - - - - - - - - - - - + + + + + + image/svg+xml + + + + + + + diff --git a/images/themes/default/mActionFindReplace.svg b/images/themes/default/mActionFindReplace.svg new file mode 100644 index 00000000000..932a4dbcd40 --- /dev/null +++ b/images/themes/default/mActionFindReplace.svg @@ -0,0 +1,55 @@ + + + + + + image/svg+xml + + + + + + + + + diff --git a/python/plugins/processing/gui/ScriptEditorDialog.py b/python/plugins/processing/gui/ScriptEditorDialog.py index 0e0202ad63e..4adec901bf9 100644 --- a/python/plugins/processing/gui/ScriptEditorDialog.py +++ b/python/plugins/processing/gui/ScriptEditorDialog.py @@ -64,6 +64,8 @@ class ScriptEditorDialog(BASE, WIDGET): Qt.WindowMaximizeButtonHint | Qt.WindowCloseButtonHint) + self.searchWidget.setVisible(False) + settings = QgsSettings() self.restoreState(settings.value("/Processing/stateScriptEditor", QByteArray())) self.restoreGeometry(settings.value("/Processing/geometryScriptEditor", QByteArray())) @@ -90,6 +92,8 @@ class ScriptEditorDialog(BASE, WIDGET): QgsApplication.getThemeIcon('/mActionUndo.svg')) self.actionRedo.setIcon( QgsApplication.getThemeIcon('/mActionRedo.svg')) + self.actionFindReplace.setIcon( + QgsApplication.getThemeIcon('/mActionFindReplace.svg')) self.actionIncreaseFontSize.setIcon( QgsApplication.getThemeIcon('/mActionIncreaseFont.svg')) self.actionDecreaseFontSize.setIcon( @@ -106,10 +110,15 @@ class ScriptEditorDialog(BASE, WIDGET): self.actionPaste.triggered.connect(self.editor.paste) self.actionUndo.triggered.connect(self.editor.undo) self.actionRedo.triggered.connect(self.editor.redo) + self.actionFindReplace.toggled.connect(self.toggleSearchBox) self.actionIncreaseFontSize.triggered.connect(self.editor.zoomIn) self.actionDecreaseFontSize.triggered.connect(self.editor.zoomOut) self.editor.textChanged.connect(lambda: self.setHasChanged(True)) + self.btnFind.clicked.connect(self.find) + self.btnReplace.clicked.connect(self.replace) + self.lastSearch = None + self.alg = alg self.algType = algType @@ -287,3 +296,19 @@ class ScriptEditorDialog(BASE, WIDGET): except: pass canvas.setMapTool(prevMapTool) + + def find(self): + textToFind = self.leFindText.text() + caseSensitive = self.chkCaseSensitive.isChecked() + wholeWord = self.chkWholeWord.isChecked() + if self.lastSearch is None or textToFind != self.lastSearch: + self.editor.findFirst(textToFind, False, caseSensitive, wholeWord, True) + else: + self.editor.findNext() + + def replace(self): + textToReplace = self.leReplaceText.text() + self.editor.replaceSelectedText(textToReplace) + + def toggleSearchBox(self, checked): + self.searchWidget.setVisible(checked) diff --git a/python/plugins/processing/ui/DlgScriptEditor.ui b/python/plugins/processing/ui/DlgScriptEditor.ui index 828adfa315d..e3de69b7a8e 100644 --- a/python/plugins/processing/ui/DlgScriptEditor.ui +++ b/python/plugins/processing/ui/DlgScriptEditor.ui @@ -18,6 +18,79 @@ + + + + + 0 + + + 5 + + + 0 + + + 5 + + + + + Case sensitive + + + + + + + Whole word + + + + + + + Replace + + + + + + + Find what: + + + + + + + Replace with: + + + + + + + + + + Find + + + + + + + + + + Qt::Vertical + + + + + + @@ -45,6 +118,8 @@ + + @@ -171,6 +246,14 @@ Decrease font size + + + true + + + FindReplace + +