26 |
26 |
27 class VcsProjectBrowserHelper(QObject): |
27 class VcsProjectBrowserHelper(QObject): |
28 """ |
28 """ |
29 Class implementing the base class of the VCS project browser helper. |
29 Class implementing the base class of the VCS project browser helper. |
30 """ |
30 """ |
31 def __init__(self, vcsObject, browserObject, projectObject, isTranslationsBrowser, |
31 def __init__(self, vcsObject, browserObject, projectObject, |
32 parent=None, name=None): |
32 isTranslationsBrowser, parent=None, name=None): |
33 """ |
33 """ |
34 Constructor |
34 Constructor |
35 |
35 |
36 @param vcsObject reference to the vcs object |
36 @param vcsObject reference to the vcs object |
37 @param browserObject reference to the project browser object |
37 @param browserObject reference to the project browser object |
38 @param projectObject reference to the project object |
38 @param projectObject reference to the project object |
39 @param isTranslationsBrowser flag indicating, the helper is requested for the |
39 @param isTranslationsBrowser flag indicating, the helper is requested |
40 translations browser (this needs some special treatment) |
40 for the translations browser (this needs some special treatment) |
41 @param parent parent widget (QWidget) |
41 @param parent parent widget (QWidget) |
42 @param name name of this object (string) |
42 @param name name of this object (string) |
43 """ |
43 """ |
44 super(VcsProjectBrowserHelper, self).__init__(parent) |
44 super(VcsProjectBrowserHelper, self).__init__(parent) |
45 if name: |
45 if name: |
48 self.vcs = vcsObject |
48 self.vcs = vcsObject |
49 self.browser = browserObject |
49 self.browser = browserObject |
50 self.isTranslationsBrowser = isTranslationsBrowser |
50 self.isTranslationsBrowser = isTranslationsBrowser |
51 self.project = projectObject |
51 self.project = projectObject |
52 |
52 |
53 def addVCSMenus(self, mainMenu, multiMenu, backMenu, dirMenu, dirMultiMenu): |
53 def addVCSMenus(self, mainMenu, multiMenu, backMenu, dirMenu, |
54 """ |
54 dirMultiMenu): |
55 Public method to add the VCS entries to the various project browser menus. |
55 """ |
|
56 Public method to add the VCS entries to the various project browser |
|
57 menus. |
56 |
58 |
57 @param mainMenu reference to the main menu (QPopupMenu) |
59 @param mainMenu reference to the main menu (QPopupMenu) |
58 @param multiMenu reference to the multiple selection menu (QPopupMenu) |
60 @param multiMenu reference to the multiple selection menu (QPopupMenu) |
59 @param backMenu reference to the background menu (QPopupMenu) |
61 @param backMenu reference to the background menu (QPopupMenu) |
60 @param dirMenu reference to the directory menu (QPopupMenu) |
62 @param dirMenu reference to the directory menu (QPopupMenu) |
73 |
75 |
74 It enables/disables the VCS menu entries depending on the overall |
76 It enables/disables the VCS menu entries depending on the overall |
75 VCS status and the file status. |
77 VCS status and the file status. |
76 |
78 |
77 @param menu reference to the menu to be shown |
79 @param menu reference to the menu to be shown |
78 @param standardItems array of standard items that need activation/deactivation |
80 @param standardItems array of standard items that need |
79 depending on the overall VCS status |
81 activation/deactivation depending on the overall VCS status |
|
82 @exception RuntimeError to indicate that this method must be |
|
83 implemented by a subclass |
80 """ |
84 """ |
81 raise RuntimeError('Not implemented') |
85 raise RuntimeError('Not implemented') |
82 |
86 |
83 def showContextMenuMulti(self, menu, standardItems): |
87 def showContextMenuMulti(self, menu, standardItems): |
84 """ |
88 """ |
86 |
90 |
87 It enables/disables the VCS menu entries depending on the overall |
91 It enables/disables the VCS menu entries depending on the overall |
88 VCS status and the files status. |
92 VCS status and the files status. |
89 |
93 |
90 @param menu reference to the menu to be shown |
94 @param menu reference to the menu to be shown |
91 @param standardItems array of standard items that need activation/deactivation |
95 @param standardItems array of standard items that need |
92 depending on the overall VCS status |
96 activation/deactivation depending on the overall VCS status |
|
97 @exception RuntimeError to indicate that this method must be |
|
98 implemented by a subclass |
93 """ |
99 """ |
94 raise RuntimeError('Not implemented') |
100 raise RuntimeError('Not implemented') |
95 |
101 |
96 def showContextMenuDir(self, menu, standardItems): |
102 def showContextMenuDir(self, menu, standardItems): |
97 """ |
103 """ |
99 |
105 |
100 It enables/disables the VCS menu entries depending on the overall |
106 It enables/disables the VCS menu entries depending on the overall |
101 VCS status and the directory status. |
107 VCS status and the directory status. |
102 |
108 |
103 @param menu reference to the menu to be shown |
109 @param menu reference to the menu to be shown |
104 @param standardItems array of standard items that need activation/deactivation |
110 @param standardItems array of standard items that |
105 depending on the overall VCS status |
111 need activation/deactivation depending on the overall VCS status |
|
112 @exception RuntimeError to indicate that this method must be |
|
113 implemented by a subclass |
106 """ |
114 """ |
107 raise RuntimeError('Not implemented') |
115 raise RuntimeError('Not implemented') |
108 |
116 |
109 def showContextMenuDirMulti(self, menu, standardItems): |
117 def showContextMenuDirMulti(self, menu, standardItems): |
110 """ |
118 """ |
112 |
120 |
113 It enables/disables the VCS menu entries depending on the overall |
121 It enables/disables the VCS menu entries depending on the overall |
114 VCS status and the directory status. |
122 VCS status and the directory status. |
115 |
123 |
116 @param menu reference to the menu to be shown |
124 @param menu reference to the menu to be shown |
117 @param standardItems array of standard items that need activation/deactivation |
125 @param standardItems array of standard items that need |
118 depending on the overall VCS status |
126 activation/deactivation depending on the overall VCS status |
|
127 @exception RuntimeError to indicate that this method must be |
|
128 implemented by a subclass |
119 """ |
129 """ |
120 raise RuntimeError('Not implemented') |
130 raise RuntimeError('Not implemented') |
121 |
131 |
122 ############################################################################ |
132 ########################################################################### |
123 ## General menu handling methods below |
133 ## General menu handling methods below |
124 ############################################################################ |
134 ########################################################################### |
125 |
135 |
126 def _VCSUpdate(self): |
136 def _VCSUpdate(self): |
127 """ |
137 """ |
128 Protected slot called by the context menu to update a file from the |
138 Protected slot called by the context menu to update a file from the |
129 VCS repository. |
139 VCS repository. |
130 """ |
140 """ |
131 if self.isTranslationsBrowser: |
141 if self.isTranslationsBrowser: |
132 names = [itm.dirName() \ |
142 names = [itm.dirName() |
133 for itm in self.browser.getSelectedItems( |
143 for itm in self.browser.getSelectedItems( |
134 [ProjectBrowserSimpleDirectoryItem])] |
144 [ProjectBrowserSimpleDirectoryItem])] |
135 if not names: |
145 if not names: |
136 names = [itm.fileName() \ |
146 names = [itm.fileName() |
137 for itm in self.browser.getSelectedItems([ProjectBrowserFileItem])] |
147 for itm in self.browser.getSelectedItems( |
|
148 [ProjectBrowserFileItem])] |
138 else: |
149 else: |
139 names = [] |
150 names = [] |
140 for itm in self.browser.getSelectedItems(): |
151 for itm in self.browser.getSelectedItems(): |
141 try: |
152 try: |
142 name = itm.fileName() |
153 name = itm.fileName() |
149 """ |
160 """ |
150 Protected slot called by the context menu to commit the changes to the |
161 Protected slot called by the context menu to commit the changes to the |
151 VCS repository. |
162 VCS repository. |
152 """ |
163 """ |
153 if self.isTranslationsBrowser: |
164 if self.isTranslationsBrowser: |
154 names = [itm.dirName() \ |
165 names = [itm.dirName() |
155 for itm in self.browser.getSelectedItems( |
166 for itm in self.browser.getSelectedItems( |
156 [ProjectBrowserSimpleDirectoryItem])] |
167 [ProjectBrowserSimpleDirectoryItem])] |
157 if not names: |
168 if not names: |
158 names = [itm.fileName() \ |
169 names = [itm.fileName() |
159 for itm in self.browser.getSelectedItems([ProjectBrowserFileItem])] |
170 for itm in self.browser.getSelectedItems( |
|
171 [ProjectBrowserFileItem])] |
160 else: |
172 else: |
161 names = [] |
173 names = [] |
162 for itm in self.browser.getSelectedItems(): |
174 for itm in self.browser.getSelectedItems(): |
163 try: |
175 try: |
164 name = itm.fileName() |
176 name = itm.fileName() |
171 vm.saveEditor(name) |
183 vm.saveEditor(name) |
172 self.vcs.vcsCommit(names, '') |
184 self.vcs.vcsCommit(names, '') |
173 |
185 |
174 def _VCSAdd(self): |
186 def _VCSAdd(self): |
175 """ |
187 """ |
176 Protected slot called by the context menu to add the selected file to the |
188 Protected slot called by the context menu to add the selected file to |
177 VCS repository. |
189 the VCS repository. |
178 """ |
190 """ |
179 if self.isTranslationsBrowser: |
191 if self.isTranslationsBrowser: |
180 items = self.browser.getSelectedItems([ProjectBrowserSimpleDirectoryItem]) |
192 items = self.browser.getSelectedItems( |
|
193 [ProjectBrowserSimpleDirectoryItem]) |
181 if items: |
194 if items: |
182 names = [itm.dirName() for itm in items] |
195 names = [itm.dirName() for itm in items] |
183 qnames = [] |
196 qnames = [] |
184 else: |
197 else: |
185 items = self.browser.getSelectedItems([ProjectBrowserFileItem]) |
198 items = self.browser.getSelectedItems([ProjectBrowserFileItem]) |
240 for fn in names: |
253 for fn in names: |
241 self._updateVCSStatus(fn) |
254 self._updateVCSStatus(fn) |
242 |
255 |
243 def _VCSRemove(self): |
256 def _VCSRemove(self): |
244 """ |
257 """ |
245 Protected slot called by the context menu to remove the selected file from the |
258 Protected slot called by the context menu to remove the selected file |
246 VCS repository. |
259 from the VCS repository. |
247 """ |
260 """ |
248 if self.isTranslationsBrowser: |
261 if self.isTranslationsBrowser: |
249 items = self.browser.getSelectedItems([ProjectBrowserSimpleDirectoryItem]) |
262 items = self.browser.getSelectedItems( |
|
263 [ProjectBrowserSimpleDirectoryItem]) |
250 if items: |
264 if items: |
251 return # not supported |
265 return # not supported |
252 |
266 |
253 isRemoveDirs = False |
267 isRemoveDirs = False |
254 items = self.browser.getSelectedItems([ProjectBrowserFileItem]) |
268 items = self.browser.getSelectedItems([ProjectBrowserFileItem]) |
255 names = [itm.fileName() for itm in items] |
269 names = [itm.fileName() for itm in items] |
256 |
270 |
257 dlg = DeleteFilesConfirmationDialog(self.parent(), |
271 dlg = DeleteFilesConfirmationDialog(self.parent(), |
258 self.trUtf8("Remove from repository (and disk)"), |
272 self.trUtf8("Remove from repository (and disk)"), |
259 self.trUtf8("Do you really want to remove these translation files from" |
273 self.trUtf8( |
|
274 "Do you really want to remove these translation files from" |
260 " the repository (and disk)?"), |
275 " the repository (and disk)?"), |
261 names) |
276 names) |
262 else: |
277 else: |
263 items = self.browser.getSelectedItems() |
278 items = self.browser.getSelectedItems() |
264 isRemoveDirs = len(items) == \ |
279 isRemoveDirs = len(items) == \ |
265 self.browser.getSelectedItemsCount( |
280 self.browser.getSelectedItemsCount( |
266 [ProjectBrowserSimpleDirectoryItem, ProjectBrowserDirectoryItem]) |
281 [ProjectBrowserSimpleDirectoryItem, |
|
282 ProjectBrowserDirectoryItem]) |
267 if isRemoveDirs: |
283 if isRemoveDirs: |
268 names = [itm.dirName() for itm in items] |
284 names = [itm.dirName() for itm in items] |
269 else: |
285 else: |
270 names = [itm.fileName() for itm in items] |
286 names = [itm.fileName() for itm in items] |
271 files = [self.browser.project.getRelativePath(name) \ |
287 files = [self.browser.project.getRelativePath(name) \ |
272 for name in names] |
288 for name in names] |
273 |
289 |
274 dlg = DeleteFilesConfirmationDialog(self.parent(), |
290 dlg = DeleteFilesConfirmationDialog(self.parent(), |
275 self.trUtf8("Remove from repository (and disk)"), |
291 self.trUtf8("Remove from repository (and disk)"), |
276 self.trUtf8("Do you really want to remove these files/directories" |
292 self.trUtf8( |
|
293 "Do you really want to remove these files/directories" |
277 " from the repository (and disk)?"), |
294 " from the repository (and disk)?"), |
278 files) |
295 files) |
279 |
296 |
280 if dlg.exec_() == QDialog.Accepted: |
297 if dlg.exec_() == QDialog.Accepted: |
281 status = self.vcs.vcsRemove(names) |
298 status = self.vcs.vcsRemove(names) |
282 if status: |
299 if status: |
283 if isRemoveDirs: |
300 if isRemoveDirs: |
284 self.browser._removeDir() # remove directories from Project |
301 self.browser._removeDir() # remove directories from |
|
302 # Project |
285 else: |
303 else: |
286 self.browser._removeFile() # remove file(s) from project |
304 self.browser._removeFile() # remove file(s) from project |
287 |
305 |
288 def _VCSLog(self): |
306 def _VCSLog(self): |
289 """ |
307 """ |
290 Protected slot called by the context menu to show the VCS log of a file/directory. |
308 Protected slot called by the context menu to show the VCS log of a |
|
309 file/directory. |
291 """ |
310 """ |
292 itm = self.browser.currentItem() |
311 itm = self.browser.currentItem() |
293 try: |
312 try: |
294 fn = itm.fileName() |
313 fn = itm.fileName() |
295 except AttributeError: |
314 except AttributeError: |
313 def _VCSStatus(self): |
332 def _VCSStatus(self): |
314 """ |
333 """ |
315 Protected slot called by the context menu to show the status of a file. |
334 Protected slot called by the context menu to show the status of a file. |
316 """ |
335 """ |
317 if self.isTranslationsBrowser: |
336 if self.isTranslationsBrowser: |
318 items = self.browser.getSelectedItems([ProjectBrowserSimpleDirectoryItem]) |
337 items = self.browser.getSelectedItems( |
|
338 [ProjectBrowserSimpleDirectoryItem]) |
319 if items: |
339 if items: |
320 names = [itm.dirName() for itm in items] |
340 names = [itm.dirName() for itm in items] |
321 else: |
341 else: |
322 items = self.browser.getSelectedItems([ProjectBrowserFileItem]) |
342 items = self.browser.getSelectedItems([ProjectBrowserFileItem]) |
323 names = [itm.fileName() for itm in items] |
343 names = [itm.fileName() for itm in items] |