src/eric7/Plugins/VcsPlugins/vcsGit/ConfigurationPage/GitPage.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 """
8 Module implementing the Git configuration page.
9 """
10
11 import os
12 import contextlib
13
14 from PyQt6.QtCore import pyqtSlot
15 from PyQt6.QtWidgets import QDialog
16
17 from Preferences.ConfigurationPages.ConfigurationPageBase import (
18 ConfigurationPageBase
19 )
20 from .Ui_GitPage import Ui_GitPage
21
22
23 class GitPage(ConfigurationPageBase, Ui_GitPage):
24 """
25 Class implementing the Git configuration page.
26 """
27 def __init__(self, plugin):
28 """
29 Constructor
30
31 @param plugin reference to the plugin object
32 """
33 super().__init__()
34 self.setupUi(self)
35 self.setObjectName("GitPage")
36
37 self.__plugin = plugin
38
39 # set initial values
40 # log
41 self.logSpinBox.setValue(
42 self.__plugin.getPreferences("LogLimit"))
43 self.logWidthSpinBox.setValue(
44 self.__plugin.getPreferences("LogSubjectColumnWidth"))
45 self.findHarderCheckBox.setChecked(
46 self.__plugin.getPreferences("FindCopiesHarder"))
47 # commit
48 self.commitIdSpinBox.setValue(
49 self.__plugin.getPreferences("CommitIdLength"))
50 # cleanup
51 self.cleanupPatternEdit.setText(
52 self.__plugin.getPreferences("CleanupPatterns"))
53 # repository optimization
54 self.aggressiveCheckBox.setChecked(
55 self.__plugin.getPreferences("AggressiveGC"))
56
57 def save(self):
58 """
59 Public slot to save the Git configuration.
60 """
61 # log
62 self.__plugin.setPreferences(
63 "LogLimit", self.logSpinBox.value())
64 self.__plugin.setPreferences(
65 "LogSubjectColumnWidth", self.logWidthSpinBox.value())
66 self.__plugin.setPreferences(
67 "FindCopiesHarder", self.findHarderCheckBox.isChecked())
68 # commit
69 self.__plugin.setPreferences(
70 "CommitIdLength", self.commitIdSpinBox.value())
71 # cleanup
72 self.__plugin.setPreferences(
73 "CleanupPatterns", self.cleanupPatternEdit.text())
74 # repository optimization
75 self.__plugin.setPreferences(
76 "AggressiveGC", self.aggressiveCheckBox.isChecked())
77
78 @pyqtSlot()
79 def on_configButton_clicked(self):
80 """
81 Private slot to edit the (per user) Git configuration file.
82 """
83 from QScintilla.MiniEditor import MiniEditor
84 cfgFile = self.__plugin.getConfigPath()
85 if not os.path.exists(cfgFile):
86 from ..GitUserConfigDataDialog import GitUserConfigDataDialog
87 dlg = GitUserConfigDataDialog()
88 if dlg.exec() == QDialog.DialogCode.Accepted:
89 firstName, lastName, email = dlg.getData()
90 else:
91 firstName, lastName, email = (
92 "Firstname", "Lastname", "email_address")
93 with contextlib.suppress(OSError), open(cfgFile, "w") as f:
94 f.write("[user]\n")
95 f.write(" name = {0} {1}\n".format(firstName, lastName))
96 f.write(" email = {0}\n".format(email))
97 editor = MiniEditor(cfgFile, "Properties", self)
98 editor.show()

eric ide

mercurial