UI/FindFileDialog.py

changeset 268
f6f53503b8d6
parent 248
f4561c24989a
child 293
9ecc02b50325
equal deleted inserted replaced
267:f4cd9c07da76 268:f6f53503b8d6
67 self.replacetextCombo.hide() 67 self.replacetextCombo.hide()
68 self.replaceButton.hide() 68 self.replaceButton.hide()
69 69
70 self.findProgressLabel.setMaximumWidth(550) 70 self.findProgressLabel.setMaximumWidth(550)
71 71
72 self.searchHistory = [] 72 self.searchHistory = Preferences.toList(
73 self.replaceHistory = [] 73 Preferences.Prefs.settings.value("FindFileDialog/SearchHistory"))
74 self.replaceHistory = Preferences.toList(
75 Preferences.Prefs.settings.value("FindFileDialog/ReplaceHistory"))
76 self.dirHistory = Preferences.toList(
77 Preferences.Prefs.settings.value("FindFileDialog/DirectoryHistory"))
78 self.findtextCombo.addItems(self.searchHistory)
79 self.replacetextCombo.addItems(self.replaceHistory)
80 self.dirCombo.addItems(self.dirHistory)
81
74 self.project = project 82 self.project = project
75 83
76 self.findList.headerItem().setText(self.findList.columnCount(), "") 84 self.findList.headerItem().setText(self.findList.columnCount(), "")
77 self.findList.header().setSortIndicator(0, Qt.AscendingOrder) 85 self.findList.header().setSortIndicator(0, Qt.AscendingOrder)
78 self.__section0Size = self.findList.header().sectionSize(0) 86 self.__section0Size = self.findList.header().sectionSize(0)
156 164
157 if self.__replaceMode: 165 if self.__replaceMode:
158 self.findList.clear() 166 self.findList.clear()
159 self.replacetextCombo.setEditText("") 167 self.replacetextCombo.setEditText("")
160 168
169 self.dirCombo.setEditText("")
170
161 QDialog.show(self) 171 QDialog.show(self)
162 172
163 def on_findtextCombo_editTextChanged(self, text): 173 def on_findtextCombo_editTextChanged(self, text):
164 """ 174 """
165 Private slot to handle the editTextChanged signal of the find text combo. 175 Private slot to handle the editTextChanged signal of the find text combo.
174 184
175 @param text (ignored) 185 @param text (ignored)
176 """ 186 """
177 self.__enableFindButton() 187 self.__enableFindButton()
178 188
179 def on_dirEdit_textChanged(self, text): 189 def on_dirCombo_editTextChanged(self, text):
180 """ 190 """
181 Private slot to handle the textChanged signal of the directory edit. 191 Private slot to handle the textChanged signal of the directory combo box.
182 192
183 @param text (ignored) 193 @param text (ignored)
184 """ 194 """
185 self.__enableFindButton() 195 self.__enableFindButton()
186 196
219 Private slot called to enable the find button. 229 Private slot called to enable the find button.
220 """ 230 """
221 if self.findtextCombo.currentText() == "" or \ 231 if self.findtextCombo.currentText() == "" or \
222 (self.__replaceMode and self.replacetextCombo.currentText() == "") or \ 232 (self.__replaceMode and self.replacetextCombo.currentText() == "") or \
223 (self.dirButton.isChecked() and \ 233 (self.dirButton.isChecked() and \
224 (self.dirEdit.text() == "" or \ 234 (self.dirCombo.currentText() == "" or \
225 not os.path.exists(os.path.abspath(self.dirEdit.text())))) or \ 235 not os.path.exists(os.path.abspath(self.dirCombo.currentText())))) or \
226 (self.filterCheckBox.isChecked() and self.filterEdit.text() == ""): 236 (self.filterCheckBox.isChecked() and self.filterEdit.text() == ""):
227 self.findButton.setEnabled(False) 237 self.findButton.setEnabled(False)
228 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 238 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
229 else: 239 else:
230 self.findButton.setEnabled(True) 240 self.findButton.setEnabled(True)
294 filters.append(self.filterInterfaces) 304 filters.append(self.filterInterfaces)
295 if self.resourcesCheckBox.isChecked(): 305 if self.resourcesCheckBox.isChecked():
296 filters.append(self.filterResources) 306 filters.append(self.filterResources)
297 filterString = "|".join(filters) 307 filterString = "|".join(filters)
298 filterRe = re.compile(filterString) 308 filterRe = re.compile(filterString)
299 files = self.__getFileList(os.path.abspath(self.dirEdit.text()), 309 files = self.__getFileList(os.path.abspath(self.dirCombo.currentText()),
300 filterRe) 310 filterRe)
301 elif self.openFilesButton.isChecked(): 311 elif self.openFilesButton.isChecked():
302 files = e5App().getObject("ViewManager").getOpenFilenames() 312 files = e5App().getObject("ViewManager").getOpenFilenames()
303 313
304 self.findList.clear() 314 self.findList.clear()
337 if ct in self.searchHistory: 347 if ct in self.searchHistory:
338 self.searchHistory.remove(ct) 348 self.searchHistory.remove(ct)
339 self.searchHistory.insert(0, ct) 349 self.searchHistory.insert(0, ct)
340 self.findtextCombo.clear() 350 self.findtextCombo.clear()
341 self.findtextCombo.addItems(self.searchHistory) 351 self.findtextCombo.addItems(self.searchHistory)
352 Preferences.Prefs.settings.setValue("FindFileDialog/SearchHistory",
353 self.searchHistory[:30])
354
342 if self.__replaceMode: 355 if self.__replaceMode:
343 replTxt = self.replacetextCombo.currentText() 356 replTxt = self.replacetextCombo.currentText()
344 if replTxt in self.replaceHistory: 357 if replTxt in self.replaceHistory:
345 self.replaceHistory.remove(replTxt) 358 self.replaceHistory.remove(replTxt)
346 self.replaceHistory.insert(0, replTxt) 359 self.replaceHistory.insert(0, replTxt)
347 self.replacetextCombo.clear() 360 self.replacetextCombo.clear()
348 self.replacetextCombo.addItems(self.replaceHistory) 361 self.replacetextCombo.addItems(self.replaceHistory)
362 Preferences.Prefs.settings.setValue("FindFileDialog/ReplaceHistory",
363 self.replaceHistory[:30])
364
365 if self.dirButton.isChecked():
366 dir = self.dirCombo.currentText()
367 if dir in self.dirHistory:
368 self.dirHistory.remove(dir)
369 self.dirHistory.insert(0, dir)
370 self.dirCombo.clear()
371 self.dirCombo.addItems(self.dirHistory)
372 Preferences.Prefs.settings.setValue("FindFileDialog/DirectoryHistory",
373 self.dirHistory[:30])
349 374
350 # now go through all the files 375 # now go through all the files
351 self.__populating = True 376 self.__populating = True
352 self.findList.setUpdatesEnabled(False) 377 self.findList.setUpdatesEnabled(False)
353 progress = 0 378 progress = 0
465 Private slot to display a directory selection dialog. 490 Private slot to display a directory selection dialog.
466 """ 491 """
467 directory = QFileDialog.getExistingDirectory(\ 492 directory = QFileDialog.getExistingDirectory(\
468 self, 493 self,
469 self.trUtf8("Select directory"), 494 self.trUtf8("Select directory"),
470 self.dirEdit.text(), 495 self.dirCombo.currentText(),
471 QFileDialog.Options(QFileDialog.ShowDirsOnly)) 496 QFileDialog.Options(QFileDialog.ShowDirsOnly))
472 497
473 if directory: 498 if directory:
474 self.dirEdit.setText(Utilities.toNativeSeparators(directory)) 499 self.dirCombo.setEditText(Utilities.toNativeSeparators(directory))
475 500
476 def __getFileList(self, path, filterRe): 501 def __getFileList(self, path, filterRe):
477 """ 502 """
478 Private method to get a list of files to search. 503 Private method to get a list of files to search.
479 504
495 Public slot to set the name of the directory to search in. 520 Public slot to set the name of the directory to search in.
496 521
497 @param searchDir name of the directory to search in (string) 522 @param searchDir name of the directory to search in (string)
498 """ 523 """
499 self.dirButton.setChecked(True) 524 self.dirButton.setChecked(True)
500 self.dirEdit.setText(Utilities.toNativeSeparators(searchDir)) 525 self.dirCombo.setEditText(Utilities.toNativeSeparators(searchDir))
501 526
502 @pyqtSlot() 527 @pyqtSlot()
503 def on_replaceButton_clicked(self): 528 def on_replaceButton_clicked(self):
504 """ 529 """
505 Private slot to perform the requested replace actions. 530 Private slot to perform the requested replace actions.

eric ide

mercurial