5 |
5 |
6 """ |
6 """ |
7 Module implementing the bookmark dialog. |
7 Module implementing the bookmark dialog. |
8 """ |
8 """ |
9 |
9 |
|
10 import enum |
|
11 |
10 from PyQt6.QtCore import pyqtSlot |
12 from PyQt6.QtCore import pyqtSlot |
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
13 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
12 |
14 |
13 from .Ui_HgBookmarkDialog import Ui_HgBookmarkDialog |
15 from .Ui_HgBookmarkDialog import Ui_HgBookmarkDialog |
|
16 |
|
17 |
|
18 class HgBookmarkAction(enum.Enum): |
|
19 """ |
|
20 Class defining the supported bookmark actions. |
|
21 """ |
|
22 |
|
23 DEFINE = 0 |
|
24 MOVE = 1 |
14 |
25 |
15 |
26 |
16 class HgBookmarkDialog(QDialog, Ui_HgBookmarkDialog): |
27 class HgBookmarkDialog(QDialog, Ui_HgBookmarkDialog): |
17 """ |
28 """ |
18 Class mplementing the bookmark dialog. |
29 Class mplementing the bookmark dialog. |
19 """ |
30 """ |
20 |
31 |
21 # TODO: change this to an enum |
32 def __init__(self, action, tagsList, branchesList, bookmarksList, parent=None): |
22 DEFINE_MODE = 0 |
|
23 MOVE_MODE = 1 |
|
24 |
|
25 def __init__(self, mode, tagsList, branchesList, bookmarksList, parent=None): |
|
26 """ |
33 """ |
27 Constructor |
34 Constructor |
28 |
35 |
29 @param mode of the dialog |
36 @param action bookmark action to be performed |
30 @type int |
37 @type HgBookmarkAction |
31 @param tagsList list of tags |
38 @param tagsList list of tags |
32 @type list of str |
39 @type list of str |
33 @param branchesList list of branches |
40 @param branchesList list of branches |
34 @type list of str |
41 @type list of str |
35 @param bookmarksList list of bookmarks |
42 @param bookmarksList list of bookmarks |
40 super().__init__(parent) |
47 super().__init__(parent) |
41 self.setupUi(self) |
48 self.setupUi(self) |
42 |
49 |
43 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
50 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
44 |
51 |
45 self.__mode = mode |
52 self.__action = action |
46 if mode == self.MOVE_MODE: |
53 if action == HgBookmarkAction.MOVE: |
47 self.nameEdit.hide() |
54 self.nameEdit.hide() |
48 self.nameCombo.addItems([""] + sorted(bookmarksList)) |
55 self.nameCombo.addItems([""] + sorted(bookmarksList)) |
49 self.setWindowTitle(self.tr("Move Bookmark")) |
56 self.setWindowTitle(self.tr("Move Bookmark")) |
50 else: |
57 else: |
51 self.nameCombo.hide() |
58 self.nameCombo.hide() |
83 """ |
90 """ |
84 Private slot to update the OK button. |
91 Private slot to update the OK button. |
85 """ |
92 """ |
86 enabled = ( |
93 enabled = ( |
87 bool(self.nameCombo.currentText()) |
94 bool(self.nameCombo.currentText()) |
88 if self.__mode == self.MOVE_MODE |
95 if self.__action == HgBookmarkAction.MOVE |
89 else bool(self.nameEdit.text()) |
96 else bool(self.nameEdit.text()) |
90 ) |
97 ) |
91 |
98 |
92 if self.idButton.isChecked(): |
99 if self.idButton.isChecked(): |
93 enabled = bool(self.idEdit.text()) |
100 enabled = bool(self.idEdit.text()) |
104 |
111 |
105 def __updateBookmarksCombo(self): |
112 def __updateBookmarksCombo(self): |
106 """ |
113 """ |
107 Private slot to update the bookmarks combo. |
114 Private slot to update the bookmarks combo. |
108 """ |
115 """ |
109 if self.__mode == self.MOVE_MODE: |
116 if self.__action == HgBookmarkAction.MOVE: |
110 bookmark = self.nameCombo.currentText() |
117 bookmark = self.nameCombo.currentText() |
111 selectedBookmark = self.bookmarkCombo.currentText() |
118 selectedBookmark = self.bookmarkCombo.currentText() |
112 self.bookmarkCombo.clearEditText() |
119 self.bookmarkCombo.clearEditText() |
113 self.bookmarkCombo.clear() |
120 self.bookmarkCombo.clear() |
114 self.bookmarkCombo.addItems(sorted(self.__bookmarksList)) |
121 self.bookmarkCombo.addItems(sorted(self.__bookmarksList)) |