|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to browse the change lists. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 import os |
|
13 import sys |
|
14 |
|
15 import pysvn |
|
16 |
|
17 from PyQt5.QtCore import pyqtSlot, Qt, QMutexLocker |
|
18 from PyQt5.QtGui import QCursor |
|
19 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QListWidgetItem, \ |
|
20 QApplication |
|
21 |
|
22 from .SvnDialogMixin import SvnDialogMixin |
|
23 |
|
24 from .Ui_SvnChangeListsDialog import Ui_SvnChangeListsDialog |
|
25 |
|
26 |
|
27 class SvnChangeListsDialog(QDialog, SvnDialogMixin, Ui_SvnChangeListsDialog): |
|
28 """ |
|
29 Class implementing a dialog to browse the change lists. |
|
30 """ |
|
31 def __init__(self, vcs, parent=None): |
|
32 """ |
|
33 Constructor |
|
34 |
|
35 @param vcs reference to the vcs object |
|
36 @param parent parent widget (QWidget) |
|
37 """ |
|
38 super(SvnChangeListsDialog, self).__init__(parent) |
|
39 self.setupUi(self) |
|
40 SvnDialogMixin.__init__(self) |
|
41 self.setWindowFlags(Qt.Window) |
|
42 |
|
43 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
|
44 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
|
45 |
|
46 self.vcs = vcs |
|
47 |
|
48 self.client = self.vcs.getClient() |
|
49 self.client.callback_cancel = \ |
|
50 self._clientCancelCallback |
|
51 self.client.callback_get_login = \ |
|
52 self._clientLoginCallback |
|
53 self.client.callback_ssl_server_trust_prompt = \ |
|
54 self._clientSslServerTrustPromptCallback |
|
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 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
|
84 QApplication.processEvents() |
|
85 |
|
86 locker = QMutexLocker(self.vcs.vcsExecutionMutex) |
|
87 try: |
|
88 entries = self.client.get_changelist( |
|
89 path, depth=pysvn.depth.infinity) |
|
90 for entry in entries: |
|
91 file = entry[0] |
|
92 changelist = entry[1] |
|
93 if sys.version_info[0] == 2: |
|
94 file = file.decode('utf-8') |
|
95 changelist = changelist.decode('utf-8') |
|
96 if changelist not in self.changeListsDict: |
|
97 self.changeListsDict[changelist] = [] |
|
98 filename = file.replace(path + os.sep, "") |
|
99 if filename not in self.changeListsDict[changelist]: |
|
100 self.changeListsDict[changelist].append(filename) |
|
101 except pysvn.ClientError as e: |
|
102 locker.unlock() |
|
103 self.__showError(e.args[0]) |
|
104 self.__finish() |
|
105 |
|
106 def __finish(self): |
|
107 """ |
|
108 Private slot called when the user pressed the button. |
|
109 """ |
|
110 self.changeLists.addItems(sorted(self.changeListsDict.keys())) |
|
111 QApplication.restoreOverrideCursor() |
|
112 |
|
113 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
|
114 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
|
115 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
|
116 |
|
117 if len(self.changeListsDict) == 0: |
|
118 self.changeLists.addItem(self.tr("No changelists found")) |
|
119 self.buttonBox.button(QDialogButtonBox.Close).setFocus( |
|
120 Qt.OtherFocusReason) |
|
121 else: |
|
122 self.changeLists.setCurrentRow(0) |
|
123 self.changeLists.setFocus(Qt.OtherFocusReason) |
|
124 |
|
125 def on_buttonBox_clicked(self, button): |
|
126 """ |
|
127 Private slot called by a button of the button box clicked. |
|
128 |
|
129 @param button button that was clicked (QAbstractButton) |
|
130 """ |
|
131 if button == self.buttonBox.button(QDialogButtonBox.Close): |
|
132 self.close() |
|
133 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): |
|
134 self.cancelled = True |
|
135 self.__finish() |