src/eric7/Plugins/VcsPlugins/vcsMercurial/ShelveBuiltin/ProjectBrowserHelper.py

branch
eric7
changeset 11068
15f0385e0471
parent 10439
21c28b0f9e41
child 11090
f5f5f5803935
equal deleted inserted replaced
11067:67b92e2cb719 11068:15f0385e0471
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2014 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the shelve extension project browser helper.
8 """
9
10 from PyQt6.QtWidgets import QMenu
11
12 from eric7.EricWidgets import EricMessageBox
13
14 from ..HgExtensionProjectBrowserHelper import HgExtensionProjectBrowserHelper
15
16
17 class ShelveProjectBrowserHelper(HgExtensionProjectBrowserHelper):
18 """
19 Class implementing the shelve extension project browser helper.
20 """
21
22 def __init__(self, vcsObject, browserObject, projectObject):
23 """
24 Constructor
25
26 @param vcsObject reference to the vcs object
27 @type Hg
28 @param browserObject reference to the project browser object
29 @type ProjectBaseBrowser
30 @param projectObject reference to the project object
31 @type Project
32 """
33 super().__init__(vcsObject, browserObject, projectObject)
34
35 def initMenus(self):
36 """
37 Public method to generate the extension menus.
38
39 @return dictionary of populated menu. The dict must have the keys 'mainMenu',
40 'multiMenu', 'backMenu', 'dirMenu' and 'dirMultiMenu'.
41 @rtype dict of QMenu
42 """
43 self.__menus = {}
44
45 menu = QMenu(self.menuTitle())
46 menu.setTearOffEnabled(True)
47 menu.addAction(self.tr("Shelve changes"), self.__hgShelve)
48 self.__menus["mainMenu"] = menu
49
50 menu = QMenu(self.menuTitle())
51 menu.setTearOffEnabled(True)
52 menu.addAction(self.tr("Shelve changes"), self.__hgShelve)
53 self.__menus["multiMenu"] = menu
54
55 menu = QMenu(self.menuTitle())
56 menu.setTearOffEnabled(True)
57 menu.addAction(self.tr("Shelve changes"), self.__hgShelve)
58 self.__menus["dirMenu"] = menu
59
60 menu = QMenu(self.menuTitle())
61 menu.setTearOffEnabled(True)
62 menu.addAction(self.tr("Shelve changes"), self.__hgShelve)
63 self.__menus["dirMultiMenu"] = menu
64
65 return self.__menus
66
67 def menuTitle(self):
68 """
69 Public method to get the menu title.
70
71 @return title of the menu
72 @rtype str
73 """
74 return self.tr("Shelve")
75
76 def showMenu(self, key, controlled):
77 """
78 Public method to prepare the extension menu for display.
79
80 @param key menu key (one of 'mainMenu', 'multiMenu', 'backMenu', 'dirMenu'
81 or 'dirMultiMenu')
82 @type str
83 @param controlled flag indicating to prepare the menu for a
84 version controlled entry or a non-version controlled entry
85 @type bool
86 """
87 if key in self.__menus:
88 self.__menus[key].setEnabled(controlled)
89
90 def __reopenProject(self, shouldReopen, title):
91 """
92 Private method to reopen the project if needed and wanted.
93
94 @param shouldReopen flag indicating that the project should
95 be reopened
96 @type bool
97 @param title title of the message box
98 @type str
99 """
100 if shouldReopen:
101 res = EricMessageBox.yesNo(
102 None,
103 title,
104 self.tr("""The project should be reread. Do this now?"""),
105 yesDefault=True,
106 )
107 if res:
108 self.project.reopenProject()
109
110 def __hgShelve(self):
111 """
112 Private slot used to shelve all current changes.
113 """
114 names = []
115 for itm in self.browser.getSelectedItems():
116 try:
117 name = itm.fileName()
118 except AttributeError:
119 name = itm.dirName()
120 names.append(name)
121 shouldReopen = self.vcs.getBuiltinObject("shelve").hgShelve(names)
122 self.__reopenProject(shouldReopen, self.tr("Shelve"))

eric ide

mercurial