|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter a list of worktree paths. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import pyqtSlot |
|
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QListWidgetItem |
|
12 |
|
13 from eric7.EricWidgets import EricPathPickerDialog |
|
14 |
|
15 from .Ui_GitWorktreePathsDialog import Ui_GitWorktreePathsDialog |
|
16 |
|
17 |
|
18 class GitWorktreePathsDialog(QDialog, Ui_GitWorktreePathsDialog): |
|
19 """ |
|
20 Class implementing a dialog to enter a list of worktree paths. |
|
21 """ |
|
22 |
|
23 def __init__(self, parentDirectory, parent=None): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param parentDirectory path of the worktrees parent directory |
|
28 @type str |
|
29 @param parent reference to the parent widget (defaults to None) |
|
30 @type QWidget (optional) |
|
31 """ |
|
32 super().__init__(parent) |
|
33 self.setupUi(self) |
|
34 |
|
35 self.__parentDir = parentDirectory |
|
36 |
|
37 self.removeButton.setEnabled(False) |
|
38 |
|
39 self.__updateOK |
|
40 |
|
41 def __updateOK(self): |
|
42 """ |
|
43 Private method to set the enabled state of the OK button. |
|
44 """ |
|
45 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
|
46 self.pathsList.count() > 0 |
|
47 ) |
|
48 |
|
49 @pyqtSlot() |
|
50 def on_addButton_clicked(self): |
|
51 """ |
|
52 Private slot to add a path entry. |
|
53 """ |
|
54 worktree, ok = EricPathPickerDialog.getStrPath( |
|
55 self, |
|
56 self.tr("Worktree Path"), |
|
57 self.tr("Enter new path of the worktree:"), |
|
58 mode=EricPathPickerDialog.EricPathPickerModes.DIRECTORY_MODE, |
|
59 strPath=self.__parentDir, |
|
60 defaultDirectory=self.__parentDir, |
|
61 ) |
|
62 if ok and worktree: |
|
63 QListWidgetItem(worktree, self.pathsList) |
|
64 |
|
65 self.__updateOK() |
|
66 |
|
67 @pyqtSlot() |
|
68 def on_removeButton_clicked(self): |
|
69 """ |
|
70 Private slot to remove the selected items. |
|
71 """ |
|
72 for itm in self.pathsList.selectedItems(): |
|
73 self.pathsList.takeItem(self.pathsList.row(itm)) |
|
74 del itm |
|
75 |
|
76 self.__updateOK() |
|
77 |
|
78 @pyqtSlot() |
|
79 def on_removeAllButton_clicked(self): |
|
80 """ |
|
81 Private slot to remove all items from the list. |
|
82 """ |
|
83 self.pathsList.clear() |
|
84 self.__updateOK() |
|
85 |
|
86 @pyqtSlot() |
|
87 def on_pathsList_itemSelectionChanged(self): |
|
88 """ |
|
89 Private slot handling a change of selected items. |
|
90 """ |
|
91 self.removeButton.setEnabled(bool(self.pathsList.selectedItems())) |
|
92 |
|
93 def getPathsList(self): |
|
94 """ |
|
95 Public method to get the entered worktree paths. |
|
96 |
|
97 @return list of worktree paths |
|
98 @rtype list of str |
|
99 """ |
|
100 return [ |
|
101 self.pathsList.item(row).text() for row in range(self.pathsList.count()) |
|
102 ] |