5 |
5 |
6 """ |
6 """ |
7 Module implementing a dialog to show a list of incoming or outgoing bookmarks. |
7 Module implementing a dialog to show a list of incoming or outgoing bookmarks. |
8 """ |
8 """ |
9 |
9 |
|
10 import enum |
|
11 |
10 from PyQt6.QtCore import QCoreApplication, Qt |
12 from PyQt6.QtCore import QCoreApplication, Qt |
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QHeaderView, QTreeWidgetItem |
13 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QHeaderView, QTreeWidgetItem |
12 |
14 |
13 from .Ui_HgBookmarksInOutDialog import Ui_HgBookmarksInOutDialog |
15 from .Ui_HgBookmarksInOutDialog import Ui_HgBookmarksInOutDialog |
|
16 |
|
17 |
|
18 class HgBookmarksInOutDialogMode(enum.Enum): |
|
19 """ |
|
20 Class defining the modes of the dialog. |
|
21 """ |
|
22 |
|
23 INCOMING = 0 |
|
24 OUTGOING = 1 |
14 |
25 |
15 |
26 |
16 class HgBookmarksInOutDialog(QDialog, Ui_HgBookmarksInOutDialog): |
27 class HgBookmarksInOutDialog(QDialog, Ui_HgBookmarksInOutDialog): |
17 """ |
28 """ |
18 Class implementing a dialog to show a list of incoming or outgoing |
29 Class implementing a dialog to show a list of incoming or outgoing |
19 bookmarks. |
30 bookmarks. |
20 """ |
31 """ |
21 |
32 |
22 # TODO: change this to an enum |
|
23 INCOMING = 0 |
|
24 OUTGOING = 1 |
|
25 |
|
26 def __init__(self, vcs, mode, parent=None): |
33 def __init__(self, vcs, mode, parent=None): |
27 """ |
34 """ |
28 Constructor |
35 Constructor |
29 |
36 |
30 @param vcs reference to the vcs object |
37 @param vcs reference to the vcs object |
31 @type Hg |
38 @type Hg |
32 @param mode mode of the dialog (HgBookmarksInOutDialog.INCOMING, |
39 @param mode mode of the dialog |
33 HgBookmarksInOutDialog.OUTGOING) |
40 @type HgBookmarksInOutDialogMode |
34 @type int |
|
35 @param parent reference to the parent widget |
41 @param parent reference to the parent widget |
36 @type QWidget |
42 @type QWidget |
37 @exception ValueError raised to indicate an invalid dialog mode |
43 @exception ValueError raised to indicate an invalid dialog mode |
38 """ |
44 """ |
39 super().__init__(parent) |
45 super().__init__(parent) |
41 self.setWindowFlags(Qt.WindowType.Window) |
47 self.setWindowFlags(Qt.WindowType.Window) |
42 |
48 |
43 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False) |
49 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False) |
44 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
50 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
45 |
51 |
46 if mode not in [self.INCOMING, self.OUTGOING]: |
52 if not isinstance(mode, HgBookmarksInOutDialogMode): |
47 raise ValueError("Bad value for mode") |
53 raise ValueError("Bad value for mode") |
48 if mode == self.INCOMING: |
54 |
|
55 if mode == HgBookmarksInOutDialogMode.INCOMING: |
49 self.setWindowTitle(self.tr("Mercurial Incoming Bookmarks")) |
56 self.setWindowTitle(self.tr("Mercurial Incoming Bookmarks")) |
50 elif mode == self.OUTGOING: |
57 elif mode == HgBookmarksInOutDialogMode.OUTGOING: |
51 self.setWindowTitle(self.tr("Mercurial Outgoing Bookmarks")) |
58 self.setWindowTitle(self.tr("Mercurial Outgoing Bookmarks")) |
52 |
59 |
53 self.vcs = vcs |
60 self.vcs = vcs |
54 self.mode = mode |
61 self.__mode = mode |
55 self.__hgClient = vcs.getClient() |
62 self.__hgClient = vcs.getClient() |
56 |
63 |
57 self.bookmarksList.headerItem().setText(self.bookmarksList.columnCount(), "") |
64 self.bookmarksList.headerItem().setText(self.bookmarksList.columnCount(), "") |
58 self.bookmarksList.header().setSortIndicator(3, Qt.SortOrder.AscendingOrder) |
65 self.bookmarksList.header().setSortIndicator(3, Qt.SortOrder.AscendingOrder) |
59 |
66 |
73 e.accept() |
80 e.accept() |
74 |
81 |
75 def start(self): |
82 def start(self): |
76 """ |
83 """ |
77 Public slot to start the bookmarks command. |
84 Public slot to start the bookmarks command. |
78 |
|
79 @exception ValueError raised to indicate an invalid dialog mode |
|
80 """ |
85 """ |
81 self.errorGroup.hide() |
86 self.errorGroup.hide() |
82 |
87 |
83 self.intercept = False |
88 self.intercept = False |
84 self.activateWindow() |
89 self.activateWindow() |
85 |
90 |
86 if self.mode not in (self.INCOMING, self.OUTGOING): |
|
87 raise ValueError("Bad value for mode") |
|
88 |
|
89 args = ( |
91 args = ( |
90 self.vcs.initCommand("incoming") |
92 self.vcs.initCommand("incoming") |
91 if self.mode == self.INCOMING |
93 if self.__mode == HgBookmarksInOutDialogMode.INCOMING |
92 else self.vcs.initCommand("outgoing") |
94 else self.vcs.initCommand("outgoing") |
93 ) |
95 ) |
94 |
96 |
95 args.append("--bookmarks") |
97 args.append("--bookmarks") |
96 |
98 |