Skip to content

Commit

Permalink
[processing] added search and replace functionality to script editor
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Aug 23, 2017
1 parent 64f3e67 commit 870d1ad
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 7 deletions.
27 changes: 27 additions & 0 deletions python/plugins/processing/gui/ScriptEditorDialog.py
Expand Up @@ -62,6 +62,8 @@ def __init__(self, algType, alg):
super(ScriptEditorDialog, self).__init__(None)
self.setupUi(self)

self.searchWidget.setVisible(False)

self.setWindowFlags(Qt.WindowMinimizeButtonHint |
Qt.WindowMaximizeButtonHint |
Qt.WindowCloseButtonHint)
Expand All @@ -76,6 +78,8 @@ def __init__(self, algType, alg):
QIcon(os.path.join(pluginPath, 'images', 'edithelp.png')))
self.btnRun.setIcon(
QIcon(os.path.join(pluginPath, 'images', 'runalgorithm.png')))
self.btnSearch.setIcon(
QIcon(os.path.join(pluginPath, 'images', 'search.png')))
self.btnCut.setIcon(QgsApplication.getThemeIcon('/mActionEditCut.svg'))
self.btnCopy.setIcon(
QgsApplication.getThemeIcon('/mActionEditCopy.svg'))
Expand All @@ -97,10 +101,15 @@ def __init__(self, algType, alg):
self.btnPaste.clicked.connect(self.editor.paste)
self.btnUndo.clicked.connect(self.editor.undo)
self.btnRedo.clicked.connect(self.editor.redo)
self.btnSearch.clicked.connect(self.toggleSearchBox)
self.btnIncreaseFont.clicked.connect(self.editor.zoomIn)
self.btnDecreaseFont.clicked.connect(self.editor.zoomOut)
self.btnFind.clicked.connect(self.find)
self.btnReplace.clicked.connect(self.replace)
self.editor.textChanged.connect(lambda: self.setHasChanged(True))

self.lastSearch = None

self.alg = alg
self.algType = algType

Expand Down Expand Up @@ -138,6 +147,24 @@ def __init__(self, algType, alg):

self.editor.setLexerType(self.algType)


def find(self):
txt = self.findBox.text()
cs = self.chkCaseSensitive.isChecked()
wo = self.chkWholeWord.isChecked()
if self.lastSearch is None or txt != self.lastSearch:
self.editor.findFirst(txt, False, cs, wo, True)
else:
self.editor.findNext()

def replace(self):
txt = self.replaceBox.text()
self.editor.replaceSelectedText(txt)

def toggleSearchBox(self):
self.searchWidget.setVisible(not self.searchWidget.isVisible())


def showSnippets(self, evt):
popupmenu = QMenu()
for name, snippet in self.snippets.iteritems():
Expand Down
101 changes: 94 additions & 7 deletions python/plugins/processing/ui/DlgScriptEditor.ui
Expand Up @@ -7,19 +7,13 @@
<x>0</x>
<y>0</y>
<width>720</width>
<height>480</height>
<height>518</height>
</rect>
</property>
<property name="windowTitle">
<string>Script editor</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>6</number>
</property>
<property name="margin">
<number>9</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
Expand Down Expand Up @@ -243,6 +237,20 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnSearch">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_7">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnIncreaseFont">
<property name="text">
Expand Down Expand Up @@ -281,6 +289,85 @@
<item>
<widget class="ScriptEdit" name="editor"/>
</item>
<item>
<widget class="QWidget" name="searchWidget" native="true">
<layout class="QGridLayout" name="gridLayout">
<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="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<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="replaceBox"/>
</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="findBox"/>
</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>
<customwidgets>
Expand Down

0 comments on commit 870d1ad

Please sign in to comment.