Skip to content

Commit 492fb4a

Browse files
authored
Merge pull request #5860 from volaya/script_search
[FEATURE][processing][needs-docs]Script search
2 parents eacbdb9 + 05e6ec2 commit 492fb4a

File tree

3 files changed

+119
-7
lines changed

3 files changed

+119
-7
lines changed

python/plugins/processing/gui/ScriptEditorDialog.py

+25
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def __init__(self, algType, alg):
6262
super(ScriptEditorDialog, self).__init__(None)
6363
self.setupUi(self)
6464

65+
self.searchWidget.setVisible(False)
66+
6567
self.setWindowFlags(Qt.WindowMinimizeButtonHint |
6668
Qt.WindowMaximizeButtonHint |
6769
Qt.WindowCloseButtonHint)
@@ -76,6 +78,8 @@ def __init__(self, algType, alg):
7678
QIcon(os.path.join(pluginPath, 'images', 'edithelp.png')))
7779
self.btnRun.setIcon(
7880
QIcon(os.path.join(pluginPath, 'images', 'runalgorithm.png')))
81+
self.btnSearch.setIcon(
82+
QIcon(os.path.join(pluginPath, 'images', 'search.png')))
7983
self.btnCut.setIcon(QgsApplication.getThemeIcon('/mActionEditCut.svg'))
8084
self.btnCopy.setIcon(
8185
QgsApplication.getThemeIcon('/mActionEditCopy.svg'))
@@ -97,10 +101,15 @@ def __init__(self, algType, alg):
97101
self.btnPaste.clicked.connect(self.editor.paste)
98102
self.btnUndo.clicked.connect(self.editor.undo)
99103
self.btnRedo.clicked.connect(self.editor.redo)
104+
self.btnSearch.clicked.connect(self.toggleSearchBox)
100105
self.btnIncreaseFont.clicked.connect(self.editor.zoomIn)
101106
self.btnDecreaseFont.clicked.connect(self.editor.zoomOut)
107+
self.btnFind.clicked.connect(self.find)
108+
self.btnReplace.clicked.connect(self.replace)
102109
self.editor.textChanged.connect(lambda: self.setHasChanged(True))
103110

111+
self.lastSearch = None
112+
104113
self.alg = alg
105114
self.algType = algType
106115

@@ -138,6 +147,22 @@ def __init__(self, algType, alg):
138147

139148
self.editor.setLexerType(self.algType)
140149

150+
def find(self):
151+
txt = self.findBox.text()
152+
cs = self.chkCaseSensitive.isChecked()
153+
wo = self.chkWholeWord.isChecked()
154+
if self.lastSearch is None or txt != self.lastSearch:
155+
self.editor.findFirst(txt, False, cs, wo, True)
156+
else:
157+
self.editor.findNext()
158+
159+
def replace(self):
160+
txt = self.replaceBox.text()
161+
self.editor.replaceSelectedText(txt)
162+
163+
def toggleSearchBox(self):
164+
self.searchWidget.setVisible(not self.searchWidget.isVisible())
165+
141166
def showSnippets(self, evt):
142167
popupmenu = QMenu()
143168
for name, snippet in self.snippets.iteritems():
2.05 KB
Loading

python/plugins/processing/ui/DlgScriptEditor.ui

+94-7
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,13 @@
77
<x>0</x>
88
<y>0</y>
99
<width>720</width>
10-
<height>480</height>
10+
<height>518</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Script editor</string>
1515
</property>
1616
<layout class="QVBoxLayout" name="verticalLayout">
17-
<property name="spacing">
18-
<number>6</number>
19-
</property>
20-
<property name="margin">
21-
<number>9</number>
22-
</property>
2317
<item>
2418
<layout class="QHBoxLayout" name="horizontalLayout">
2519
<property name="spacing">
@@ -243,6 +237,20 @@
243237
</property>
244238
</widget>
245239
</item>
240+
<item>
241+
<widget class="QToolButton" name="btnSearch">
242+
<property name="text">
243+
<string>...</string>
244+
</property>
245+
</widget>
246+
</item>
247+
<item>
248+
<widget class="Line" name="line_7">
249+
<property name="orientation">
250+
<enum>Qt::Vertical</enum>
251+
</property>
252+
</widget>
253+
</item>
246254
<item>
247255
<widget class="QToolButton" name="btnIncreaseFont">
248256
<property name="text">
@@ -281,6 +289,85 @@
281289
<item>
282290
<widget class="ScriptEdit" name="editor"/>
283291
</item>
292+
<item>
293+
<widget class="QWidget" name="searchWidget" native="true">
294+
<layout class="QGridLayout" name="gridLayout">
295+
<property name="leftMargin">
296+
<number>0</number>
297+
</property>
298+
<property name="topMargin">
299+
<number>5</number>
300+
</property>
301+
<property name="rightMargin">
302+
<number>0</number>
303+
</property>
304+
<property name="bottomMargin">
305+
<number>5</number>
306+
</property>
307+
<item row="0" column="0">
308+
<widget class="QCheckBox" name="chkCaseSensitive">
309+
<property name="text">
310+
<string>Case sensitive</string>
311+
</property>
312+
</widget>
313+
</item>
314+
<item row="1" column="0">
315+
<widget class="QCheckBox" name="chkWholeWord">
316+
<property name="text">
317+
<string>Whole word</string>
318+
</property>
319+
</widget>
320+
</item>
321+
<item row="1" column="4" colspan="2">
322+
<widget class="QPushButton" name="btnReplace">
323+
<property name="sizePolicy">
324+
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
325+
<horstretch>0</horstretch>
326+
<verstretch>0</verstretch>
327+
</sizepolicy>
328+
</property>
329+
<property name="text">
330+
<string>Replace</string>
331+
</property>
332+
</widget>
333+
</item>
334+
<item row="0" column="2">
335+
<widget class="QLabel" name="label">
336+
<property name="text">
337+
<string>Find what:</string>
338+
</property>
339+
</widget>
340+
</item>
341+
<item row="1" column="2">
342+
<widget class="QLabel" name="label_2">
343+
<property name="text">
344+
<string>Replace with:</string>
345+
</property>
346+
</widget>
347+
</item>
348+
<item row="1" column="3">
349+
<widget class="QLineEdit" name="replaceBox"/>
350+
</item>
351+
<item row="0" column="4" colspan="2">
352+
<widget class="QPushButton" name="btnFind">
353+
<property name="text">
354+
<string>Find</string>
355+
</property>
356+
</widget>
357+
</item>
358+
<item row="0" column="3">
359+
<widget class="QLineEdit" name="findBox"/>
360+
</item>
361+
<item row="0" column="1" rowspan="2">
362+
<widget class="Line" name="line_8">
363+
<property name="orientation">
364+
<enum>Qt::Vertical</enum>
365+
</property>
366+
</widget>
367+
</item>
368+
</layout>
369+
</widget>
370+
</item>
284371
</layout>
285372
</widget>
286373
<customwidgets>

0 commit comments

Comments
 (0)