eric6/Plugins/PluginVcsMercurial.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7009
eaf5ed6ef298
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2010 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Mercurial version control plugin.
8 """
9
10 from __future__ import unicode_literals
11
12 import os
13
14 from PyQt5.QtCore import QObject, QCoreApplication, QByteArray
15
16 from E5Gui.E5Application import e5App
17
18 import Preferences
19 from Preferences.Shortcuts import readShortcuts
20
21 from VcsPlugins.vcsMercurial.HgUtilities import getConfigPath
22
23 import Utilities
24 import UI.Info
25
26 # Start-Of-Header
27 name = "Mercurial Plugin"
28 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
29 autoactivate = False
30 deactivateable = True
31 version = UI.Info.VersionOnly
32 pluginType = "version_control"
33 pluginTypename = "Mercurial"
34 className = "VcsMercurialPlugin"
35 packageName = "__core__"
36 shortDescription = "Implements the Mercurial version control interface."
37 longDescription = \
38 """This plugin provides the Mercurial version control interface."""
39 pyqtApi = 2
40 python2Compatible = True
41 # End-Of-Header
42
43 error = ""
44
45
46 def exeDisplayData():
47 """
48 Public method to support the display of some executable info.
49
50 @return dictionary containing the data to query the presence of
51 the executable
52 """
53 exe = 'hg'
54 if Utilities.isWindowsPlatform():
55 exe += '.exe'
56
57 data = {
58 "programEntry": True,
59 "header": QCoreApplication.translate(
60 "VcsMercurialPlugin", "Version Control - Mercurial"),
61 "exe": exe,
62 "versionCommand": 'version',
63 "versionStartsWith": 'Mercurial',
64 "versionPosition": -1,
65 "version": "",
66 "versionCleanup": (0, -1),
67 }
68
69 return data
70
71
72 def getVcsSystemIndicator():
73 """
74 Public function to get the indicators for this version control system.
75
76 @return dictionary with indicator as key and a tuple with the vcs name
77 (string) and vcs display string (string)
78 """
79 global pluginTypename
80 data = {}
81 exe = 'hg'
82 if Utilities.isWindowsPlatform():
83 exe += '.exe'
84 if Utilities.isinpath(exe):
85 data[".hg"] = (pluginTypename, displayString())
86 data["_hg"] = (pluginTypename, displayString())
87 return data
88
89
90 def displayString():
91 """
92 Public function to get the display string.
93
94 @return display string (string)
95 """
96 exe = 'hg'
97 if Utilities.isWindowsPlatform():
98 exe += '.exe'
99 if Utilities.isinpath(exe):
100 return QCoreApplication.translate('VcsMercurialPlugin', 'Mercurial')
101 else:
102 return ""
103
104 mercurialCfgPluginObject = None
105
106
107 def createConfigurationPage(configDlg):
108 """
109 Module function to create the configuration page.
110
111 @param configDlg reference to the configuration dialog (QDialog)
112 @return reference to the configuration page
113 """
114 global mercurialCfgPluginObject
115 from VcsPlugins.vcsMercurial.ConfigurationPage.MercurialPage import \
116 MercurialPage
117 if mercurialCfgPluginObject is None:
118 mercurialCfgPluginObject = VcsMercurialPlugin(None)
119 page = MercurialPage(mercurialCfgPluginObject)
120 return page
121
122
123 def getConfigData():
124 """
125 Module function returning data as required by the configuration dialog.
126
127 @return dictionary with key "zzz_mercurialPage" containing the relevant
128 data
129 """
130 return {
131 "zzz_mercurialPage":
132 [QCoreApplication.translate("VcsMercurialPlugin", "Mercurial"),
133 os.path.join("VcsPlugins", "vcsMercurial", "icons",
134 "preferences-mercurial.png"),
135 createConfigurationPage, "vcsPage", None],
136 }
137
138
139 def prepareUninstall():
140 """
141 Module function to prepare for an uninstallation.
142 """
143 if not e5App().getObject("PluginManager").isPluginLoaded(
144 "PluginVcsMercurial"):
145 Preferences.Prefs.settings.remove("Mercurial")
146
147
148 def clearPrivateData():
149 """
150 Module function to clear the private data of the plug-in.
151 """
152 for key in ["RepositoryUrlHistory"]:
153 VcsMercurialPlugin.setPreferences(key, [])
154
155
156 class VcsMercurialPlugin(QObject):
157 """
158 Class implementing the Mercurial version control plugin.
159 """
160 MercurialDefaults = {
161 "StopLogOnCopy": True, # used in log browser
162 "LogLimit": 20,
163 "CommitMessages": 20,
164 "Commits": [],
165 "CommitAuthorsLimit": 20,
166 "CommitAuthors": [],
167 "PullUpdate": False,
168 "PreferUnbundle": False,
169 "ServerPort": 8000,
170 "ServerStyle": "",
171 "CleanupPatterns": "*.orig *.rej *~",
172 "CreateBackup": False,
173 "InternalMerge": False,
174 "Encoding": "utf-8",
175 "EncodingMode": "strict",
176 "ConsiderHidden": False,
177 "LogMessageColumnWidth": 30,
178 "LogBrowserGeometry": QByteArray(),
179 "LogBrowserSplitterStates": [QByteArray(), QByteArray(),
180 QByteArray()],
181 # mainSplitter, detailsSplitter, diffSplitter
182 "StatusDialogGeometry": QByteArray(),
183 "StatusDialogSplitterState": QByteArray(),
184 "MqStatusDialogGeometry": QByteArray(),
185 "MqStatusDialogSplitterState": QByteArray(),
186 "RepositoryUrlHistory": [],
187 }
188
189 def __init__(self, ui):
190 """
191 Constructor
192
193 @param ui reference to the user interface object (UI.UserInterface)
194 """
195 super(VcsMercurialPlugin, self).__init__(ui)
196 self.__ui = ui
197
198 from VcsPlugins.vcsMercurial.ProjectHelper import HgProjectHelper
199 self.__projectHelperObject = HgProjectHelper(None, None)
200 try:
201 e5App().registerPluginObject(
202 pluginTypename, self.__projectHelperObject, pluginType)
203 except KeyError:
204 pass # ignore duplicate registration
205 readShortcuts(pluginName=pluginTypename)
206
207 def getProjectHelper(self):
208 """
209 Public method to get a reference to the project helper object.
210
211 @return reference to the project helper object
212 """
213 return self.__projectHelperObject
214
215 def initToolbar(self, ui, toolbarManager):
216 """
217 Public slot to initialize the VCS toolbar.
218
219 @param ui reference to the main window (UserInterface)
220 @param toolbarManager reference to a toolbar manager object
221 (E5ToolBarManager)
222 """
223 if self.__projectHelperObject:
224 self.__projectHelperObject.initToolbar(ui, toolbarManager)
225
226 def activate(self):
227 """
228 Public method to activate this plugin.
229
230 @return tuple of reference to instantiated viewmanager and
231 activation status (boolean)
232 """
233 from VcsPlugins.vcsMercurial.hg import Hg
234 self.__object = Hg(self, self.__ui)
235
236 tb = self.__ui.getToolbar("vcs")[1]
237 tb.setVisible(False)
238 tb.setEnabled(False)
239
240 tb = self.__ui.getToolbar("mercurial")[1]
241 tb.setVisible(True)
242 tb.setEnabled(True)
243
244 return self.__object, True
245
246 def deactivate(self):
247 """
248 Public method to deactivate this plugin.
249 """
250 self.__object = None
251
252 tb = self.__ui.getToolbar("mercurial")[1]
253 tb.setVisible(False)
254 tb.setEnabled(False)
255
256 tb = self.__ui.getToolbar("vcs")[1]
257 tb.setVisible(True)
258 tb.setEnabled(True)
259
260 @classmethod
261 def getPreferences(cls, key):
262 """
263 Class method to retrieve the various settings.
264
265 @param key the key of the value to get
266 @return the requested setting
267 """
268 if key in ["StopLogOnCopy", "PullUpdate", "PreferUnbundle",
269 "CreateBackup", "InternalMerge", "ConsiderHidden"]:
270 return Preferences.toBool(Preferences.Prefs.settings.value(
271 "Mercurial/" + key, cls.MercurialDefaults[key]))
272 elif key in ["LogLimit", "CommitMessages", "CommitAuthorsLimit",
273 "ServerPort", "LogMessageColumnWidth"]:
274 return int(Preferences.Prefs.settings.value(
275 "Mercurial/" + key, cls.MercurialDefaults[key]))
276 elif key in ["Commits", "CommitAuthors", "RepositoryUrlHistory"]:
277 return Preferences.toList(Preferences.Prefs.settings.value(
278 "Mercurial/" + key, cls.MercurialDefaults[key]))
279 elif key in ["LogBrowserGeometry", "StatusDialogGeometry",
280 "StatusDialogSplitterState", "MqStatusDialogGeometry",
281 "MqStatusDialogSplitterState"]:
282 # QByteArray values
283 v = Preferences.Prefs.settings.value("Mercurial/" + key)
284 if v is not None:
285 return v
286 else:
287 return cls.MercurialDefaults[key]
288 elif key in ["LogBrowserSplitterStates"]:
289 # list of QByteArray values
290 states = Preferences.Prefs.settings.value("Mercurial/" + key)
291 if states is not None:
292 return states
293 else:
294 return cls.MercurialDefaults[key]
295 else:
296 return Preferences.Prefs.settings.value(
297 "Mercurial/" + key, cls.MercurialDefaults[key])
298
299 @classmethod
300 def setPreferences(cls, key, value):
301 """
302 Class method to store the various settings.
303
304 @param key the key of the setting to be set
305 @param value the value to be set
306 """
307 Preferences.Prefs.settings.setValue("Mercurial/" + key, value)
308
309 def getGlobalOptions(self):
310 """
311 Public method to build a list of global options.
312
313 @return list of global options (list of string)
314 """
315 args = []
316 if self.getPreferences("Encoding") != \
317 self.MercurialDefaults["Encoding"]:
318 args.append("--encoding")
319 args.append(self.getPreferences("Encoding"))
320 if self.getPreferences("EncodingMode") != \
321 self.MercurialDefaults["EncodingMode"]:
322 args.append("--encodingmode")
323 args.append(self.getPreferences("EncodingMode"))
324 if self.getPreferences("ConsiderHidden"):
325 args.append("--hidden")
326 return args
327
328 def getConfigPath(self):
329 """
330 Public method to get the filename of the config file.
331
332 @return filename of the config file (string)
333 """
334 return getConfigPath()
335
336 def prepareUninstall(self):
337 """
338 Public method to prepare for an uninstallation.
339 """
340 e5App().unregisterPluginObject(pluginTypename)
341
342 def prepareUnload(self):
343 """
344 Public method to prepare for an unload.
345 """
346 if self.__projectHelperObject:
347 self.__projectHelperObject.removeToolbar(
348 self.__ui, e5App().getObject("ToolbarManager"))
349 e5App().unregisterPluginObject(pluginTypename)

eric ide

mercurial