src/eric7/Plugins/VcsPlugins/vcsPySvn/SvnPropListDialog.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2003 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to show the output of the svn proplist command
8 process.
9 """
10
11 import os
12
13 import pysvn
14
15 from PyQt6.QtCore import pyqtSlot, Qt
16 from PyQt6.QtWidgets import (
17 QWidget, QHeaderView, QApplication, QDialogButtonBox, QTreeWidgetItem
18 )
19
20 from EricUtilities.EricMutexLocker import EricMutexLocker
21
22 from .SvnDialogMixin import SvnDialogMixin
23 from .Ui_SvnPropListDialog import Ui_SvnPropListDialog
24
25
26 class SvnPropListDialog(QWidget, SvnDialogMixin, Ui_SvnPropListDialog):
27 """
28 Class implementing a dialog to show the output of the svn proplist command
29 process.
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().__init__(parent)
39 self.setupUi(self)
40 SvnDialogMixin.__init__(self)
41
42 self.refreshButton = self.buttonBox.addButton(
43 self.tr("Refresh"), QDialogButtonBox.ButtonRole.ActionRole)
44 self.refreshButton.setToolTip(
45 self.tr("Press to refresh the properties display"))
46 self.refreshButton.setEnabled(False)
47 self.buttonBox.button(
48 QDialogButtonBox.StandardButton.Close).setEnabled(False)
49 self.buttonBox.button(
50 QDialogButtonBox.StandardButton.Cancel).setDefault(True)
51
52 self.vcs = vcs
53
54 self.propsList.headerItem().setText(self.propsList.columnCount(), "")
55 self.propsList.header().setSortIndicator(
56 0, Qt.SortOrder.AscendingOrder)
57
58 self.client = self.vcs.getClient()
59 self.client.callback_cancel = self._clientCancelCallback
60 self.client.callback_get_login = self._clientLoginCallback
61 self.client.callback_ssl_server_trust_prompt = (
62 self._clientSslServerTrustPromptCallback
63 )
64
65 def __resort(self):
66 """
67 Private method to resort the tree.
68 """
69 self.propsList.sortItems(
70 self.propsList.sortColumn(),
71 self.propsList.header().sortIndicatorOrder())
72
73 def __resizeColumns(self):
74 """
75 Private method to resize the list columns.
76 """
77 self.propsList.header().resizeSections(
78 QHeaderView.ResizeMode.ResizeToContents)
79 self.propsList.header().setStretchLastSection(True)
80
81 def __generateItem(self, path, propName, propValue):
82 """
83 Private method to generate a properties item in the properties list.
84
85 @param path file/directory name the property applies to (string)
86 @param propName name of the property (string)
87 @param propValue value of the property (string)
88 """
89 QTreeWidgetItem(self.propsList, [path, propName, propValue])
90
91 def start(self, fn, recursive=False):
92 """
93 Public slot to start the svn status command.
94
95 @param fn filename(s) (string or list of strings)
96 @param recursive flag indicating a recursive list is requested
97 """
98 self.errorGroup.hide()
99
100 self.propsList.clear()
101
102 self.__args = fn
103 self.__recursive = recursive
104
105 self.buttonBox.button(
106 QDialogButtonBox.StandardButton.Close).setEnabled(False)
107 self.buttonBox.button(
108 QDialogButtonBox.StandardButton.Cancel).setEnabled(True)
109 self.buttonBox.button(
110 QDialogButtonBox.StandardButton.Cancel).setDefault(True)
111 self.refreshButton.setEnabled(False)
112
113 QApplication.processEvents()
114 self.propsFound = False
115 if isinstance(fn, list):
116 dname, fnames = self.vcs.splitPathList(fn)
117 else:
118 dname, fname = self.vcs.splitPath(fn)
119 fnames = [fname]
120
121 cwd = os.getcwd()
122 os.chdir(dname)
123 with EricMutexLocker(self.vcs.vcsExecutionMutex):
124 try:
125 for name in fnames:
126 proplist = self.client.proplist(name, recurse=recursive)
127 for counter, (path, prop) in enumerate(proplist):
128 for propName, propVal in list(prop.items()):
129 self.__generateItem(path, propName, propVal)
130 self.propsFound = True
131 if (
132 counter % 30 == 0 and
133 self._clientCancelCallback()
134 ):
135 # check for cancel every 30 items
136 break
137 if self._clientCancelCallback():
138 break
139 except pysvn.ClientError as e:
140 self.__showError(e.args[0])
141
142 self.__finish()
143 os.chdir(cwd)
144
145 def __finish(self):
146 """
147 Private slot called when the process finished or the user pressed the
148 button.
149 """
150 if not self.propsFound:
151 self.__generateItem("", self.tr("None"), "")
152
153 self.__resort()
154 self.__resizeColumns()
155
156 self.buttonBox.button(
157 QDialogButtonBox.StandardButton.Close).setEnabled(True)
158 self.buttonBox.button(
159 QDialogButtonBox.StandardButton.Cancel).setEnabled(False)
160 self.buttonBox.button(
161 QDialogButtonBox.StandardButton.Close).setDefault(True)
162
163 self.refreshButton.setEnabled(True)
164
165 self._cancel()
166
167 def on_buttonBox_clicked(self, button):
168 """
169 Private slot called by a button of the button box clicked.
170
171 @param button button that was clicked (QAbstractButton)
172 """
173 if button == self.buttonBox.button(
174 QDialogButtonBox.StandardButton.Close
175 ):
176 self.close()
177 elif button == self.buttonBox.button(
178 QDialogButtonBox.StandardButton.Cancel
179 ):
180 self.__finish()
181 elif button == self.refreshButton:
182 self.on_refreshButton_clicked()
183
184 @pyqtSlot()
185 def on_refreshButton_clicked(self):
186 """
187 Private slot to refresh the status display.
188 """
189 self.start(self.__args, recursive=self.__recursive)
190
191 def __showError(self, msg):
192 """
193 Private slot to show an error message.
194
195 @param msg error message to show (string)
196 """
197 self.errorGroup.show()
198 self.errors.insertPlainText(msg)
199 self.errors.ensureCursorVisible()

eric ide

mercurial