UI/FindFileDialog.py

changeset 945
8cd4d08fa9f6
parent 894
eab7b8d39807
child 1112
8a7d1b9d18db
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
18 18
19 from .Ui_FindFileDialog import Ui_FindFileDialog 19 from .Ui_FindFileDialog import Ui_FindFileDialog
20 20
21 import Utilities 21 import Utilities
22 import Preferences 22 import Preferences
23
23 24
24 class FindFileDialog(QDialog, Ui_FindFileDialog): 25 class FindFileDialog(QDialog, Ui_FindFileDialog):
25 """ 26 """
26 Class implementing a dialog to search for text in files. 27 Class implementing a dialog to search for text in files.
27 28
34 @signal designerFile(str) emitted to open a Qt-Designer file 35 @signal designerFile(str) emitted to open a Qt-Designer file
35 """ 36 """
36 sourceFile = pyqtSignal(str, int, str, int, int) 37 sourceFile = pyqtSignal(str, int, str, int, int)
37 designerFile = pyqtSignal(str) 38 designerFile = pyqtSignal(str)
38 39
39 lineRole = Qt.UserRole + 1 40 lineRole = Qt.UserRole + 1
40 startRole = Qt.UserRole + 2 41 startRole = Qt.UserRole + 2
41 endRole = Qt.UserRole + 3 42 endRole = Qt.UserRole + 3
42 replaceRole = Qt.UserRole + 4 43 replaceRole = Qt.UserRole + 4
43 md5Role = Qt.UserRole + 5 44 md5Role = Qt.UserRole + 5
44 45
45 def __init__(self, project, replaceMode = False, parent=None): 46 def __init__(self, project, replaceMode=False, parent=None):
46 """ 47 """
47 Constructor 48 Constructor
48 49
49 @param project reference to the project object 50 @param project reference to the project object
50 @param parent parent widget of this dialog (QWidget) 51 @param parent parent widget of this dialog (QWidget)
54 self.setWindowFlags(Qt.WindowFlags(Qt.Window)) 55 self.setWindowFlags(Qt.WindowFlags(Qt.Window))
55 56
56 self.__replaceMode = replaceMode 57 self.__replaceMode = replaceMode
57 58
58 self.stopButton = \ 59 self.stopButton = \
59 self.buttonBox.addButton(self.trUtf8("Stop"), 60 self.buttonBox.addButton(self.trUtf8("Stop"),
60 QDialogButtonBox.ActionRole) 61 QDialogButtonBox.ActionRole)
61 self.stopButton.setEnabled(False) 62 self.stopButton.setEnabled(False)
62 63
63 self.findButton = \ 64 self.findButton = \
64 self.buttonBox.addButton(self.trUtf8("Find"), 65 self.buttonBox.addButton(self.trUtf8("Find"),
65 QDialogButtonBox.ActionRole) 66 QDialogButtonBox.ActionRole)
66 self.findButton.setEnabled(False) 67 self.findButton.setEnabled(False)
67 self.findButton.setDefault(True) 68 self.findButton.setDefault(True)
68 69
69 if self.__replaceMode: 70 if self.__replaceMode:
140 self.__lastFileItem.setFirstColumnSpanned(True) 141 self.__lastFileItem.setFirstColumnSpanned(True)
141 self.__lastFileItem.setExpanded(True) 142 self.__lastFileItem.setExpanded(True)
142 if self.__replaceMode: 143 if self.__replaceMode:
143 self.__lastFileItem.setFlags(self.__lastFileItem.flags() | \ 144 self.__lastFileItem.setFlags(self.__lastFileItem.flags() | \
144 Qt.ItemFlags(Qt.ItemIsUserCheckable | Qt.ItemIsTristate)) 145 Qt.ItemFlags(Qt.ItemIsUserCheckable | Qt.ItemIsTristate))
145 # Qt bug: 146 # Qt bug:
146 # item is not user checkable if setFirstColumnSpanned 147 # item is not user checkable if setFirstColumnSpanned
147 # is True (< 4.5.0) 148 # is True (< 4.5.0)
148 self.__lastFileItem.setData(0, self.md5Role, md5) 149 self.__lastFileItem.setData(0, self.md5Role, md5)
149 150
150 itm = QTreeWidgetItem(self.__lastFileItem, 151 itm = QTreeWidgetItem(self.__lastFileItem,
151 [' {0:5d} '.format(line), text]) 152 [' {0:5d} '.format(line), text])
152 itm.setTextAlignment(0, Qt.AlignRight) 153 itm.setTextAlignment(0, Qt.AlignRight)
153 itm.setData(0, self.lineRole, line) 154 itm.setData(0, self.lineRole, line)
154 itm.setData(0, self.startRole, start) 155 itm.setData(0, self.startRole, start)
155 itm.setData(0, self.endRole, end) 156 itm.setData(0, self.endRole, end)
157 if self.__replaceMode: 158 if self.__replaceMode:
158 itm.setFlags(itm.flags() | Qt.ItemFlags(Qt.ItemIsUserCheckable)) 159 itm.setFlags(itm.flags() | Qt.ItemFlags(Qt.ItemIsUserCheckable))
159 itm.setCheckState(0, Qt.Checked) 160 itm.setCheckState(0, Qt.Checked)
160 self.replaceButton.setEnabled(True) 161 self.replaceButton.setEnabled(True)
161 162
162 def show(self, txt = ""): 163 def show(self, txt=""):
163 """ 164 """
164 Overwritten method to enable/disable the project button. 165 Overwritten method to enable/disable the project button.
165 166
166 @param txt text to be shown in the searchtext combo (string) 167 @param txt text to be shown in the searchtext combo (string)
167 """ 168 """
332 if self.resourcesCheckBox.isChecked(): 333 if self.resourcesCheckBox.isChecked():
333 filters.append(self.filterResources) 334 filters.append(self.filterResources)
334 filterString = "|".join(filters) 335 filterString = "|".join(filters)
335 filterRe = re.compile(filterString) 336 filterRe = re.compile(filterString)
336 files = self.__getFileList( 337 files = self.__getFileList(
337 os.path.abspath(self.dirCombo.currentText()), 338 os.path.abspath(self.dirCombo.currentText()),
338 filterRe) 339 filterRe)
339 elif self.openFilesButton.isChecked(): 340 elif self.openFilesButton.isChecked():
340 files = e5App().getObject("ViewManager").getOpenFilenames() 341 files = e5App().getObject("ViewManager").getOpenFilenames()
341 342
342 self.findList.clear() 343 self.findList.clear()
343 QApplication.processEvents() 344 QApplication.processEvents()
344 QApplication.processEvents() 345 QApplication.processEvents()
345 self.findProgress.setMaximum(len(files)) 346 self.findProgress.setMaximum(len(files))
346 347
347 # retrieve the values 348 # retrieve the values
348 reg = self.regexpCheckBox.isChecked() 349 reg = self.regexpCheckBox.isChecked()
349 wo = self.wordCheckBox.isChecked() 350 wo = self.wordCheckBox.isChecked()
350 cs = self.caseCheckBox.isChecked() 351 cs = self.caseCheckBox.isChecked()
351 ct = self.findtextCombo.currentText() 352 ct = self.findtextCombo.currentText()
352 if reg: 353 if reg:
353 txt = ct 354 txt = ct
367 """<p>Error: {0}</p>""").format(str(why))) 368 """<p>Error: {0}</p>""").format(str(why)))
368 self.stopButton.setEnabled(False) 369 self.stopButton.setEnabled(False)
369 self.findButton.setEnabled(True) 370 self.findButton.setEnabled(True)
370 self.findButton.setDefault(True) 371 self.findButton.setDefault(True)
371 return 372 return
372
373
374 # reset the findtextCombo 373 # reset the findtextCombo
375 if ct in self.searchHistory: 374 if ct in self.searchHistory:
376 self.searchHistory.remove(ct) 375 self.searchHistory.remove(ct)
377 self.searchHistory.insert(0, ct) 376 self.searchHistory.insert(0, ct)
378 self.findtextCombo.clear() 377 self.findtextCombo.clear()
379 self.findtextCombo.addItems(self.searchHistory) 378 self.findtextCombo.addItems(self.searchHistory)
380 Preferences.Prefs.settings.setValue( 379 Preferences.Prefs.settings.setValue(
381 "FindFileDialog/SearchHistory", 380 "FindFileDialog/SearchHistory",
382 self.searchHistory[:30]) 381 self.searchHistory[:30])
383 382
384 if self.__replaceMode: 383 if self.__replaceMode:
385 replTxt = self.replacetextCombo.currentText() 384 replTxt = self.replacetextCombo.currentText()
386 if replTxt in self.replaceHistory: 385 if replTxt in self.replaceHistory:
387 self.replaceHistory.remove(replTxt) 386 self.replaceHistory.remove(replTxt)
388 self.replaceHistory.insert(0, replTxt) 387 self.replaceHistory.insert(0, replTxt)
389 self.replacetextCombo.clear() 388 self.replacetextCombo.clear()
390 self.replacetextCombo.addItems(self.replaceHistory) 389 self.replacetextCombo.addItems(self.replaceHistory)
391 Preferences.Prefs.settings.setValue( 390 Preferences.Prefs.settings.setValue(
392 "FindFileDialog/ReplaceHistory", 391 "FindFileDialog/ReplaceHistory",
393 self.replaceHistory[:30]) 392 self.replaceHistory[:30])
394 393
395 if self.dirButton.isChecked(): 394 if self.dirButton.isChecked():
396 searchDir = self.dirCombo.currentText() 395 searchDir = self.dirCombo.currentText()
397 if searchDir in self.dirHistory: 396 if searchDir in self.dirHistory:
398 self.dirHistory.remove(searchDir) 397 self.dirHistory.remove(searchDir)
399 self.dirHistory.insert(0, searchDir) 398 self.dirHistory.insert(0, searchDir)
400 self.dirCombo.clear() 399 self.dirCombo.clear()
401 self.dirCombo.addItems(self.dirHistory) 400 self.dirCombo.addItems(self.dirHistory)
402 Preferences.Prefs.settings.setValue( 401 Preferences.Prefs.settings.setValue(
403 "FindFileDialog/DirectoryHistory", 402 "FindFileDialog/DirectoryHistory",
404 self.dirHistory[:30]) 403 self.dirHistory[:30])
405 404
406 # set the button states 405 # set the button states
407 self.stopButton.setEnabled(True) 406 self.stopButton.setEnabled(True)
408 self.stopButton.setDefault(True) 407 self.stopButton.setDefault(True)
454 if self.__replaceMode: 453 if self.__replaceMode:
455 if len(rline) > 1024: 454 if len(rline) > 1024:
456 rline = "{0} ...".format(line[:1024]) 455 rline = "{0} ...".format(line[:1024])
457 line = "- {0}\n+ {1}".format( 456 line = "- {0}\n+ {1}".format(
458 line, self.__stripEol(rline)) 457 line, self.__stripEol(rline))
459 self.__createItem(file, count, line, start, end, 458 self.__createItem(file, count, line, start, end,
460 rline, hash) 459 rline, hash)
461 460
462 if self.feelLikeCheckBox.isChecked(): 461 if self.feelLikeCheckBox.isChecked():
463 fn = os.path.join(self.project.ppath, file) 462 fn = os.path.join(self.project.ppath, file)
464 self.sourceFile.emit(fn, count, "", start, end) 463 self.sourceFile.emit(fn, count, "", start, end)
476 self.findProgress.setValue(1) 475 self.findProgress.setValue(1)
477 476
478 self.findProgressLabel.setPath("") 477 self.findProgressLabel.setPath("")
479 478
480 self.findList.setUpdatesEnabled(True) 479 self.findList.setUpdatesEnabled(True)
481 self.findList.sortItems(self.findList.sortColumn(), 480 self.findList.sortItems(self.findList.sortColumn(),
482 self.findList.header().sortIndicatorOrder()) 481 self.findList.header().sortIndicatorOrder())
483 self.findList.resizeColumnToContents(1) 482 self.findList.resizeColumnToContents(1)
484 if self.__replaceMode: 483 if self.__replaceMode:
485 self.findList.header().resizeSection(0, self.__section0Size + 30) 484 self.findList.header().resizeSection(0, self.__section0Size + 30)
486 self.findList.header().setStretchLastSection(True) 485 self.findList.header().setStretchLastSection(True)
493 if breakSearch: 492 if breakSearch:
494 self.close() 493 self.close()
495 494
496 def on_findList_itemDoubleClicked(self, itm, column): 495 def on_findList_itemDoubleClicked(self, itm, column):
497 """ 496 """
498 Private slot to handle the double click on a file item. 497 Private slot to handle the double click on a file item.
499 498
500 It emits the signal 499 It emits the signal
501 sourceFile or designerFile depending on the file extension. 500 sourceFile or designerFile depending on the file extension.
502 501
503 @param itm the double clicked tree item (QTreeWidgetItem) 502 @param itm the double clicked tree item (QTreeWidgetItem)
656 @param pos position the context menu shall be shown (QPoint) 655 @param pos position the context menu shall be shown (QPoint)
657 """ 656 """
658 menu = QMenu(self) 657 menu = QMenu(self)
659 658
660 menu.addAction(self.trUtf8("Open"), self.__openFile) 659 menu.addAction(self.trUtf8("Open"), self.__openFile)
661 menu.addAction(self.trUtf8("Copy Path to Clipboard"), 660 menu.addAction(self.trUtf8("Copy Path to Clipboard"),
662 self.__copyToClipboard) 661 self.__copyToClipboard)
663 662
664 menu.exec_(QCursor.pos()) 663 menu.exec_(QCursor.pos())
665 664
666 def __openFile(self): 665 def __openFile(self):

eric ide

mercurial