src/eric7/Plugins/VcsPlugins/vcsMercurial/UncommitExtension/ProjectHelper.py

branch
eric7
changeset 11082
58838580274e
equal deleted inserted replaced
11081:7391035e7bc9 11082:58838580274e
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2025 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the uncommit extension project helper.
8 """
9
10 from PyQt6.QtCore import pyqtSlot
11 from PyQt6.QtWidgets import QMenu
12
13 from eric7.EricGui import EricPixmapCache
14 from eric7.EricGui.EricAction import EricAction
15 from eric7.EricWidgets import EricMessageBox
16
17 from ..HgExtensionProjectHelper import HgExtensionProjectHelper
18
19
20 class UncommitProjectHelper(HgExtensionProjectHelper):
21 """
22 Class implementing the uncommit extension project helper.
23 """
24
25 def __init__(self):
26 """
27 Constructor
28 """
29 super().__init__()
30
31 def initActions(self):
32 """
33 Public method to generate the action objects.
34 """
35 self.hgUncommitAct = EricAction(
36 self.tr("Undo Local Commit"),
37 EricPixmapCache.getIcon("vcsUncommit"),
38 self.tr("Undo Local Commit"),
39 0,
40 0,
41 self,
42 "mercurial_uncommit",
43 )
44 self.hgUncommitAct.setStatusTip(self.tr("Undo the effect of a local commit."))
45 self.hgUncommitAct.setWhatsThis(
46 self.tr(
47 """<b>Undo Local Commit</b>"""
48 """<p>This undoes the effect of a local commit, returning the"""
49 """ affected files to their uncommitted state.</p>"""
50 )
51 )
52 self.hgUncommitAct.triggered.connect(self.__hgUncommit)
53 self.actions.append(self.hgUncommitAct)
54
55 def initMenu(self, mainMenu):
56 """
57 Public method to generate the extension menu.
58
59 @param mainMenu reference to the main menu
60 @type QMenu
61 @return populated menu
62 @rtype QMenu
63 """
64 menu = QMenu(self.menuTitle(), mainMenu)
65 menu.setIcon(EricPixmapCache.getIcon("vcsUncommit"))
66 menu.setTearOffEnabled(True)
67
68 menu.addAction(self.hgUncommitAct)
69
70 return menu
71
72 def menuTitle(self):
73 """
74 Public method to get the menu title.
75
76 @return title of the menu
77 @rtype str
78 """
79 return self.tr("Uncommit")
80
81 def __reopenProject(self, shouldReopen, title):
82 """
83 Private method to reopen the project if needed and wanted.
84
85 @param shouldReopen flag indicating that the project should
86 be reopened
87 @type bool
88 @param title title of the message box
89 @type str
90 """
91 if shouldReopen:
92 res = EricMessageBox.yesNo(
93 None,
94 title,
95 self.tr("""The project should be reread. Do this now?"""),
96 yesDefault=True,
97 )
98 if res:
99 self.project.reopenProject()
100
101 @pyqtSlot()
102 def __hgUncommit(self):
103 """
104 Private slot to undo a local commit.
105 """
106 shouldReopen = self.vcs.getExtensionObject("uncommit").hgUncommit()
107 self.__reopenProject(shouldReopen, self.tr("Undo Local Commit"))

eric ide

mercurial