src/eric7/Plugins/PluginVcsSubversion.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) 2007 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Subversion version control plugin.
8 """
9
10 import os
11 import contextlib
12
13 from PyQt6.QtCore import QObject, QCoreApplication
14
15 from EricWidgets.EricApplication import ericApp
16
17 import Preferences
18 from Preferences.Shortcuts import readShortcuts
19
20 from VcsPlugins.vcsSubversion.SvnUtilities import getConfigPath, getServersPath
21
22 import Utilities
23 import UI.Info
24
25 # Start-Of-Header
26 name = "Subversion 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 = "Subversion"
33 className = "VcsSubversionPlugin"
34 packageName = "__core__"
35 shortDescription = "Implements the Subversion version control interface."
36 longDescription = (
37 """This plugin provides the Subversion 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 = 'svn'
53 if Utilities.isWindowsPlatform():
54 exe += '.exe'
55
56 data = {
57 "programEntry": True,
58 "header": QCoreApplication.translate(
59 "VcsSubversionPlugin", "Version Control - Subversion (svn)"),
60 "exe": exe,
61 "versionCommand": '--version',
62 "versionStartsWith": 'svn',
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 = 'svn'
81 if Utilities.isWindowsPlatform():
82 exe += '.exe'
83 if Utilities.isinpath(exe):
84 data[".svn"] = (pluginTypename, displayString())
85 data["_svn"] = (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 = 'svn'
96 if Utilities.isWindowsPlatform():
97 exe += '.exe'
98 if Utilities.isinpath(exe):
99 return QCoreApplication.translate(
100 'VcsSubversionPlugin', 'Subversion (svn)')
101 else:
102 return ""
103
104 subversionCfgPluginObject = 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 subversionCfgPluginObject
115 from VcsPlugins.vcsSubversion.ConfigurationPage.SubversionPage import (
116 SubversionPage
117 )
118 if subversionCfgPluginObject is None:
119 subversionCfgPluginObject = VcsSubversionPlugin(None)
120 page = SubversionPage(subversionCfgPluginObject)
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_subversionPage" containing the relevant
129 data
130 """
131 return {
132 "zzz_subversionPage":
133 [QCoreApplication.translate("VcsSubversionPlugin", "Subversion"),
134 os.path.join("VcsPlugins", "vcsSubversion", "icons",
135 "preferences-subversion.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 "PluginVcsSubversion"):
146 Preferences.getSettings().remove("Subversion")
147
148
149 class VcsSubversionPlugin(QObject):
150 """
151 Class implementing the Subversion version control plugin.
152 """
153 def __init__(self, ui):
154 """
155 Constructor
156
157 @param ui reference to the user interface object (UI.UserInterface)
158 """
159 super().__init__(ui)
160 self.__ui = ui
161
162 self.__subversionDefaults = {
163 "StopLogOnCopy": True,
164 "LogLimit": 20,
165 }
166
167 from VcsPlugins.vcsSubversion.ProjectHelper import SvnProjectHelper
168 self.__projectHelperObject = SvnProjectHelper(None, None)
169 with contextlib.suppress(KeyError):
170 ericApp().registerPluginObject(
171 pluginTypename, self.__projectHelperObject, pluginType)
172 readShortcuts(pluginName=pluginTypename)
173
174 def getProjectHelper(self):
175 """
176 Public method to get a reference to the project helper object.
177
178 @return reference to the project helper object
179 """
180 return self.__projectHelperObject
181
182 def initToolbar(self, ui, toolbarManager):
183 """
184 Public slot to initialize the VCS toolbar.
185
186 @param ui reference to the main window (UserInterface)
187 @param toolbarManager reference to a toolbar manager object
188 (EricToolBarManager)
189 """
190 if self.__projectHelperObject:
191 self.__projectHelperObject.initToolbar(ui, toolbarManager)
192
193 def activate(self):
194 """
195 Public method to activate this plugin.
196
197 @return tuple of reference to instantiated viewmanager and
198 activation status (boolean)
199 """
200 from VcsPlugins.vcsSubversion.subversion import Subversion
201 self.__object = Subversion(self, self.__ui)
202
203 tb = self.__ui.getToolbar("vcs")[1]
204 tb.setVisible(False)
205 tb.setEnabled(False)
206
207 tb = self.__ui.getToolbar("subversion")[1]
208 tb.setVisible(Preferences.getVCS("ShowVcsToolbar"))
209 tb.setEnabled(True)
210
211 return self.__object, True
212
213 def deactivate(self):
214 """
215 Public method to deactivate this plugin.
216 """
217 self.__object = None
218
219 tb = self.__ui.getToolbar("subversion")[1]
220 tb.setVisible(False)
221 tb.setEnabled(False)
222
223 tb = self.__ui.getToolbar("vcs")[1]
224 tb.setVisible(Preferences.getVCS("ShowVcsToolbar"))
225 tb.setEnabled(True)
226
227 def getPreferences(self, key):
228 """
229 Public method to retrieve the various settings.
230
231 @param key the key of the value to get
232 @return the requested setting
233 """
234 if key in ["StopLogOnCopy"]:
235 return Preferences.toBool(Preferences.getSettings().value(
236 "Subversion/" + key, self.__subversionDefaults[key]))
237 elif key in ["LogLimit"]:
238 return int(Preferences.getSettings().value(
239 "Subversion/" + key,
240 self.__subversionDefaults[key]))
241 elif key in ["Commits"]:
242 return Preferences.toList(Preferences.getSettings().value(
243 "Subversion/" + key))
244 else:
245 return Preferences.getSettings().value("Subversion/" + key)
246
247 def setPreferences(self, key, value):
248 """
249 Public method to store the various settings.
250
251 @param key the key of the setting to be set
252 @param value the value to be set
253 """
254 Preferences.getSettings().setValue("Subversion/" + key, value)
255
256 def getServersPath(self):
257 """
258 Public method to get the filename of the servers file.
259
260 @return filename of the servers file (string)
261 """
262 return getServersPath()
263
264 def getConfigPath(self):
265 """
266 Public method to get the filename of the config file.
267
268 @return filename of the config file (string)
269 """
270 return getConfigPath()
271
272 def prepareUninstall(self):
273 """
274 Public method to prepare for an uninstallation.
275 """
276 ericApp().unregisterPluginObject(pluginTypename)
277
278 def prepareUnload(self):
279 """
280 Public method to prepare for an unload.
281 """
282 if self.__projectHelperObject:
283 self.__projectHelperObject.removeToolbar(
284 self.__ui, ericApp().getObject("ToolbarManager"))
285 ericApp().unregisterPluginObject(pluginTypename)

eric ide

mercurial