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

eric ide

mercurial