src/eric7/Plugins/PluginVcsGit.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2014 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Git version control plugin.
8 """
9
10 import os
11 import contextlib
12
13 from PyQt6.QtCore import QObject, QCoreApplication, QByteArray
14
15 from EricWidgets.EricApplication import ericApp
16
17 import Preferences
18 from Preferences.Shortcuts import readShortcuts
19
20 from VcsPlugins.vcsGit.GitUtilities import getConfigPath
21
22 import Utilities
23 import UI.Info
24
25 # Start-Of-Header
26 name = "Git Plugin"
27 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
28 autoactivate = False
29 deactivateable = True
30 version = UI.Info.VersionOnly
31 pluginType = "version_control"
32 pluginTypename = "Git"
33 className = "VcsGitPlugin"
34 packageName = "__core__"
35 shortDescription = "Implements the Git version control interface."
36 longDescription = (
37 """This plugin provides the Git version control interface."""
38 )
39 pyqtApi = 2
40 # End-Of-Header
41
42 error = ""
43
44
45 def exeDisplayData():
46 """
47 Public method to support the display of some executable info.
48
49 @return dictionary containing the data to query the presence of
50 the executable
51 """
52 exe = 'git'
53 if Utilities.isWindowsPlatform():
54 exe += '.exe'
55
56 data = {
57 "programEntry": True,
58 "header": QCoreApplication.translate(
59 "VcsGitPlugin", "Version Control - Git"),
60 "exe": exe,
61 "versionCommand": 'version',
62 "versionStartsWith": 'git',
63 "versionPosition": 2,
64 "version": "",
65 "versionCleanup": None,
66 }
67
68 return data
69
70
71 def getVcsSystemIndicator():
72 """
73 Public function to get the indicators for this version control system.
74
75 @return dictionary with indicator as key and a tuple with the vcs name
76 (string) and vcs display string (string)
77 """
78 global pluginTypename
79 data = {}
80 exe = 'git'
81 if Utilities.isWindowsPlatform():
82 exe += '.exe'
83 if Utilities.isinpath(exe):
84 data[".git"] = (pluginTypename, displayString())
85 data["_git"] = (pluginTypename, displayString())
86 return data
87
88
89 def displayString():
90 """
91 Public function to get the display string.
92
93 @return display string (string)
94 """
95 exe = 'git'
96 if Utilities.isWindowsPlatform():
97 exe += '.exe'
98 if Utilities.isinpath(exe):
99 return QCoreApplication.translate('VcsGitPlugin', 'Git')
100 else:
101 return ""
102
103
104 gitCfgPluginObject = 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 gitCfgPluginObject
115 from VcsPlugins.vcsGit.ConfigurationPage.GitPage import (
116 GitPage
117 )
118 if gitCfgPluginObject is None:
119 gitCfgPluginObject = VcsGitPlugin(None)
120 page = GitPage(gitCfgPluginObject)
121 return page
122
123
124 def getConfigData():
125 """
126 Module function returning data as required by the configuration dialog.
127
128 @return dictionary with key "zzz_gitPage" containing the relevant
129 data
130 """
131 return {
132 "zzz_gitPage":
133 [QCoreApplication.translate("VcsGitPlugin", "Git"),
134 os.path.join("VcsPlugins", "vcsGit", "icons",
135 "preferences-git.svg"),
136 createConfigurationPage, "vcsPage", None],
137 }
138
139
140 def prepareUninstall():
141 """
142 Module function to prepare for an uninstallation.
143 """
144 if not ericApp().getObject("PluginManager").isPluginLoaded(
145 "PluginVcsGit"):
146 Preferences.getSettings().remove("Git")
147
148
149 def clearPrivateData():
150 """
151 Module function to clear the private data of the plug-in.
152 """
153 for key in ["RepositoryUrlHistory"]:
154 VcsGitPlugin.setPreferences(key, [])
155
156
157 class VcsGitPlugin(QObject):
158 """
159 Class implementing the Git version control plugin.
160 """
161 GitDefaults = {
162 "StopLogOnCopy": True, # used in log browser
163 "ShowAuthorColumns": True, # used in log browser
164 "ShowCommitterColumns": True, # used in log browser
165 "ShowCommitIdColumn": True, # used in log browser
166 "ShowBranchesColumn": True, # used in log browser
167 "ShowTagsColumn": True, # used in log browser
168 "FindCopiesHarder": False, # used in log browser
169 "LogLimit": 20,
170 "LogSubjectColumnWidth": 30,
171 "LogBrowserGeometry": QByteArray(),
172 "LogBrowserSplitterStates": [QByteArray(), QByteArray(),
173 QByteArray()],
174 # mainSplitter, detailsSplitter, diffSplitter
175 "StatusDialogGeometry": QByteArray(),
176 "StatusDialogSplitterStates": [QByteArray(), QByteArray()],
177 # vertical splitter, horizontal splitter
178 "Commits": [],
179 "CommitIdLength": 10,
180 "CleanupPatterns": "*.orig *.rej *~",
181 "AggressiveGC": True,
182 "RepositoryUrlHistory": [],
183 }
184
185 def __init__(self, ui):
186 """
187 Constructor
188
189 @param ui reference to the user interface object (UI.UserInterface)
190 """
191 super().__init__(ui)
192 self.__ui = ui
193
194 from VcsPlugins.vcsGit.ProjectHelper import GitProjectHelper
195 self.__projectHelperObject = GitProjectHelper(None, None)
196 with contextlib.suppress(KeyError):
197 ericApp().registerPluginObject(
198 pluginTypename, self.__projectHelperObject, pluginType)
199
200 readShortcuts(pluginName=pluginTypename)
201
202 def getProjectHelper(self):
203 """
204 Public method to get a reference to the project helper object.
205
206 @return reference to the project helper object
207 """
208 return self.__projectHelperObject
209
210 def initToolbar(self, ui, toolbarManager):
211 """
212 Public slot to initialize the VCS toolbar.
213
214 @param ui reference to the main window (UserInterface)
215 @param toolbarManager reference to a toolbar manager object
216 (EricToolBarManager)
217 """
218 if self.__projectHelperObject:
219 self.__projectHelperObject.initToolbar(ui, toolbarManager)
220
221 def activate(self):
222 """
223 Public method to activate this plugin.
224
225 @return tuple of reference to instantiated viewmanager and
226 activation status (boolean)
227 """
228 from VcsPlugins.vcsGit.git import Git
229 self.__object = Git(self, self.__ui)
230
231 tb = self.__ui.getToolbar("vcs")[1]
232 tb.setVisible(False)
233 tb.setEnabled(False)
234
235 tb = self.__ui.getToolbar("git")[1]
236 tb.setVisible(Preferences.getVCS("ShowVcsToolbar"))
237 tb.setEnabled(True)
238
239 return self.__object, True
240
241 def deactivate(self):
242 """
243 Public method to deactivate this plugin.
244 """
245 self.__object = None
246
247 tb = self.__ui.getToolbar("git")[1]
248 tb.setVisible(False)
249 tb.setEnabled(False)
250
251 tb = self.__ui.getToolbar("vcs")[1]
252 tb.setVisible(Preferences.getVCS("ShowVcsToolbar"))
253 tb.setEnabled(True)
254
255 @classmethod
256 def getPreferences(cls, key):
257 """
258 Class method to retrieve the various settings.
259
260 @param key the key of the value to get
261 @return the requested setting
262 """
263 if key in ["StopLogOnCopy", "ShowReflogInfo", "ShowAuthorColumns",
264 "ShowCommitterColumns", "ShowCommitIdColumn",
265 "ShowBranchesColumn", "ShowTagsColumn", "FindCopiesHarder",
266 "AggressiveGC"]:
267 return Preferences.toBool(Preferences.getSettings().value(
268 "Git/" + key, cls.GitDefaults[key]))
269 elif key in ["LogLimit", "CommitIdLength", "LogSubjectColumnWidth"]:
270 return int(Preferences.getSettings().value(
271 "Git/" + key, cls.GitDefaults[key]))
272 elif key in ["Commits", "RepositoryUrlHistory"]:
273 return Preferences.toList(Preferences.getSettings().value(
274 "Git/" + key))
275 elif key in ["LogBrowserGeometry", "StatusDialogGeometry"]:
276 v = Preferences.getSettings().value("Git/" + key)
277 if v is not None:
278 return v
279 else:
280 return cls.GitDefaults[key]
281 elif key in ["LogBrowserSplitterStates", "StatusDialogSplitterStates"]:
282 states = Preferences.getSettings().value("Git/" + key)
283 if states is not None:
284 return states
285 else:
286 return cls.GitDefaults[key]
287 else:
288 return Preferences.getSettings().value(
289 "Git/" + key, cls.GitDefaults[key])
290
291 @classmethod
292 def setPreferences(cls, key, value):
293 """
294 Class method to store the various settings.
295
296 @param key the key of the setting to be set
297 @param value the value to be set
298 """
299 Preferences.getSettings().setValue("Git/" + key, value)
300
301 def getConfigPath(self):
302 """
303 Public method to get the filename of the config file.
304
305 @return filename of the config file (string)
306 """
307 return getConfigPath()
308
309 def prepareUninstall(self):
310 """
311 Public method to prepare for an uninstallation.
312 """
313 ericApp().unregisterPluginObject(pluginTypename)
314
315 def prepareUnload(self):
316 """
317 Public method to prepare for an unload.
318 """
319 if self.__projectHelperObject:
320 self.__projectHelperObject.removeToolbar(
321 self.__ui, ericApp().getObject("ToolbarManager"))
322 ericApp().unregisterPluginObject(pluginTypename)
323
324 #
325 # eflag: noqa = M801

eric ide

mercurial