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