|
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 browser 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.EricWidgets import EricMessageBox |
|
15 |
|
16 from ..HgExtensionProjectBrowserHelper import HgExtensionProjectBrowserHelper |
|
17 |
|
18 |
|
19 class UncommitProjectBrowserHelper(HgExtensionProjectBrowserHelper): |
|
20 """ |
|
21 Class implementing the uncommit extension project browser helper. |
|
22 """ |
|
23 |
|
24 def __init__(self, vcsObject, browserObject, projectObject): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param vcsObject reference to the vcs object |
|
29 @type Hg |
|
30 @param browserObject reference to the project browser object |
|
31 @type ProjectBaseBrowser |
|
32 @param projectObject reference to the project object |
|
33 @type Project |
|
34 """ |
|
35 super().__init__(vcsObject, browserObject, projectObject) |
|
36 |
|
37 def initMenus(self): |
|
38 """ |
|
39 Public method to generate the extension menus. |
|
40 |
|
41 @return dictionary of populated menu. The dict must have the keys 'mainMenu', |
|
42 'multiMenu', 'backMenu', 'dirMenu' and 'dirMultiMenu'. |
|
43 @rtype dict of QMenu |
|
44 """ |
|
45 self.__menus = {} |
|
46 |
|
47 menu = QMenu(self.menuTitle()) |
|
48 menu.setIcon(EricPixmapCache.getIcon("vcsUncommit")) |
|
49 menu.setTearOffEnabled(True) |
|
50 menu.addAction( |
|
51 EricPixmapCache.getIcon("vcsUncommit"), |
|
52 self.tr("Undo Local Commit"), |
|
53 self.__hgUncommit, |
|
54 ) |
|
55 self.__menus["mainMenu"] = menu |
|
56 |
|
57 menu = QMenu(self.menuTitle()) |
|
58 menu.setIcon(EricPixmapCache.getIcon("vcsUncommit")) |
|
59 menu.setTearOffEnabled(True) |
|
60 menu.addAction( |
|
61 EricPixmapCache.getIcon("vcsUncommit"), |
|
62 self.tr("Undo Local Commit"), |
|
63 self.__hgUncommit, |
|
64 ) |
|
65 self.__menus["multiMenu"] = menu |
|
66 |
|
67 menu = QMenu(self.menuTitle()) |
|
68 menu.setIcon(EricPixmapCache.getIcon("vcsUncommit")) |
|
69 menu.setTearOffEnabled(True) |
|
70 menu.addAction( |
|
71 EricPixmapCache.getIcon("vcsUncommit"), |
|
72 self.tr("Undo Local Commit"), |
|
73 self.__hgUncommit, |
|
74 ) |
|
75 self.__menus["dirMenu"] = menu |
|
76 |
|
77 menu = QMenu(self.menuTitle()) |
|
78 menu.setIcon(EricPixmapCache.getIcon("vcsUncommit")) |
|
79 menu.setTearOffEnabled(True) |
|
80 menu.addAction( |
|
81 EricPixmapCache.getIcon("vcsUncommit"), |
|
82 self.tr("Undo Local Commit"), |
|
83 self.__hgUncommit, |
|
84 ) |
|
85 self.__menus["dirMultiMenu"] = menu |
|
86 |
|
87 return self.__menus |
|
88 |
|
89 def menuTitle(self): |
|
90 """ |
|
91 Public method to get the menu title. |
|
92 |
|
93 @return title of the menu |
|
94 @rtype str |
|
95 """ |
|
96 return self.tr("Uncommit") |
|
97 |
|
98 def showMenu(self, key, controlled): |
|
99 """ |
|
100 Public method to prepare the extension menu for display. |
|
101 |
|
102 @param key menu key (one of 'mainMenu', 'multiMenu', 'backMenu', 'dirMenu' |
|
103 or 'dirMultiMenu') |
|
104 @type str |
|
105 @param controlled flag indicating to prepare the menu for a |
|
106 version controlled entry or a non-version controlled entry |
|
107 @type bool |
|
108 """ |
|
109 if key in self.__menus: |
|
110 self.__menus[key].setEnabled(controlled) |
|
111 |
|
112 def __reopenProject(self, shouldReopen, title): |
|
113 """ |
|
114 Private method to reopen the project if needed and wanted. |
|
115 |
|
116 @param shouldReopen flag indicating that the project should |
|
117 be reopened |
|
118 @type bool |
|
119 @param title title of the message box |
|
120 @type str |
|
121 """ |
|
122 if shouldReopen: |
|
123 res = EricMessageBox.yesNo( |
|
124 None, |
|
125 title, |
|
126 self.tr("""The project should be reread. Do this now?"""), |
|
127 yesDefault=True, |
|
128 ) |
|
129 if res: |
|
130 self.project.reopenProject() |
|
131 |
|
132 @pyqtSlot() |
|
133 def __hgUncommit(self): |
|
134 """ |
|
135 Private slot to undo the effect of a local commit. |
|
136 """ |
|
137 names = [] |
|
138 for itm in self.browser.getSelectedItems(): |
|
139 try: |
|
140 name = itm.fileName() |
|
141 except AttributeError: |
|
142 name = itm.dirName() |
|
143 names.append(name) |
|
144 shouldReopen = self.vcs.getExtensionObject("uncommit").hgUncommit(names) |
|
145 self.__reopenProject(shouldReopen, self.tr("Undo Local Commit")) |