|
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 browse the change lists. |
|
8 """ |
|
9 |
|
10 import os |
|
11 |
|
12 import pysvn |
|
13 |
|
14 from PyQt6.QtCore import pyqtSlot, Qt |
|
15 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QListWidgetItem |
|
16 |
|
17 from EricGui.EricOverrideCursor import EricOverrideCursor |
|
18 |
|
19 from EricUtilities.EricMutexLocker import EricMutexLocker |
|
20 |
|
21 from .SvnDialogMixin import SvnDialogMixin |
|
22 |
|
23 from .Ui_SvnChangeListsDialog import Ui_SvnChangeListsDialog |
|
24 |
|
25 |
|
26 class SvnChangeListsDialog(QDialog, SvnDialogMixin, Ui_SvnChangeListsDialog): |
|
27 """ |
|
28 Class implementing a dialog to browse the change lists. |
|
29 """ |
|
30 def __init__(self, vcs, parent=None): |
|
31 """ |
|
32 Constructor |
|
33 |
|
34 @param vcs reference to the vcs object |
|
35 @param parent parent widget (QWidget) |
|
36 """ |
|
37 super().__init__(parent) |
|
38 self.setupUi(self) |
|
39 SvnDialogMixin.__init__(self) |
|
40 self.setWindowFlags(Qt.WindowType.Window) |
|
41 |
|
42 self.buttonBox.button( |
|
43 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
|
44 self.buttonBox.button( |
|
45 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
|
46 |
|
47 self.vcs = vcs |
|
48 |
|
49 self.client = self.vcs.getClient() |
|
50 self.client.callback_cancel = self._clientCancelCallback |
|
51 self.client.callback_get_login = self._clientLoginCallback |
|
52 self.client.callback_ssl_server_trust_prompt = ( |
|
53 self._clientSslServerTrustPromptCallback |
|
54 ) |
|
55 |
|
56 @pyqtSlot(QListWidgetItem, QListWidgetItem) |
|
57 def on_changeLists_currentItemChanged(self, current, previous): |
|
58 """ |
|
59 Private slot to handle the selection of a new item. |
|
60 |
|
61 @param current current item (QListWidgetItem) |
|
62 @param previous previous current item (QListWidgetItem) |
|
63 """ |
|
64 self.filesList.clear() |
|
65 if current is not None: |
|
66 changelist = current.text() |
|
67 if changelist in self.changeListsDict: |
|
68 self.filesList.addItems( |
|
69 sorted(self.changeListsDict[changelist])) |
|
70 |
|
71 def start(self, path): |
|
72 """ |
|
73 Public slot to populate the data. |
|
74 |
|
75 @param path directory name to show change lists for (string) |
|
76 """ |
|
77 self.changeListsDict = {} |
|
78 self.cancelled = False |
|
79 |
|
80 self.filesLabel.setText( |
|
81 self.tr("Files (relative to {0}):").format(path)) |
|
82 |
|
83 with EricOverrideCursor(): |
|
84 try: |
|
85 with EricMutexLocker(self.vcs.vcsExecutionMutex): |
|
86 entries = self.client.get_changelist( |
|
87 path, depth=pysvn.depth.infinity) |
|
88 for entry in entries: |
|
89 file = entry[0] |
|
90 changelist = entry[1] |
|
91 if changelist not in self.changeListsDict: |
|
92 self.changeListsDict[changelist] = [] |
|
93 filename = file.replace(path + os.sep, "") |
|
94 if filename not in self.changeListsDict[changelist]: |
|
95 self.changeListsDict[changelist].append(filename) |
|
96 except pysvn.ClientError as e: |
|
97 self.__showError(e.args[0]) |
|
98 self.__finish() |
|
99 |
|
100 def __finish(self): |
|
101 """ |
|
102 Private slot called when the user pressed the button. |
|
103 """ |
|
104 self.changeLists.addItems(sorted(self.changeListsDict.keys())) |
|
105 |
|
106 self.buttonBox.button( |
|
107 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
|
108 self.buttonBox.button( |
|
109 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
|
110 self.buttonBox.button( |
|
111 QDialogButtonBox.StandardButton.Close).setDefault(True) |
|
112 |
|
113 if len(self.changeListsDict) == 0: |
|
114 self.changeLists.addItem(self.tr("No changelists found")) |
|
115 self.buttonBox.button( |
|
116 QDialogButtonBox.StandardButton.Close).setFocus( |
|
117 Qt.FocusReason.OtherFocusReason) |
|
118 else: |
|
119 self.changeLists.setCurrentRow(0) |
|
120 self.changeLists.setFocus(Qt.FocusReason.OtherFocusReason) |
|
121 |
|
122 def on_buttonBox_clicked(self, button): |
|
123 """ |
|
124 Private slot called by a button of the button box clicked. |
|
125 |
|
126 @param button button that was clicked (QAbstractButton) |
|
127 """ |
|
128 if button == self.buttonBox.button( |
|
129 QDialogButtonBox.StandardButton.Close |
|
130 ): |
|
131 self.close() |
|
132 elif button == self.buttonBox.button( |
|
133 QDialogButtonBox.StandardButton.Cancel |
|
134 ): |
|
135 self.cancelled = True |
|
136 self.__finish() |