25 def __init__(self, pro, parent=None, fileTypeFilter=None, name=None, 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 @type Project |
31 @param fileTypeFilter filter specification for the file to add (string) |
31 @param parent parent widget of this dialog |
32 @param name name of this dialog (string) |
32 @type QWidget |
|
33 @param fileTypeFilter filter specification for the file to add |
|
34 @type str |
|
35 @param name name of this dialog |
|
36 @type str |
33 @param startdir start directory for the selection dialog |
37 @param startdir start directory for the selection dialog |
|
38 @type str |
34 """ |
39 """ |
35 super().__init__(parent) |
40 super().__init__(parent) |
36 if name: |
41 if name: |
37 self.setObjectName(name) |
42 self.setObjectName(name) |
38 self.setupUi(self) |
43 self.setupUi(self) |
42 self.targetDirPicker.setDefaultDirectory(startdir) |
47 self.targetDirPicker.setDefaultDirectory(startdir) |
43 |
48 |
44 if startdir: |
49 if startdir: |
45 self.targetDirPicker.setText(startdir) |
50 self.targetDirPicker.setText(startdir) |
46 else: |
51 else: |
47 self.targetDirPicker.setText(pro.ppath) |
52 self.targetDirPicker.setText(pro.getProjectPath()) |
48 self.fileTypeFilter = fileTypeFilter |
53 self.fileTypeFilter = fileTypeFilter |
49 self.ppath = pro.ppath |
54 self.__project = pro |
50 self.startdir = startdir |
55 self.startdir = startdir |
51 self.filetypes = pro.getProjectData(dataKey="FILETYPES") |
|
52 # save a reference to the filetypes dict |
|
53 |
56 |
54 if self.fileTypeFilter is not None: |
57 if self.fileTypeFilter is not None: |
55 self.sourcecodeCheckBox.hide() |
58 self.sourcecodeCheckBox.hide() |
56 |
59 |
57 msh = self.minimumSizeHint() |
60 msh = self.minimumSizeHint() |
66 path = self.targetDirPicker.text() |
69 path = self.targetDirPicker.text() |
67 if not path: |
70 if not path: |
68 path = self.startdir |
71 path = self.startdir |
69 self.sourceFilesPicker.setDefaultDirectory(path) |
72 self.sourceFilesPicker.setDefaultDirectory(path) |
70 |
73 |
|
74 caption = self.tr("Select Files") |
71 if self.fileTypeFilter is None: |
75 if self.fileTypeFilter is None: |
72 patterns = { |
76 dfilter = self.__project.getFileCategoryFilterString(withAll=True) |
73 "SOURCES": [], |
77 elif ( |
74 "FORMS": [], |
78 self.fileTypeFilter != "OTHERS" |
75 "RESOURCES": [], |
79 and self.fileTypeFilter in self.__project.getFileCategories() |
76 "INTERFACES": [], |
80 ): |
77 "PROTOCOLS": [], |
81 dfilter = self.__project.getFileCategoryFilterString( |
78 "TRANSLATIONS": [], |
82 [self.fileTypeFilter], withAll=False |
79 } |
|
80 for pattern, filetype in list(self.filetypes.items()): |
|
81 if filetype in patterns: |
|
82 patterns[filetype].append(pattern) |
|
83 dfilter = self.tr( |
|
84 "Source Files ({0});;" |
|
85 "Forms Files ({1});;" |
|
86 "Resource Files ({2});;" |
|
87 "Interface Files ({3});;" |
|
88 "Protocol Files ({4});;" |
|
89 "Translation Files ({5});;" |
|
90 "All Files (*)" |
|
91 ).format( |
|
92 " ".join(patterns["SOURCES"]), |
|
93 " ".join(patterns["FORMS"]), |
|
94 " ".join(patterns["RESOURCES"]), |
|
95 " ".join(patterns["INTERFACES"]), |
|
96 " ".join(patterns["PROTOCOLS"]), |
|
97 " ".join(patterns["TRANSLATIONS"]), |
|
98 ) |
83 ) |
99 caption = self.tr("Select Files") |
84 elif self.fileTypeFilter == "OTHERS": |
100 elif self.fileTypeFilter == "form": |
|
101 patterns = [] |
|
102 for pattern, filetype in list(self.filetypes.items()): |
|
103 if filetype == "FORMS": |
|
104 patterns.append(pattern) |
|
105 dfilter = self.tr("Forms Files ({0})").format(" ".join(patterns)) |
|
106 caption = self.tr("Select user-interface files") |
|
107 elif self.fileTypeFilter == "resource": |
|
108 patterns = [] |
|
109 for pattern, filetype in list(self.filetypes.items()): |
|
110 if filetype == "RESOURCES": |
|
111 patterns.append(pattern) |
|
112 dfilter = self.tr("Resource Files ({0})").format(" ".join(patterns)) |
|
113 caption = self.tr("Select resource files") |
|
114 elif self.fileTypeFilter == "source": |
|
115 patterns = [] |
|
116 for pattern, filetype in list(self.filetypes.items()): |
|
117 if filetype == "SOURCES": |
|
118 patterns.append(pattern) |
|
119 dfilter = self.tr("Source Files ({0});;All Files (*)").format( |
|
120 " ".join(patterns) |
|
121 ) |
|
122 caption = self.tr("Select source files") |
|
123 elif self.fileTypeFilter == "interface": |
|
124 patterns = [] |
|
125 for pattern, filetype in list(self.filetypes.items()): |
|
126 if filetype == "INTERFACES": |
|
127 patterns.append(pattern) |
|
128 dfilter = self.tr("Interface Files ({0})").format(" ".join(patterns)) |
|
129 caption = self.tr("Select interface files") |
|
130 elif self.fileTypeFilter == "protocol": |
|
131 patterns = [] |
|
132 for pattern, filetype in list(self.filetypes.items()): |
|
133 if filetype == "PROTOCOLS": |
|
134 patterns.append(pattern) |
|
135 dfilter = self.tr("Protocol Files ({0})").format(" ".join(patterns)) |
|
136 caption = self.tr("Select protocol files") |
|
137 elif self.fileTypeFilter == "translation": |
|
138 patterns = [] |
|
139 for pattern, filetype in list(self.filetypes.items()): |
|
140 if filetype == "TRANSLATIONS": |
|
141 patterns.append(pattern) |
|
142 dfilter = self.tr("Translation Files ({0})").format(" ".join(patterns)) |
|
143 caption = self.tr("Select translation files") |
|
144 elif self.fileTypeFilter == "others": |
|
145 dfilter = self.tr("All Files (*)") |
85 dfilter = self.tr("All Files (*)") |
146 caption = self.tr("Select files") |
|
147 else: |
86 else: |
148 dfilter = "" |
87 dfilter = "" |
149 caption = "" |
88 caption = "" |
150 |
89 |
151 self.sourceFilesPicker.setWindowTitle(caption) |
90 self.sourceFilesPicker.setWindowTitle(caption) |
159 If the entered source directory is a subdirectory of the current |
98 If the entered source directory is a subdirectory of the current |
160 projects main directory, the target directory path is synchronized. |
99 projects main directory, the target directory path is synchronized. |
161 It is assumed, that the user wants to add a bunch of files to |
100 It is assumed, that the user wants to add a bunch of files to |
162 the project in place. |
101 the project in place. |
163 |
102 |
164 @param sfile the text of the source file picker (string) |
103 @param sfile the text of the source file picker |
|
104 @type str |
165 """ |
105 """ |
166 sfile = str(self.sourceFilesPicker.firstPath()) |
106 sfile = str(self.sourceFilesPicker.firstPath()) |
167 if sfile.startswith(self.ppath): |
107 if sfile.startswith(self.__project.getProjectPath()): |
168 if os.path.isdir(sfile): |
108 if os.path.isdir(sfile): |
169 directory = sfile |
109 directory = sfile |
170 else: |
110 else: |
171 directory = os.path.dirname(sfile) |
111 directory = os.path.dirname(sfile) |
172 self.targetDirPicker.setText(directory) |
112 self.targetDirPicker.setText(directory) |
173 |
113 |
174 def getData(self): |
114 def getData(self): |
175 """ |
115 """ |
176 Public slot to retrieve the dialogs data. |
116 Public slot to retrieve the dialogs data. |
177 |
117 |
178 @return tuple of three values (list of string, string, boolean) |
118 @return tuple containing the source files, the target directory and a flag |
179 giving the source files, the target directory and a flag |
|
180 telling, whether the files shall be added as source code |
119 telling, whether the files shall be added as source code |
|
120 @rtype tuple of (list of string, string, boolean) |
181 """ |
121 """ |
182 return ( |
122 return ( |
183 [str(p) for p in self.sourceFilesPicker.paths()], |
123 [str(p) for p in self.sourceFilesPicker.paths()], |
184 self.targetDirPicker.text(), |
124 self.targetDirPicker.text(), |
185 self.sourcecodeCheckBox.isChecked(), |
125 self.sourcecodeCheckBox.isChecked(), |