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