eric7/UI/FindFileWidget.py

Sun, 09 Jan 2022 17:43:29 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 09 Jan 2022 17:43:29 +0100
branch
eric7
changeset 8917
18901f50f971
parent 8881
54e42bc2437a
child 8932
a21e80dde10e
permissions
-rw-r--r--

FindFileWidget: adde code to ensure the file type tab is the current one upon startup.

0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
8881
54e42bc2437a Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8859
diff changeset
3 # Copyright (c) 2002 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to search for text in files.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import re
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
8636
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
13 from PyQt6.QtCore import pyqtSignal, pyqtSlot, Qt, QPoint, QUrl
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
14 from PyQt6.QtGui import QCursor, QDesktopServices, QImageReader
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
15 from PyQt6.QtWidgets import (
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
16 QWidget, QApplication, QMenu, QTreeWidgetItem, QComboBox
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
17 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
8358
144a6b854f70 Sorted the eric specific extensions into packages named like the corresponding PyQt packages (i.e. EricCore,EricGui and EricWidgets).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8356
diff changeset
19 from EricWidgets.EricApplication import ericApp
144a6b854f70 Sorted the eric specific extensions into packages named like the corresponding PyQt packages (i.e. EricCore,EricGui and EricWidgets).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8356
diff changeset
20 from EricWidgets import EricMessageBox
144a6b854f70 Sorted the eric specific extensions into packages named like the corresponding PyQt packages (i.e. EricCore,EricGui and EricWidgets).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8356
diff changeset
21 from EricWidgets.EricPathPicker import EricPathPickerModes
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
23 from .Ui_FindFileWidget import Ui_FindFileWidget
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
25 import Preferences
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
26 import UI.PixmapCache
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 import Utilities
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 894
diff changeset
28
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3186
diff changeset
29
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
30 class FindFileWidget(QWidget, Ui_FindFileWidget):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
32 Class implementing a widget to search for text in files and replace it
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
33 with some other text.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
35 The occurrences found are displayed in a tree showing the file name,
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
36 the line number and the text found. The file will be opened upon a double
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
37 click onto the respective entry of the list. If the widget is in replace
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
38 mode the line below shows the text after replacement. Replacements can
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
39 be authorized by ticking them on. Pressing the replace button performs
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
40 all ticked replacement operations.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
846
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
42 @signal sourceFile(str, int, str, int, int) emitted to open a source file
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
43 at a specificline
501
5c615a85241a Finished porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 500
diff changeset
44 @signal designerFile(str) emitted to open a Qt-Designer file
8636
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
45 @signal linguistFile(str) emitted to open a Qt-Linguist (*.ts) file
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
46 @signal trpreview([str]) emitted to preview Qt-Linguist (*.qm) files
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
47 @signal pixmapFile(str) emitted to open a pixmap file
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
48 @signal svgFile(str) emitted to open a SVG file
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
49 @signal umlFile(str) emitted to open an eric UML file
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
476
121633976eca Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 458
diff changeset
51 sourceFile = pyqtSignal(str, int, str, int, int)
500
c3abc7895a01 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 489
diff changeset
52 designerFile = pyqtSignal(str)
8636
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
53 linguistFile = pyqtSignal(str)
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
54 trpreview = pyqtSignal(list)
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
55 pixmapFile = pyqtSignal(str)
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
56 svgFile = pyqtSignal(str)
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
57 umlFile = pyqtSignal(str)
476
121633976eca Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 458
diff changeset
58
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7992
diff changeset
59 lineRole = Qt.ItemDataRole.UserRole + 1
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7992
diff changeset
60 startRole = Qt.ItemDataRole.UserRole + 2
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7992
diff changeset
61 endRole = Qt.ItemDataRole.UserRole + 3
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7992
diff changeset
62 replaceRole = Qt.ItemDataRole.UserRole + 4
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7992
diff changeset
63 md5Role = Qt.ItemDataRole.UserRole + 5
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
65 def __init__(self, project, parent=None):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 Constructor
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 @param project reference to the project object
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
70 @type Project
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
71 @param parent parent widget of this dialog (defaults to None)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
72 @type QWidget (optional)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8149
diff changeset
74 super().__init__(parent)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.setupUi(self)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
77 self.layout().setContentsMargins(0, 3, 0, 0)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
78
8846
4196ec4c37a5 Some optimizations to the find location and find in file panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8809
diff changeset
79 self.caseToolButton.setIcon(UI.PixmapCache.getIcon("caseSensitive"))
4196ec4c37a5 Some optimizations to the find location and find in file panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8809
diff changeset
80 self.wordToolButton.setIcon(UI.PixmapCache.getIcon("wholeWord"))
4196ec4c37a5 Some optimizations to the find location and find in file panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8809
diff changeset
81 self.regexpToolButton.setIcon(UI.PixmapCache.getIcon("regexp"))
4196ec4c37a5 Some optimizations to the find location and find in file panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8809
diff changeset
82
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8347
diff changeset
83 self.dirPicker.setMode(EricPathPickerModes.DIRECTORY_MODE)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7992
diff changeset
84 self.dirPicker.setInsertPolicy(QComboBox.InsertPolicy.InsertAtTop)
4589
b648ccbdbef9 Modified more dialogs to use the path picker widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4278
diff changeset
85 self.dirPicker.setSizeAdjustPolicy(
8149
3fefc0c430f2 Changed sze adjuyt policy of some combo boxes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
86 QComboBox.SizeAdjustPolicy.AdjustToMinimumContentsLengthWithIcon)
3186
a05eff845522 Changed all the file or directory selection buttons to QToolButton and gave them an icon.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
87
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
88 self.stopButton.setEnabled(False)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
89 self.stopButton.clicked.connect(self.__stopSearch)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
90 self.stopButton.setIcon(UI.PixmapCache.getIcon("stopLoading"))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 self.findButton.setEnabled(False)
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
93 self.findButton.clicked.connect(self.__doSearch)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
94 self.findButton.setIcon(UI.PixmapCache.getIcon("find"))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95
8809
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
96 self.clearButton.setEnabled(False)
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
97 self.clearButton.clicked.connect(self.__clearResults)
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
98 self.clearButton.setIcon(UI.PixmapCache.getIcon("clear"))
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
99
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
100 self.replaceButton.setIcon(UI.PixmapCache.getIcon("editReplace"))
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
101
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
102 self.modeToggleButton.clicked.connect(self.__toggleReplaceMode)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 self.findProgressLabel.setMaximumWidth(550)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105
268
f6f53503b8d6 Changed the Find in Files dialog to remember the history of the search string, replace string and the search directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 248
diff changeset
106 self.searchHistory = Preferences.toList(
8636
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
107 Preferences.getSettings().value(
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
108 "FindFileWidget/SearchHistory"))
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
109 self.findtextCombo.lineEdit().setClearButtonEnabled(True)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
110 self.findtextCombo.lineEdit().returnPressed.connect(self.__doSearch)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
111 self.findtextCombo.setCompleter(None)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
112 self.findtextCombo.addItems(self.searchHistory)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
113 self.findtextCombo.setEditText("")
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
114
268
f6f53503b8d6 Changed the Find in Files dialog to remember the history of the search string, replace string and the search directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 248
diff changeset
115 self.replaceHistory = Preferences.toList(
8636
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
116 Preferences.getSettings().value(
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
117 "FindFileWidget/ReplaceHistory"))
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
118 self.replacetextCombo.lineEdit().setClearButtonEnabled(True)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
119 self.replacetextCombo.lineEdit().returnPressed.connect(self.__doSearch)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
120 self.replacetextCombo.setCompleter(None)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
121 self.replacetextCombo.addItems(self.replaceHistory)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
122 self.replacetextCombo.setEditText("")
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
123
268
f6f53503b8d6 Changed the Find in Files dialog to remember the history of the search string, replace string and the search directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 248
diff changeset
124 self.dirHistory = Preferences.toList(
8636
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
125 Preferences.getSettings().value(
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
126 "FindFileWidget/DirectoryHistory"))
4589
b648ccbdbef9 Modified more dialogs to use the path picker widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4278
diff changeset
127 self.dirPicker.addItems(self.dirHistory)
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
128 self.dirPicker.setText("")
268
f6f53503b8d6 Changed the Find in Files dialog to remember the history of the search string, replace string and the search directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 248
diff changeset
129
7992
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
130 self.excludeHiddenCheckBox.setChecked(Preferences.toBool(
8636
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
131 Preferences.getSettings().value(
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
132 "FindFileWidget/ExcludeHidden", True)
7992
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
133 ))
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
134
8917
18901f50f971 FindFileWidget: adde code to ensure the file type tab is the current one upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
135 # ensure the file type tab is the current one
18901f50f971 FindFileWidget: adde code to ensure the file type tab is the current one upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
136 self.fileOptionsWidget.setCurrentWidget(self.fileTypeTab)
18901f50f971 FindFileWidget: adde code to ensure the file type tab is the current one upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
137
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 self.project = project
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
139 self.project.projectOpened.connect(self.__projectOpened)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
140 self.project.projectClosed.connect(self.__projectClosed)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
142 self.__standardListFont = self.findList.font()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 self.findList.headerItem().setText(self.findList.columnCount(), "")
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7992
diff changeset
144 self.findList.header().setSortIndicator(0, Qt.SortOrder.AscendingOrder)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 self.__section0Size = self.findList.header().sectionSize(0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 self.findList.setExpandsOnDoubleClick(False)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 # Qt Designer form files
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 self.filterForms = r'.*\.ui$'
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 self.formsExt = ['*.ui']
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 # Corba interface files
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 self.filterInterfaces = r'.*\.idl$'
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 self.interfacesExt = ['*.idl']
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155
5986
1e78a1aa438b Some more protobuf related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5603
diff changeset
156 # Protobuf protocol files
1e78a1aa438b Some more protobuf related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5603
diff changeset
157 self.filterProtocols = r'.*\.proto$'
1e78a1aa438b Some more protobuf related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5603
diff changeset
158 self.protocolsExt = ['*.proto']
1e78a1aa438b Some more protobuf related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5603
diff changeset
159
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 # Qt resources files
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 self.filterResources = r'.*\.qrc$'
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 self.resourcesExt = ['*.qrc']
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 self.__cancelSearch = False
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 self.__lastFileItem = None
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 self.__populating = False
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7992
diff changeset
168 self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
458
1695e7a2db54 Continued porting signal/slot usage to the new API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 432
diff changeset
169 self.customContextMenuRequested.connect(self.__contextMenuRequested)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
171 self.__replaceMode = True
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
172 self.__toggleReplaceMode()
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
173
846
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
174 def __createItem(self, file, line, text, start, end, replTxt="", md5=""):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 Private method to create an entry in the file list.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
178 @param file filename of file
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
179 @type str
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
180 @param line line number
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
181 @type int
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
182 @param text text found
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
183 @type str
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
184 @param start start position of match
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
185 @type int
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
186 @param end end position of match
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
187 @type int
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
188 @param replTxt text with replacements applied (defaults to "")
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
189 @type str (optional)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
190 @param md5 MD5 hash of the file (defaults to "")
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
191 @type str (optional)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 if self.__lastFileItem is None:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 # It's a new file
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 self.__lastFileItem = QTreeWidgetItem(self.findList, [file])
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 self.__lastFileItem.setFirstColumnSpanned(True)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 self.__lastFileItem.setExpanded(True)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 if self.__replaceMode:
3030
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3020
diff changeset
199 self.__lastFileItem.setFlags(
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
200 self.__lastFileItem.flags() |
8324
83084f088655 Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
201 Qt.ItemFlag.ItemIsUserCheckable |
8347
ca9ef7600df7 Corrected the useof ItemIsTristate, which is obsolete.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8327
diff changeset
202 Qt.ItemFlag.ItemIsAutoTristate)
682
91114a975eda Added a check to the find and replace dialog to make sure, that no external changes were done between the find run and the replace run.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 654
diff changeset
203 self.__lastFileItem.setData(0, self.md5Role, md5)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204
1640
1699d46026cd Fixed a compatibility issue with Qt 4.8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
205 itm = QTreeWidgetItem(self.__lastFileItem)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7992
diff changeset
206 itm.setTextAlignment(0, Qt.AlignmentFlag.AlignRight)
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7992
diff changeset
207 itm.setData(0, Qt.ItemDataRole.DisplayRole, line)
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7992
diff changeset
208 itm.setData(1, Qt.ItemDataRole.DisplayRole, text)
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6
diff changeset
209 itm.setData(0, self.lineRole, line)
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6
diff changeset
210 itm.setData(0, self.startRole, start)
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6
diff changeset
211 itm.setData(0, self.endRole, end)
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6
diff changeset
212 itm.setData(0, self.replaceRole, replTxt)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 if self.__replaceMode:
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7992
diff changeset
214 itm.setFlags(itm.flags() |
8324
83084f088655 Continued porting eric to PyQt6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
215 Qt.ItemFlag.ItemIsUserCheckable)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7992
diff changeset
216 itm.setCheckState(0, Qt.CheckState.Checked)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 self.replaceButton.setEnabled(True)
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
218
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
219 def activate(self, replaceMode=False, txt="", searchDir="",
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
220 openFiles=False):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 """
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
222 Public method to activate the widget with a given mode, a text
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
223 to search for and some search parameters.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
225 @param replaceMode flag indicating replacement mode (defaults to False)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
226 @type bool (optional)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
227 @param txt text to be searched for (defaults to "")
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
228 @type str (optional)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
229 @param searchDir directory to search in (defaults to "")
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
230 @type str (optional)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
231 @param openFiles flag indicating to operate on open files only
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
232 (defaults to False)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
233 @type bool (optional)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 """
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
235 if self.project.isOpen():
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 self.projectButton.setEnabled(True)
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
237 self.projectButton.setChecked(True)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 self.projectButton.setEnabled(False)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 self.dirButton.setChecked(True)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 self.findtextCombo.setEditText(txt)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 self.findtextCombo.lineEdit().selectAll()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 self.findtextCombo.setFocus()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
246 if self.__replaceMode != replaceMode:
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
247 self.__toggleReplaceMode()
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
248
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
249 if searchDir:
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
250 self.setSearchDirectory(searchDir)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
251 if openFiles:
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
252 self.setOpenFiles()
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
253
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
254 @pyqtSlot()
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
255 def __toggleReplaceMode(self):
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
256 """
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
257 Private slot to toggle the dialog mode.
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
258 """
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
259 self.__replaceMode = not self.__replaceMode
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
260
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
261 # change some interface elements and properties
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
262 self.findList.clear()
8809
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
263 self.clearButton.setEnabled(False)
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
264
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265 if self.__replaceMode:
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
266 self.replaceButton.show()
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
267 self.replaceLabel.show()
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
268 self.replacetextCombo.show()
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
269
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
270 self.replaceButton.setEnabled(False)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 self.replacetextCombo.setEditText("")
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
272
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
273 font = Preferences.getEditorOtherFonts("MonospacedFont")
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
274 self.findList.setFont(font)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
275
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
276 self.modeToggleButton.setIcon(UI.PixmapCache.getIcon("1uparrow"))
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
277 else:
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
278 self.replaceLabel.hide()
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
279 self.replacetextCombo.hide()
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
280 self.replaceButton.hide()
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
281
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
282 self.findList.setFont(self.__standardListFont)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
283
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
284 self.modeToggleButton.setIcon(UI.PixmapCache.getIcon("1downarrow"))
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
285
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
286 @pyqtSlot()
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
287 def __projectOpened(self):
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
288 """
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
289 Private slot to react to the opening of a project.
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
290 """
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
291 self.projectButton.setEnabled(True)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
292 self.projectButton.setChecked(True)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
293
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
294 @pyqtSlot()
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
295 def __projectClosed(self):
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
296 """
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
297 Private slot to react to the closing of a project.
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
298 """
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
299 self.projectButton.setEnabled(False)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
300 if self.projectButton.isChecked():
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
301 self.dirButton.setChecked(True)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
302
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
303 @pyqtSlot(str)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 def on_findtextCombo_editTextChanged(self, text):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 """
846
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
306 Private slot to handle the editTextChanged signal of the find
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
307 text combo.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 @param text (ignored)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 self.__enableFindButton()
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
312
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
313 @pyqtSlot(str)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 def on_replacetextCombo_editTextChanged(self, text):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315 """
846
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
316 Private slot to handle the editTextChanged signal of the replace
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
317 text combo.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 @param text (ignored)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 self.__enableFindButton()
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
322
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
323 @pyqtSlot(str)
4589
b648ccbdbef9 Modified more dialogs to use the path picker widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4278
diff changeset
324 def on_dirPicker_editTextChanged(self, text):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 """
846
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
326 Private slot to handle the textChanged signal of the directory
4589
b648ccbdbef9 Modified more dialogs to use the path picker widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4278
diff changeset
327 picker.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 @param text (ignored)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 self.__enableFindButton()
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
332
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 @pyqtSlot()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 def on_projectButton_clicked(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 """
7109
6191abce8002 FindFileDialog: fixed a situation where the Find button is not enabled when it should.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
336 Private slot to handle the selection of the 'Project' radio button.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 self.__enableFindButton()
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
339
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340 @pyqtSlot()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 def on_dirButton_clicked(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342 """
7109
6191abce8002 FindFileDialog: fixed a situation where the Find button is not enabled when it should.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
343 Private slot to handle the selection of the 'Directory' radio button.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 self.__enableFindButton()
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
346
7109
6191abce8002 FindFileDialog: fixed a situation where the Find button is not enabled when it should.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
347 @pyqtSlot()
6191abce8002 FindFileDialog: fixed a situation where the Find button is not enabled when it should.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
348 def on_openFilesButton_clicked(self):
7139
9bb36ec2d1b5 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7109
diff changeset
349 """
9bb36ec2d1b5 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7109
diff changeset
350 Private slot to handle the selection of the 'Open Files' radio button.
9bb36ec2d1b5 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7109
diff changeset
351 """
9bb36ec2d1b5 Fixed some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7109
diff changeset
352 self.__enableFindButton()
7109
6191abce8002 FindFileDialog: fixed a situation where the Find button is not enabled when it should.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
353
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354 @pyqtSlot()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 def on_filterCheckBox_clicked(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 Private slot to handle the selection of the file filter check box.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 self.__enableFindButton()
7109
6191abce8002 FindFileDialog: fixed a situation where the Find button is not enabled when it should.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
360
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 @pyqtSlot(str)
489
844a0a278269 Fixed an issue in the find in files dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 476
diff changeset
362 def on_filterEdit_textEdited(self, text):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 Private slot to handle the textChanged signal of the file filter edit.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366 @param text (ignored)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 self.__enableFindButton()
7109
6191abce8002 FindFileDialog: fixed a situation where the Find button is not enabled when it should.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
369
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
370 @pyqtSlot()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 def __enableFindButton(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 Private slot called to enable the find button.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 """
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
375 if (
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
376 self.findtextCombo.currentText() == "" or
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
377 (self.dirButton.isChecked() and
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
378 (self.dirPicker.currentText() == "" or
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
379 not os.path.exists(os.path.abspath(
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
380 self.dirPicker.currentText())))) or
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
381 (self.filterCheckBox.isChecked() and
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
382 self.filterEdit.text() == "")
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
383 ):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 self.findButton.setEnabled(False)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 self.findButton.setEnabled(True)
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
387
855
d8c4113a9274 Fixed an issue of the find/replace in file dialog where a replace would change the eol as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 846
diff changeset
388 def __stripEol(self, txt):
d8c4113a9274 Fixed an issue of the find/replace in file dialog where a replace would change the eol as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 846
diff changeset
389 """
d8c4113a9274 Fixed an issue of the find/replace in file dialog where a replace would change the eol as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 846
diff changeset
390 Private method to strip the eol part.
d8c4113a9274 Fixed an issue of the find/replace in file dialog where a replace would change the eol as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 846
diff changeset
391
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
392 @param txt line of text that should be treated
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
393 @type str
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
394 @return text with eol stripped
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
395 @rtype str
855
d8c4113a9274 Fixed an issue of the find/replace in file dialog where a replace would change the eol as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 846
diff changeset
396 """
d8c4113a9274 Fixed an issue of the find/replace in file dialog where a replace would change the eol as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 846
diff changeset
397 return txt.replace("\r", "").replace("\n", "")
8632
f25cd4b94eb0 Changed the Find File dialog to an integrated widget (right side)
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8614
diff changeset
398
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
399 @pyqtSlot()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 def __stopSearch(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 Private slot to handle the stop button being pressed.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
404 self.__cancelSearch = True
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
405
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
406 @pyqtSlot()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
407 def __doSearch(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
408 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
409 Private slot to handle the find button being pressed.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
410 """
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
411 if (
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
412 self.__replaceMode and
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8347
diff changeset
413 not ericApp().getObject("ViewManager").checkAllDirty()
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
414 ):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
415 return
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
416
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
417 self.__cancelSearch = False
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
418
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
419 if self.filterCheckBox.isChecked():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
420 fileFilter = self.filterEdit.text()
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
421 fileFilterList = [
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
422 "^{0}$".format(filter.replace(".", r"\.").replace("*", ".*"))
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
423 for filter in fileFilter.split(";")
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
424 ]
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425 filterRe = re.compile("|".join(fileFilterList))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
426
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427 if self.projectButton.isChecked():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 if self.filterCheckBox.isChecked():
7992
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
429 files = [
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
430 self.project.getRelativePath(file)
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
431 for file in
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
432 self.__getFileList(
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
433 self.project.getProjectPath(),
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
434 filterRe,
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
435 excludeHiddenDirs=self.excludeHiddenCheckBox
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
436 .isChecked(),
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
437 )
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
438 ]
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
439 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
440 files = []
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 if self.sourcesCheckBox.isChecked():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442 files += self.project.pdata["SOURCES"]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443 if self.formsCheckBox.isChecked():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
444 files += self.project.pdata["FORMS"]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445 if self.interfacesCheckBox.isChecked():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
446 files += self.project.pdata["INTERFACES"]
5986
1e78a1aa438b Some more protobuf related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5603
diff changeset
447 if self.protocolsCheckBox.isChecked():
1e78a1aa438b Some more protobuf related changes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5603
diff changeset
448 files += self.project.pdata["PROTOCOLS"]
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
449 if self.resourcesCheckBox.isChecked():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
450 files += self.project.pdata["RESOURCES"]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
451 elif self.dirButton.isChecked():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
452 if not self.filterCheckBox.isChecked():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
453 filters = []
7992
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
454 if (
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
455 self.project.isOpen() and
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
456 os.path.abspath(self.dirPicker.currentText()).startswith(
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
457 self.project.getProjectPath())
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
458 ):
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
459 if self.sourcesCheckBox.isChecked():
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
460 filters.extend([
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
461 "^{0}$".format(
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
462 assoc.replace(".", r"\.").replace("*", ".*")
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
463 ) for assoc in
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
464 self.project.getFiletypeAssociations("SOURCES")
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
465 ])
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
466 if self.formsCheckBox.isChecked():
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
467 filters.extend([
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
468 "^{0}$".format(
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
469 assoc.replace(".", r"\.").replace("*", ".*")
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
470 ) for assoc in
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
471 self.project.getFiletypeAssociations("FORMS")
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
472 ])
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
473 if self.interfacesCheckBox.isChecked():
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
474 filters.extend([
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
475 "^{0}$".format(
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
476 assoc.replace(".", r"\.").replace("*", ".*")
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
477 ) for assoc in
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
478 self.project.getFiletypeAssociations("INTERFACES")
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
479 ])
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
480 if self.protocolsCheckBox.isChecked():
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
481 filters.extend([
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
482 "^{0}$".format(
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
483 assoc.replace(".", r"\.").replace("*", ".*")
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
484 ) for assoc in
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
485 self.project.getFiletypeAssociations("PROTOCOLS")
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
486 ])
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
487 if self.resourcesCheckBox.isChecked():
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
488 filters.extend([
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
489 "^{0}$".format(
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
490 assoc.replace(".", r"\.").replace("*", ".*")
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
491 ) for assoc in
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
492 self.project.getFiletypeAssociations("RESOURCES")
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
493 ])
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
494 else:
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
495 if self.sourcesCheckBox.isChecked():
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
496 filters.extend([
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
497 "^{0}$".format(
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
498 assoc.replace(".", r"\.").replace("*", ".*"))
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
499 for assoc in list(
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
500 Preferences.getEditorLexerAssocs().keys())
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
501 if assoc not in
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
502 self.formsExt + self.interfacesExt +
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
503 self.protocolsExt + self.resourcesExt
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
504 ])
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
505 if self.formsCheckBox.isChecked():
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
506 filters.append(self.filterForms)
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
507 if self.interfacesCheckBox.isChecked():
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
508 filters.append(self.filterInterfaces)
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
509 if self.protocolsCheckBox.isChecked():
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
510 filters.append(self.filterProtocols)
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
511 if self.resourcesCheckBox.isChecked():
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
512 filters.append(self.filterResources)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
513 filterString = "|".join(filters)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
514 filterRe = re.compile(filterString)
846
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
515 files = self.__getFileList(
4589
b648ccbdbef9 Modified more dialogs to use the path picker widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4278
diff changeset
516 os.path.abspath(self.dirPicker.currentText()),
7992
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
517 filterRe,
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
518 excludeHiddenDirs=self.excludeHiddenCheckBox.isChecked(),
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
519 excludeHiddenFiles=self.excludeHiddenCheckBox.isChecked(),
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
520 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
521 elif self.openFilesButton.isChecked():
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8347
diff changeset
522 vm = ericApp().getObject("ViewManager")
2214
4ce1ebcc3806 Added actions to open the find in files and replace in files dialogs in a mode that searches open files only.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1640
diff changeset
523 vm.checkAllDirty()
4ce1ebcc3806 Added actions to open the find in files and replace in files dialogs in a mode that searches open files only.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1640
diff changeset
524 files = vm.getOpenFilenames()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
525
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
526 self.findList.clear()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
527 QApplication.processEvents()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
528 QApplication.processEvents()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
529 self.findProgress.setMaximum(len(files))
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
530
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
531 # retrieve the values
8846
4196ec4c37a5 Some optimizations to the find location and find in file panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8809
diff changeset
532 reg = self.regexpToolButton.isChecked()
4196ec4c37a5 Some optimizations to the find location and find in file panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8809
diff changeset
533 wo = self.wordToolButton.isChecked()
4196ec4c37a5 Some optimizations to the find location and find in file panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8809
diff changeset
534 cs = self.caseToolButton.isChecked()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
535 ct = self.findtextCombo.currentText()
8235
78e6d29eb773 Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator) (batch 3).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8220
diff changeset
536 txt = ct if reg else re.escape(ct)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
537 if wo:
432
497e188ee86e Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 293
diff changeset
538 txt = "\\b{0}\\b".format(txt)
7192
a22eee00b052 Started removing runtime support for Python2 and PyQt4.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7139
diff changeset
539 flags = re.UNICODE
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
540 if not cs:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
541 flags |= re.IGNORECASE
6
52e8c820d0dd Removed some superfluous unicode() calls.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
542 try:
52e8c820d0dd Removed some superfluous unicode() calls.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
543 search = re.compile(txt, flags)
12
1d8dd9706f46 First commit after changing to Python 3.1.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7
diff changeset
544 except re.error as why:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8347
diff changeset
545 EricMessageBox.critical(
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3012
diff changeset
546 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3186
diff changeset
547 self.tr("Invalid search expression"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3186
diff changeset
548 self.tr("""<p>The search expression is not valid.</p>"""
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3186
diff changeset
549 """<p>Error: {0}</p>""").format(str(why)))
6
52e8c820d0dd Removed some superfluous unicode() calls.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
550 self.stopButton.setEnabled(False)
52e8c820d0dd Removed some superfluous unicode() calls.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
551 self.findButton.setEnabled(True)
52e8c820d0dd Removed some superfluous unicode() calls.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 0
diff changeset
552 return
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
553 # reset the findtextCombo
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
554 if ct in self.searchHistory:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
555 self.searchHistory.remove(ct)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
556 self.searchHistory.insert(0, ct)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
557 self.findtextCombo.clear()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
558 self.findtextCombo.addItems(self.searchHistory)
8636
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
559 Preferences.getSettings().setValue(
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
560 "FindFileWidget/SearchHistory",
846
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
561 self.searchHistory[:30])
8636
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
562 Preferences.getSettings().setValue(
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
563 "FindFileWidget/ExcludeHidden",
7992
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
564 self.excludeHiddenCheckBox.isChecked())
268
f6f53503b8d6 Changed the Find in Files dialog to remember the history of the search string, replace string and the search directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 248
diff changeset
565
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
566 if self.__replaceMode:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
567 replTxt = self.replacetextCombo.currentText()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
568 if replTxt in self.replaceHistory:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
569 self.replaceHistory.remove(replTxt)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
570 self.replaceHistory.insert(0, replTxt)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
571 self.replacetextCombo.clear()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
572 self.replacetextCombo.addItems(self.replaceHistory)
8637
394377638256 Replaced the direct access to 'Preferences.Prefs.settings' with 'Preferences.getSettings()'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8636
diff changeset
573 Preferences.getSettings().setValue(
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
574 "FindFileWidget/ReplaceHistory",
846
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
575 self.replaceHistory[:30])
268
f6f53503b8d6 Changed the Find in Files dialog to remember the history of the search string, replace string and the search directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 248
diff changeset
576
f6f53503b8d6 Changed the Find in Files dialog to remember the history of the search string, replace string and the search directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 248
diff changeset
577 if self.dirButton.isChecked():
4589
b648ccbdbef9 Modified more dialogs to use the path picker widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4278
diff changeset
578 searchDir = self.dirPicker.currentText()
293
9ecc02b50325 Fixed a variable naming issue in FindFileDialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 268
diff changeset
579 if searchDir in self.dirHistory:
9ecc02b50325 Fixed a variable naming issue in FindFileDialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 268
diff changeset
580 self.dirHistory.remove(searchDir)
9ecc02b50325 Fixed a variable naming issue in FindFileDialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 268
diff changeset
581 self.dirHistory.insert(0, searchDir)
4589
b648ccbdbef9 Modified more dialogs to use the path picker widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4278
diff changeset
582 self.dirPicker.clear()
b648ccbdbef9 Modified more dialogs to use the path picker widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4278
diff changeset
583 self.dirPicker.addItems(self.dirHistory)
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
584 self.dirPicker.setText(self.dirHistory[0])
8636
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
585 Preferences.getSettings().setValue(
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
586 "FindFileWidget/DirectoryHistory",
846
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
587 self.dirHistory[:30])
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
588
489
844a0a278269 Fixed an issue in the find in files dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 476
diff changeset
589 # set the button states
844a0a278269 Fixed an issue in the find in files dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 476
diff changeset
590 self.stopButton.setEnabled(True)
844a0a278269 Fixed an issue in the find in files dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 476
diff changeset
591 self.findButton.setEnabled(False)
8809
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
592 self.clearButton.setEnabled(False)
489
844a0a278269 Fixed an issue in the find in files dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 476
diff changeset
593
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
594 # now go through all the files
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
595 self.__populating = True
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
596 self.findList.setUpdatesEnabled(False)
3343
f7a6d271bb40 Modified the find in files dialog to show some statistics when done.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3192
diff changeset
597 occurrences = 0
f7a6d271bb40 Modified the find in files dialog to show some statistics when done.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3192
diff changeset
598 fileOccurrences = 0
8220
006ee31b4835 Applied some more code simplifications suggested by the new Simplify checker (Y113: use enumerate()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
599 for progress, file in enumerate(files, start=1):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
600 self.__lastFileItem = None
3343
f7a6d271bb40 Modified the find in files dialog to show some statistics when done.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3192
diff changeset
601 found = False
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
602 if self.__cancelSearch:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
603 break
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
604
8260
2161475d9639 Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8235
diff changeset
605 fn = (
8636
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
606 os.path.join(self.project.getProjectPath(), file)
8260
2161475d9639 Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8235
diff changeset
607 if self.projectButton.isChecked() else
2161475d9639 Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8235
diff changeset
608 file
2161475d9639 Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8235
diff changeset
609 )
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
610 # read the file and split it into textlines
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
611 try:
5603
4f2dd0850803 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5558
diff changeset
612 text, encoding, hashStr = Utilities.readEncodedFileWithHash(fn)
855
d8c4113a9274 Fixed an issue of the find/replace in file dialog where a replace would change the eol as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 846
diff changeset
613 lines = text.splitlines(True)
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
614 except (UnicodeError, OSError):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
615 self.findProgress.setValue(progress)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
616 continue
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
617
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
618 # now perform the search and display the lines found
8220
006ee31b4835 Applied some more code simplifications suggested by the new Simplify checker (Y113: use enumerate()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
619 for count, line in enumerate(lines, start=1):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
620 if self.__cancelSearch:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
621 break
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
622
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
623 contains = search.search(line)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
624 if contains:
3343
f7a6d271bb40 Modified the find in files dialog to show some statistics when done.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3192
diff changeset
625 occurrences += 1
f7a6d271bb40 Modified the find in files dialog to show some statistics when done.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3192
diff changeset
626 found = True
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
627 start = contains.start()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
628 end = contains.end()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
629 if self.__replaceMode:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
630 rline = search.sub(replTxt, line)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
631 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
632 rline = ""
855
d8c4113a9274 Fixed an issue of the find/replace in file dialog where a replace would change the eol as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 846
diff changeset
633 line = self.__stripEol(line)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
634 if len(line) > 1024:
432
497e188ee86e Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 293
diff changeset
635 line = "{0} ...".format(line[:1024])
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
636 if self.__replaceMode:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
637 if len(rline) > 1024:
432
497e188ee86e Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 293
diff changeset
638 rline = "{0} ...".format(line[:1024])
855
d8c4113a9274 Fixed an issue of the find/replace in file dialog where a replace would change the eol as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 846
diff changeset
639 line = "- {0}\n+ {1}".format(
d8c4113a9274 Fixed an issue of the find/replace in file dialog where a replace would change the eol as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 846
diff changeset
640 line, self.__stripEol(rline))
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 894
diff changeset
641 self.__createItem(file, count, line, start, end,
5603
4f2dd0850803 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5558
diff changeset
642 rline, hashStr)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
643
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
644 QApplication.processEvents()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
645
3343
f7a6d271bb40 Modified the find in files dialog to show some statistics when done.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3192
diff changeset
646 if found:
f7a6d271bb40 Modified the find in files dialog to show some statistics when done.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3192
diff changeset
647 fileOccurrences += 1
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
648 self.findProgress.setValue(progress)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
649
42
23b45a742e17 Fixed a bunch of issues including a workaround for a bug in the Python email package (s. EmailDialog.py).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
650 if not files:
23b45a742e17 Fixed a bunch of issues including a workaround for a bug in the Python email package (s. EmailDialog.py).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
651 self.findProgress.setMaximum(1)
23b45a742e17 Fixed a bunch of issues including a workaround for a bug in the Python email package (s. EmailDialog.py).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
652 self.findProgress.setValue(1)
23b45a742e17 Fixed a bunch of issues including a workaround for a bug in the Python email package (s. EmailDialog.py).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 13
diff changeset
653
3343
f7a6d271bb40 Modified the find in files dialog to show some statistics when done.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3192
diff changeset
654 resultFormat = self.tr("{0} / {1}", "occurrences / files")
f7a6d271bb40 Modified the find in files dialog to show some statistics when done.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3192
diff changeset
655 self.findProgressLabel.setPath(resultFormat.format(
f7a6d271bb40 Modified the find in files dialog to show some statistics when done.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3192
diff changeset
656 self.tr("%n occurrence(s)", "", occurrences),
f7a6d271bb40 Modified the find in files dialog to show some statistics when done.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3192
diff changeset
657 self.tr("%n file(s)", "", fileOccurrences)))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
658
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
659 self.findList.setUpdatesEnabled(True)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 894
diff changeset
660 self.findList.sortItems(self.findList.sortColumn(),
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
661 self.findList.header().sortIndicatorOrder())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
662 self.findList.resizeColumnToContents(1)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
663 if self.__replaceMode:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
664 self.findList.header().resizeSection(0, self.__section0Size + 30)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
665 self.findList.header().setStretchLastSection(True)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
666 self.__populating = False
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
667
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
668 self.stopButton.setEnabled(False)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
669 self.findButton.setEnabled(True)
8809
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
670 self.clearButton.setEnabled(self.findList.topLevelItemCount() != 0)
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
671
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
672 @pyqtSlot()
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
673 def __clearResults(self):
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
674 """
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
675 Private slot to clear the current search results.
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
676 """
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
677 self.findList.clear()
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
678 self.replaceButton.setEnabled(False)
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
679 self.clearButton.setEnabled(False)
8846
4196ec4c37a5 Some optimizations to the find location and find in file panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8809
diff changeset
680 self.findProgressLabel.setPath("")
4196ec4c37a5 Some optimizations to the find location and find in file panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8809
diff changeset
681 self.findProgress.setValue(0)
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
682
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
683 @pyqtSlot(QTreeWidgetItem, int)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
684 def on_findList_itemDoubleClicked(self, itm, column):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
685 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 894
diff changeset
686 Private slot to handle the double click on a file item.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
687
8636
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
688 It emits a signal depending on the file extension.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
689
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
690 @param itm the double clicked tree item
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
691 @type QTreeWidgetItem
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
692 @param column column that was double clicked (ignored)
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
693 @type int
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
694 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
695 if itm.parent():
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
696 file = itm.parent().text(0)
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6
diff changeset
697 line = itm.data(0, self.lineRole)
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6
diff changeset
698 start = itm.data(0, self.startRole)
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6
diff changeset
699 end = itm.data(0, self.endRole)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
700 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
701 file = itm.text(0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
702 line = 1
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
703 start = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
704 end = 0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
705
8636
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
706 fileName = (
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
707 os.path.join(self.project.getProjectPath(), file)
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
708 if self.project.isOpen() else
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
709 file
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
710 )
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
711 fileExt = os.path.splitext(fileName)[1]
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
712
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
713 if fileExt == ".ui":
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
714 self.designerFile.emit(fileName)
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
715 elif fileExt == ".ts":
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
716 self.linguistFile.emit(fileName)
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
717 elif fileExt == ".qm":
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
718 self.trpreview.emit([fileName])
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
719 elif fileExt in (".egj", ".e5g"):
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
720 self.umlFile.emit(fileName)
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
721 elif fileExt == ".svg":
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
722 self.svgFile.emit(fileName)
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
723 elif fileExt[1:] in QImageReader.supportedImageFormats():
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
724 self.pixmapFile.emit(fileName)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
725 else:
8636
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
726 if Utilities.MimeTypes.isTextFile(fileName):
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
727 self.sourceFile.emit(fileName, line, "", start, end)
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
728 else:
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
729 QDesktopServices.openUrl(QUrl(fileName))
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
730
7992
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
731 def __getFileList(self, path, filterRe, excludeHiddenDirs=False,
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
732 excludeHiddenFiles=False):
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
733 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
734 Private method to get a list of files to search.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
735
7992
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
736 @param path the root directory to search in
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
737 @type str
846
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
738 @param filterRe regular expression defining the filter
7992
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
739 criteria
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
740 @type regexp object
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
741 @param excludeHiddenDirs flag indicating to exclude hidden directories
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
742 @type bool
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
743 @param excludeHiddenFiles flag indicating to exclude hidden files
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
744 @type bool
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
745 @return list of files to be processed
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
746 @rtype list of str
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
747 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
748 path = os.path.abspath(path)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
749 files = []
7992
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
750 for dirname, dirs, filenames in os.walk(path):
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
751 files.extend([
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
752 os.path.join(dirname, f) for f in filenames
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
753 if (not (excludeHiddenFiles and f.startswith(".")) and
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
754 re.match(filterRe, f))
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
755 ])
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
756 if excludeHiddenDirs:
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
757 for d in dirs[:]:
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
758 if d .startswith("."):
0d1e35a10a0b Find File Dialog
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
759 dirs.remove(d)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
760 return files
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
761
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
762 def setSearchDirectory(self, searchDir):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
763 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
764 Public slot to set the name of the directory to search in.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
765
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
766 @param searchDir name of the directory to search in
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
767 @type str
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
768 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
769 self.dirButton.setChecked(True)
4589
b648ccbdbef9 Modified more dialogs to use the path picker widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4278
diff changeset
770 self.dirPicker.setEditText(Utilities.toNativeSeparators(searchDir))
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
771
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
772 @pyqtSlot()
2214
4ce1ebcc3806 Added actions to open the find in files and replace in files dialogs in a mode that searches open files only.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1640
diff changeset
773 def setOpenFiles(self):
4ce1ebcc3806 Added actions to open the find in files and replace in files dialogs in a mode that searches open files only.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1640
diff changeset
774 """
4ce1ebcc3806 Added actions to open the find in files and replace in files dialogs in a mode that searches open files only.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1640
diff changeset
775 Public slot to set the mode to search in open files.
4ce1ebcc3806 Added actions to open the find in files and replace in files dialogs in a mode that searches open files only.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1640
diff changeset
776 """
4ce1ebcc3806 Added actions to open the find in files and replace in files dialogs in a mode that searches open files only.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1640
diff changeset
777 self.openFilesButton.setChecked(True)
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
778
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
779 @pyqtSlot()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
780 def on_replaceButton_clicked(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
781 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
782 Private slot to perform the requested replace actions.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
783 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
784 self.findProgress.setMaximum(self.findList.topLevelItemCount())
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
785 self.findProgress.setValue(0)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
786
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
787 for index in range(self.findList.topLevelItemCount()):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
788 itm = self.findList.topLevelItem(index)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7992
diff changeset
789 if itm.checkState(0) in [Qt.CheckState.PartiallyChecked,
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7992
diff changeset
790 Qt.CheckState.Checked]:
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
791 file = itm.text(0)
682
91114a975eda Added a check to the find and replace dialog to make sure, that no external changes were done between the find run and the replace run.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 654
diff changeset
792 origHash = itm.data(0, self.md5Role)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
793
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
794 if self.projectButton.isChecked():
8636
c0a3a6e40815 Extended the supported file type specific signals in the two 'Find' related widgets.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8632
diff changeset
795 fn = os.path.join(self.project.getProjectPath(), file)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
796 else:
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
797 fn = file
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
798
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
799 # read the file and split it into textlines
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
800 try:
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
801 text, encoding, hashStr = (
846
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
802 Utilities.readEncodedFileWithHash(fn)
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
803 )
855
d8c4113a9274 Fixed an issue of the find/replace in file dialog where a replace would change the eol as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 846
diff changeset
804 lines = text.splitlines(True)
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
805 except (UnicodeError, OSError) as err:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8347
diff changeset
806 EricMessageBox.critical(
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3012
diff changeset
807 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3186
diff changeset
808 self.tr("Replace in Files"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3186
diff changeset
809 self.tr(
846
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
810 """<p>Could not read the file <b>{0}</b>."""
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
811 """ Skipping it.</p><p>Reason: {1}</p>""")
3039
8dd0165d805d Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
812 .format(fn, str(err))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
813 )
8220
006ee31b4835 Applied some more code simplifications suggested by the new Simplify checker (Y113: use enumerate()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
814 self.findProgress.setValue(index)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
815 continue
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
816
682
91114a975eda Added a check to the find and replace dialog to make sure, that no external changes were done between the find run and the replace run.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 654
diff changeset
817 # Check the original and the current hash. Skip the file,
91114a975eda Added a check to the find and replace dialog to make sure, that no external changes were done between the find run and the replace run.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 654
diff changeset
818 # if hashes are different.
5603
4f2dd0850803 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5558
diff changeset
819 if origHash != hashStr:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8347
diff changeset
820 EricMessageBox.critical(
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3012
diff changeset
821 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3186
diff changeset
822 self.tr("Replace in Files"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3186
diff changeset
823 self.tr(
846
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
824 """<p>The current and the original hash of the"""
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
825 """ file <b>{0}</b> are different. Skipping it."""
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
826 """</p><p>Hash 1: {1}</p><p>Hash 2: {2}</p>""")
5603
4f2dd0850803 Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5558
diff changeset
827 .format(fn, origHash, hashStr)
682
91114a975eda Added a check to the find and replace dialog to make sure, that no external changes were done between the find run and the replace run.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 654
diff changeset
828 )
8220
006ee31b4835 Applied some more code simplifications suggested by the new Simplify checker (Y113: use enumerate()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
829 self.findProgress.setValue(index)
682
91114a975eda Added a check to the find and replace dialog to make sure, that no external changes were done between the find run and the replace run.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 654
diff changeset
830 continue
91114a975eda Added a check to the find and replace dialog to make sure, that no external changes were done between the find run and the replace run.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 654
diff changeset
831
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
832 # replace the lines authorized by the user
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
833 for cindex in range(itm.childCount()):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
834 citm = itm.child(cindex)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7992
diff changeset
835 if citm.checkState(0) == Qt.CheckState.Checked:
7
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6
diff changeset
836 line = citm.data(0, self.lineRole)
c679fb30c8f3 Change code dealing with QVariant (and QSettings) to use the PyQt4 QVariant v2 API.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6
diff changeset
837 rline = citm.data(0, self.replaceRole)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
838 lines[line - 1] = rline
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
839
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
840 # write the file
855
d8c4113a9274 Fixed an issue of the find/replace in file dialog where a replace would change the eol as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 846
diff changeset
841 txt = "".join(lines)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
842 try:
45
9a18f4dbb493 Did a lot of encoding related stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 42
diff changeset
843 Utilities.writeEncodedFile(fn, txt, encoding)
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
844 except (OSError, Utilities.CodingError, UnicodeError) as err:
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8347
diff changeset
845 EricMessageBox.critical(
3020
542e97d4ecb3 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3012
diff changeset
846 self,
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3186
diff changeset
847 self.tr("Replace in Files"),
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3186
diff changeset
848 self.tr(
846
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
849 """<p>Could not save the file <b>{0}</b>."""
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
850 """ Skipping it.</p><p>Reason: {1}</p>""")
3039
8dd0165d805d Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
851 .format(fn, str(err))
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
852 )
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
853
8265
0090cfa83159 Converted enum names to use all uppercase letters (except for E5PathPickerModes to keep plug-ins using this compatible with previous eric releases).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8260
diff changeset
854 self.findProgress.setValue(index + 1)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
855
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
856 self.findProgressLabel.setPath("")
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
857
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
858 self.findList.clear()
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
859 self.replaceButton.setEnabled(False)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
860 self.findButton.setEnabled(True)
8809
29471a3867ac Added a 'Clear' button to the 'search in files' and 'search location' panes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8637
diff changeset
861 self.clearButton.setEnabled(False)
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
862
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
863 @pyqtSlot(QPoint)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
864 def __contextMenuRequested(self, pos):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
865 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
866 Private slot to handle the context menu request.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
867
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
868 @param pos position the context menu shall be shown
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
869 @type QPoint
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
870 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
871 menu = QMenu(self)
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
872
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3186
diff changeset
873 menu.addAction(self.tr("Open"), self.__openFile)
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3186
diff changeset
874 menu.addAction(self.tr("Copy Path to Clipboard"),
846
869c200be26e Fixed an omission in the find and replace dialog and formatted it according PEP 8.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
875 self.__copyToClipboard)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
876
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
877 menu.exec(QCursor.pos())
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
878
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
879 @pyqtSlot()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
880 def __openFile(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
881 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
882 Private slot to open the currently selected entry.
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
883 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
884 itm = self.findList.selectedItems()[0]
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
885 self.on_findList_itemDoubleClicked(itm, 0)
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
886
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
887 @pyqtSlot()
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
888 def __copyToClipboard(self):
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
889 """
8614
4a3a68e51b92 Find In Files
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
890 Private slot to copy the path of an entry to the clipboard.
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
891 """
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
892 itm = self.findList.selectedItems()[0]
8235
78e6d29eb773 Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator) (batch 3).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8220
diff changeset
893 fn = itm.parent().text(0) if itm.parent() else itm.text(0)
0
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
894
de9c2efb9d02 Started porting eric4 to Python3
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
895 cb = QApplication.clipboard()
654
72d4c6f31157 Fixed an issue in the FindFileDialog class replacing text.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 564
diff changeset
896 cb.setText(fn)

eric ide

mercurial