src/eric7/Plugins/PluginVcsMercurial.py

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

eric ide

mercurial