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