|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Mercurial version control plugin. |
|
8 """ |
|
9 |
|
10 import os |
|
11 |
|
12 from PyQt4.QtGui import QApplication |
|
13 |
|
14 from E5Gui.E5Application import e5App |
|
15 |
|
16 import Preferences |
|
17 from Preferences.Shortcuts import readShortcuts |
|
18 |
|
19 from VcsPlugins.vcsMercurial.HgUtilities import getConfigPath |
|
20 |
|
21 import Utilities |
|
22 |
|
23 # Start-Of-Header |
|
24 name = "Mercurial Plugin" |
|
25 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
|
26 autoactivate = False |
|
27 deactivateable = True |
|
28 version = "5.0.0" |
|
29 pluginType = "version_control" |
|
30 pluginTypename = "Mercurial" |
|
31 className = "VcsMercurialPlugin" |
|
32 packageName = "__core__" |
|
33 shortDescription = "Implements the Mercurial version control interface." |
|
34 longDescription = """This plugin provides the Mercurial version control interface.""" |
|
35 pyqtApi = 2 |
|
36 # End-Of-Header |
|
37 |
|
38 error = "" |
|
39 |
|
40 def exeDisplayData(): |
|
41 """ |
|
42 Public method to support the display of some executable info. |
|
43 |
|
44 @return dictionary containing the data to query the presence of |
|
45 the executable |
|
46 """ |
|
47 exe = 'hg' |
|
48 if Utilities.isWindowsPlatform(): |
|
49 exe += '.exe' |
|
50 |
|
51 data = { |
|
52 "programEntry" : True, |
|
53 "header" : QApplication.translate("VcsMercurialPlugin", |
|
54 "Version Control - Mercurial"), |
|
55 "exe" : exe, |
|
56 "versionCommand" : 'version', |
|
57 "versionStartsWith" : 'Mercurial', |
|
58 "versionPosition" : -1, |
|
59 "version" : "", |
|
60 "versionCleanup" : (0, -1), |
|
61 } |
|
62 |
|
63 return data |
|
64 |
|
65 def getVcsSystemIndicator(): |
|
66 """ |
|
67 Public function to get the indicators for this version control system. |
|
68 |
|
69 @return dictionary with indicator as key and a tuple with the vcs name (string) |
|
70 and vcs display string (string) |
|
71 """ |
|
72 global pluginTypename |
|
73 data = {} |
|
74 exe = 'hg' |
|
75 if Utilities.isWindowsPlatform(): |
|
76 exe += '.exe' |
|
77 if Utilities.isinpath(exe): |
|
78 data[".hg"] = (pluginTypename, displayString()) |
|
79 data["_hg"] = (pluginTypename, displayString()) |
|
80 return data |
|
81 |
|
82 def displayString(): |
|
83 """ |
|
84 Public function to get the display string. |
|
85 |
|
86 @return display string (string) |
|
87 """ |
|
88 exe = 'hg' |
|
89 if Utilities.isWindowsPlatform(): |
|
90 exe += '.exe' |
|
91 if Utilities.isinpath(exe): |
|
92 return QApplication.translate('VcsMercurialPlugin', 'Mercurial') |
|
93 else: |
|
94 return "" |
|
95 |
|
96 mercurialCfgPluginObject = None |
|
97 |
|
98 def createConfigurationPage(configDlg): |
|
99 """ |
|
100 Module function to create the configuration page. |
|
101 |
|
102 @return reference to the configuration page |
|
103 """ |
|
104 global mercurialCfgPluginObject |
|
105 from VcsPlugins.vcsMercurial.ConfigurationPage.MercurialPage import MercurialPage |
|
106 if mercurialCfgPluginObject is None: |
|
107 mercurialCfgPluginObject = VcsMercurialPlugin(None) |
|
108 page = MercurialPage(mercurialCfgPluginObject) |
|
109 return page |
|
110 |
|
111 def getConfigData(): |
|
112 """ |
|
113 Module function returning data as required by the configuration dialog. |
|
114 |
|
115 @return dictionary with key "zzz_mercurialPage" containing the relevant data |
|
116 """ |
|
117 return { |
|
118 "zzz_mercurialPage" : \ |
|
119 [QApplication.translate("VcsMercurialPlugin", "Mercurial"), |
|
120 os.path.join("VcsPlugins", "vcsMercurial", "icons", |
|
121 "preferences-mercurial.png"), |
|
122 createConfigurationPage, "vcsPage", None], |
|
123 } |
|
124 |
|
125 def prepareUninstall(): |
|
126 """ |
|
127 Module function to prepare for an uninstallation. |
|
128 """ |
|
129 if not e5App().getObject("PluginManager").isPluginLoaded("PluginVcsMercurial"): |
|
130 Preferences.Prefs.settings.remove("Mercurial") |
|
131 |
|
132 class VcsMercurialPlugin(object): |
|
133 """ |
|
134 Class implementing the Mercurial version control plugin. |
|
135 """ |
|
136 def __init__(self, ui): |
|
137 """ |
|
138 Constructor |
|
139 |
|
140 @param ui reference to the user interface object (UI.UserInterface) |
|
141 """ |
|
142 self.__ui = ui |
|
143 |
|
144 self.__mercurialDefaults = { |
|
145 "StopLogOnCopy" : True, # used in log browser |
|
146 "LogLimit" : 100, |
|
147 "CommitMessages" : 20, |
|
148 } |
|
149 |
|
150 from VcsPlugins.vcsMercurial.ProjectHelper import HgProjectHelper |
|
151 self.__projectHelperObject = HgProjectHelper(None, None) |
|
152 try: |
|
153 e5App().registerPluginObject(pluginTypename, self.__projectHelperObject, |
|
154 pluginType) |
|
155 except KeyError: |
|
156 pass # ignore duplicate registration |
|
157 readShortcuts(pluginName = pluginTypename) |
|
158 |
|
159 def getProjectHelper(self): |
|
160 """ |
|
161 Public method to get a reference to the project helper object. |
|
162 |
|
163 @return reference to the project helper object |
|
164 """ |
|
165 return self.__projectHelperObject |
|
166 |
|
167 def activate(self): |
|
168 """ |
|
169 Public method to activate this plugin. |
|
170 |
|
171 @return tuple of reference to instantiated viewmanager and |
|
172 activation status (boolean) |
|
173 """ |
|
174 from VcsPlugins.vcsMercurial.hg import Hg |
|
175 self.__object = Hg(self, self.__ui) |
|
176 return self.__object, True |
|
177 |
|
178 def deactivate(self): |
|
179 """ |
|
180 Public method to deactivate this plugin. |
|
181 """ |
|
182 self.__object = None |
|
183 |
|
184 def getPreferences(self, key): |
|
185 """ |
|
186 Public method to retrieve the various settings. |
|
187 |
|
188 @param key the key of the value to get |
|
189 @return the requested setting |
|
190 """ |
|
191 if key in ["StopLogOnCopy"]: |
|
192 return Preferences.toBool(Preferences.Prefs.settings.value( |
|
193 "Mercurial/" + key, self.__mercurialDefaults[key])) |
|
194 elif key in ["LogLimit", "CommitMessages"]: |
|
195 return int(Preferences.Prefs.settings.value("Mercurial/" + key, |
|
196 self.__mercurialDefaults[key])) |
|
197 elif key in ["Commits"]: |
|
198 return Preferences.toList(Preferences.Prefs.settings.value( |
|
199 "Mercurial/" + key)) |
|
200 else: |
|
201 return Preferences.Prefs.settings.value("Mercurial/" + key) |
|
202 |
|
203 def setPreferences(self, key, value): |
|
204 """ |
|
205 Public method to store the various settings. |
|
206 |
|
207 @param key the key of the setting to be set |
|
208 @param value the value to be set |
|
209 """ |
|
210 Preferences.Prefs.settings.setValue("Mercurial/" + key, value) |
|
211 |
|
212 def getConfigPath(self): |
|
213 """ |
|
214 Public method to get the filename of the config file. |
|
215 |
|
216 @return filename of the config file (string) |
|
217 """ |
|
218 return getConfigPath() |
|
219 |
|
220 def prepareUninstall(self): |
|
221 """ |
|
222 Public method to prepare for an uninstallation. |
|
223 """ |
|
224 e5App().unregisterPluginObject(pluginTypename) |