|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the purge extension project helper. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtWidgets import QMenu |
|
11 |
|
12 from E5Gui.E5Action import E5Action |
|
13 |
|
14 from ..HgExtensionProjectHelper import HgExtensionProjectHelper |
|
15 |
|
16 import UI.PixmapCache |
|
17 |
|
18 |
|
19 class PurgeProjectHelper(HgExtensionProjectHelper): |
|
20 """ |
|
21 Class implementing the purge extension project helper. |
|
22 """ |
|
23 def __init__(self): |
|
24 """ |
|
25 Constructor |
|
26 """ |
|
27 super().__init__() |
|
28 |
|
29 def initActions(self): |
|
30 """ |
|
31 Public method to generate the action objects. |
|
32 """ |
|
33 self.hgPurgeAct = E5Action( |
|
34 self.tr('Purge Files'), |
|
35 UI.PixmapCache.getIcon("fileDelete"), |
|
36 self.tr('Purge Files'), |
|
37 0, 0, self, 'mercurial_purge') |
|
38 self.hgPurgeAct.setStatusTip(self.tr( |
|
39 'Delete files and directories not known to Mercurial' |
|
40 )) |
|
41 self.hgPurgeAct.setWhatsThis(self.tr( |
|
42 """<b>Purge Files</b>""" |
|
43 """<p>This deletes files and directories not known to Mercurial.""" |
|
44 """ That means that purge will delete:<ul>""" |
|
45 """<li>unknown files (marked with "not tracked" in the status""" |
|
46 """ dialog)</li>""" |
|
47 """<li>empty directories</li>""" |
|
48 """</ul>Note that ignored files will be left untouched.</p>""" |
|
49 )) |
|
50 self.hgPurgeAct.triggered.connect(self.__hgPurge) |
|
51 self.actions.append(self.hgPurgeAct) |
|
52 |
|
53 self.hgPurgeAllAct = E5Action( |
|
54 self.tr('Purge All Files'), |
|
55 self.tr('Purge All Files'), |
|
56 0, 0, self, 'mercurial_purge_all') |
|
57 self.hgPurgeAllAct.setStatusTip(self.tr( |
|
58 'Delete files and directories not known to Mercurial including' |
|
59 ' ignored ones' |
|
60 )) |
|
61 self.hgPurgeAllAct.setWhatsThis(self.tr( |
|
62 """<b>Purge All Files</b>""" |
|
63 """<p>This deletes files and directories not known to Mercurial.""" |
|
64 """ That means that purge will delete:<ul>""" |
|
65 """<li>unknown files (marked with "not tracked" in the status""" |
|
66 """ dialog)</li>""" |
|
67 """<li>empty directories</li>""" |
|
68 """<li>ignored files and directories</li>""" |
|
69 """</ul></p>""" |
|
70 )) |
|
71 self.hgPurgeAllAct.triggered.connect(self.__hgPurgeAll) |
|
72 self.actions.append(self.hgPurgeAllAct) |
|
73 |
|
74 self.hgPurgeListAct = E5Action( |
|
75 self.tr('List Files to be Purged'), |
|
76 UI.PixmapCache.getIcon("fileDeleteList"), |
|
77 self.tr('List Files to be Purged...'), |
|
78 0, 0, self, 'mercurial_purge_list') |
|
79 self.hgPurgeListAct.setStatusTip(self.tr( |
|
80 'List files and directories not known to Mercurial' |
|
81 )) |
|
82 self.hgPurgeListAct.setWhatsThis(self.tr( |
|
83 """<b>List Files to be Purged</b>""" |
|
84 """<p>This lists files and directories not known to Mercurial.""" |
|
85 """ These would be deleted by the "Purge Files" menu entry.</p>""" |
|
86 )) |
|
87 self.hgPurgeListAct.triggered.connect(self.__hgPurgeList) |
|
88 self.actions.append(self.hgPurgeListAct) |
|
89 |
|
90 self.hgPurgeAllListAct = E5Action( |
|
91 self.tr('List All Files to be Purged'), |
|
92 self.tr('List All Files to be Purged...'), |
|
93 0, 0, self, 'mercurial_purge_all_list') |
|
94 self.hgPurgeAllListAct.setStatusTip(self.tr( |
|
95 'List files and directories not known to Mercurial including' |
|
96 ' ignored ones' |
|
97 )) |
|
98 self.hgPurgeAllListAct.setWhatsThis(self.tr( |
|
99 """<b>List All Files to be Purged</b>""" |
|
100 """<p>This lists files and directories not known to Mercurial""" |
|
101 """ including ignored ones. These would be deleted by the""" |
|
102 """ "Purge All Files" menu entry.</p>""" |
|
103 )) |
|
104 self.hgPurgeAllListAct.triggered.connect(self.__hgPurgeAllList) |
|
105 self.actions.append(self.hgPurgeAllListAct) |
|
106 |
|
107 def initMenu(self, mainMenu): |
|
108 """ |
|
109 Public method to generate the extension menu. |
|
110 |
|
111 @param mainMenu reference to the main menu (QMenu) |
|
112 @return populated menu (QMenu) |
|
113 """ |
|
114 menu = QMenu(self.menuTitle(), mainMenu) |
|
115 menu.setIcon(UI.PixmapCache.getIcon("fileDelete")) |
|
116 menu.setTearOffEnabled(True) |
|
117 |
|
118 menu.addAction(self.hgPurgeAct) |
|
119 menu.addAction(self.hgPurgeAllAct) |
|
120 menu.addSeparator() |
|
121 menu.addAction(self.hgPurgeListAct) |
|
122 menu.addAction(self.hgPurgeAllListAct) |
|
123 |
|
124 return menu |
|
125 |
|
126 def menuTitle(self): |
|
127 """ |
|
128 Public method to get the menu title. |
|
129 |
|
130 @return title of the menu (string) |
|
131 """ |
|
132 return self.tr("Purge") |
|
133 |
|
134 def __hgPurge(self): |
|
135 """ |
|
136 Private slot used to remove files not tracked by Mercurial. |
|
137 """ |
|
138 self.vcs.getExtensionObject("purge").hgPurge(deleteAll=False) |
|
139 |
|
140 def __hgPurgeAll(self): |
|
141 """ |
|
142 Private slot used to remove all files not tracked by Mercurial. |
|
143 """ |
|
144 self.vcs.getExtensionObject("purge").hgPurge(deleteAll=True) |
|
145 |
|
146 def __hgPurgeList(self): |
|
147 """ |
|
148 Private slot used to list files not tracked by Mercurial. |
|
149 """ |
|
150 self.vcs.getExtensionObject("purge").hgPurgeList(deleteAll=False) |
|
151 |
|
152 def __hgPurgeAllList(self): |
|
153 """ |
|
154 Private slot used to list all files not tracked by Mercurial. |
|
155 """ |
|
156 self.vcs.getExtensionObject("purge").hgPurgeList(deleteAll=True) |