QScintilla/SearchReplaceWidget.py

branch
Py2 comp.
changeset 3058
0a02c433f52d
parent 3057
10516539f238
parent 3030
4a0a82ddd9d2
child 3060
5883ce99ee12
equal deleted inserted replaced
3057:10516539f238 3058:0a02c433f52d
52 self.findHistory = vm.getSRHistory('search') 52 self.findHistory = vm.getSRHistory('search')
53 if replace: 53 if replace:
54 from .Ui_ReplaceWidget import Ui_ReplaceWidget 54 from .Ui_ReplaceWidget import Ui_ReplaceWidget
55 self.replaceHistory = vm.getSRHistory('replace') 55 self.replaceHistory = vm.getSRHistory('replace')
56 self.ui = Ui_ReplaceWidget() 56 self.ui = Ui_ReplaceWidget()
57 whatsThis = self.trUtf8(r""" 57 whatsThis = self.trUtf8(
58 <b>Find and Replace</b> 58 r"""<b>Find and Replace</b>
59 <p>This dialog is used to find some text and replace it with another text. 59 <p>This dialog is used to find some text and replace it with another text.
60 By checking the various checkboxes, the search can be made more specific. 60 By checking the various checkboxes, the search can be made more specific.
61 The search string might be a regular expression. In a regular expression, 61 The search string might be a regular expression. In a regular expression,
62 special characters interpreted are:</p> 62 special characters interpreted are:</p>
63 """ 63 """
64 ) 64 )
65 else: 65 else:
66 from .Ui_SearchWidget import Ui_SearchWidget 66 from .Ui_SearchWidget import Ui_SearchWidget
67 self.ui = Ui_SearchWidget() 67 self.ui = Ui_SearchWidget()
68 whatsThis = self.trUtf8(r""" 68 whatsThis = self.trUtf8(
69 <b>Find</b> 69 r"""<b>Find</b>
70 <p>This dialog is used to find some text. By checking the various checkboxes, 70 <p>This dialog is used to find some text. By checking the various checkboxes,
71 the search can be made more specific. The search string might be a regular 71 the search can be made more specific. The search string might be a regular
72 expression. In a regular expression, special characters interpreted are:</p> 72 expression. In a regular expression, special characters interpreted are:</p>
73 """ 73 """
74 ) 74 )
75 self.ui.setupUi(self) 75 self.ui.setupUi(self)
76 if not replace: 76 if not replace:
77 self.ui.wrapCheckBox.setChecked(True) 77 self.ui.wrapCheckBox.setChecked(True)
78 78
79 whatsThis += self.trUtf8(r""" 79 whatsThis += self.trUtf8(
80 <table border="0"> 80 r"""<table border="0">
81 <tr><td><code>.</code></td><td>Matches any character</td></tr> 81 <tr><td><code>.</code></td><td>Matches any character</td></tr>
82 <tr><td><code>\(</code></td><td>This marks the start of a region for tagging a 82 <tr><td><code>\(</code></td><td>This marks the start of a region for tagging a
83 match.</td></tr> 83 match.</td></tr>
84 <tr><td><code>\)</code></td><td>This marks the end of a tagged region. 84 <tr><td><code>\)</code></td><td>This marks the end of a tagged region.
85 </td></tr> 85 </td></tr>
139 self.__findByReturnPressed) 139 self.__findByReturnPressed)
140 if replace: 140 if replace:
141 self.ui.replacetextCombo.lineEdit().returnPressed.connect( 141 self.ui.replacetextCombo.lineEdit().returnPressed.connect(
142 self.on_replaceButton_clicked) 142 self.on_replaceButton_clicked)
143 143
144 self.findNextAct = E5Action(self.trUtf8('Find Next'), 144 self.findNextAct = E5Action(
145 self.trUtf8('Find Next'), 145 self.trUtf8('Find Next'),
146 0, 0, self, 'search_widget_find_next') 146 self.trUtf8('Find Next'),
147 0, 0, self, 'search_widget_find_next')
147 self.findNextAct.triggered[()].connect(self.on_findNextButton_clicked) 148 self.findNextAct.triggered[()].connect(self.on_findNextButton_clicked)
148 self.findNextAct.setEnabled(False) 149 self.findNextAct.setEnabled(False)
149 self.ui.findtextCombo.addAction(self.findNextAct) 150 self.ui.findtextCombo.addAction(self.findNextAct)
150 151
151 self.findPrevAct = E5Action(self.trUtf8('Find Prev'), 152 self.findPrevAct = E5Action(
152 self.trUtf8('Find Prev'), 153 self.trUtf8('Find Prev'),
153 0, 0, self, 'search_widget_find_prev') 154 self.trUtf8('Find Prev'),
155 0, 0, self, 'search_widget_find_prev')
154 self.findPrevAct.triggered[()].connect(self.on_findPrevButton_clicked) 156 self.findPrevAct.triggered[()].connect(self.on_findPrevButton_clicked)
155 self.findPrevAct.setEnabled(False) 157 self.findPrevAct.setEnabled(False)
156 self.ui.findtextCombo.addAction(self.findPrevAct) 158 self.ui.findtextCombo.addAction(self.findPrevAct)
157 159
158 self.havefound = False 160 self.havefound = False
241 if ok: 243 if ok:
242 if self.replace: 244 if self.replace:
243 self.ui.replaceButton.setEnabled(True) 245 self.ui.replaceButton.setEnabled(True)
244 self.ui.replaceSearchButton.setEnabled(True) 246 self.ui.replaceSearchButton.setEnabled(True)
245 else: 247 else:
246 E5MessageBox.information(self, self.windowTitle(), 248 E5MessageBox.information(
249 self, self.windowTitle(),
247 self.trUtf8("'{0}' was not found.").format(txt)) 250 self.trUtf8("'{0}' was not found.").format(txt))
248 251
249 @pyqtSlot() 252 @pyqtSlot()
250 def on_findPrevButton_clicked(self): 253 def on_findPrevButton_clicked(self):
251 """ 254 """
277 if ok: 280 if ok:
278 if self.replace: 281 if self.replace:
279 self.ui.replaceButton.setEnabled(True) 282 self.ui.replaceButton.setEnabled(True)
280 self.ui.replaceSearchButton.setEnabled(True) 283 self.ui.replaceSearchButton.setEnabled(True)
281 else: 284 else:
282 E5MessageBox.information(self, self.windowTitle(), 285 E5MessageBox.information(
286 self, self.windowTitle(),
283 self.trUtf8("'{0}' was not found.").format(txt)) 287 self.trUtf8("'{0}' was not found.").format(txt))
284 288
285 def __findByReturnPressed(self): 289 def __findByReturnPressed(self):
286 """ 290 """
287 Private slot to handle the returnPressed signal of the findtext 291 Private slot to handle the returnPressed signal of the findtext
305 indexTo = -1 309 indexTo = -1
306 if self.ui.selectionCheckBox.isChecked(): 310 if self.ui.selectionCheckBox.isChecked():
307 lineFrom, indexFrom, lineTo, indexTo = self.__selectionBoundary() 311 lineFrom, indexFrom, lineTo, indexTo = self.__selectionBoundary()
308 312
309 aw.clearSearchIndicators() 313 aw.clearSearchIndicators()
310 ok = aw.findFirstTarget(txt, 314 ok = aw.findFirstTarget(
311 self.ui.regexpCheckBox.isChecked(), 315 txt,
312 self.ui.caseCheckBox.isChecked(), 316 self.ui.regexpCheckBox.isChecked(),
313 self.ui.wordCheckBox.isChecked(), 317 self.ui.caseCheckBox.isChecked(),
314 lineFrom, indexFrom, lineTo, indexTo) 318 self.ui.wordCheckBox.isChecked(),
319 lineFrom, indexFrom, lineTo, indexTo)
315 while ok: 320 while ok:
316 tgtPos, tgtLen = aw.getFoundTarget() 321 tgtPos, tgtLen = aw.getFoundTarget()
317 if tgtLen == 0: 322 if tgtLen == 0:
318 break 323 break
319 if len(self.__selections) > 1: 324 if len(self.__selections) > 1:
398 else: 403 else:
399 line = lineTo 404 line = lineTo
400 index = indexTo 405 index = indexTo
401 406
402 if ok: 407 if ok:
403 ok = aw.findFirst(txt, 408 ok = aw.findFirst(
409 txt,
404 self.ui.regexpCheckBox.isChecked(), 410 self.ui.regexpCheckBox.isChecked(),
405 self.ui.caseCheckBox.isChecked(), 411 self.ui.caseCheckBox.isChecked(),
406 self.ui.wordCheckBox.isChecked(), 412 self.ui.wordCheckBox.isChecked(),
407 self.ui.wrapCheckBox.isChecked(), 413 self.ui.wrapCheckBox.isChecked(),
408 not backwards, 414 not backwards,
448 else: 454 else:
449 line, index = self.__selections[ind][:2] 455 line, index = self.__selections[ind][:2]
450 break 456 break
451 else: 457 else:
452 break 458 break
453 ok = aw.findFirst(txt, 459 ok = aw.findFirst(
460 txt,
454 self.ui.regexpCheckBox.isChecked(), 461 self.ui.regexpCheckBox.isChecked(),
455 self.ui.caseCheckBox.isChecked(), 462 self.ui.caseCheckBox.isChecked(),
456 self.ui.wordCheckBox.isChecked(), 463 self.ui.wordCheckBox.isChecked(),
457 self.ui.wrapCheckBox.isChecked(), 464 self.ui.wrapCheckBox.isChecked(),
458 not backwards, 465 not backwards,
473 # try it again 480 # try it again
474 if backwards: 481 if backwards:
475 line, index = boundary[2:] 482 line, index = boundary[2:]
476 else: 483 else:
477 line, index = boundary[:2] 484 line, index = boundary[:2]
478 ok = aw.findFirst(txt, 485 ok = aw.findFirst(
486 txt,
479 self.ui.regexpCheckBox.isChecked(), 487 self.ui.regexpCheckBox.isChecked(),
480 self.ui.caseCheckBox.isChecked(), 488 self.ui.caseCheckBox.isChecked(),
481 self.ui.wordCheckBox.isChecked(), 489 self.ui.wordCheckBox.isChecked(),
482 self.ui.wrapCheckBox.isChecked(), 490 self.ui.wrapCheckBox.isChecked(),
483 not backwards, 491 not backwards,
493 ok = True 501 ok = True
494 break 502 break
495 else: 503 else:
496 ok = False 504 ok = False
497 elif (lineFrom == boundary[0] and \ 505 elif (lineFrom == boundary[0] and \
498 indexFrom >= boundary[1]) or \ 506 indexFrom >= boundary[1]) or \
499 (lineFrom > boundary[0] and \ 507 (lineFrom > boundary[0] and \
500 lineFrom < boundary[2]) or \ 508 lineFrom < boundary[2]) or \
501 (lineFrom == boundary[2] \ 509 (lineFrom == boundary[2] \
502 and indexFrom <= boundary[3]): 510 and indexFrom <= boundary[3]):
503 ok = True 511 ok = True
504 else: 512 else:
505 ok = False 513 ok = False
506 else: 514 else:
507 ok = False 515 ok = False
626 ok = self.__findNextPrev(ftxt, self.__findBackwards) 634 ok = self.__findNextPrev(ftxt, self.__findBackwards)
627 635
628 if not ok: 636 if not ok:
629 self.ui.replaceButton.setEnabled(False) 637 self.ui.replaceButton.setEnabled(False)
630 self.ui.replaceSearchButton.setEnabled(False) 638 self.ui.replaceSearchButton.setEnabled(False)
631 E5MessageBox.information(self, self.windowTitle(), 639 E5MessageBox.information(
632 self.trUtf8("'{0}' was not found.").format(ftxt)) 640 self, self.windowTitle(),
641 self.trUtf8("'{0}' was not found.").format(ftxt))
633 else: 642 else:
634 self.ui.replaceButton.setEnabled(False) 643 self.ui.replaceButton.setEnabled(False)
635 self.ui.replaceSearchButton.setEnabled(False) 644 self.ui.replaceSearchButton.setEnabled(False)
636 645
637 self.__finding = False 646 self.__finding = False
667 if self.ui.selectionCheckBox.isChecked(): 676 if self.ui.selectionCheckBox.isChecked():
668 line, index = boundary[:2] 677 line, index = boundary[:2]
669 else: 678 else:
670 line = 0 679 line = 0
671 index = 0 680 index = 0
672 ok = aw.findFirst(ftxt, 681 ok = aw.findFirst(
673 self.ui.regexpCheckBox.isChecked(), 682 ftxt,
674 self.ui.caseCheckBox.isChecked(), 683 self.ui.regexpCheckBox.isChecked(),
675 self.ui.wordCheckBox.isChecked(), 684 self.ui.caseCheckBox.isChecked(),
676 False, True, line, index) 685 self.ui.wordCheckBox.isChecked(),
686 False, True, line, index)
677 687
678 if ok and self.ui.selectionCheckBox.isChecked(): 688 if ok and self.ui.selectionCheckBox.isChecked():
679 lineFrom, indexFrom, lineTo, indexTo = aw.getSelection() 689 lineFrom, indexFrom, lineTo, indexTo = aw.getSelection()
680 if len(self.__selections) > 1: 690 if len(self.__selections) > 1:
681 for sel in self.__selections: 691 for sel in self.__selections:
705 else: 715 else:
706 line, index = self.__selections[ind][:2] 716 line, index = self.__selections[ind][:2]
707 break 717 break
708 else: 718 else:
709 break 719 break
710 ok = aw.findFirst(ftxt, 720 ok = aw.findFirst(
711 self.ui.regexpCheckBox.isChecked(), 721 ftxt,
712 self.ui.caseCheckBox.isChecked(), 722 self.ui.regexpCheckBox.isChecked(),
713 self.ui.wordCheckBox.isChecked(), 723 self.ui.caseCheckBox.isChecked(),
714 False, True, line, index) 724 self.ui.wordCheckBox.isChecked(),
725 False, True, line, index)
715 if ok: 726 if ok:
716 lineFrom, indexFrom, lineTo, indexTo = \ 727 lineFrom, indexFrom, lineTo, indexTo = \
717 aw.getSelection() 728 aw.getSelection()
718 if lineFrom < boundary[0] or \ 729 if lineFrom < boundary[0] or \
719 lineFrom > boundary[2] or \ 730 lineFrom > boundary[2] or \
744 self.ui.wrapCheckBox.setChecked(True) 755 self.ui.wrapCheckBox.setChecked(True)
745 self.ui.replaceButton.setEnabled(False) 756 self.ui.replaceButton.setEnabled(False)
746 self.ui.replaceSearchButton.setEnabled(False) 757 self.ui.replaceSearchButton.setEnabled(False)
747 758
748 if found: 759 if found:
749 E5MessageBox.information(self, self.windowTitle(), 760 E5MessageBox.information(
761 self, self.windowTitle(),
750 self.trUtf8("Replaced {0} occurrences.") 762 self.trUtf8("Replaced {0} occurrences.")
751 .format(replacements)) 763 .format(replacements))
752 else: 764 else:
753 E5MessageBox.information(self, self.windowTitle(), 765 E5MessageBox.information(
766 self, self.windowTitle(),
754 self.trUtf8("Nothing replaced because '{0}' was not found.") 767 self.trUtf8("Nothing replaced because '{0}' was not found.")
755 .format(ftxt)) 768 .format(ftxt))
756 769
757 aw.setCursorPosition(cline, cindex) 770 aw.setCursorPosition(cline, cindex)
758 aw.ensureCursorVisible() 771 aw.ensureCursorVisible()

eric ide

mercurial