|
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 helper. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtWidgets import QMenu |
|
11 |
|
12 from eric7.EricGui.EricAction import EricAction |
|
13 from eric7.EricWidgets import EricMessageBox |
|
14 |
|
15 from ..HgExtensionProjectHelper import HgExtensionProjectHelper |
|
16 |
|
17 |
|
18 class ShelveProjectHelper(HgExtensionProjectHelper): |
|
19 """ |
|
20 Class implementing the shelve extension project helper. |
|
21 """ |
|
22 |
|
23 def __init__(self): |
|
24 """ |
|
25 Constructor |
|
26 """ |
|
27 super().__init__() |
|
28 |
|
29 def initActions(self): |
|
30 """ |
|
31 Public method to generate the action objects. |
|
32 """ |
|
33 self.hgShelveAct = EricAction( |
|
34 self.tr("Shelve changes"), |
|
35 self.tr("Shelve changes..."), |
|
36 0, |
|
37 0, |
|
38 self, |
|
39 "mercurial_shelve", |
|
40 ) |
|
41 self.hgShelveAct.setStatusTip( |
|
42 self.tr("Shelve all current changes of the project") |
|
43 ) |
|
44 self.hgShelveAct.setWhatsThis( |
|
45 self.tr( |
|
46 """<b>Shelve changes</b>""" |
|
47 """<p>This shelves all current changes of the project.</p>""" |
|
48 ) |
|
49 ) |
|
50 self.hgShelveAct.triggered.connect(self.__hgShelve) |
|
51 self.actions.append(self.hgShelveAct) |
|
52 |
|
53 self.hgShelveBrowserAct = EricAction( |
|
54 self.tr("Show shelve browser"), |
|
55 self.tr("Show shelve browser..."), |
|
56 0, |
|
57 0, |
|
58 self, |
|
59 "mercurial_shelve_browser", |
|
60 ) |
|
61 self.hgShelveBrowserAct.setStatusTip(self.tr("Show a dialog with all shelves")) |
|
62 self.hgShelveBrowserAct.setWhatsThis( |
|
63 self.tr( |
|
64 """<b>Show shelve browser...</b>""" |
|
65 """<p>This shows a dialog listing all available shelves.""" |
|
66 """ Actions on these shelves may be executed via the""" |
|
67 """ context menu.</p>""" |
|
68 ) |
|
69 ) |
|
70 self.hgShelveBrowserAct.triggered.connect(self.__hgShelveBrowser) |
|
71 self.actions.append(self.hgShelveBrowserAct) |
|
72 |
|
73 self.hgUnshelveAct = EricAction( |
|
74 self.tr("Restore shelved change"), |
|
75 self.tr("Restore shelved change..."), |
|
76 0, |
|
77 0, |
|
78 self, |
|
79 "mercurial_unshelve", |
|
80 ) |
|
81 self.hgUnshelveAct.setStatusTip( |
|
82 self.tr("Restore a shelved change to the project directory") |
|
83 ) |
|
84 self.hgUnshelveAct.setWhatsThis( |
|
85 self.tr( |
|
86 """<b>Restore shelved change</b>""" |
|
87 """<p>This restore a shelved change to the project directory.""" |
|
88 """</p>""" |
|
89 ) |
|
90 ) |
|
91 self.hgUnshelveAct.triggered.connect(self.__hgUnshelve) |
|
92 self.actions.append(self.hgUnshelveAct) |
|
93 |
|
94 self.hgUnshelveAbortAct = EricAction( |
|
95 self.tr("Abort restore"), |
|
96 self.tr("Abort restore..."), |
|
97 0, |
|
98 0, |
|
99 self, |
|
100 "mercurial_unshelve_abort", |
|
101 ) |
|
102 self.hgUnshelveAbortAct.setStatusTip( |
|
103 self.tr("Abort the restore operation in progress") |
|
104 ) |
|
105 self.hgUnshelveAbortAct.setWhatsThis( |
|
106 self.tr( |
|
107 """<b>Abort restore</b>""" |
|
108 """<p>This aborts the restore operation in progress and reverts""" |
|
109 """ already applied changes.</p>""" |
|
110 ) |
|
111 ) |
|
112 self.hgUnshelveAbortAct.triggered.connect(self.__hgUnshelveAbort) |
|
113 self.actions.append(self.hgUnshelveAbortAct) |
|
114 |
|
115 self.hgUnshelveContinueAct = EricAction( |
|
116 self.tr("Continue restore"), |
|
117 self.tr("Continue restore..."), |
|
118 0, |
|
119 0, |
|
120 self, |
|
121 "mercurial_unshelve_continue", |
|
122 ) |
|
123 self.hgUnshelveContinueAct.setStatusTip( |
|
124 self.tr("Continue the restore operation in progress") |
|
125 ) |
|
126 self.hgUnshelveContinueAct.setWhatsThis( |
|
127 self.tr( |
|
128 """<b>Continue restore</b>""" |
|
129 """<p>This continues the restore operation in progress.</p>""" |
|
130 ) |
|
131 ) |
|
132 self.hgUnshelveContinueAct.triggered.connect(self.__hgUnshelveContinue) |
|
133 self.actions.append(self.hgUnshelveContinueAct) |
|
134 |
|
135 self.hgShelveDeleteAct = EricAction( |
|
136 self.tr("Delete shelved changes"), |
|
137 self.tr("Delete shelved changes..."), |
|
138 0, |
|
139 0, |
|
140 self, |
|
141 "mercurial_shelve_delete", |
|
142 ) |
|
143 self.hgShelveDeleteAct.setWhatsThis( |
|
144 self.tr( |
|
145 """<b>Delete shelved changes...</b>""" |
|
146 """<p>This opens a dialog to select the shelved changes to""" |
|
147 """ delete and deletes the selected ones.</p>""" |
|
148 ) |
|
149 ) |
|
150 self.hgShelveDeleteAct.triggered.connect(self.__hgDeleteShelves) |
|
151 self.actions.append(self.hgShelveDeleteAct) |
|
152 |
|
153 self.hgShelveCleanupAct = EricAction( |
|
154 self.tr("Delete ALL shelved changes"), |
|
155 self.tr("Delete ALL shelved changes"), |
|
156 0, |
|
157 0, |
|
158 self, |
|
159 "mercurial_shelve_cleanup", |
|
160 ) |
|
161 self.hgShelveCleanupAct.setWhatsThis( |
|
162 self.tr( |
|
163 """<b>Delete ALL shelved changes</b>""" |
|
164 """<p>This deletes all shelved changes.</p>""" |
|
165 ) |
|
166 ) |
|
167 self.hgShelveCleanupAct.triggered.connect(self.__hgCleanupShelves) |
|
168 self.actions.append(self.hgShelveCleanupAct) |
|
169 |
|
170 def initMenu(self, mainMenu): |
|
171 """ |
|
172 Public method to generate the extension menu. |
|
173 |
|
174 @param mainMenu reference to the main menu |
|
175 @type QMenu |
|
176 @return populated menu |
|
177 @rtype QMenu |
|
178 """ |
|
179 menu = QMenu(self.menuTitle(), mainMenu) |
|
180 menu.setTearOffEnabled(True) |
|
181 |
|
182 menu.addAction(self.hgShelveAct) |
|
183 menu.addSeparator() |
|
184 menu.addAction(self.hgShelveBrowserAct) |
|
185 menu.addSeparator() |
|
186 menu.addAction(self.hgUnshelveAct) |
|
187 menu.addAction(self.hgUnshelveContinueAct) |
|
188 menu.addAction(self.hgUnshelveAbortAct) |
|
189 menu.addSeparator() |
|
190 menu.addAction(self.hgShelveDeleteAct) |
|
191 menu.addAction(self.hgShelveCleanupAct) |
|
192 |
|
193 return menu |
|
194 |
|
195 def menuTitle(self): |
|
196 """ |
|
197 Public method to get the menu title. |
|
198 |
|
199 @return title of the menu |
|
200 @rtype str |
|
201 """ |
|
202 return self.tr("Shelve") |
|
203 |
|
204 def __reopenProject(self, shouldReopen, title): |
|
205 """ |
|
206 Private method to reopen the project if needed and wanted. |
|
207 |
|
208 @param shouldReopen flag indicating that the project should |
|
209 be reopened |
|
210 @type bool |
|
211 @param title title of the message box |
|
212 @type str |
|
213 """ |
|
214 if shouldReopen: |
|
215 res = EricMessageBox.yesNo( |
|
216 None, |
|
217 title, |
|
218 self.tr("""The project should be reread. Do this now?"""), |
|
219 yesDefault=True, |
|
220 ) |
|
221 if res: |
|
222 self.project.reopenProject() |
|
223 |
|
224 def __hgShelve(self): |
|
225 """ |
|
226 Private slot used to shelve all current changes. |
|
227 """ |
|
228 shouldReopen = self.vcs.getBuiltinObject("shelve").hgShelve( |
|
229 self.project.getProjectPath() |
|
230 ) |
|
231 self.__reopenProject(shouldReopen, self.tr("Shelve")) |
|
232 |
|
233 def __hgShelveBrowser(self): |
|
234 """ |
|
235 Private slot to show the shelve browser dialog. |
|
236 """ |
|
237 self.vcs.getBuiltinObject("shelve").hgShelveBrowser() |
|
238 |
|
239 def __hgUnshelve(self): |
|
240 """ |
|
241 Private slot used to restore a shelved change. |
|
242 """ |
|
243 shouldReopen = self.vcs.getBuiltinObject("shelve").hgUnshelve() |
|
244 self.__reopenProject(shouldReopen, self.tr("Unshelve")) |
|
245 |
|
246 def __hgUnshelveAbort(self): |
|
247 """ |
|
248 Private slot used to abort an ongoing restore operation. |
|
249 """ |
|
250 shouldReopen = self.vcs.getBuiltinObject("shelve").hgUnshelveAbort() |
|
251 self.__reopenProject(shouldReopen, self.tr("Abort Unshelve")) |
|
252 |
|
253 def __hgUnshelveContinue(self): |
|
254 """ |
|
255 Private slot used to continue an ongoing restore operation. |
|
256 """ |
|
257 shouldReopen = self.vcs.getBuiltinObject("shelve").hgUnshelveContinue() |
|
258 self.__reopenProject(shouldReopen, self.tr("Continue Unshelve")) |
|
259 |
|
260 def __hgDeleteShelves(self): |
|
261 """ |
|
262 Private slot to delete selected shelves. |
|
263 """ |
|
264 self.vcs.getBuiltinObject("shelve").hgDeleteShelves() |
|
265 |
|
266 def __hgCleanupShelves(self): |
|
267 """ |
|
268 Private slot to delete all shelves. |
|
269 """ |
|
270 self.vcs.getBuiltinObject("shelve").hgCleanupShelves() |