src/eric7/Project/AddFileDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9256
67603066f0a6
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
19 19
20 class AddFileDialog(QDialog, Ui_AddFileDialog): 20 class AddFileDialog(QDialog, Ui_AddFileDialog):
21 """ 21 """
22 Class implementing a dialog to add a file to the project. 22 Class implementing a dialog to add a file to the project.
23 """ 23 """
24 def __init__(self, pro, parent=None, fileTypeFilter=None, name=None, 24
25 startdir=None): 25 def __init__(self, pro, parent=None, fileTypeFilter=None, name=None, startdir=None):
26 """ 26 """
27 Constructor 27 Constructor
28 28
29 @param pro reference to the project object 29 @param pro reference to the project object
30 @param parent parent widget of this dialog (QWidget) 30 @param parent parent widget of this dialog (QWidget)
31 @param fileTypeFilter filter specification for the file to add (string) 31 @param fileTypeFilter filter specification for the file to add (string)
32 @param name name of this dialog (string) 32 @param name name of this dialog (string)
33 @param startdir start directory for the selection dialog 33 @param startdir start directory for the selection dialog
34 """ 34 """
35 super().__init__(parent) 35 super().__init__(parent)
36 if name: 36 if name:
37 self.setObjectName(name) 37 self.setObjectName(name)
38 self.setupUi(self) 38 self.setupUi(self)
39 39
40 self.sourceFilesPicker.setMode(EricPathPickerModes.OPEN_FILES_MODE) 40 self.sourceFilesPicker.setMode(EricPathPickerModes.OPEN_FILES_MODE)
41 self.targetDirPicker.setMode(EricPathPickerModes.DIRECTORY_MODE) 41 self.targetDirPicker.setMode(EricPathPickerModes.DIRECTORY_MODE)
42 self.targetDirPicker.setDefaultDirectory(startdir) 42 self.targetDirPicker.setDefaultDirectory(startdir)
43 43
44 self.targetDirPicker.setText(pro.ppath) 44 self.targetDirPicker.setText(pro.ppath)
45 self.fileTypeFilter = fileTypeFilter 45 self.fileTypeFilter = fileTypeFilter
46 self.ppath = pro.ppath 46 self.ppath = pro.ppath
47 self.startdir = startdir 47 self.startdir = startdir
48 self.filetypes = pro.pdata["FILETYPES"] 48 self.filetypes = pro.pdata["FILETYPES"]
49 # save a reference to the filetypes dict 49 # save a reference to the filetypes dict
50 50
51 if self.fileTypeFilter is not None: 51 if self.fileTypeFilter is not None:
52 self.sourcecodeCheckBox.hide() 52 self.sourcecodeCheckBox.hide()
53 53
54 msh = self.minimumSizeHint() 54 msh = self.minimumSizeHint()
55 self.resize(max(self.width(), msh.width()), msh.height()) 55 self.resize(max(self.width(), msh.width()), msh.height())
56 56
57 @pyqtSlot() 57 @pyqtSlot()
58 def on_sourceFilesPicker_aboutToShowPathPickerDialog(self): 58 def on_sourceFilesPicker_aboutToShowPathPickerDialog(self):
59 """ 59 """
60 Private slot to perform actions before the source files selection 60 Private slot to perform actions before the source files selection
61 dialog is shown. 61 dialog is shown.
62 """ 62 """
63 path = self.targetDirPicker.text() 63 path = self.targetDirPicker.text()
64 if not path: 64 if not path:
65 path = self.startdir 65 path = self.startdir
66 self.sourceFilesPicker.setDefaultDirectory(path) 66 self.sourceFilesPicker.setDefaultDirectory(path)
67 67
68 if self.fileTypeFilter is None: 68 if self.fileTypeFilter is None:
69 patterns = { 69 patterns = {
70 "SOURCES": [], 70 "SOURCES": [],
71 "FORMS": [], 71 "FORMS": [],
72 "RESOURCES": [], 72 "RESOURCES": [],
89 " ".join(patterns["SOURCES"]), 89 " ".join(patterns["SOURCES"]),
90 " ".join(patterns["FORMS"]), 90 " ".join(patterns["FORMS"]),
91 " ".join(patterns["RESOURCES"]), 91 " ".join(patterns["RESOURCES"]),
92 " ".join(patterns["INTERFACES"]), 92 " ".join(patterns["INTERFACES"]),
93 " ".join(patterns["PROTOCOLS"]), 93 " ".join(patterns["PROTOCOLS"]),
94 " ".join(patterns["TRANSLATIONS"]) 94 " ".join(patterns["TRANSLATIONS"]),
95 ) 95 )
96 caption = self.tr("Select Files") 96 caption = self.tr("Select Files")
97 elif self.fileTypeFilter == 'form': 97 elif self.fileTypeFilter == "form":
98 patterns = [] 98 patterns = []
99 for pattern, filetype in list(self.filetypes.items()): 99 for pattern, filetype in list(self.filetypes.items()):
100 if filetype == "FORMS": 100 if filetype == "FORMS":
101 patterns.append(pattern) 101 patterns.append(pattern)
102 dfilter = self.tr("Forms Files ({0})").format( 102 dfilter = self.tr("Forms Files ({0})").format(" ".join(patterns))
103 " ".join(patterns))
104 caption = self.tr("Select user-interface files") 103 caption = self.tr("Select user-interface files")
105 elif self.fileTypeFilter == "resource": 104 elif self.fileTypeFilter == "resource":
106 patterns = [] 105 patterns = []
107 for pattern, filetype in list(self.filetypes.items()): 106 for pattern, filetype in list(self.filetypes.items()):
108 if filetype == "RESOURCES": 107 if filetype == "RESOURCES":
109 patterns.append(pattern) 108 patterns.append(pattern)
110 dfilter = self.tr("Resource Files ({0})").format( 109 dfilter = self.tr("Resource Files ({0})").format(" ".join(patterns))
111 " ".join(patterns))
112 caption = self.tr("Select resource files") 110 caption = self.tr("Select resource files")
113 elif self.fileTypeFilter == 'source': 111 elif self.fileTypeFilter == "source":
114 patterns = [] 112 patterns = []
115 for pattern, filetype in list(self.filetypes.items()): 113 for pattern, filetype in list(self.filetypes.items()):
116 if filetype == "SOURCES": 114 if filetype == "SOURCES":
117 patterns.append(pattern) 115 patterns.append(pattern)
118 dfilter = self.tr("Source Files ({0});;All Files (*)").format( 116 dfilter = self.tr("Source Files ({0});;All Files (*)").format(
119 " ".join(patterns)) 117 " ".join(patterns)
118 )
120 caption = self.tr("Select source files") 119 caption = self.tr("Select source files")
121 elif self.fileTypeFilter == 'interface': 120 elif self.fileTypeFilter == "interface":
122 patterns = [] 121 patterns = []
123 for pattern, filetype in list(self.filetypes.items()): 122 for pattern, filetype in list(self.filetypes.items()):
124 if filetype == "INTERFACES": 123 if filetype == "INTERFACES":
125 patterns.append(pattern) 124 patterns.append(pattern)
126 dfilter = self.tr("Interface Files ({0})").format( 125 dfilter = self.tr("Interface Files ({0})").format(" ".join(patterns))
127 " ".join(patterns))
128 caption = self.tr("Select interface files") 126 caption = self.tr("Select interface files")
129 elif self.fileTypeFilter == 'protocol': 127 elif self.fileTypeFilter == "protocol":
130 patterns = [] 128 patterns = []
131 for pattern, filetype in list(self.filetypes.items()): 129 for pattern, filetype in list(self.filetypes.items()):
132 if filetype == "PROTOCOLS": 130 if filetype == "PROTOCOLS":
133 patterns.append(pattern) 131 patterns.append(pattern)
134 dfilter = self.tr("Protocol Files ({0})").format( 132 dfilter = self.tr("Protocol Files ({0})").format(" ".join(patterns))
135 " ".join(patterns))
136 caption = self.tr("Select protocol files") 133 caption = self.tr("Select protocol files")
137 elif self.fileTypeFilter == 'translation': 134 elif self.fileTypeFilter == "translation":
138 patterns = [] 135 patterns = []
139 for pattern, filetype in list(self.filetypes.items()): 136 for pattern, filetype in list(self.filetypes.items()):
140 if filetype == "TRANSLATIONS": 137 if filetype == "TRANSLATIONS":
141 patterns.append(pattern) 138 patterns.append(pattern)
142 dfilter = self.tr("Translation Files ({0})").format( 139 dfilter = self.tr("Translation Files ({0})").format(" ".join(patterns))
143 " ".join(patterns))
144 caption = self.tr("Select translation files") 140 caption = self.tr("Select translation files")
145 elif self.fileTypeFilter == 'others': 141 elif self.fileTypeFilter == "others":
146 dfilter = self.tr("All Files (*)") 142 dfilter = self.tr("All Files (*)")
147 caption = self.tr("Select files") 143 caption = self.tr("Select files")
148 else: 144 else:
149 dfilter = "" 145 dfilter = ""
150 caption = "" 146 caption = ""
151 147
152 self.sourceFilesPicker.setWindowTitle(caption) 148 self.sourceFilesPicker.setWindowTitle(caption)
153 self.sourceFilesPicker.setFilters(dfilter) 149 self.sourceFilesPicker.setFilters(dfilter)
154 150
155 @pyqtSlot(str) 151 @pyqtSlot(str)
156 def on_sourceFilesPicker_textChanged(self, sfile): 152 def on_sourceFilesPicker_textChanged(self, sfile):
157 """ 153 """
158 Private slot to handle the source file text changed. 154 Private slot to handle the source file text changed.
159 155
160 If the entered source directory is a subdirectory of the current 156 If the entered source directory is a subdirectory of the current
161 projects main directory, the target directory path is synchronized. 157 projects main directory, the target directory path is synchronized.
162 It is assumed, that the user wants to add a bunch of files to 158 It is assumed, that the user wants to add a bunch of files to
163 the project in place. 159 the project in place.
164 160
165 @param sfile the text of the source file picker (string) 161 @param sfile the text of the source file picker (string)
166 """ 162 """
167 sfile = self.sourceFilesPicker.firstPath() 163 sfile = self.sourceFilesPicker.firstPath()
168 if sfile.startswith(self.ppath): 164 if sfile.startswith(self.ppath):
169 if os.path.isdir(sfile): 165 if os.path.isdir(sfile):
170 directory = sfile 166 directory = sfile
171 else: 167 else:
172 directory = os.path.dirname(sfile) 168 directory = os.path.dirname(sfile)
173 self.targetDirPicker.setText(directory) 169 self.targetDirPicker.setText(directory)
174 170
175 def getData(self): 171 def getData(self):
176 """ 172 """
177 Public slot to retrieve the dialogs data. 173 Public slot to retrieve the dialogs data.
178 174
179 @return tuple of three values (list of string, string, boolean) 175 @return tuple of three values (list of string, string, boolean)
180 giving the source files, the target directory and a flag 176 giving the source files, the target directory and a flag
181 telling, whether the files shall be added as source code 177 telling, whether the files shall be added as source code
182 """ 178 """
183 return ( 179 return (
184 self.sourceFilesPicker.paths(), 180 self.sourceFilesPicker.paths(),
185 self.targetDirPicker.text(), 181 self.targetDirPicker.text(),
186 self.sourcecodeCheckBox.isChecked()) 182 self.sourcecodeCheckBox.isChecked(),
183 )

eric ide

mercurial