|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2016 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the strip extension project helper. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtWidgets import QMenu |
|
13 |
|
14 from E5Gui.E5Action import E5Action |
|
15 from E5Gui import E5MessageBox |
|
16 |
|
17 from ..HgExtensionProjectHelper import HgExtensionProjectHelper |
|
18 |
|
19 import UI.PixmapCache |
|
20 |
|
21 |
|
22 class StripProjectHelper(HgExtensionProjectHelper): |
|
23 """ |
|
24 Class implementing the strip extension project helper. |
|
25 """ |
|
26 def __init__(self): |
|
27 """ |
|
28 Constructor |
|
29 """ |
|
30 super(StripProjectHelper, self).__init__() |
|
31 |
|
32 def initActions(self): |
|
33 """ |
|
34 Public method to generate the action objects. |
|
35 """ |
|
36 self.hgStripAct = E5Action( |
|
37 self.tr('Strip changesets'), |
|
38 UI.PixmapCache.getIcon("fileDelete.png"), |
|
39 self.tr('Strip changesets'), |
|
40 0, 0, self, 'mercurial_strip') |
|
41 self.hgStripAct.setStatusTip(self.tr( |
|
42 'Strip changesets from a repository' |
|
43 )) |
|
44 self.hgStripAct.setWhatsThis(self.tr( |
|
45 """<b>Strip changesets</b>""" |
|
46 """<p>This deletes a changeset and all its descendants""" |
|
47 """ from a repository. Each removed changeset will be""" |
|
48 """ stored in .hg/strip-backup as a bundle file.</p>""" |
|
49 )) |
|
50 self.hgStripAct.triggered.connect(self.__hgStrip) |
|
51 self.actions.append(self.hgStripAct) |
|
52 |
|
53 def initMenu(self, mainMenu): |
|
54 """ |
|
55 Public method to generate the extension menu. |
|
56 |
|
57 @param mainMenu reference to the main menu (QMenu) |
|
58 @return populated menu (QMenu) |
|
59 """ |
|
60 menu = QMenu(self.menuTitle(), mainMenu) |
|
61 menu.setIcon(UI.PixmapCache.getIcon("fileDelete.png")) |
|
62 menu.setTearOffEnabled(True) |
|
63 |
|
64 menu.addAction(self.hgStripAct) |
|
65 |
|
66 return menu |
|
67 |
|
68 def menuTitle(self): |
|
69 """ |
|
70 Public method to get the menu title. |
|
71 |
|
72 @return title of the menu (string) |
|
73 """ |
|
74 return self.tr("Strip") |
|
75 |
|
76 def __hgStrip(self): |
|
77 """ |
|
78 Private slot used to strip revisions from a repository. |
|
79 """ |
|
80 shouldReopen = self.vcs.getExtensionObject("strip")\ |
|
81 .hgStrip(self.project.getProjectPath()) |
|
82 if shouldReopen: |
|
83 res = E5MessageBox.yesNo( |
|
84 None, |
|
85 self.tr("Strip"), |
|
86 self.tr("""The project should be reread. Do this now?"""), |
|
87 yesDefault=True) |
|
88 if res: |
|
89 self.project.reopenProject() |