|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter the data for a graft session. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import pyqtSlot, QDateTime |
|
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
|
12 |
|
13 from .Ui_HgGraftDialog import Ui_HgGraftDialog |
|
14 |
|
15 |
|
16 class HgGraftDialog(QDialog, Ui_HgGraftDialog): |
|
17 """ |
|
18 Class implementing a dialog to enter the data for a graft session. |
|
19 """ |
|
20 def __init__(self, vcs, revs=None, parent=None): |
|
21 """ |
|
22 Constructor |
|
23 |
|
24 @param vcs reference to the VCS object |
|
25 @type Hg |
|
26 @param revs list of revisions to show in the revisions pane |
|
27 @type list of str |
|
28 @param parent reference to the parent widget |
|
29 @type QWidget |
|
30 """ |
|
31 super().__init__(parent) |
|
32 self.setupUi(self) |
|
33 |
|
34 self.dateTimeEdit.setDateTime(QDateTime.currentDateTime()) |
|
35 |
|
36 if revs: |
|
37 self.revisionsEdit.setPlainText("\n".join(sorted(revs))) |
|
38 |
|
39 self.noCommitCheckBox.setEnabled(vcs.version >= (4, 7, 0)) |
|
40 |
|
41 self.__updateOk() |
|
42 |
|
43 def __updateOk(self): |
|
44 """ |
|
45 Private slot to update the state of the OK button. |
|
46 """ |
|
47 enable = self.revisionsEdit.toPlainText() != "" |
|
48 if self.userGroup.isChecked(): |
|
49 enable = ( |
|
50 enable and |
|
51 (self.currentUserCheckBox.isChecked() or |
|
52 self.userEdit.text() != "") |
|
53 ) |
|
54 |
|
55 self.buttonBox.button( |
|
56 QDialogButtonBox.StandardButton.Ok).setEnabled(enable) |
|
57 |
|
58 @pyqtSlot() |
|
59 def on_revisionsEdit_textChanged(self): |
|
60 """ |
|
61 Private slot to react upon changes of revisions. |
|
62 """ |
|
63 self.__updateOk() |
|
64 |
|
65 @pyqtSlot(bool) |
|
66 def on_userGroup_toggled(self, checked): |
|
67 """ |
|
68 Private slot to handle changes of the user group state. |
|
69 |
|
70 @param checked flag giving the checked state |
|
71 @type bool |
|
72 """ |
|
73 self.__updateOk() |
|
74 |
|
75 @pyqtSlot(bool) |
|
76 def on_currentUserCheckBox_toggled(self, checked): |
|
77 """ |
|
78 Private slot to handle changes of the current user state. |
|
79 |
|
80 @param checked flag giving the checked state |
|
81 @type bool |
|
82 """ |
|
83 self.__updateOk() |
|
84 |
|
85 @pyqtSlot(str) |
|
86 def on_userEdit_textChanged(self, txt): |
|
87 """ |
|
88 Private slot to handle changes of the user name. |
|
89 |
|
90 @param txt text of the edit (string) |
|
91 """ |
|
92 self.__updateOk() |
|
93 |
|
94 def getData(self): |
|
95 """ |
|
96 Public method to retrieve the entered data. |
|
97 |
|
98 @return tuple with list of revisions, a tuple giving a |
|
99 flag indicating to set the user, a flag indicating to use the |
|
100 current user and the user name, another tuple giving a flag |
|
101 indicating to set the date, a flag indicating to use the |
|
102 current date and the date, a flag indicating to append graft info |
|
103 to the log message, a flag indicating a dry-run and a flag |
|
104 indicating to not commit the copied changesets |
|
105 @rtype tuple of (list of str, (bool, bool, str), (bool, bool, str), |
|
106 bool, bool, bool) |
|
107 """ |
|
108 userData = ( |
|
109 self.userGroup.isChecked(), |
|
110 self.currentUserCheckBox.isChecked(), |
|
111 self.userEdit.text(), |
|
112 ) |
|
113 |
|
114 dateData = ( |
|
115 self.dateGroup.isChecked(), |
|
116 self.currentDateCheckBox.isChecked(), |
|
117 self.dateTimeEdit.dateTime().toString("yyyy-MM-dd hh:mm"), |
|
118 ) |
|
119 |
|
120 return ( |
|
121 self.revisionsEdit.toPlainText().strip().splitlines(), |
|
122 userData, |
|
123 dateData, |
|
124 self.logCheckBox.isChecked(), |
|
125 self.dryRunCheckBox.isChecked(), |
|
126 self.noCommitCheckBox.isChecked(), |
|
127 ) |