~mcfletch/eric/update-to-4.5.13

« back to all changes in this revision

Viewing changes to eric/QScintilla/SearchReplaceWidget.py

Tags: 4.5.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
2
 
3
 
# Copyright (c) 2008 - 2011 Detlev Offenbach <detlev@die-offenbachs.de>
 
3
# Copyright (c) 2008 - 2012 Detlev Offenbach <detlev@die-offenbachs.de>
4
4
#
5
5
 
6
6
"""
70
70
<tr><td><code>.</code></td><td>Matches any character</td></tr>
71
71
<tr><td><code>\(</code></td><td>This marks the start of a region for tagging a match.</td></tr>
72
72
<tr><td><code>\)</code></td><td>This marks the end of a tagged region.</td></tr>
73
 
<tr><td><code>\n</code></td>
 
73
<tr><td><code>\\n</code></td>
74
74
<td>Where <code>n</code> is 1 through 9 refers to the first through ninth tagged region
75
75
when replacing. For example, if the search string was <code>Fred\([1-9]\)XXX</code> and
76
76
the replace string was <code>Sam\1YYY</code>, when applied to <code>Fred2XXX</code> this
79
79
<td>This matches the start of a word using Scintilla's definitions of words.</td></tr>
80
80
<tr><td><code>\&gt;</code></td>
81
81
<td>This matches the end of a word using Scintilla's definition of words.</td></tr>
82
 
<tr><td><code>\x</code></td>
 
82
<tr><td><code>\\x</code></td>
83
83
<td>This allows you to use a character x that would otherwise have a special meaning. For
84
 
example, \[ would be interpreted as [ and not as the start of a character set.</td></tr>
 
84
example, \\[ would be interpreted as [ and not as the start of a character set.</td></tr>
85
85
<tr><td><code>[...]</code></td>
86
86
<td>This indicates a set of characters, for example, [abc] means any of the characters a,
87
87
b or c. You can also use ranges, for example [a-z] for any lower case character.</td></tr>
107
107
        self.ui.findNextButton.setIcon(UI.PixmapCache.getIcon("1rightarrow.png"))
108
108
        
109
109
        if replace:
110
 
            self.ui.replaceButton.setIcon(UI.PixmapCache.getIcon("editReplace.png"))
111
 
            self.ui.replaceAllButton.setIcon(UI.PixmapCache.getIcon("editReplaceAll.png"))
 
110
            self.ui.replaceButton.setIcon(
 
111
                UI.PixmapCache.getIcon("editReplace.png"))
 
112
            self.ui.replaceSearchButton.setIcon(
 
113
                UI.PixmapCache.getIcon("editReplaceSearch.png"))
 
114
            self.ui.replaceAllButton.setIcon(
 
115
                UI.PixmapCache.getIcon("editReplaceAll.png"))
112
116
        
113
117
        self.connect(self.ui.findtextCombo.lineEdit(), SIGNAL("returnPressed()"), 
114
118
                     self.__findByReturnPressed)
131
135
            self.ui.findPrevButton.setEnabled(False)
132
136
            if self.replace:
133
137
                self.ui.replaceButton.setEnabled(False)
 
138
                self.ui.replaceSearchButton.setEnabled(False)
134
139
                self.ui.replaceAllButton.setEnabled(False)
135
140
        else:
136
141
            self.ui.findNextButton.setEnabled(True)
137
142
            self.ui.findPrevButton.setEnabled(True)
138
143
            if self.replace:
139
144
                self.ui.replaceButton.setEnabled(False)
 
145
                self.ui.replaceSearchButton.setEnabled(False)
140
146
                self.ui.replaceAllButton.setEnabled(True)
141
147
 
142
148
    @pyqtSignature("")
169
175
        if ok:
170
176
            if self.replace:
171
177
                self.ui.replaceButton.setEnabled(True)
 
178
                self.ui.replaceSearchButton.setEnabled(True)
172
179
        else:
173
180
            KQMessageBox.information(self, self.windowTitle(),
174
181
                self.trUtf8("'%1' was not found.").arg(txt))
203
210
        if ok:
204
211
            if self.replace:
205
212
                self.ui.replaceButton.setEnabled(True)
 
213
                self.ui.replaceSearchButton.setEnabled(True)
206
214
        else:
207
215
            KQMessageBox.information(self, self.windowTitle(),
208
216
                self.trUtf8("'%1' was not found.").arg(txt))
271
279
                line = self.__selection[2]
272
280
                index = self.__selection[3]
273
281
            else:
274
 
                line = lineFrom
275
 
                index = indexFrom - 1
 
282
                if (lineFrom, indexFrom) == (-1, -1):
 
283
                    # no selection present
 
284
                    line = cline
 
285
                    index = cindex
 
286
                else:
 
287
                    line = lineFrom
 
288
                    index = indexFrom - 1
276
289
            if self.ui.selectionCheckBox.isChecked() and \
277
290
               line == self.__selection[0] and \
278
291
               index >= 0 and \
377
390
        self.ui.findtextCombo.setEditText(text)
378
391
        self.ui.findtextCombo.lineEdit().selectAll()
379
392
        self.ui.findtextCombo.setFocus()
 
393
        self.on_findtextCombo_editTextChanged(text)
380
394
        
381
395
        self.ui.caseCheckBox.setChecked(False)
382
396
        self.ui.wordCheckBox.setChecked(False)
420
434
        """
