src/eric7/ViewManager/BookmarkedFilesDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
20 20
21 class BookmarkedFilesDialog(QDialog, Ui_BookmarkedFilesDialog): 21 class BookmarkedFilesDialog(QDialog, Ui_BookmarkedFilesDialog):
22 """ 22 """
23 Class implementing a configuration dialog for the bookmarked files menu. 23 Class implementing a configuration dialog for the bookmarked files menu.
24 """ 24 """
25
25 def __init__(self, bookmarks, parent=None): 26 def __init__(self, bookmarks, parent=None):
26 """ 27 """
27 Constructor 28 Constructor
28 29
29 @param bookmarks list of bookmarked files (list of strings) 30 @param bookmarks list of bookmarked files (list of strings)
30 @param parent parent widget (QWidget) 31 @param parent parent widget (QWidget)
31 """ 32 """
32 super().__init__(parent) 33 super().__init__(parent)
33 self.setupUi(self) 34 self.setupUi(self)
34 35
35 self.filePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) 36 self.filePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
36 37
37 self.bookmarks = bookmarks[:] 38 self.bookmarks = bookmarks[:]
38 for bookmark in self.bookmarks: 39 for bookmark in self.bookmarks:
39 itm = QListWidgetItem(bookmark, self.filesList) 40 itm = QListWidgetItem(bookmark, self.filesList)
40 if not pathlib.Path(bookmark).exists(): 41 if not pathlib.Path(bookmark).exists():
41 itm.setBackground(QColor(Qt.GlobalColor.red)) 42 itm.setBackground(QColor(Qt.GlobalColor.red))
42 43
43 if len(self.bookmarks): 44 if len(self.bookmarks):
44 self.filesList.setCurrentRow(0) 45 self.filesList.setCurrentRow(0)
45 46
46 def on_filePicker_textChanged(self, txt): 47 def on_filePicker_textChanged(self, txt):
47 """ 48 """
48 Private slot to handle the textChanged signal of the file edit. 49 Private slot to handle the textChanged signal of the file edit.
49 50
50 @param txt the text of the file edit (string) 51 @param txt the text of the file edit (string)
51 """ 52 """
52 self.addButton.setEnabled(txt != "") 53 self.addButton.setEnabled(txt != "")
53 self.changeButton.setEnabled( 54 self.changeButton.setEnabled(txt != "" and self.filesList.currentRow() != -1)
54 txt != "" and 55
55 self.filesList.currentRow() != -1)
56
57 def on_filesList_currentRowChanged(self, row): 56 def on_filesList_currentRowChanged(self, row):
58 """ 57 """
59 Private slot to set the lineedit depending on the selected entry. 58 Private slot to set the lineedit depending on the selected entry.
60 59
61 @param row the current row (integer) 60 @param row the current row (integer)
62 """ 61 """
63 if row == -1: 62 if row == -1:
64 self.filePicker.clear() 63 self.filePicker.clear()
65 self.downButton.setEnabled(False) 64 self.downButton.setEnabled(False)
70 maxIndex = len(self.bookmarks) - 1 69 maxIndex = len(self.bookmarks) - 1
71 self.upButton.setEnabled(row != 0) 70 self.upButton.setEnabled(row != 0)
72 self.downButton.setEnabled(row != maxIndex) 71 self.downButton.setEnabled(row != maxIndex)
73 self.deleteButton.setEnabled(True) 72 self.deleteButton.setEnabled(True)
74 self.changeButton.setEnabled(True) 73 self.changeButton.setEnabled(True)
75 74
76 bookmark = self.bookmarks[row] 75 bookmark = self.bookmarks[row]
77 self.filePicker.setText(bookmark) 76 self.filePicker.setText(bookmark)
78 77
79 @pyqtSlot() 78 @pyqtSlot()
80 def on_addButton_clicked(self): 79 def on_addButton_clicked(self):
81 """ 80 """
82 Private slot to add a new entry. 81 Private slot to add a new entry.
83 """ 82 """
88 itm.setBackground(QColor(Qt.GlobalColor.red)) 87 itm.setBackground(QColor(Qt.GlobalColor.red))
89 self.filePicker.clear() 88 self.filePicker.clear()
90 self.bookmarks.append(bookmark) 89 self.bookmarks.append(bookmark)
91 row = self.filesList.currentRow() 90 row = self.filesList.currentRow()
92 self.on_filesList_currentRowChanged(row) 91 self.on_filesList_currentRowChanged(row)
93 92
94 @pyqtSlot() 93 @pyqtSlot()
95 def on_changeButton_clicked(self): 94 def on_changeButton_clicked(self):
96 """ 95 """
97 Private slot to change an entry. 96 Private slot to change an entry.
98 """ 97 """
103 itm.setText(bookmark) 102 itm.setText(bookmark)
104 if not pathlib.Path(bookmark).exists(): 103 if not pathlib.Path(bookmark).exists():
105 itm.setBackground(QColor(Qt.GlobalColor.red)) 104 itm.setBackground(QColor(Qt.GlobalColor.red))
106 else: 105 else:
107 itm.setBackground(QColor()) 106 itm.setBackground(QColor())
108 107
109 @pyqtSlot() 108 @pyqtSlot()
110 def on_deleteButton_clicked(self): 109 def on_deleteButton_clicked(self):
111 """ 110 """
112 Private slot to delete the selected entry. 111 Private slot to delete the selected entry.
113 """ 112 """
115 itm = self.filesList.takeItem(row) 114 itm = self.filesList.takeItem(row)
116 del itm 115 del itm
117 del self.bookmarks[row] 116 del self.bookmarks[row]
118 row = self.filesList.currentRow() 117 row = self.filesList.currentRow()
119 self.on_filesList_currentRowChanged(row) 118 self.on_filesList_currentRowChanged(row)
120 119
121 @pyqtSlot() 120 @pyqtSlot()
122 def on_downButton_clicked(self): 121 def on_downButton_clicked(self):
123 """ 122 """
124 Private slot to move an entry down in the list. 123 Private slot to move an entry down in the list.
125 """ 124 """
126 rows = self.filesList.count() 125 rows = self.filesList.count()
127 row = self.filesList.currentRow() 126 row = self.filesList.currentRow()
128 if row == rows - 1: 127 if row == rows - 1:
129 # we're already at the end 128 # we're already at the end
130 return 129 return
131 130
132 self.__swap(row, row + 1) 131 self.__swap(row, row + 1)
133 itm = self.filesList.takeItem(row) 132 itm = self.filesList.takeItem(row)
134 self.filesList.insertItem(row + 1, itm) 133 self.filesList.insertItem(row + 1, itm)
135 self.filesList.setCurrentItem(itm) 134 self.filesList.setCurrentItem(itm)
136 self.upButton.setEnabled(True) 135 self.upButton.setEnabled(True)
137 if row == rows - 2: 136 if row == rows - 2:
138 self.downButton.setEnabled(False) 137 self.downButton.setEnabled(False)
139 else: 138 else:
140 self.downButton.setEnabled(True) 139 self.downButton.setEnabled(True)
141 140
142 @pyqtSlot() 141 @pyqtSlot()
143 def on_upButton_clicked(self): 142 def on_upButton_clicked(self):
144 """ 143 """
145 Private slot to move an entry up in the list. 144 Private slot to move an entry up in the list.
146 """ 145 """
147 row = self.filesList.currentRow() 146 row = self.filesList.currentRow()
148 if row == 0: 147 if row == 0:
149 # we're already at the top 148 # we're already at the top
150 return 149 return
151 150
152 self.__swap(row - 1, row) 151 self.__swap(row - 1, row)
153 itm = self.filesList.takeItem(row) 152 itm = self.filesList.takeItem(row)
154 self.filesList.insertItem(row - 1, itm) 153 self.filesList.insertItem(row - 1, itm)
155 self.filesList.setCurrentItem(itm) 154 self.filesList.setCurrentItem(itm)
156 if row == 1: 155 if row == 1:
157 self.upButton.setEnabled(False) 156 self.upButton.setEnabled(False)
158 else: 157 else:
159 self.upButton.setEnabled(True) 158 self.upButton.setEnabled(True)
160 self.downButton.setEnabled(True) 159 self.downButton.setEnabled(True)
161 160
162 def getBookmarkedFiles(self): 161 def getBookmarkedFiles(self):
163 """ 162 """
164 Public method to retrieve the tools list. 163 Public method to retrieve the tools list.
165 164
166 @return a list of filenames (list of strings) 165 @return a list of filenames (list of strings)
167 """ 166 """
168 return self.bookmarks 167 return self.bookmarks
169 168
170 def __swap(self, itm1, itm2): 169 def __swap(self, itm1, itm2):
171 """ 170 """
172 Private method used two swap two list entries given by their index. 171 Private method used two swap two list entries given by their index.
173 172
174 @param itm1 index of first entry (int) 173 @param itm1 index of first entry (int)
175 @param itm2 index of second entry (int) 174 @param itm2 index of second entry (int)
176 """ 175 """
177 tmp = self.bookmarks[itm1] 176 tmp = self.bookmarks[itm1]
178 self.bookmarks[itm1] = self.bookmarks[itm2] 177 self.bookmarks[itm1] = self.bookmarks[itm2]

eric ide

mercurial