Skip to content

Commit

Permalink
[FEATURE][processing][needs-docs] add find and replace functionality to
Browse files Browse the repository at this point in the history
Processing script editor (forward-port from 2.18 branch)
  • Loading branch information
alexbruy committed Dec 15, 2017
1 parent 5c28eca commit 5016c21
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 11 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -599,6 +599,7 @@
<file>themes/default/mActionRegularPolygon2Points.svg</file>
<file>themes/default/mActionCircle3Tangents.svg</file>
<file>themes/default/mActionAddGeoPackageLayer.svg</file>
<file>themes/default/mActionFindReplace.svg</file>
<file>icons/qgis_icon.svg</file>
<file>themes/default/mActionCircle2TangentsPoint.svg</file>
<file>themes/default/mActionRegularPolygonCenterPoint.svg</file>
Expand Down
64 changes: 53 additions & 11 deletions images/themes/default/mActionAddAllToOverview.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions images/themes/default/mActionFindReplace.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions python/plugins/processing/gui/ScriptEditorDialog.py
Expand Up @@ -64,6 +64,8 @@ def __init__(self, algType, alg):
Qt.WindowMaximizeButtonHint |
Qt.WindowCloseButtonHint)

self.searchWidget.setVisible(False)

settings = QgsSettings()
self.restoreState(settings.value("/Processing/stateScriptEditor", QByteArray()))
self.restoreGeometry(settings.value("/Processing/geometryScriptEditor", QByteArray()))
Expand All @@ -90,6 +92,8 @@ def __init__(self, algType, alg):
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(
Expand All @@ -106,10 +110,15 @@ def __init__(self, algType, alg):
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

Expand Down Expand Up @@ -287,3 +296,19 @@ def runAlgorithm(self):
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)
83 changes: 83 additions & 0 deletions python/plugins/processing/ui/DlgScriptEditor.ui
Expand Up @@ -18,6 +18,79 @@
<item row="0" column="0">
<widget class="ScriptEdit" name="editor"/>
</item>
<item row="1" column="0">
<widget class="QWidget" name="searchWidget" native="true">
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item row="0" column="0">
<widget class="QCheckBox" name="chkCaseSensitive">
<property name="text">
<string>Case sensitive</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="chkWholeWord">
<property name="text">
<string>Whole word</string>
</property>
</widget>
</item>
<item row="1" column="4" colspan="2">
<widget class="QPushButton" name="btnReplace">
<property name="text">
<string>Replace</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Find what:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Replace with:</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="leReplaceText"/>
</item>
<item row="0" column="4" colspan="2">
<widget class="QPushButton" name="btnFind">
<property name="text">
<string>Find</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLineEdit" name="leFindText"/>
</item>
<item row="0" column="1" rowspan="2">
<widget class="Line" name="line_8">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QToolBar" name="toolBar">
Expand Down Expand Up @@ -45,6 +118,8 @@
<addaction name="actionUndo"/>
<addaction name="actionRedo"/>
<addaction name="separator"/>
<addaction name="actionFindReplace"/>
<addaction name="separator"/>
<addaction name="actionIncreaseFontSize"/>
<addaction name="actionDecreaseFontSize"/>
</widget>
Expand Down Expand Up @@ -171,6 +246,14 @@
<string>Decrease font size</string>
</property>
</action>
<action name="actionFindReplace">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>FindReplace</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down

0 comments on commit 5016c21

Please sign in to comment.