|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2005 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the VCS project browser helper for subversion. |
|
8 """ |
|
9 |
|
10 import os |
|
11 from PyQt5.QtWidgets import QMenu |
|
12 |
|
13 from E5Gui.E5Application import e5App |
|
14 |
|
15 from VCS.ProjectBrowserHelper import VcsProjectBrowserHelper |
|
16 |
|
17 from Project.ProjectBrowserModel import ProjectBrowserFileItem |
|
18 |
|
19 import UI.PixmapCache |
|
20 |
|
21 |
|
22 class SvnProjectBrowserHelper(VcsProjectBrowserHelper): |
|
23 """ |
|
24 Class implementing the VCS project browser helper for subversion. |
|
25 """ |
|
26 def __init__(self, vcsObject, browserObject, projectObject, |
|
27 isTranslationsBrowser, parent=None, name=None): |
|
28 """ |
|
29 Constructor |
|
30 |
|
31 @param vcsObject reference to the vcs object |
|
32 @param browserObject reference to the project browser object |
|
33 @param projectObject reference to the project object |
|
34 @param isTranslationsBrowser flag indicating, the helper is requested |
|
35 for the translations browser (this needs some special treatment) |
|
36 @param parent parent widget (QWidget) |
|
37 @param name name of this object (string) |
|
38 """ |
|
39 VcsProjectBrowserHelper.__init__(self, vcsObject, browserObject, |
|
40 projectObject, isTranslationsBrowser, |
|
41 parent, name) |
|
42 |
|
43 def showContextMenu(self, menu, standardItems): |
|
44 """ |
|
45 Public slot called before the context menu is shown. |
|
46 |
|
47 It enables/disables the VCS menu entries depending on the overall |
|
48 VCS status and the file status. |
|
49 |
|
50 @param menu reference to the menu to be shown |
|
51 @param standardItems array of standard items that need |
|
52 activation/deactivation depending on the overall VCS status |
|
53 """ |
|
54 if self.browser.currentItem().data(1) == self.vcs.vcsName(): |
|
55 for act in self.vcsMenuActions: |
|
56 act.setEnabled(True) |
|
57 for act in self.vcsAddMenuActions: |
|
58 act.setEnabled(False) |
|
59 for act in standardItems: |
|
60 act.setEnabled(False) |
|
61 if not hasattr(self.browser.currentItem(), 'fileName'): |
|
62 self.blameAct.setEnabled(False) |
|
63 else: |
|
64 for act in self.vcsMenuActions: |
|
65 act.setEnabled(False) |
|
66 for act in self.vcsAddMenuActions: |
|
67 act.setEnabled(True) |
|
68 if 1 in self.browser.specialMenuEntries: |
|
69 try: |
|
70 name = self.browser.currentItem().fileName() |
|
71 except AttributeError: |
|
72 name = self.browser.currentItem().dirName() |
|
73 if not os.path.isdir(name): |
|
74 self.vcsMenuAddTree.setEnabled(False) |
|
75 for act in standardItems: |
|
76 act.setEnabled(True) |
|
77 |
|
78 def showContextMenuMulti(self, menu, standardItems): |
|
79 """ |
|
80 Public slot called before the context menu (multiple selections) is |
|
81 shown. |
|
82 |
|
83 It enables/disables the VCS menu entries depending on the overall |
|
84 VCS status and the files status. |
|
85 |
|
86 @param menu reference to the menu to be shown |
|
87 @param standardItems array of standard items that need |
|
88 activation/deactivation depending on the overall VCS status |
|
89 """ |
|
90 vcsName = self.vcs.vcsName() |
|
91 items = self.browser.getSelectedItems() |
|
92 vcsItems = 0 |
|
93 # determine number of selected items under VCS control |
|
94 for itm in items: |
|
95 if itm.data(1) == vcsName: |
|
96 vcsItems += 1 |
|
97 |
|
98 if vcsItems > 0: |
|
99 if vcsItems != len(items): |
|
100 for act in self.vcsMultiMenuActions: |
|
101 act.setEnabled(False) |
|
102 else: |
|
103 for act in self.vcsMultiMenuActions: |
|
104 act.setEnabled(True) |
|
105 for act in self.vcsAddMultiMenuActions: |
|
106 act.setEnabled(False) |
|
107 for act in standardItems: |
|
108 act.setEnabled(False) |
|
109 else: |
|
110 for act in self.vcsMultiMenuActions: |
|
111 act.setEnabled(False) |
|
112 for act in self.vcsAddMultiMenuActions: |
|
113 act.setEnabled(True) |
|
114 if ( |
|
115 1 in self.browser.specialMenuEntries and |
|
116 self.__itemsHaveFiles(items) |
|
117 ): |
|
118 self.vcsMultiMenuAddTree.setEnabled(False) |
|
119 for act in standardItems: |
|
120 act.setEnabled(True) |
|
121 |
|
122 def showContextMenuDir(self, menu, standardItems): |
|
123 """ |
|
124 Public slot called before the context menu is shown. |
|
125 |
|
126 It enables/disables the VCS menu entries depending on the overall |
|
127 VCS status and the directory status. |
|
128 |
|
129 @param menu reference to the menu to be shown |
|
130 @param standardItems array of standard items that need |
|
131 activation/deactivation depending on the overall VCS status |
|
132 """ |
|
133 if self.browser.currentItem().data(1) == self.vcs.vcsName(): |
|
134 for act in self.vcsDirMenuActions: |
|
135 act.setEnabled(True) |
|
136 for act in self.vcsAddDirMenuActions: |
|
137 act.setEnabled(False) |
|
138 for act in standardItems: |
|
139 act.setEnabled(False) |
|
140 else: |
|
141 for act in self.vcsDirMenuActions: |
|
142 act.setEnabled(False) |
|
143 for act in self.vcsAddDirMenuActions: |
|
144 act.setEnabled(True) |
|
145 for act in standardItems: |
|
146 act.setEnabled(True) |
|
147 |
|
148 def showContextMenuDirMulti(self, menu, standardItems): |
|
149 """ |
|
150 Public slot called before the context menu is shown. |
|
151 |
|
152 It enables/disables the VCS menu entries depending on the overall |
|
153 VCS status and the directory status. |
|
154 |
|
155 @param menu reference to the menu to be shown |
|
156 @param standardItems array of standard items that need |
|
157 activation/deactivation depending on the overall VCS status |
|
158 """ |
|
159 vcsName = self.vcs.vcsName() |
|
160 items = self.browser.getSelectedItems() |
|
161 vcsItems = 0 |
|
162 # determine number of selected items under VCS control |
|
163 for itm in items: |
|
164 if itm.data(1) == vcsName: |
|
165 vcsItems += 1 |
|
166 |
|
167 if vcsItems > 0: |
|
168 if vcsItems != len(items): |
|
169 for act in self.vcsDirMultiMenuActions: |
|
170 act.setEnabled(False) |
|
171 else: |
|
172 for act in self.vcsDirMultiMenuActions: |
|
173 act.setEnabled(True) |
|
174 for act in self.vcsAddDirMultiMenuActions: |
|
175 act.setEnabled(False) |
|
176 for act in standardItems: |
|
177 act.setEnabled(False) |
|
178 else: |
|
179 for act in self.vcsDirMultiMenuActions: |
|
180 act.setEnabled(False) |
|
181 for act in self.vcsAddDirMultiMenuActions: |
|
182 act.setEnabled(True) |
|
183 for act in standardItems: |
|
184 act.setEnabled(True) |
|
185 |
|
186 ########################################################################### |
|
187 # Protected menu generation methods below |
|
188 ########################################################################### |
|
189 |
|
190 def _addVCSMenu(self, mainMenu): |
|
191 """ |
|
192 Protected method used to add the VCS menu to all project browsers. |
|
193 |
|
194 @param mainMenu reference to the menu to be amended |
|
195 """ |
|
196 self.vcsMenuActions = [] |
|
197 self.vcsAddMenuActions = [] |
|
198 |
|
199 menu = QMenu(self.tr("Version Control")) |
|
200 |
|
201 act = menu.addAction( |
|
202 UI.PixmapCache.getIcon( |
|
203 os.path.join("VcsPlugins", "vcsSubversion", "icons", |
|
204 "subversion.svg")), |
|
205 self.vcs.vcsName(), self._VCSInfoDisplay) |
|
206 font = act.font() |
|
207 font.setBold(True) |
|
208 act.setFont(font) |
|
209 menu.addSeparator() |
|
210 |
|
211 act = menu.addAction( |
|
212 UI.PixmapCache.getIcon("vcsUpdate"), |
|
213 self.tr('Update from repository'), self._VCSUpdate) |
|
214 self.vcsMenuActions.append(act) |
|
215 act = menu.addAction( |
|
216 UI.PixmapCache.getIcon("vcsCommit"), |
|
217 self.tr('Commit changes to repository...'), |
|
218 self._VCSCommit) |
|
219 self.vcsMenuActions.append(act) |
|
220 menu.addSeparator() |
|
221 act = menu.addAction( |
|
222 UI.PixmapCache.getIcon("vcsAdd"), |
|
223 self.tr('Add to repository'), |
|
224 self._VCSAdd) |
|
225 self.vcsAddMenuActions.append(act) |
|
226 if 1 in self.browser.specialMenuEntries: |
|
227 self.vcsMenuAddTree = menu.addAction( |
|
228 UI.PixmapCache.getIcon("vcsAdd"), |
|
229 self.tr('Add tree to repository'), |
|
230 self._VCSAddTree) |
|
231 self.vcsAddMenuActions.append(self.vcsMenuAddTree) |
|
232 act = menu.addAction( |
|
233 UI.PixmapCache.getIcon("vcsRemove"), |
|
234 self.tr('Remove from repository (and disk)'), |
|
235 self._VCSRemove) |
|
236 self.vcsMenuActions.append(act) |
|
237 menu.addSeparator() |
|
238 act = menu.addAction(self.tr('Copy'), self.__SVNCopy) |
|
239 self.vcsMenuActions.append(act) |
|
240 act = menu.addAction(self.tr('Move'), self.__SVNMove) |
|
241 self.vcsMenuActions.append(act) |
|
242 if self.vcs.version >= (1, 5, 0): |
|
243 menu.addSeparator() |
|
244 act = menu.addAction( |
|
245 self.tr("Add to Changelist"), |
|
246 self.__SVNAddToChangelist) |
|
247 self.vcsMenuActions.append(act) |
|
248 act = menu.addAction( |
|
249 self.tr("Remove from Changelist"), |
|
250 self.__SVNRemoveFromChangelist) |
|
251 self.vcsMenuActions.append(act) |
|
252 menu.addSeparator() |
|
253 act = menu.addAction( |
|
254 UI.PixmapCache.getIcon("vcsLog"), |
|
255 self.tr('Show log browser'), self._VCSLogBrowser) |
|
256 self.vcsMenuActions.append(act) |
|
257 menu.addSeparator() |
|
258 act = menu.addAction( |
|
259 UI.PixmapCache.getIcon("vcsStatus"), |
|
260 self.tr('Show status'), self._VCSStatus) |
|
261 self.vcsMenuActions.append(act) |
|
262 menu.addSeparator() |
|
263 act = menu.addAction( |
|
264 UI.PixmapCache.getIcon("vcsDiff"), |
|
265 self.tr('Show differences'), self._VCSDiff) |
|
266 self.vcsMenuActions.append(act) |
|
267 act = menu.addAction( |
|
268 UI.PixmapCache.getIcon("vcsSbsDiff"), |
|
269 self.tr('Show differences side-by-side'), self.__SVNSbsDiff) |
|
270 self.vcsMenuActions.append(act) |
|
271 act = menu.addAction( |
|
272 UI.PixmapCache.getIcon("vcsDiff"), |
|
273 self.tr('Show differences (extended)'), |
|
274 self.__SVNExtendedDiff) |
|
275 self.vcsMenuActions.append(act) |
|
276 act = menu.addAction( |
|
277 UI.PixmapCache.getIcon("vcsSbsDiff"), |
|
278 self.tr('Show differences side-by-side (extended)'), |
|
279 self.__SVNSbsExtendedDiff) |
|
280 self.vcsMenuActions.append(act) |
|
281 act = menu.addAction( |
|
282 UI.PixmapCache.getIcon("vcsDiff"), |
|
283 self.tr('Show differences (URLs)'), |
|
284 self.__SVNUrlDiff) |
|
285 self.vcsMenuActions.append(act) |
|
286 self.blameAct = menu.addAction( |
|
287 self.tr('Show annotated file'), |
|
288 self.__SVNBlame) |
|
289 self.vcsMenuActions.append(self.blameAct) |
|
290 menu.addSeparator() |
|
291 act = menu.addAction( |
|
292 UI.PixmapCache.getIcon("vcsRevert"), |
|
293 self.tr('Revert changes'), self._VCSRevert) |
|
294 self.vcsMenuActions.append(act) |
|
295 act = menu.addAction( |
|
296 UI.PixmapCache.getIcon("vcsMerge"), |
|
297 self.tr('Merge changes'), self._VCSMerge) |
|
298 self.vcsMenuActions.append(act) |
|
299 act = menu.addAction( |
|
300 self.tr('Conflicts resolved'), self.__SVNResolve) |
|
301 self.vcsMenuActions.append(act) |
|
302 if self.vcs.version >= (1, 2, 0): |
|
303 menu.addSeparator() |
|
304 act = menu.addAction( |
|
305 UI.PixmapCache.getIcon("vcsLock"), |
|
306 self.tr('Lock'), self.__SVNLock) |
|
307 self.vcsMenuActions.append(act) |
|
308 act = menu.addAction( |
|
309 UI.PixmapCache.getIcon("vcsUnlock"), |
|
310 self.tr('Unlock'), self.__SVNUnlock) |
|
311 self.vcsMenuActions.append(act) |
|
312 act = menu.addAction( |
|
313 UI.PixmapCache.getIcon("vcsUnlock"), |
|
314 self.tr('Break Lock'), self.__SVNBreakLock) |
|
315 self.vcsMenuActions.append(act) |
|
316 act = menu.addAction( |
|
317 UI.PixmapCache.getIcon("vcsUnlock"), |
|
318 self.tr('Steal Lock'), self.__SVNStealLock) |
|
319 self.vcsMenuActions.append(act) |
|
320 menu.addSeparator() |
|
321 act = menu.addAction(self.tr('Set Property'), self.__SVNSetProp) |
|
322 self.vcsMenuActions.append(act) |
|
323 act = menu.addAction( |
|
324 self.tr('List Properties'), self.__SVNListProps) |
|
325 self.vcsMenuActions.append(act) |
|
326 act = menu.addAction(self.tr('Delete Property'), self.__SVNDelProp) |
|
327 self.vcsMenuActions.append(act) |
|
328 menu.addSeparator() |
|
329 menu.addAction(self.tr('Select all local file entries'), |
|
330 self.browser.selectLocalEntries) |
|
331 menu.addAction(self.tr('Select all versioned file entries'), |
|
332 self.browser.selectVCSEntries) |
|
333 menu.addAction(self.tr('Select all local directory entries'), |
|
334 self.browser.selectLocalDirEntries) |
|
335 menu.addAction(self.tr('Select all versioned directory entries'), |
|
336 self.browser.selectVCSDirEntries) |
|
337 menu.addSeparator() |
|
338 menu.addAction(self.tr("Configure..."), self.__SVNConfigure) |
|
339 |
|
340 mainMenu.addSeparator() |
|
341 mainMenu.addMenu(menu) |
|
342 self.menu = menu |
|
343 |
|
344 def _addVCSMenuMulti(self, mainMenu): |
|
345 """ |
|
346 Protected method used to add the VCS menu for multi selection to all |
|
347 project browsers. |
|
348 |
|
349 @param mainMenu reference to the menu to be amended |
|
350 """ |
|
351 self.vcsMultiMenuActions = [] |
|
352 self.vcsAddMultiMenuActions = [] |
|
353 |
|
354 menu = QMenu(self.tr("Version Control")) |
|
355 |
|
356 act = menu.addAction( |
|
357 UI.PixmapCache.getIcon( |
|
358 os.path.join("VcsPlugins", "vcsSubversion", "icons", |
|
359 "subversion.svg")), |
|
360 self.vcs.vcsName(), self._VCSInfoDisplay) |
|
361 font = act.font() |
|
362 font.setBold(True) |
|
363 act.setFont(font) |
|
364 menu.addSeparator() |
|
365 |
|
366 act = menu.addAction( |
|
367 UI.PixmapCache.getIcon("vcsUpdate"), |
|
368 self.tr('Update from repository'), self._VCSUpdate) |
|
369 self.vcsMultiMenuActions.append(act) |
|
370 act = menu.addAction( |
|
371 UI.PixmapCache.getIcon("vcsCommit"), |
|
372 self.tr('Commit changes to repository...'), |
|
373 self._VCSCommit) |
|
374 self.vcsMultiMenuActions.append(act) |
|
375 menu.addSeparator() |
|
376 act = menu.addAction( |
|
377 UI.PixmapCache.getIcon("vcsAdd"), |
|
378 self.tr('Add to repository'), self._VCSAdd) |
|
379 self.vcsAddMultiMenuActions.append(act) |
|
380 if 1 in self.browser.specialMenuEntries: |
|
381 self.vcsMultiMenuAddTree = menu.addAction( |
|
382 UI.PixmapCache.getIcon("vcsAdd"), |
|
383 self.tr('Add tree to repository'), self._VCSAddTree) |
|
384 self.vcsAddMultiMenuActions.append(self.vcsMultiMenuAddTree) |
|
385 act = menu.addAction( |
|
386 UI.PixmapCache.getIcon("vcsRemove"), |
|
387 self.tr('Remove from repository (and disk)'), |
|
388 self._VCSRemove) |
|
389 self.vcsMultiMenuActions.append(act) |
|
390 if self.vcs.version >= (1, 5, 0): |
|
391 menu.addSeparator() |
|
392 act = menu.addAction( |
|
393 self.tr("Add to Changelist"), |
|
394 self.__SVNAddToChangelist) |
|
395 self.vcsMenuActions.append(act) |
|
396 act = menu.addAction( |
|
397 self.tr("Remove from Changelist"), |
|
398 self.__SVNRemoveFromChangelist) |
|
399 self.vcsMenuActions.append(act) |
|
400 menu.addSeparator() |
|
401 act = menu.addAction( |
|
402 UI.PixmapCache.getIcon("vcsStatus"), |
|
403 self.tr('Show status'), self._VCSStatus) |
|
404 self.vcsMultiMenuActions.append(act) |
|
405 menu.addSeparator() |
|
406 act = menu.addAction( |
|
407 UI.PixmapCache.getIcon("vcsDiff"), |
|
408 self.tr('Show differences'), self._VCSDiff) |
|
409 self.vcsMultiMenuActions.append(act) |
|
410 act = menu.addAction( |
|
411 UI.PixmapCache.getIcon("vcsDiff"), |
|
412 self.tr('Show differences (extended)'), |
|
413 self.__SVNExtendedDiff) |
|
414 self.vcsMultiMenuActions.append(act) |
|
415 act = menu.addAction( |
|
416 UI.PixmapCache.getIcon("vcsDiff"), |
|
417 self.tr('Show differences (URLs)'), |
|
418 self.__SVNUrlDiff) |
|
419 self.vcsMultiMenuActions.append(act) |
|
420 menu.addSeparator() |
|
421 act = menu.addAction( |
|
422 UI.PixmapCache.getIcon("vcsRevert"), |
|
423 self.tr('Revert changes'), self._VCSRevert) |
|
424 self.vcsMultiMenuActions.append(act) |
|
425 act = menu.addAction( |
|
426 self.tr('Conflicts resolved'), self.__SVNResolve) |
|
427 self.vcsMultiMenuActions.append(act) |
|
428 if self.vcs.version >= (1, 2, 0): |
|
429 menu.addSeparator() |
|
430 act = menu.addAction( |
|
431 UI.PixmapCache.getIcon("vcsLock"), |
|
432 self.tr('Lock'), self.__SVNLock) |
|
433 self.vcsMultiMenuActions.append(act) |
|
434 act = menu.addAction( |
|
435 UI.PixmapCache.getIcon("vcsUnlock"), |
|
436 self.tr('Unlock'), self.__SVNUnlock) |
|
437 self.vcsMultiMenuActions.append(act) |
|
438 act = menu.addAction( |
|
439 UI.PixmapCache.getIcon("vcsUnlock"), |
|
440 self.tr('Break Lock'), self.__SVNBreakLock) |
|
441 self.vcsMultiMenuActions.append(act) |
|
442 act = menu.addAction( |
|
443 UI.PixmapCache.getIcon("vcsUnlock"), |
|
444 self.tr('Steal Lock'), self.__SVNStealLock) |
|
445 self.vcsMultiMenuActions.append(act) |
|
446 menu.addSeparator() |
|
447 act = menu.addAction(self.tr('Set Property'), self.__SVNSetProp) |
|
448 self.vcsMultiMenuActions.append(act) |
|
449 act = menu.addAction( |
|
450 self.tr('List Properties'), self.__SVNListProps) |
|
451 self.vcsMultiMenuActions.append(act) |
|
452 act = menu.addAction(self.tr('Delete Property'), self.__SVNDelProp) |
|
453 self.vcsMultiMenuActions.append(act) |
|
454 menu.addSeparator() |
|
455 menu.addAction(self.tr('Select all local file entries'), |
|
456 self.browser.selectLocalEntries) |
|
457 menu.addAction(self.tr('Select all versioned file entries'), |
|
458 self.browser.selectVCSEntries) |
|
459 menu.addAction(self.tr('Select all local directory entries'), |
|
460 self.browser.selectLocalDirEntries) |
|
461 menu.addAction(self.tr('Select all versioned directory entries'), |
|
462 self.browser.selectVCSDirEntries) |
|
463 menu.addSeparator() |
|
464 menu.addAction(self.tr("Configure..."), self.__SVNConfigure) |
|
465 |
|
466 mainMenu.addSeparator() |
|
467 mainMenu.addMenu(menu) |
|
468 self.menuMulti = menu |
|
469 |
|
470 def _addVCSMenuBack(self, mainMenu): |
|
471 """ |
|
472 Protected method used to add the VCS menu to all project browsers. |
|
473 |
|
474 @param mainMenu reference to the menu to be amended |
|
475 """ |
|
476 menu = QMenu(self.tr("Version Control")) |
|
477 |
|
478 act = menu.addAction( |
|
479 UI.PixmapCache.getIcon( |
|
480 os.path.join("VcsPlugins", "vcsSubversion", "icons", |
|
481 "subversion.svg")), |
|
482 self.vcs.vcsName(), self._VCSInfoDisplay) |
|
483 font = act.font() |
|
484 font.setBold(True) |
|
485 act.setFont(font) |
|
486 menu.addSeparator() |
|
487 |
|
488 menu.addAction(self.tr('Select all local file entries'), |
|
489 self.browser.selectLocalEntries) |
|
490 menu.addAction(self.tr('Select all versioned file entries'), |
|
491 self.browser.selectVCSEntries) |
|
492 menu.addAction(self.tr('Select all local directory entries'), |
|
493 self.browser.selectLocalDirEntries) |
|
494 menu.addAction(self.tr('Select all versioned directory entries'), |
|
495 self.browser.selectVCSDirEntries) |
|
496 menu.addSeparator() |
|
497 menu.addAction(self.tr("Configure..."), self.__SVNConfigure) |
|
498 |
|
499 mainMenu.addSeparator() |
|
500 mainMenu.addMenu(menu) |
|
501 self.menuBack = menu |
|
502 |
|
503 def _addVCSMenuDir(self, mainMenu): |
|
504 """ |
|
505 Protected method used to add the VCS menu to all project browsers. |
|
506 |
|
507 @param mainMenu reference to the menu to be amended |
|
508 """ |
|
509 if mainMenu is None: |
|
510 return |
|
511 |
|
512 self.vcsDirMenuActions = [] |
|
513 self.vcsAddDirMenuActions = [] |
|
514 |
|
515 menu = QMenu(self.tr("Version Control")) |
|
516 |
|
517 act = menu.addAction( |
|
518 UI.PixmapCache.getIcon( |
|
519 os.path.join("VcsPlugins", "vcsSubversion", "icons", |
|
520 "subversion.svg")), |
|
521 self.vcs.vcsName(), self._VCSInfoDisplay) |
|
522 font = act.font() |
|
523 font.setBold(True) |
|
524 act.setFont(font) |
|
525 menu.addSeparator() |
|
526 |
|
527 act = menu.addAction( |
|
528 UI.PixmapCache.getIcon("vcsUpdate"), |
|
529 self.tr('Update from repository'), self._VCSUpdate) |
|
530 self.vcsDirMenuActions.append(act) |
|
531 act = menu.addAction( |
|
532 UI.PixmapCache.getIcon("vcsCommit"), |
|
533 self.tr('Commit changes to repository...'), |
|
534 self._VCSCommit) |
|
535 self.vcsDirMenuActions.append(act) |
|
536 menu.addSeparator() |
|
537 act = menu.addAction( |
|
538 UI.PixmapCache.getIcon("vcsAdd"), |
|
539 self.tr('Add to repository'), self._VCSAdd) |
|
540 self.vcsAddDirMenuActions.append(act) |
|
541 act = menu.addAction( |
|
542 UI.PixmapCache.getIcon("vcsRemove"), |
|
543 self.tr('Remove from repository (and disk)'), |
|
544 self._VCSRemove) |
|
545 self.vcsDirMenuActions.append(act) |
|
546 menu.addSeparator() |
|
547 act = menu.addAction(self.tr('Copy'), self.__SVNCopy) |
|
548 self.vcsDirMenuActions.append(act) |
|
549 act = menu.addAction(self.tr('Move'), self.__SVNMove) |
|
550 self.vcsDirMenuActions.append(act) |
|
551 if self.vcs.version >= (1, 5, 0): |
|
552 menu.addSeparator() |
|
553 act = menu.addAction( |
|
554 self.tr("Add to Changelist"), |
|
555 self.__SVNAddToChangelist) |
|
556 self.vcsMenuActions.append(act) |
|
557 act = menu.addAction( |
|
558 self.tr("Remove from Changelist"), |
|
559 self.__SVNRemoveFromChangelist) |
|
560 self.vcsMenuActions.append(act) |
|
561 menu.addSeparator() |
|
562 act = menu.addAction( |
|
563 UI.PixmapCache.getIcon("vcsLog"), |
|
564 self.tr('Show log browser'), self._VCSLogBrowser) |
|
565 self.vcsDirMenuActions.append(act) |
|
566 menu.addSeparator() |
|
567 act = menu.addAction( |
|
568 UI.PixmapCache.getIcon("vcsStatus"), |
|
569 self.tr('Show status'), self._VCSStatus) |
|
570 self.vcsDirMenuActions.append(act) |
|
571 menu.addSeparator() |
|
572 act = menu.addAction( |
|
573 UI.PixmapCache.getIcon("vcsDiff"), |
|
574 self.tr('Show differences'), self._VCSDiff) |
|
575 self.vcsDirMenuActions.append(act) |
|
576 act = menu.addAction( |
|
577 UI.PixmapCache.getIcon("vcsDiff"), |
|
578 self.tr('Show differences (extended)'), |
|
579 self.__SVNExtendedDiff) |
|
580 self.vcsDirMenuActions.append(act) |
|
581 act = menu.addAction( |
|
582 UI.PixmapCache.getIcon("vcsDiff"), |
|
583 self.tr('Show differences (URLs)'), |
|
584 self.__SVNUrlDiff) |
|
585 self.vcsDirMenuActions.append(act) |
|
586 menu.addSeparator() |
|
587 act = menu.addAction( |
|
588 UI.PixmapCache.getIcon("vcsRevert"), |
|
589 self.tr('Revert changes'), self._VCSRevert) |
|
590 self.vcsDirMenuActions.append(act) |
|
591 act = menu.addAction( |
|
592 UI.PixmapCache.getIcon("vcsMerge"), |
|
593 self.tr('Merge changes'), self._VCSMerge) |
|
594 self.vcsDirMenuActions.append(act) |
|
595 act = menu.addAction( |
|
596 self.tr('Conflicts resolved'), self.__SVNResolve) |
|
597 self.vcsDirMenuActions.append(act) |
|
598 menu.addSeparator() |
|
599 act = menu.addAction(self.tr('Set Property'), self.__SVNSetProp) |
|
600 self.vcsDirMenuActions.append(act) |
|
601 act = menu.addAction( |
|
602 self.tr('List Properties'), self.__SVNListProps) |
|
603 self.vcsDirMenuActions.append(act) |
|
604 act = menu.addAction(self.tr('Delete Property'), self.__SVNDelProp) |
|
605 self.vcsDirMenuActions.append(act) |
|
606 menu.addSeparator() |
|
607 menu.addAction(self.tr('Select all local file entries'), |
|
608 self.browser.selectLocalEntries) |
|
609 menu.addAction(self.tr('Select all versioned file entries'), |
|
610 self.browser.selectVCSEntries) |
|
611 menu.addAction(self.tr('Select all local directory entries'), |
|
612 self.browser.selectLocalDirEntries) |
|
613 menu.addAction(self.tr('Select all versioned directory entries'), |
|
614 self.browser.selectVCSDirEntries) |
|
615 menu.addSeparator() |
|
616 menu.addAction(self.tr("Configure..."), self.__SVNConfigure) |
|
617 |
|
618 mainMenu.addSeparator() |
|
619 mainMenu.addMenu(menu) |
|
620 self.menuDir = menu |
|
621 |
|
622 def _addVCSMenuDirMulti(self, mainMenu): |
|
623 """ |
|
624 Protected method used to add the VCS menu to all project browsers. |
|
625 |
|
626 @param mainMenu reference to the menu to be amended |
|
627 """ |
|
628 if mainMenu is None: |
|
629 return |
|
630 |
|
631 self.vcsDirMultiMenuActions = [] |
|
632 self.vcsAddDirMultiMenuActions = [] |
|
633 |
|
634 menu = QMenu(self.tr("Version Control")) |
|
635 |
|
636 act = menu.addAction( |
|
637 UI.PixmapCache.getIcon( |
|
638 os.path.join("VcsPlugins", "vcsSubversion", "icons", |
|
639 "subversion.svg")), |
|
640 self.vcs.vcsName(), self._VCSInfoDisplay) |
|
641 font = act.font() |
|
642 font.setBold(True) |
|
643 act.setFont(font) |
|
644 menu.addSeparator() |
|
645 |
|
646 act = menu.addAction( |
|
647 UI.PixmapCache.getIcon("vcsUpdate"), |
|
648 self.tr('Update from repository'), self._VCSUpdate) |
|
649 self.vcsDirMultiMenuActions.append(act) |
|
650 act = menu.addAction( |
|
651 UI.PixmapCache.getIcon("vcsCommit"), |
|
652 self.tr('Commit changes to repository...'), |
|
653 self._VCSCommit) |
|
654 self.vcsDirMultiMenuActions.append(act) |
|
655 menu.addSeparator() |
|
656 act = menu.addAction( |
|
657 UI.PixmapCache.getIcon("vcsAdd"), |
|
658 self.tr('Add to repository'), self._VCSAdd) |
|
659 self.vcsAddDirMultiMenuActions.append(act) |
|
660 act = menu.addAction( |
|
661 UI.PixmapCache.getIcon("vcsRemove"), |
|
662 self.tr('Remove from repository (and disk)'), |
|
663 self._VCSRemove) |
|
664 self.vcsDirMultiMenuActions.append(act) |
|
665 if self.vcs.version >= (1, 5, 0): |
|
666 menu.addSeparator() |
|
667 act = menu.addAction( |
|
668 self.tr("Add to Changelist"), |
|
669 self.__SVNAddToChangelist) |
|
670 self.vcsMenuActions.append(act) |
|
671 act = menu.addAction( |
|
672 self.tr("Remove from Changelist"), |
|
673 self.__SVNRemoveFromChangelist) |
|
674 self.vcsMenuActions.append(act) |
|
675 menu.addSeparator() |
|
676 act = menu.addAction( |
|
677 UI.PixmapCache.getIcon("vcsStatus"), |
|
678 self.tr('Show status'), self._VCSStatus) |
|
679 self.vcsDirMultiMenuActions.append(act) |
|
680 menu.addSeparator() |
|
681 act = menu.addAction( |
|
682 UI.PixmapCache.getIcon("vcsDiff"), |
|
683 self.tr('Show differences'), self._VCSDiff) |
|
684 self.vcsDirMultiMenuActions.append(act) |
|
685 act = menu.addAction( |
|
686 UI.PixmapCache.getIcon("vcsDiff"), |
|
687 self.tr('Show differences (extended)'), |
|
688 self.__SVNExtendedDiff) |
|
689 self.vcsDirMultiMenuActions.append(act) |
|
690 act = menu.addAction( |
|
691 UI.PixmapCache.getIcon("vcsDiff"), |
|
692 self.tr('Show differences (URLs)'), |
|
693 self.__SVNUrlDiff) |
|
694 self.vcsDirMultiMenuActions.append(act) |
|
695 menu.addSeparator() |
|
696 act = menu.addAction( |
|
697 UI.PixmapCache.getIcon("vcsRevert"), |
|
698 self.tr('Revert changes'), self._VCSRevert) |
|
699 self.vcsDirMultiMenuActions.append(act) |
|
700 act = menu.addAction( |
|
701 UI.PixmapCache.getIcon("vcsMerge"), |
|
702 self.tr('Merge changes'), self._VCSMerge) |
|
703 self.vcsDirMultiMenuActions.append(act) |
|
704 act = menu.addAction( |
|
705 self.tr('Conflicts resolved'), self.__SVNResolve) |
|
706 self.vcsDirMultiMenuActions.append(act) |
|
707 menu.addSeparator() |
|
708 act = menu.addAction(self.tr('Set Property'), self.__SVNSetProp) |
|
709 self.vcsDirMultiMenuActions.append(act) |
|
710 act = menu.addAction( |
|
711 self.tr('List Properties'), self.__SVNListProps) |
|
712 self.vcsDirMultiMenuActions.append(act) |
|
713 act = menu.addAction(self.tr('Delete Property'), self.__SVNDelProp) |
|
714 self.vcsDirMultiMenuActions.append(act) |
|
715 menu.addSeparator() |
|
716 menu.addAction(self.tr('Select all local file entries'), |
|
717 self.browser.selectLocalEntries) |
|
718 menu.addAction(self.tr('Select all versioned file entries'), |
|
719 self.browser.selectVCSEntries) |
|
720 menu.addAction(self.tr('Select all local directory entries'), |
|
721 self.browser.selectLocalDirEntries) |
|
722 menu.addAction(self.tr('Select all versioned directory entries'), |
|
723 self.browser.selectVCSDirEntries) |
|
724 menu.addSeparator() |
|
725 menu.addAction(self.tr("Configure..."), self.__SVNConfigure) |
|
726 |
|
727 mainMenu.addSeparator() |
|
728 mainMenu.addMenu(menu) |
|
729 self.menuDirMulti = menu |
|
730 |
|
731 ########################################################################### |
|
732 # Menu handling methods below |
|
733 ########################################################################### |
|
734 |
|
735 def __SVNCopy(self): |
|
736 """ |
|
737 Private slot called by the context menu to copy the selected file. |
|
738 """ |
|
739 itm = self.browser.currentItem() |
|
740 try: |
|
741 fn = itm.fileName() |
|
742 except AttributeError: |
|
743 fn = itm.dirName() |
|
744 self.vcs.svnCopy(fn, self.project) |
|
745 |
|
746 def __SVNMove(self): |
|
747 """ |
|
748 Private slot called by the context menu to move the selected file. |
|
749 """ |
|
750 itm = self.browser.currentItem() |
|
751 try: |
|
752 fn = itm.fileName() |
|
753 except AttributeError: |
|
754 fn = itm.dirName() |
|
755 isFile = os.path.isfile(fn) |
|
756 movefiles = self.browser.project.getFiles(fn) |
|
757 self.browser.project.stopFileSystemMonitoring() |
|
758 if self.vcs.vcsMove(fn, self.project): |
|
759 if isFile: |
|
760 self.browser.closeSourceWindow.emit(fn) |
|
761 else: |
|
762 for mf in movefiles: |
|
763 self.browser.closeSourceWindow.emit(mf) |
|
764 self.browser.project.startFileSystemMonitoring() |
|
765 |
|
766 def __SVNResolve(self): |
|
767 """ |
|
768 Private slot called by the context menu to resolve conflicts of a file. |
|
769 """ |
|
770 names = [] |
|
771 for itm in self.browser.getSelectedItems(): |
|
772 try: |
|
773 names.append(itm.fileName()) |
|
774 except AttributeError: |
|
775 names.append(itm.dirName()) |
|
776 self.vcs.svnResolve(names) |
|
777 |
|
778 def __SVNListProps(self): |
|
779 """ |
|
780 Private slot called by the context menu to list the subversion |
|
781 properties of a file. |
|
782 """ |
|
783 names = [] |
|
784 for itm in self.browser.getSelectedItems(): |
|
785 try: |
|
786 names.append(itm.fileName()) |
|
787 except AttributeError: |
|
788 names.append(itm.dirName()) |
|
789 self.vcs.svnListProps(names) |
|
790 |
|
791 def __SVNSetProp(self): |
|
792 """ |
|
793 Private slot called by the context menu to set a subversion property |
|
794 of a file. |
|
795 """ |
|
796 names = [] |
|
797 for itm in self.browser.getSelectedItems(): |
|
798 try: |
|
799 names.append(itm.fileName()) |
|
800 except AttributeError: |
|
801 names.append(itm.dirName()) |
|
802 self.vcs.svnSetProp(names) |
|
803 |
|
804 def __SVNDelProp(self): |
|
805 """ |
|
806 Private slot called by the context menu to delete a subversion |
|
807 property of a file. |
|
808 """ |
|
809 names = [] |
|
810 for itm in self.browser.getSelectedItems(): |
|
811 try: |
|
812 names.append(itm.fileName()) |
|
813 except AttributeError: |
|
814 names.append(itm.dirName()) |
|
815 self.vcs.svnDelProp(names) |
|
816 |
|
817 def __SVNExtendedDiff(self): |
|
818 """ |
|
819 Private slot called by the context menu to show the difference of a |
|
820 file to the repository. |
|
821 |
|
822 This gives the chance to enter the revisions to compare. |
|
823 """ |
|
824 names = [] |
|
825 for itm in self.browser.getSelectedItems(): |
|
826 try: |
|
827 names.append(itm.fileName()) |
|
828 except AttributeError: |
|
829 names.append(itm.dirName()) |
|
830 self.vcs.svnExtendedDiff(names) |
|
831 |
|
832 def __SVNUrlDiff(self): |
|
833 """ |
|
834 Private slot called by the context menu to show the difference of a |
|
835 file of two repository URLs. |
|
836 |
|
837 This gives the chance to enter the repository URLs to compare. |
|
838 """ |
|
839 names = [] |
|
840 for itm in self.browser.getSelectedItems(): |
|
841 try: |
|
842 names.append(itm.fileName()) |
|
843 except AttributeError: |
|
844 names.append(itm.dirName()) |
|
845 self.vcs.svnUrlDiff(names) |
|
846 |
|
847 def __SVNSbsDiff(self): |
|
848 """ |
|
849 Private slot called by the context menu to show the difference of a |
|
850 file to the repository side-by-side. |
|
851 """ |
|
852 itm = self.browser.currentItem() |
|
853 fn = itm.fileName() |
|
854 self.vcs.svnSbsDiff(fn) |
|
855 |
|
856 def __SVNSbsExtendedDiff(self): |
|
857 """ |
|
858 Private slot called by the context menu to show the difference of a |
|
859 file to the repository side-by-side. |
|
860 |
|
861 It allows the selection of revisions to compare. |
|
862 """ |
|
863 itm = self.browser.currentItem() |
|
864 fn = itm.fileName() |
|
865 self.vcs.svnSbsDiff(fn, extended=True) |
|
866 |
|
867 def __SVNBlame(self): |
|
868 """ |
|
869 Private slot called by the context menu to show the blame of a file. |
|
870 """ |
|
871 itm = self.browser.currentItem() |
|
872 fn = itm.fileName() |
|
873 self.vcs.svnBlame(fn) |
|
874 |
|
875 def __SVNLock(self): |
|
876 """ |
|
877 Private slot called by the context menu to lock files in the |
|
878 repository. |
|
879 """ |
|
880 names = [] |
|
881 for itm in self.browser.getSelectedItems(): |
|
882 try: |
|
883 names.append(itm.fileName()) |
|
884 except AttributeError: |
|
885 names.append(itm.dirName()) |
|
886 self.vcs.svnLock(names) |
|
887 |
|
888 def __SVNUnlock(self): |
|
889 """ |
|
890 Private slot called by the context menu to unlock files in the |
|
891 repository. |
|
892 """ |
|
893 names = [] |
|
894 for itm in self.browser.getSelectedItems(): |
|
895 try: |
|
896 names.append(itm.fileName()) |
|
897 except AttributeError: |
|
898 names.append(itm.dirName()) |
|
899 self.vcs.svnUnlock(names) |
|
900 |
|
901 def __SVNBreakLock(self): |
|
902 """ |
|
903 Private slot called by the context menu to break lock files in the |
|
904 repository. |
|
905 """ |
|
906 names = [] |
|
907 for itm in self.browser.getSelectedItems(): |
|
908 try: |
|
909 names.append(itm.fileName()) |
|
910 except AttributeError: |
|
911 names.append(itm.dirName()) |
|
912 self.vcs.svnUnlock(names, breakIt=True) |
|
913 |
|
914 def __SVNStealLock(self): |
|
915 """ |
|
916 Private slot called by the context menu to steal lock files in the |
|
917 repository. |
|
918 """ |
|
919 names = [] |
|
920 for itm in self.browser.getSelectedItems(): |
|
921 try: |
|
922 names.append(itm.fileName()) |
|
923 except AttributeError: |
|
924 names.append(itm.dirName()) |
|
925 self.vcs.svnLock(names, stealIt=True) |
|
926 |
|
927 def __SVNConfigure(self): |
|
928 """ |
|
929 Private method to open the configuration dialog. |
|
930 """ |
|
931 e5App().getObject("UserInterface").showPreferences( |
|
932 "zzz_subversionPage") |
|
933 |
|
934 def __SVNAddToChangelist(self): |
|
935 """ |
|
936 Private slot called by the context menu to add files to a changelist. |
|
937 """ |
|
938 names = [] |
|
939 for itm in self.browser.getSelectedItems(): |
|
940 try: |
|
941 names.append(itm.fileName()) |
|
942 except AttributeError: |
|
943 names.append(itm.dirName()) |
|
944 self.vcs.svnAddToChangelist(names) |
|
945 |
|
946 def __SVNRemoveFromChangelist(self): |
|
947 """ |
|
948 Private slot called by the context menu to remove files from their |
|
949 changelist. |
|
950 """ |
|
951 names = [] |
|
952 for itm in self.browser.getSelectedItems(): |
|
953 try: |
|
954 names.append(itm.fileName()) |
|
955 except AttributeError: |
|
956 names.append(itm.dirName()) |
|
957 self.vcs.svnRemoveFromChangelist(names) |
|
958 |
|
959 ########################################################################### |
|
960 # Some private utility methods below |
|
961 ########################################################################### |
|
962 |
|
963 def __itemsHaveFiles(self, items): |
|
964 """ |
|
965 Private method to check, if items contain file type items. |
|
966 |
|
967 @param items items to check (list of QTreeWidgetItems) |
|
968 @return flag indicating items contain file type items (boolean) |
|
969 """ |
|
970 return any(isinstance(itm, ProjectBrowserFileItem) for itm in items) |