26 |
24 |
27 class SvnBlameDialog(QDialog, SvnDialogMixin, Ui_SvnBlameDialog): |
25 class SvnBlameDialog(QDialog, SvnDialogMixin, Ui_SvnBlameDialog): |
28 """ |
26 """ |
29 Class implementing a dialog to show the output of the svn blame command. |
27 Class implementing a dialog to show the output of the svn blame command. |
30 """ |
28 """ |
|
29 |
31 def __init__(self, vcs, parent=None): |
30 def __init__(self, vcs, parent=None): |
32 """ |
31 """ |
33 Constructor |
32 Constructor |
34 |
33 |
35 @param vcs reference to the vcs object |
34 @param vcs reference to the vcs object |
36 @param parent parent widget (QWidget) |
35 @param parent parent widget (QWidget) |
37 """ |
36 """ |
38 super().__init__(parent) |
37 super().__init__(parent) |
39 self.setupUi(self) |
38 self.setupUi(self) |
40 SvnDialogMixin.__init__(self) |
39 SvnDialogMixin.__init__(self) |
41 self.setWindowFlags(Qt.WindowType.Window) |
40 self.setWindowFlags(Qt.WindowType.Window) |
42 |
41 |
43 self.buttonBox.button( |
42 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False) |
44 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
43 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
45 self.buttonBox.button( |
44 |
46 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
|
47 |
|
48 self.vcs = vcs |
45 self.vcs = vcs |
49 |
46 |
50 self.blameList.headerItem().setText(self.blameList.columnCount(), "") |
47 self.blameList.headerItem().setText(self.blameList.columnCount(), "") |
51 font = Preferences.getEditorOtherFonts("MonospacedFont") |
48 font = Preferences.getEditorOtherFonts("MonospacedFont") |
52 self.blameList.setFont(font) |
49 self.blameList.setFont(font) |
53 |
50 |
54 self.client = self.vcs.getClient() |
51 self.client = self.vcs.getClient() |
55 self.client.callback_cancel = self._clientCancelCallback |
52 self.client.callback_cancel = self._clientCancelCallback |
56 self.client.callback_get_login = self._clientLoginCallback |
53 self.client.callback_get_login = self._clientLoginCallback |
57 self.client.callback_ssl_server_trust_prompt = ( |
54 self.client.callback_ssl_server_trust_prompt = ( |
58 self._clientSslServerTrustPromptCallback |
55 self._clientSslServerTrustPromptCallback |
59 ) |
56 ) |
60 |
57 |
61 def start(self, fn): |
58 def start(self, fn): |
62 """ |
59 """ |
63 Public slot to start the svn blame command. |
60 Public slot to start the svn blame command. |
64 |
61 |
65 @param fn filename to show the blame for (string) |
62 @param fn filename to show the blame for (string) |
66 """ |
63 """ |
67 self.blameList.clear() |
64 self.blameList.clear() |
68 self.errorGroup.hide() |
65 self.errorGroup.hide() |
69 self.activateWindow() |
66 self.activateWindow() |
70 |
67 |
71 dname, fname = self.vcs.splitPath(fn) |
68 dname, fname = self.vcs.splitPath(fn) |
72 |
69 |
73 cwd = os.getcwd() |
70 cwd = os.getcwd() |
74 os.chdir(dname) |
71 os.chdir(dname) |
75 try: |
72 try: |
76 with EricMutexLocker(self.vcs.vcsExecutionMutex): |
73 with EricMutexLocker(self.vcs.vcsExecutionMutex): |
77 annotations = self.client.annotate(fname) |
74 annotations = self.client.annotate(fname) |
78 for annotation in annotations: |
75 for annotation in annotations: |
79 author = annotation["author"] |
76 author = annotation["author"] |
80 line = annotation["line"] |
77 line = annotation["line"] |
81 self.__generateItem( |
78 self.__generateItem( |
82 annotation["revision"].number, author, |
79 annotation["revision"].number, |
83 annotation["number"] + 1, line) |
80 author, |
|
81 annotation["number"] + 1, |
|
82 line, |
|
83 ) |
84 except pysvn.ClientError as e: |
84 except pysvn.ClientError as e: |
85 self.__showError(e.args[0] + '\n') |
85 self.__showError(e.args[0] + "\n") |
86 self.__finish() |
86 self.__finish() |
87 os.chdir(cwd) |
87 os.chdir(cwd) |
88 |
88 |
89 def __finish(self): |
89 def __finish(self): |
90 """ |
90 """ |
91 Private slot called when the process finished or the user pressed the |
91 Private slot called when the process finished or the user pressed the |
92 button. |
92 button. |
93 """ |
93 """ |
94 self.buttonBox.button( |
94 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(True) |
95 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
95 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
96 self.buttonBox.button( |
96 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True) |
97 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
97 |
98 self.buttonBox.button( |
|
99 QDialogButtonBox.StandardButton.Close).setDefault(True) |
|
100 |
|
101 self.__resizeColumns() |
98 self.__resizeColumns() |
102 |
99 |
103 self._cancel() |
100 self._cancel() |
104 |
101 |
105 def on_buttonBox_clicked(self, button): |
102 def on_buttonBox_clicked(self, button): |
106 """ |
103 """ |
107 Private slot called by a button of the button box clicked. |
104 Private slot called by a button of the button box clicked. |
108 |
105 |
109 @param button button that was clicked (QAbstractButton) |
106 @param button button that was clicked (QAbstractButton) |
110 """ |
107 """ |
111 if button == self.buttonBox.button( |
108 if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close): |
112 QDialogButtonBox.StandardButton.Close |
|
113 ): |
|
114 self.close() |
109 self.close() |
115 elif button == self.buttonBox.button( |
110 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel): |
116 QDialogButtonBox.StandardButton.Cancel |
|
117 ): |
|
118 self.__finish() |
111 self.__finish() |
119 |
112 |
120 def __resizeColumns(self): |
113 def __resizeColumns(self): |
121 """ |
114 """ |
122 Private method to resize the list columns. |
115 Private method to resize the list columns. |
123 """ |
116 """ |
124 self.blameList.header().resizeSections( |
117 self.blameList.header().resizeSections(QHeaderView.ResizeMode.ResizeToContents) |
125 QHeaderView.ResizeMode.ResizeToContents) |
118 |
126 |
|
127 def __generateItem(self, revision, author, lineno, text): |
119 def __generateItem(self, revision, author, lineno, text): |
128 """ |
120 """ |
129 Private method to generate a blame item in the blame list. |
121 Private method to generate a blame item in the blame list. |
130 |
122 |
131 @param revision revision string (string) |
123 @param revision revision string (string) |
132 @param author author of the change (string) |
124 @param author author of the change (string) |
133 @param lineno linenumber (string) |
125 @param lineno linenumber (string) |
134 @param text line of text from the annotated file (string) |
126 @param text line of text from the annotated file (string) |
135 """ |
127 """ |
136 itm = QTreeWidgetItem( |
128 itm = QTreeWidgetItem( |
137 self.blameList, |
129 self.blameList, |
138 ["{0:d}".format(revision), author, "{0:d}".format(lineno), text]) |
130 ["{0:d}".format(revision), author, "{0:d}".format(lineno), text], |
|
131 ) |
139 itm.setTextAlignment(0, Qt.AlignmentFlag.AlignRight) |
132 itm.setTextAlignment(0, Qt.AlignmentFlag.AlignRight) |
140 itm.setTextAlignment(2, Qt.AlignmentFlag.AlignRight) |
133 itm.setTextAlignment(2, Qt.AlignmentFlag.AlignRight) |
141 |
134 |
142 def __showError(self, msg): |
135 def __showError(self, msg): |
143 """ |
136 """ |
144 Private slot to show an error message. |
137 Private slot to show an error message. |
145 |
138 |
146 @param msg error message to show (string) |
139 @param msg error message to show (string) |
147 """ |
140 """ |
148 self.errorGroup.show() |
141 self.errorGroup.show() |
149 self.errors.insertPlainText(msg) |
142 self.errors.insertPlainText(msg) |
150 self.errors.ensureCursorVisible() |
143 self.errors.ensureCursorVisible() |