13 import re |
13 import re |
14 |
14 |
15 from PyQt5.QtCore import pyqtSignal, Qt, pyqtSlot |
15 from PyQt5.QtCore import pyqtSignal, Qt, pyqtSlot |
16 from PyQt5.QtGui import QCursor |
16 from PyQt5.QtGui import QCursor |
17 from PyQt5.QtWidgets import QDialog, QApplication, QMenu, QDialogButtonBox, \ |
17 from PyQt5.QtWidgets import QDialog, QApplication, QMenu, QDialogButtonBox, \ |
18 QTreeWidgetItem |
18 QTreeWidgetItem, QComboBox |
19 |
19 |
20 from E5Gui.E5Application import e5App |
20 from E5Gui.E5Application import e5App |
21 from E5Gui import E5MessageBox, E5FileDialog |
21 from E5Gui import E5MessageBox |
|
22 from E5Gui.E5PathPicker import E5PathPickerModes |
22 |
23 |
23 from .Ui_FindFileDialog import Ui_FindFileDialog |
24 from .Ui_FindFileDialog import Ui_FindFileDialog |
24 |
25 |
25 import Utilities |
26 import Utilities |
26 import Preferences |
27 import Preferences |
27 import UI.PixmapCache |
|
28 |
28 |
29 |
29 |
30 class FindFileDialog(QDialog, Ui_FindFileDialog): |
30 class FindFileDialog(QDialog, Ui_FindFileDialog): |
31 """ |
31 """ |
32 Class implementing a dialog to search for text in files. |
32 Class implementing a dialog to search for text in files. |
58 """ |
58 """ |
59 super(FindFileDialog, self).__init__(parent) |
59 super(FindFileDialog, self).__init__(parent) |
60 self.setupUi(self) |
60 self.setupUi(self) |
61 self.setWindowFlags(Qt.Window) |
61 self.setWindowFlags(Qt.Window) |
62 |
62 |
63 self.dirSelectButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
63 self.dirPicker.setMode(E5PathPickerModes.DirectoryMode) |
|
64 self.dirPicker.setInsertPolicy(QComboBox.InsertAtTop) |
|
65 self.dirPicker.setSizeAdjustPolicy( |
|
66 QComboBox.AdjustToMinimumContentsLength) |
64 |
67 |
65 self.__replaceMode = replaceMode |
68 self.__replaceMode = replaceMode |
66 |
69 |
67 self.stopButton = \ |
70 self.stopButton = \ |
68 self.buttonBox.addButton(self.tr("Stop"), |
71 self.buttonBox.addButton(self.tr("Stop"), |
97 self.dirHistory = Preferences.toList( |
100 self.dirHistory = Preferences.toList( |
98 Preferences.Prefs.settings.value( |
101 Preferences.Prefs.settings.value( |
99 "FindFileDialog/DirectoryHistory")) |
102 "FindFileDialog/DirectoryHistory")) |
100 self.findtextCombo.addItems(self.searchHistory) |
103 self.findtextCombo.addItems(self.searchHistory) |
101 self.replacetextCombo.addItems(self.replaceHistory) |
104 self.replacetextCombo.addItems(self.replaceHistory) |
102 self.dirCombo.addItems(self.dirHistory) |
105 self.dirPicker.addItems(self.dirHistory) |
103 |
106 |
104 self.project = project |
107 self.project = project |
105 |
108 |
106 self.findList.headerItem().setText(self.findList.columnCount(), "") |
109 self.findList.headerItem().setText(self.findList.columnCount(), "") |
107 self.findList.header().setSortIndicator(0, Qt.AscendingOrder) |
110 self.findList.header().setSortIndicator(0, Qt.AscendingOrder) |
207 |
210 |
208 @param text (ignored) |
211 @param text (ignored) |
209 """ |
212 """ |
210 self.__enableFindButton() |
213 self.__enableFindButton() |
211 |
214 |
212 def on_dirCombo_editTextChanged(self, text): |
215 def on_dirPicker_editTextChanged(self, text): |
213 """ |
216 """ |
214 Private slot to handle the textChanged signal of the directory |
217 Private slot to handle the textChanged signal of the directory |
215 combo box. |
218 picker. |
216 |
219 |
217 @param text (ignored) |
220 @param text (ignored) |
218 """ |
221 """ |
219 self.__enableFindButton() |
222 self.__enableFindButton() |
220 |
223 |
254 """ |
257 """ |
255 if self.findtextCombo.currentText() == "" or \ |
258 if self.findtextCombo.currentText() == "" or \ |
256 (self.__replaceMode and |
259 (self.__replaceMode and |
257 self.replacetextCombo.currentText() == "") or \ |
260 self.replacetextCombo.currentText() == "") or \ |
258 (self.dirButton.isChecked() and |
261 (self.dirButton.isChecked() and |
259 (self.dirCombo.currentText() == "" or |
262 (self.dirPicker.currentText() == "" or |
260 not os.path.exists(os.path.abspath( |
263 not os.path.exists(os.path.abspath( |
261 self.dirCombo.currentText())))) or \ |
264 self.dirPicker.currentText())))) or \ |
262 (self.filterCheckBox.isChecked() and self.filterEdit.text() == ""): |
265 (self.filterCheckBox.isChecked() and self.filterEdit.text() == ""): |
263 self.findButton.setEnabled(False) |
266 self.findButton.setEnabled(False) |
264 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
267 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
265 else: |
268 else: |
266 self.findButton.setEnabled(True) |
269 self.findButton.setEnabled(True) |
342 if self.resourcesCheckBox.isChecked(): |
345 if self.resourcesCheckBox.isChecked(): |
343 filters.append(self.filterResources) |
346 filters.append(self.filterResources) |
344 filterString = "|".join(filters) |
347 filterString = "|".join(filters) |
345 filterRe = re.compile(filterString) |
348 filterRe = re.compile(filterString) |
346 files = self.__getFileList( |
349 files = self.__getFileList( |
347 os.path.abspath(self.dirCombo.currentText()), |
350 os.path.abspath(self.dirPicker.currentText()), |
348 filterRe) |
351 filterRe) |
349 elif self.openFilesButton.isChecked(): |
352 elif self.openFilesButton.isChecked(): |
350 vm = e5App().getObject("ViewManager") |
353 vm = e5App().getObject("ViewManager") |
351 vm.checkAllDirty() |
354 vm.checkAllDirty() |
352 files = vm.getOpenFilenames() |
355 files = vm.getOpenFilenames() |
402 Preferences.Prefs.settings.setValue( |
405 Preferences.Prefs.settings.setValue( |
403 "FindFileDialog/ReplaceHistory", |
406 "FindFileDialog/ReplaceHistory", |
404 self.replaceHistory[:30]) |
407 self.replaceHistory[:30]) |
405 |
408 |
406 if self.dirButton.isChecked(): |
409 if self.dirButton.isChecked(): |
407 searchDir = self.dirCombo.currentText() |
410 searchDir = self.dirPicker.currentText() |
408 if searchDir in self.dirHistory: |
411 if searchDir in self.dirHistory: |
409 self.dirHistory.remove(searchDir) |
412 self.dirHistory.remove(searchDir) |
410 self.dirHistory.insert(0, searchDir) |
413 self.dirHistory.insert(0, searchDir) |
411 self.dirCombo.clear() |
414 self.dirPicker.clear() |
412 self.dirCombo.addItems(self.dirHistory) |
415 self.dirPicker.addItems(self.dirHistory) |
413 Preferences.Prefs.settings.setValue( |
416 Preferences.Prefs.settings.setValue( |
414 "FindFileDialog/DirectoryHistory", |
417 "FindFileDialog/DirectoryHistory", |
415 self.dirHistory[:30]) |
418 self.dirHistory[:30]) |
416 |
419 |
417 # set the button states |
420 # set the button states |
542 if fn.endswith('.ui'): |
545 if fn.endswith('.ui'): |
543 self.designerFile.emit(fn) |
546 self.designerFile.emit(fn) |
544 else: |
547 else: |
545 self.sourceFile.emit(fn, line, "", start, end) |
548 self.sourceFile.emit(fn, line, "", start, end) |
546 |
549 |
547 @pyqtSlot() |
|
548 def on_dirSelectButton_clicked(self): |
|
549 """ |
|
550 Private slot to display a directory selection dialog. |
|
551 """ |
|
552 directory = E5FileDialog.getExistingDirectory( |
|
553 self, |
|
554 self.tr("Select directory"), |
|
555 self.dirCombo.currentText(), |
|
556 E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) |
|
557 |
|
558 if directory: |
|
559 self.dirCombo.setEditText(Utilities.toNativeSeparators(directory)) |
|
560 |
|
561 def __getFileList(self, path, filterRe): |
550 def __getFileList(self, path, filterRe): |
562 """ |
551 """ |
563 Private method to get a list of files to search. |
552 Private method to get a list of files to search. |
564 |
553 |
565 @param path the root directory to search in (string) |
554 @param path the root directory to search in (string) |
581 Public slot to set the name of the directory to search in. |
570 Public slot to set the name of the directory to search in. |
582 |
571 |
583 @param searchDir name of the directory to search in (string) |
572 @param searchDir name of the directory to search in (string) |
584 """ |
573 """ |
585 self.dirButton.setChecked(True) |
574 self.dirButton.setChecked(True) |
586 self.dirCombo.setEditText(Utilities.toNativeSeparators(searchDir)) |
575 self.dirPicker.setEditText(Utilities.toNativeSeparators(searchDir)) |
587 |
576 |
588 def setOpenFiles(self): |
577 def setOpenFiles(self): |
589 """ |
578 """ |
590 Public slot to set the mode to search in open files. |
579 Public slot to set the mode to search in open files. |
591 """ |
580 """ |