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