eric6/Plugins/VcsPlugins/vcsMercurial/ProjectBrowserHelper.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2010 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the VCS project browser helper for Mercurial.
8 """
9
10 from __future__ import unicode_literals
11
12 import os
13
14 from PyQt5.QtWidgets import QMenu, QDialog
15
16 from E5Gui.E5Application import e5App
17
18 from Project.ProjectBrowserModel import ProjectBrowserFileItem
19
20 from VCS.ProjectBrowserHelper import VcsProjectBrowserHelper
21
22 import UI.PixmapCache
23
24
25 class HgProjectBrowserHelper(VcsProjectBrowserHelper):
26 """
27 Class implementing the VCS project browser helper for Mercurial.
28 """
29 def __init__(self, vcsObject, browserObject, projectObject,
30 isTranslationsBrowser, parent=None, name=None):
31 """
32 Constructor
33
34 @param vcsObject reference to the vcs object
35 @param browserObject reference to the project browser object
36 @param projectObject reference to the project object
37 @param isTranslationsBrowser flag indicating, the helper is requested
38 for the translations browser (this needs some special treatment)
39 @param parent parent widget (QWidget)
40 @param name name of this object (string)
41 """
42 VcsProjectBrowserHelper.__init__(self, vcsObject, browserObject,
43 projectObject, isTranslationsBrowser,
44 parent, name)
45
46 # instantiate the extensions
47 from .ShelveExtension.ProjectBrowserHelper import \
48 ShelveProjectBrowserHelper
49 from .LargefilesExtension.ProjectBrowserHelper import \
50 LargefilesProjectBrowserHelper
51 self.__extensions = {
52 "shelve": ShelveProjectBrowserHelper(
53 vcsObject, browserObject, projectObject),
54 "largefiles": LargefilesProjectBrowserHelper(
55 vcsObject, browserObject, projectObject),
56 }
57
58 self.__extensionMenuTitles = {}
59 for extension in self.__extensions:
60 self.__extensionMenuTitles[
61 self.__extensions[extension].menuTitle()] = extension
62 self.__extensionMenus = {}
63 for extension in self.__extensions:
64 self.__extensionMenus[extension] = \
65 self.__extensions[extension].initMenus()
66
67 def __showExtensionMenu(self, key, controlled):
68 """
69 Private slot showing the extensions menu.
70
71 @param key menu key (string, one of 'mainMenu', 'multiMenu',
72 'backMenu', 'dirMenu' or 'dirMultiMenu')
73 @param controlled flag indicating to show the menu for a
74 version controlled entry or a non-version controlled entry
75 (boolean)
76 """
77 for extensionName in self.__extensionMenus:
78 if key in self.__extensionMenus[extensionName]:
79 self.__extensionMenus[extensionName][key].setEnabled(
80 self.vcs.isExtensionActive(extensionName))
81 if self.__extensionMenus[extensionName][key].isEnabled():
82 # adjust individual extension menu entries
83 self.__extensions[extensionName].showExtensionMenu(
84 key, controlled)
85 if (not self.__extensionMenus[extensionName][key]
86 .isEnabled() and self.__extensionMenus[extensionName][key]
87 .isTearOffMenuVisible()):
88 self.__extensionMenus[extensionName][key].hideTearOffMenu()
89
90 def showContextMenu(self, menu, standardItems):
91 """
92 Public slot called before the context menu is shown.
93
94 It enables/disables the VCS menu entries depending on the overall
95 VCS status and the file status.
96
97 @param menu reference to the menu to be shown
98 @param standardItems array of standard items that need
99 activation/deactivation depending on the overall VCS status
100 """
101 if self.browser.currentItem().data(1) == self.vcs.vcsName():
102 controlled = True
103 for act in self.vcsMenuActions:
104 act.setEnabled(True)
105 for act in self.vcsAddMenuActions:
106 act.setEnabled(False)
107 for act in standardItems:
108 act.setEnabled(False)
109 if not hasattr(self.browser.currentItem(), 'fileName'):
110 self.annotateAct.setEnabled(False)
111 else:
112 controlled = False
113 for act in self.vcsMenuActions:
114 act.setEnabled(False)
115 for act in self.vcsAddMenuActions:
116 act.setEnabled(True)
117 for act in standardItems:
118 act.setEnabled(True)
119 self.__showExtensionMenu("mainMenu", controlled)
120
121 def showContextMenuMulti(self, menu, standardItems):
122 """
123 Public slot called before the context menu (multiple selections) is
124 shown.
125
126 It enables/disables the VCS menu entries depending on the overall
127 VCS status and the files 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 vcsName = self.vcs.vcsName()
134 items = self.browser.getSelectedItems()
135 vcsItems = 0
136 # determine number of selected items under VCS control
137 for itm in items:
138 if itm.data(1) == vcsName:
139 vcsItems += 1
140
141 if vcsItems > 0:
142 controlled = True
143 if vcsItems != len(items):
144 for act in self.vcsMultiMenuActions:
145 act.setEnabled(False)
146 else:
147 for act in self.vcsMultiMenuActions:
148 act.setEnabled(True)
149 for act in self.vcsAddMultiMenuActions:
150 act.setEnabled(False)
151 for act in standardItems:
152 act.setEnabled(False)
153 else:
154 controlled = False
155 for act in self.vcsMultiMenuActions:
156 act.setEnabled(False)
157 for act in self.vcsAddMultiMenuActions:
158 act.setEnabled(True)
159 for act in standardItems:
160 act.setEnabled(True)
161 self.__showExtensionMenu("multiMenu", controlled)
162
163 def showContextMenuDir(self, menu, standardItems):
164 """
165 Public slot called before the context menu is shown.
166
167 It enables/disables the VCS menu entries depending on the overall
168 VCS status and the directory status.
169
170 @param menu reference to the menu to be shown
171 @param standardItems array of standard items that need
172 activation/deactivation depending on the overall VCS status
173 """
174 if self.browser.currentItem().data(1) == self.vcs.vcsName():
175 controlled = True
176 for act in self.vcsDirMenuActions:
177 act.setEnabled(True)
178 for act in self.vcsAddDirMenuActions:
179 act.setEnabled(False)
180 for act in standardItems:
181 act.setEnabled(False)
182 else:
183 controlled = False
184 for act in self.vcsDirMenuActions:
185 act.setEnabled(False)
186 for act in self.vcsAddDirMenuActions:
187 act.setEnabled(True)
188 for act in standardItems:
189 act.setEnabled(True)
190 self.__showExtensionMenu("dirMenu", controlled)
191
192 def showContextMenuDirMulti(self, menu, standardItems):
193 """
194 Public slot called before the context menu is shown.
195
196 It enables/disables the VCS menu entries depending on the overall
197 VCS status and the directory status.
198
199 @param menu reference to the menu to be shown
200 @param standardItems array of standard items that need
201 activation/deactivation depending on the overall VCS status
202 """
203 vcsName = self.vcs.vcsName()
204 items = self.browser.getSelectedItems()
205 vcsItems = 0
206 # determine number of selected items under VCS control
207 for itm in items:
208 if itm.data(1) == vcsName:
209 vcsItems += 1
210
211 if vcsItems > 0:
212 controlled = True
213 if vcsItems != len(items):
214 for act in self.vcsDirMultiMenuActions:
215 act.setEnabled(False)
216 else:
217 for act in self.vcsDirMultiMenuActions:
218 act.setEnabled(True)
219 for act in self.vcsAddDirMultiMenuActions:
220 act.setEnabled(False)
221 for act in standardItems:
222 act.setEnabled(False)
223 else:
224 controlled = False
225 for act in self.vcsDirMultiMenuActions:
226 act.setEnabled(False)
227 for act in self.vcsAddDirMultiMenuActions:
228 act.setEnabled(True)
229 for act in standardItems:
230 act.setEnabled(True)
231 self.__showExtensionMenu("dirMultiMenu", controlled)
232
233 ###########################################################################
234 ## Private menu generation methods below
235 ###########################################################################
236
237 def __addExtensionsMenu(self, menu, key):
238 """
239 Private method to add an extension menu entry.
240
241 @param menu menu to add it to (QMenu)
242 @param key menu key (string, one of 'mainMenu', 'multiMenu',
243 'backMenu', 'dirMenu' or 'dirMultiMenu')
244 @return reference to the menu action (QAction)
245 """
246 act = None
247 if key in ['mainMenu', 'multiMenu', 'backMenu', 'dirMenu',
248 'dirMultiMenu']:
249 extensionsMenu = QMenu(self.tr("Extensions"), menu)
250 extensionsMenu.setTearOffEnabled(True)
251 for extensionMenuTitle in sorted(self.__extensionMenuTitles):
252 extensionName = self.__extensionMenuTitles[extensionMenuTitle]
253 if key in self.__extensionMenus[extensionName]:
254 extensionsMenu.addMenu(
255 self.__extensionMenus[extensionName][key])
256 if not extensionsMenu.isEmpty():
257 if not menu.isEmpty():
258 menu.addSeparator()
259 act = menu.addMenu(extensionsMenu)
260 return act
261
262 ###########################################################################
263 ## Protected menu generation methods below
264 ###########################################################################
265
266 def _addVCSMenu(self, mainMenu):
267 """
268 Protected method used to add the VCS menu to all project browsers.
269
270 @param mainMenu reference to the menu to be amended
271 """
272 self.vcsMenuActions = []
273 self.vcsAddMenuActions = []
274
275 menu = QMenu(self.tr("Version Control"))
276
277 act = menu.addAction(
278 UI.PixmapCache.getIcon(
279 os.path.join("VcsPlugins", "vcsMercurial", "icons",
280 "mercurial.png")),
281 self.vcs.vcsName(), self._VCSInfoDisplay)
282 font = act.font()
283 font.setBold(True)
284 act.setFont(font)
285 menu.addSeparator()
286
287 act = menu.addAction(
288 UI.PixmapCache.getIcon("vcsCommit.png"),
289 self.tr('Commit changes to repository...'),
290 self._VCSCommit)
291 self.vcsMenuActions.append(act)
292 self.__addExtensionsMenu(menu, 'mainMenu')
293 menu.addSeparator()
294 act = menu.addAction(
295 UI.PixmapCache.getIcon("vcsAdd.png"),
296 self.tr('Add to repository'),
297 self._VCSAdd)
298 self.vcsAddMenuActions.append(act)
299 act = menu.addAction(
300 UI.PixmapCache.getIcon("vcsRemove.png"),
301 self.tr('Remove from repository (and disk)'),
302 self._VCSRemove)
303 self.vcsMenuActions.append(act)
304 act = menu.addAction(
305 UI.PixmapCache.getIcon("vcsRemove.png"),
306 self.tr('Remove from repository only'),
307 self.__HgForget)
308 self.vcsMenuActions.append(act)
309 menu.addSeparator()
310 act = menu.addAction(self.tr('Copy'), self.__HgCopy)
311 self.vcsMenuActions.append(act)
312 act = menu.addAction(self.tr('Move'), self.__HgMove)
313 self.vcsMenuActions.append(act)
314 menu.addSeparator()
315 act = menu.addAction(
316 UI.PixmapCache.getIcon("vcsLog.png"),
317 self.tr('Show log browser'), self._VCSLogBrowser)
318 self.vcsMenuActions.append(act)
319 menu.addSeparator()
320 act = menu.addAction(
321 UI.PixmapCache.getIcon("vcsStatus.png"),
322 self.tr('Show status'), self._VCSStatus)
323 self.vcsMenuActions.append(act)
324 menu.addSeparator()
325 act = menu.addAction(
326 UI.PixmapCache.getIcon("vcsDiff.png"),
327 self.tr('Show differences'), self._VCSDiff)
328 self.vcsMenuActions.append(act)
329 act = menu.addAction(
330 UI.PixmapCache.getIcon("vcsSbsDiff.png"),
331 self.tr('Show differences side-by-side'), self.__HgSbsDiff)
332 self.vcsMenuActions.append(act)
333 act = menu.addAction(
334 UI.PixmapCache.getIcon("vcsDiff.png"),
335 self.tr('Show differences (extended)'),
336 self.__HgExtendedDiff)
337 self.vcsMenuActions.append(act)
338 act = menu.addAction(
339 UI.PixmapCache.getIcon("vcsSbsDiff.png"),
340 self.tr('Show differences side-by-side (extended)'),
341 self.__HgSbsExtendedDiff)
342 self.vcsMenuActions.append(act)
343 self.annotateAct = menu.addAction(
344 self.tr('Show annotated file'),
345 self.__HgAnnotate)
346 self.vcsMenuActions.append(self.annotateAct)
347 menu.addSeparator()
348 act = menu.addAction(
349 UI.PixmapCache.getIcon("vcsRevert.png"),
350 self.tr('Revert changes'), self.__HgRevert)
351 self.vcsMenuActions.append(act)
352 act = menu.addAction(
353 self.tr('Conflicts resolved'), self.__HgResolved)
354 self.vcsMenuActions.append(act)
355 act = menu.addAction(
356 self.tr('Conflicts unresolved'), self.__HgUnresolved)
357 self.vcsMenuActions.append(act)
358 act = menu.addAction(
359 self.tr('Re-Merge'), self.__HgReMerge)
360 self.vcsMenuActions.append(act)
361 menu.addSeparator()
362 menu.addAction(self.tr('Select all local file entries'),
363 self.browser.selectLocalEntries)
364 menu.addAction(self.tr('Select all versioned file entries'),
365 self.browser.selectVCSEntries)
366 menu.addAction(self.tr('Select all local directory entries'),
367 self.browser.selectLocalDirEntries)
368 menu.addAction(self.tr('Select all versioned directory entries'),
369 self.browser.selectVCSDirEntries)
370 menu.addSeparator()
371 menu.addAction(self.tr("Configure..."), self.__HgConfigure)
372
373 mainMenu.addSeparator()
374 mainMenu.addMenu(menu)
375 self.menu = menu
376
377 def _addVCSMenuMulti(self, mainMenu):
378 """
379 Protected method used to add the VCS menu for multi selection to all
380 project browsers.
381
382 @param mainMenu reference to the menu to be amended
383 """
384 self.vcsMultiMenuActions = []
385 self.vcsAddMultiMenuActions = []
386
387 menu = QMenu(self.tr("Version Control"))
388
389 act = menu.addAction(
390 UI.PixmapCache.getIcon(
391 os.path.join("VcsPlugins", "vcsMercurial", "icons",
392 "mercurial.png")),
393 self.vcs.vcsName(), self._VCSInfoDisplay)
394 font = act.font()
395 font.setBold(True)
396 act.setFont(font)
397 menu.addSeparator()
398
399 act = menu.addAction(
400 UI.PixmapCache.getIcon("vcsCommit.png"),
401 self.tr('Commit changes to repository...'),
402 self._VCSCommit)
403 self.vcsMultiMenuActions.append(act)
404 self.__addExtensionsMenu(menu, 'multiMenu')
405 menu.addSeparator()
406 act = menu.addAction(
407 UI.PixmapCache.getIcon("vcsAdd.png"),
408 self.tr('Add to repository'), self._VCSAdd)
409 self.vcsAddMultiMenuActions.append(act)
410 act = menu.addAction(
411 UI.PixmapCache.getIcon("vcsRemove.png"),
412 self.tr('Remove from repository (and disk)'),
413 self._VCSRemove)
414 self.vcsMultiMenuActions.append(act)
415 act = menu.addAction(
416 UI.PixmapCache.getIcon("vcsRemove.png"),
417 self.tr('Remove from repository only'),
418 self.__HgForget)
419 self.vcsMultiMenuActions.append(act)
420 menu.addSeparator()
421 act = menu.addAction(
422 UI.PixmapCache.getIcon("vcsStatus.png"),
423 self.tr('Show status'), self._VCSStatus)
424 self.vcsMultiMenuActions.append(act)
425 menu.addSeparator()
426 act = menu.addAction(
427 UI.PixmapCache.getIcon("vcsDiff.png"),
428 self.tr('Show differences'), self._VCSDiff)
429 self.vcsMultiMenuActions.append(act)
430 act = menu.addAction(
431 UI.PixmapCache.getIcon("vcsDiff.png"),
432 self.tr('Show differences (extended)'),
433 self.__HgExtendedDiff)
434 self.vcsMultiMenuActions.append(act)
435 menu.addSeparator()
436 act = menu.addAction(
437 UI.PixmapCache.getIcon("vcsRevert.png"),
438 self.tr('Revert changes'), self.__HgRevert)
439 self.vcsMultiMenuActions.append(act)
440 act = menu.addAction(
441 self.tr('Conflicts resolved'), self.__HgResolved)
442 self.vcsMultiMenuActions.append(act)
443 act = menu.addAction(
444 self.tr('Conflicts unresolved'), self.__HgUnresolved)
445 self.vcsMultiMenuActions.append(act)
446 act = menu.addAction(
447 self.tr('Re-Merge'), self.__HgReMerge)
448 self.vcsMultiMenuActions.append(act)
449 menu.addSeparator()
450 menu.addAction(self.tr('Select all local file entries'),
451 self.browser.selectLocalEntries)
452 menu.addAction(self.tr('Select all versioned file entries'),
453 self.browser.selectVCSEntries)
454 menu.addAction(self.tr('Select all local directory entries'),
455 self.browser.selectLocalDirEntries)
456 menu.addAction(self.tr('Select all versioned directory entries'),
457 self.browser.selectVCSDirEntries)
458 menu.addSeparator()
459 menu.addAction(self.tr("Configure..."), self.__HgConfigure)
460
461 mainMenu.addSeparator()
462 mainMenu.addMenu(menu)
463 self.menuMulti = menu
464
465 def _addVCSMenuBack(self, mainMenu):
466 """
467 Protected method used to add the VCS menu to all project browsers.
468
469 @param mainMenu reference to the menu to be amended
470 """
471 menu = QMenu(self.tr("Version Control"))
472
473 act = menu.addAction(
474 UI.PixmapCache.getIcon(
475 os.path.join("VcsPlugins", "vcsMercurial", "icons",
476 "mercurial.png")),
477 self.vcs.vcsName(), self._VCSInfoDisplay)
478 font = act.font()
479 font.setBold(True)
480 act.setFont(font)
481 menu.addSeparator()
482
483 menu.addAction(self.tr('Select all local file entries'),
484 self.browser.selectLocalEntries)
485 menu.addAction(self.tr('Select all versioned file entries'),
486 self.browser.selectVCSEntries)
487 menu.addAction(self.tr('Select all local directory entries'),
488 self.browser.selectLocalDirEntries)
489 menu.addAction(self.tr('Select all versioned directory entries'),
490 self.browser.selectVCSDirEntries)
491 menu.addSeparator()
492 menu.addAction(self.tr("Configure..."), self.__HgConfigure)
493
494 mainMenu.addSeparator()
495 mainMenu.addMenu(menu)
496 self.menuBack = menu
497
498 def _addVCSMenuDir(self, mainMenu):
499 """
500 Protected method used to add the VCS menu to all project browsers.
501
502 @param mainMenu reference to the menu to be amended
503 """
504 if mainMenu is None:
505 return
506
507 self.vcsDirMenuActions = []
508 self.vcsAddDirMenuActions = []
509
510 menu = QMenu(self.tr("Version Control"))
511
512 act = menu.addAction(
513 UI.PixmapCache.getIcon(
514 os.path.join("VcsPlugins", "vcsMercurial", "icons",
515 "mercurial.png")),
516 self.vcs.vcsName(), self._VCSInfoDisplay)
517 font = act.font()
518 font.setBold(True)
519 act.setFont(font)
520 menu.addSeparator()
521
522 act = menu.addAction(
523 UI.PixmapCache.getIcon("vcsCommit.png"),
524 self.tr('Commit changes to repository...'),
525 self._VCSCommit)
526 self.vcsDirMenuActions.append(act)
527 self.__addExtensionsMenu(menu, 'dirMenu')
528 menu.addSeparator()
529 act = menu.addAction(
530 UI.PixmapCache.getIcon("vcsAdd.png"),
531 self.tr('Add to repository'), self._VCSAdd)
532 self.vcsAddDirMenuActions.append(act)
533 act = menu.addAction(
534 UI.PixmapCache.getIcon("vcsRemove.png"),
535 self.tr('Remove from repository (and disk)'),
536 self._VCSRemove)
537 self.vcsDirMenuActions.append(act)
538 menu.addSeparator()
539 act = menu.addAction(self.tr('Copy'), self.__HgCopy)
540 self.vcsDirMenuActions.append(act)
541 act = menu.addAction(self.tr('Move'), self.__HgMove)
542 self.vcsDirMenuActions.append(act)
543 menu.addSeparator()
544 act = menu.addAction(
545 UI.PixmapCache.getIcon("vcsLog.png"),
546 self.tr('Show log browser'), self._VCSLogBrowser)
547 self.vcsDirMenuActions.append(act)
548 menu.addSeparator()
549 act = menu.addAction(
550 UI.PixmapCache.getIcon("vcsStatus.png"),
551 self.tr('Show status'), self._VCSStatus)
552 self.vcsDirMenuActions.append(act)
553 menu.addSeparator()
554 act = menu.addAction(
555 UI.PixmapCache.getIcon("vcsDiff.png"),
556 self.tr('Show differences'), self._VCSDiff)
557 self.vcsDirMenuActions.append(act)
558 act = menu.addAction(
559 UI.PixmapCache.getIcon("vcsDiff.png"),
560 self.tr('Show differences (extended)'),
561 self.__HgExtendedDiff)
562 self.vcsDirMenuActions.append(act)
563 menu.addSeparator()
564 act = menu.addAction(
565 UI.PixmapCache.getIcon("vcsRevert.png"),
566 self.tr('Revert changes'), self.__HgRevert)
567 self.vcsDirMenuActions.append(act)
568 act = menu.addAction(
569 self.tr('Conflicts resolved'), self.__HgResolved)
570 self.vcsDirMenuActions.append(act)
571 act = menu.addAction(
572 self.tr('Conflicts unresolved'), self.__HgUnresolved)
573 self.vcsDirMenuActions.append(act)
574 act = menu.addAction(
575 self.tr('Re-Merge'), self.__HgReMerge)
576 self.vcsDirMenuActions.append(act)
577 menu.addSeparator()
578 menu.addAction(self.tr('Select all local file entries'),
579 self.browser.selectLocalEntries)
580 menu.addAction(self.tr('Select all versioned file entries'),
581 self.browser.selectVCSEntries)
582 menu.addAction(self.tr('Select all local directory entries'),
583 self.browser.selectLocalDirEntries)
584 menu.addAction(self.tr('Select all versioned directory entries'),
585 self.browser.selectVCSDirEntries)
586 menu.addSeparator()
587 menu.addAction(self.tr("Configure..."), self.__HgConfigure)
588
589 mainMenu.addSeparator()
590 mainMenu.addMenu(menu)
591 self.menuDir = menu
592
593 def _addVCSMenuDirMulti(self, mainMenu):
594 """
595 Protected method used to add the VCS menu to all project browsers.
596
597 @param mainMenu reference to the menu to be amended
598 """
599 if mainMenu is None:
600 return
601
602 self.vcsDirMultiMenuActions = []
603 self.vcsAddDirMultiMenuActions = []
604
605 menu = QMenu(self.tr("Version Control"))
606
607 act = menu.addAction(
608 UI.PixmapCache.getIcon(
609 os.path.join("VcsPlugins", "vcsMercurial", "icons",
610 "mercurial.png")),
611 self.vcs.vcsName(), self._VCSInfoDisplay)
612 font = act.font()
613 font.setBold(True)
614 act.setFont(font)
615 menu.addSeparator()
616
617 act = menu.addAction(
618 UI.PixmapCache.getIcon("vcsCommit.png"),
619 self.tr('Commit changes to repository...'),
620 self._VCSCommit)
621 self.vcsDirMultiMenuActions.append(act)
622 self.__addExtensionsMenu(menu, 'dirMultiMenu')
623 menu.addSeparator()
624 act = menu.addAction(
625 UI.PixmapCache.getIcon("vcsAdd.png"),
626 self.tr('Add to repository'), self._VCSAdd)
627 self.vcsAddDirMultiMenuActions.append(act)
628 act = menu.addAction(
629 UI.PixmapCache.getIcon("vcsRemove.png"),
630 self.tr('Remove from repository (and disk)'),
631 self._VCSRemove)
632 self.vcsDirMultiMenuActions.append(act)
633 menu.addSeparator()
634 act = menu.addAction(
635 UI.PixmapCache.getIcon("vcsStatus.png"),
636 self.tr('Show status'), self._VCSStatus)
637 self.vcsDirMultiMenuActions.append(act)
638 menu.addSeparator()
639 act = menu.addAction(
640 UI.PixmapCache.getIcon("vcsDiff.png"),
641 self.tr('Show differences'), self._VCSDiff)
642 self.vcsDirMultiMenuActions.append(act)
643 act = menu.addAction(
644 UI.PixmapCache.getIcon("vcsDiff.png"),
645 self.tr('Show differences (extended)'),
646 self.__HgExtendedDiff)
647 self.vcsDirMultiMenuActions.append(act)
648 menu.addSeparator()
649 act = menu.addAction(
650 UI.PixmapCache.getIcon("vcsRevert.png"),
651 self.tr('Revert changes'), self.__HgRevert)
652 self.vcsDirMultiMenuActions.append(act)
653 act = menu.addAction(
654 self.tr('Conflicts resolved'), self.__HgResolved)
655 self.vcsDirMultiMenuActions.append(act)
656 act = menu.addAction(
657 self.tr('Conflicts unresolved'), self.__HgUnresolved)
658 self.vcsDirMultiMenuActions.append(act)
659 act = menu.addAction(
660 self.tr('Re-Merge'), self.__HgReMerge)
661 self.vcsDirMultiMenuActions.append(act)
662 menu.addSeparator()
663 menu.addAction(self.tr('Select all local file entries'),
664 self.browser.selectLocalEntries)
665 menu.addAction(self.tr('Select all versioned file entries'),
666 self.browser.selectVCSEntries)
667 menu.addAction(self.tr('Select all local directory entries'),
668 self.browser.selectLocalDirEntries)
669 menu.addAction(self.tr('Select all versioned directory entries'),
670 self.browser.selectVCSDirEntries)
671 menu.addSeparator()
672 menu.addAction(self.tr("Configure..."), self.__HgConfigure)
673
674 mainMenu.addSeparator()
675 mainMenu.addMenu(menu)
676 self.menuDirMulti = menu
677
678 ###########################################################################
679 ## Menu handling methods below
680 ###########################################################################
681
682 def __HgRevert(self):
683 """
684 Private slot called by the context menu to revert changes made.
685 """
686 names = []
687 for itm in self.browser.getSelectedItems():
688 try:
689 name = itm.fileName()
690 except AttributeError:
691 name = itm.dirName()
692 names.append(name)
693 self.vcs.hgRevert(names)
694
695 def __HgCopy(self):
696 """
697 Private slot called by the context menu to copy the selected file.
698 """
699 itm = self.browser.currentItem()
700 try:
701 fn = itm.fileName()
702 except AttributeError:
703 fn = itm.dirName()
704 self.vcs.hgCopy(fn, self.project)
705
706 def __HgMove(self):
707 """
708 Private slot called by the context menu to move the selected file.
709 """
710 itm = self.browser.currentItem()
711 try:
712 fn = itm.fileName()
713 except AttributeError:
714 fn = itm.dirName()
715 isFile = os.path.isfile(fn)
716 movefiles = self.browser.project.getFiles(fn)
717 if self.vcs.vcsMove(fn, self.project):
718 if isFile:
719 self.browser.closeSourceWindow.emit(fn)
720 else:
721 for mf in movefiles:
722 self.browser.closeSourceWindow.emit(mf)
723
724 def __HgExtendedDiff(self):
725 """
726 Private slot called by the context menu to show the difference of a
727 file to the repository.
728
729 This gives the chance to enter the revisions to compare.
730 """
731 names = []
732 for itm in self.browser.getSelectedItems():
733 try:
734 names.append(itm.fileName())
735 except AttributeError:
736 names.append(itm.dirName())
737 self.vcs.hgExtendedDiff(names)
738
739 def __HgSbsDiff(self):
740 """
741 Private slot called by the context menu to show the difference of a
742 file to the repository side-by-side.
743 """
744 itm = self.browser.currentItem()
745 fn = itm.fileName()
746 self.vcs.hgSbsDiff(fn)
747
748 def __HgSbsExtendedDiff(self):
749 """
750 Private slot called by the context menu to show the difference of a
751 file to the repository side-by-side.
752
753 It allows the selection of revisions to compare.
754 """
755 itm = self.browser.currentItem()
756 fn = itm.fileName()
757 self.vcs.hgSbsDiff(fn, extended=True)
758
759 def __HgAnnotate(self):
760 """
761 Private slot called by the context menu to show the annotations of a
762 file.
763 """
764 itm = self.browser.currentItem()
765 fn = itm.fileName()
766 self.vcs.hgAnnotate(fn)
767
768 def __HgResolved(self):
769 """
770 Private slot called by the context menu to mark conflicts of a file
771 as being resolved.
772 """
773 names = []
774 for itm in self.browser.getSelectedItems():
775 try:
776 names.append(itm.fileName())
777 except AttributeError:
778 names.append(itm.dirName())
779 self.vcs.hgResolved(names)
780
781 def __HgUnresolved(self):
782 """
783 Private slot called by the context menu to mark conflicts of a file
784 as being unresolved.
785 """
786 names = []
787 for itm in self.browser.getSelectedItems():
788 try:
789 names.append(itm.fileName())
790 except AttributeError:
791 names.append(itm.dirName())
792 self.vcs.hgResolved(names, unresolve=True)
793
794 def __HgReMerge(self):
795 """
796 Private slot called by the context menu to re-merge 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.hgReMerge(names)
805
806 def __HgForget(self):
807 """
808 Private slot called by the context menu to remove the selected file
809 from the Mercurial repository leaving a copy in the project directory.
810 """
811 from UI.DeleteFilesConfirmationDialog import \
812 DeleteFilesConfirmationDialog
813 if self.isTranslationsBrowser:
814 items = self.browser.getSelectedItems([ProjectBrowserFileItem])
815 names = [itm.fileName() for itm in items]
816
817 dlg = DeleteFilesConfirmationDialog(
818 self.parent(),
819 self.tr("Remove from repository only"),
820 self.tr(
821 "Do you really want to remove these files"
822 " from the repository?"),
823 names)
824 else:
825 items = self.browser.getSelectedItems()
826 names = [itm.fileName() for itm in items]
827 files = [self.browser.project.getRelativePath(name)
828 for name in names]
829
830 dlg = DeleteFilesConfirmationDialog(
831 self.parent(),
832 self.tr("Remove from repository only"),
833 self.tr(
834 "Do you really want to remove these files"
835 " from the repository?"),
836 files)
837
838 if dlg.exec_() == QDialog.Accepted:
839 self.vcs.hgForget(names)
840
841 for fn in names:
842 self._updateVCSStatus(fn)
843
844 def __HgConfigure(self):
845 """
846 Private method to open the configuration dialog.
847 """
848 e5App().getObject("UserInterface")\
849 .showPreferences("zzz_mercurialPage")

eric ide

mercurial