421
435
        Private slot to replace one occurrence of text.
422
436
        """
 
437
        self.__doReplace(False)
 
438
    
 
439
    @pyqtSignature("")
 
440
    def on_replaceSearchButton_clicked(self):
 
441
        """
 
442
        Private slot to replace one occurrence of text and search for the next one.
 
443
        """
 
444
        self.__doReplace(True)
 
445
    
 
446
    def __doReplace(self, searchNext):
 
447
        """
 
448
        Private method to replace one occurrence of text.
 
449
        
 
450
        @param searchNext flag indicating to search for the next occurrence (boolean).
 
451
        """
423
452
        self.__finding = True
424
453
        
425
454
        # Check enabled status due to dual purpose usage of this method
426
 
        if not self.ui.replaceButton.isEnabled():
 
455
        if not self.ui.replaceButton.isEnabled() and \
 
456
           not self.ui.replaceSearchButton.isEnabled():
427
457
            return
428
458
        
429
459
        ftxt = self.ui.findtextCombo.currentText()
438
468
        
439
469
        aw = self.viewmanager.activeWindow()
440
470
        aw.replace(rtxt)
441
 
        ok = self.__findNextPrev(ftxt, self.__findBackwards)
442
471
        
443
 
        if not ok:
 
472
        if searchNext:
 
473
            ok = self.__findNextPrev(ftxt, self.__findBackwards)
 
474
            if not ok:
 
475
                self.ui.replaceButton.setEnabled(False)
 
476
                self.ui.replaceSearchButton.setEnabled(False)
 
477
                KQMessageBox.information(self, self.windowTitle(),
 
478
                    self.trUtf8("'%1' was not found.").arg(ftxt))
 
479
        else:
444
480
            self.ui.replaceButton.setEnabled(False)
445
 
            KQMessageBox.information(self, self.windowTitle(),
446
 
                self.trUtf8("'%1' was not found.").arg(ftxt))
 
481
            self.ui.replaceSearchButton.setEnabled(False)
447
482
        
448
483
        self.__finding = False
449
 
        
 
484
    
450
485
    @pyqtSignature("")
451
486
    def on_replaceAllButton_clicked(self):
452
487
        """
510
545
        if wordWrap:
511
546
            self.ui.wrapCheckBox.setChecked(True)
512
547
        self.ui.replaceButton.setEnabled(False)
 
548
        self.ui.replaceSearchButton.setEnabled(False)
513
549
        
514
550
        if found:
515
551
            KQMessageBox.information(self, self.windowTitle(),
538
574
        self.ui.findtextCombo.setEditText(text)
539
575
        self.ui.findtextCombo.lineEdit().selectAll()
540
576
        self.ui.findtextCombo.setFocus()
 
577
        self.on_findtextCombo_editTextChanged(text)
541
578
        
542
579
        self.ui.replacetextCombo.clear()
543
580
        self.ui.replacetextCombo.addItems(self.replaceHistory)