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