Skip to content
Permalink
Browse files

[processing] added search and replace functionality to script editor

  • Loading branch information
volaya committed Dec 13, 2017
1 parent eacbdb9 commit 351dc15f6c529d0c33bf2f1dccc5a292005330f5
@@ -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)
@@ -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'))
@@ -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

@@ -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():
Binary file not shown.
@@ -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">
@@ -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">
@@ -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>

0 comments on commit 351dc15

Please sign in to comment.
You can’t perform that action at this time.