23 |
28 |
24 class EricToolBarItem: |
29 class EricToolBarItem: |
25 """ |
30 """ |
26 Class storing data belonging to a toolbar entry of the toolbar dialog. |
31 Class storing data belonging to a toolbar entry of the toolbar dialog. |
27 """ |
32 """ |
|
33 |
28 def __init__(self, toolBarId, actionIDs, default): |
34 def __init__(self, toolBarId, actionIDs, default): |
29 """ |
35 """ |
30 Constructor |
36 Constructor |
31 |
37 |
32 @param toolBarId id of the toolbar object (integer) |
38 @param toolBarId id of the toolbar object (integer) |
33 @param actionIDs list of action IDs belonging to the toolbar |
39 @param actionIDs list of action IDs belonging to the toolbar |
34 (list of integer) |
40 (list of integer) |
35 @param default flag indicating a default toolbar (boolean) |
41 @param default flag indicating a default toolbar (boolean) |
36 """ |
42 """ |
37 self.toolBarId = toolBarId |
43 self.toolBarId = toolBarId |
38 self.actionIDs = actionIDs[:] |
44 self.actionIDs = actionIDs[:] |
39 self.isDefault = default |
45 self.isDefault = default |
40 self.title = "" |
46 self.title = "" |
41 self.isChanged = False |
47 self.isChanged = False |
42 |
48 |
43 |
49 |
44 class EricToolBarDialog(QDialog, Ui_EricToolBarDialog): |
50 class EricToolBarDialog(QDialog, Ui_EricToolBarDialog): |
45 """ |
51 """ |
46 Class implementing a toolbar configuration dialog. |
52 Class implementing a toolbar configuration dialog. |
47 """ |
53 """ |
|
54 |
48 ActionIdRole = Qt.ItemDataRole.UserRole |
55 ActionIdRole = Qt.ItemDataRole.UserRole |
49 WidgetActionRole = Qt.ItemDataRole.UserRole + 1 |
56 WidgetActionRole = Qt.ItemDataRole.UserRole + 1 |
50 |
57 |
51 def __init__(self, toolBarManager, parent=None): |
58 def __init__(self, toolBarManager, parent=None): |
52 """ |
59 """ |
53 Constructor |
60 Constructor |
54 |
61 |
55 @param toolBarManager reference to a toolbar manager object |
62 @param toolBarManager reference to a toolbar manager object |
56 (EricToolBarManager) |
63 (EricToolBarManager) |
57 @param parent reference to the parent widget (QWidget) |
64 @param parent reference to the parent widget (QWidget) |
58 """ |
65 """ |
59 super().__init__(parent) |
66 super().__init__(parent) |
60 self.setupUi(self) |
67 self.setupUi(self) |
61 |
68 |
62 self.__manager = toolBarManager |
69 self.__manager = toolBarManager |
63 self.__toolbarItems = {} |
70 self.__toolbarItems = {} |
64 # maps toolbar item IDs to toolbar items |
71 # maps toolbar item IDs to toolbar items |
65 self.__currentToolBarItem = None |
72 self.__currentToolBarItem = None |
66 self.__removedToolBarIDs = [] |
73 self.__removedToolBarIDs = [] |
67 # remember custom toolbars to be deleted |
74 # remember custom toolbars to be deleted |
68 |
75 |
69 self.__widgetActionToToolBarItemID = {} |
76 self.__widgetActionToToolBarItemID = {} |
70 # maps widget action IDs to toolbar item IDs |
77 # maps widget action IDs to toolbar item IDs |
71 self.__toolBarItemToWidgetActionID = {} |
78 self.__toolBarItemToWidgetActionID = {} |
72 # maps toolbar item IDs to widget action IDs |
79 # maps toolbar item IDs to widget action IDs |
73 |
80 |
74 self.upButton.setIcon(UI.PixmapCache.getIcon("1uparrow")) |
81 self.upButton.setIcon(UI.PixmapCache.getIcon("1uparrow")) |
75 self.downButton.setIcon(UI.PixmapCache.getIcon("1downarrow")) |
82 self.downButton.setIcon(UI.PixmapCache.getIcon("1downarrow")) |
76 self.leftButton.setIcon(UI.PixmapCache.getIcon("1leftarrow")) |
83 self.leftButton.setIcon(UI.PixmapCache.getIcon("1leftarrow")) |
77 self.rightButton.setIcon(UI.PixmapCache.getIcon("1rightarrow")) |
84 self.rightButton.setIcon(UI.PixmapCache.getIcon("1rightarrow")) |
78 |
85 |
79 self.__restoreDefaultsButton = self.buttonBox.button( |
86 self.__restoreDefaultsButton = self.buttonBox.button( |
80 QDialogButtonBox.StandardButton.RestoreDefaults) |
87 QDialogButtonBox.StandardButton.RestoreDefaults |
|
88 ) |
81 self.__resetButton = self.buttonBox.button( |
89 self.__resetButton = self.buttonBox.button( |
82 QDialogButtonBox.StandardButton.Reset) |
90 QDialogButtonBox.StandardButton.Reset |
83 |
91 ) |
|
92 |
84 self.actionsTree.header().hide() |
93 self.actionsTree.header().hide() |
85 self.__separatorText = self.tr("--Separator--") |
94 self.__separatorText = self.tr("--Separator--") |
86 itm = QTreeWidgetItem(self.actionsTree, [self.__separatorText]) |
95 itm = QTreeWidgetItem(self.actionsTree, [self.__separatorText]) |
87 self.actionsTree.setCurrentItem(itm) |
96 self.actionsTree.setCurrentItem(itm) |
88 |
97 |
89 for category in sorted(self.__manager.categories()): |
98 for category in sorted(self.__manager.categories()): |
90 categoryItem = QTreeWidgetItem(self.actionsTree, [category]) |
99 categoryItem = QTreeWidgetItem(self.actionsTree, [category]) |
91 for action in self.__manager.categoryActions(category): |
100 for action in self.__manager.categoryActions(category): |
92 item = QTreeWidgetItem(categoryItem) |
101 item = QTreeWidgetItem(categoryItem) |
93 item.setText(0, action.text()) |
102 item.setText(0, action.text()) |
94 item.setIcon(0, action.icon()) |
103 item.setIcon(0, action.icon()) |
95 item.setTextAlignment( |
104 item.setTextAlignment( |
96 0, |
105 0, Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter |
97 Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter |
106 ) |
98 ) |
107 item.setData(0, EricToolBarDialog.ActionIdRole, int(id(action))) |
99 item.setData(0, EricToolBarDialog.ActionIdRole, |
|
100 int(id(action))) |
|
101 item.setData(0, EricToolBarDialog.WidgetActionRole, False) |
108 item.setData(0, EricToolBarDialog.WidgetActionRole, False) |
102 if self.__manager.isWidgetAction(action): |
109 if self.__manager.isWidgetAction(action): |
103 item.setData(0, EricToolBarDialog.WidgetActionRole, True) |
110 item.setData(0, EricToolBarDialog.WidgetActionRole, True) |
104 item.setData(0, Qt.ItemDataRole.ForegroundRole, |
111 item.setData( |
105 QColor(Qt.GlobalColor.blue)) |
112 0, Qt.ItemDataRole.ForegroundRole, QColor(Qt.GlobalColor.blue) |
|
113 ) |
106 self.__widgetActionToToolBarItemID[id(action)] = None |
114 self.__widgetActionToToolBarItemID[id(action)] = None |
107 categoryItem.setExpanded(True) |
115 categoryItem.setExpanded(True) |
108 |
116 |
109 for tbID, actions in list(self.__manager.toolBarsActions().items()): |
117 for tbID, actions in list(self.__manager.toolBarsActions().items()): |
110 tb = self.__manager.toolBarById(tbID) |
118 tb = self.__manager.toolBarById(tbID) |
111 default = self.__manager.isDefaultToolBar(tb) |
119 default = self.__manager.isDefaultToolBar(tb) |
112 tbItem = EricToolBarItem(tbID, [], default) |
120 tbItem = EricToolBarItem(tbID, [], default) |
113 self.__toolbarItems[id(tbItem)] = tbItem |
121 self.__toolbarItems[id(tbItem)] = tbItem |
119 else: |
127 else: |
120 aID = id(action) |
128 aID = id(action) |
121 actionIDs.append(aID) |
129 actionIDs.append(aID) |
122 if aID in self.__widgetActionToToolBarItemID: |
130 if aID in self.__widgetActionToToolBarItemID: |
123 self.__widgetActionToToolBarItemID[aID] = id(tbItem) |
131 self.__widgetActionToToolBarItemID[aID] = id(tbItem) |
124 self.__toolBarItemToWidgetActionID[id(tbItem)].append( |
132 self.__toolBarItemToWidgetActionID[id(tbItem)].append(aID) |
125 aID) |
|
126 tbItem.actionIDs = actionIDs |
133 tbItem.actionIDs = actionIDs |
127 self.toolbarComboBox.addItem(tb.windowTitle(), int(id(tbItem))) |
134 self.toolbarComboBox.addItem(tb.windowTitle(), int(id(tbItem))) |
128 if default: |
135 if default: |
129 self.toolbarComboBox.setItemData( |
136 self.toolbarComboBox.setItemData( |
130 self.toolbarComboBox.count() - 1, |
137 self.toolbarComboBox.count() - 1, |
131 QColor(Qt.GlobalColor.darkGreen), |
138 QColor(Qt.GlobalColor.darkGreen), |
132 Qt.ItemDataRole.ForegroundRole) |
139 Qt.ItemDataRole.ForegroundRole, |
|
140 ) |
133 self.toolbarComboBox.model().sort(0) |
141 self.toolbarComboBox.model().sort(0) |
134 |
142 |
135 self.toolbarComboBox.currentIndexChanged[int].connect( |
143 self.toolbarComboBox.currentIndexChanged[int].connect( |
136 self.__toolbarComboBox_currentIndexChanged) |
144 self.__toolbarComboBox_currentIndexChanged |
|
145 ) |
137 self.toolbarComboBox.setCurrentIndex(0) |
146 self.toolbarComboBox.setCurrentIndex(0) |
138 |
147 |
139 @pyqtSlot() |
148 @pyqtSlot() |
140 def on_newButton_clicked(self): |
149 def on_newButton_clicked(self): |
141 """ |
150 """ |
142 Private slot to create a new toolbar. |
151 Private slot to create a new toolbar. |
143 """ |
152 """ |
144 name, ok = QInputDialog.getText( |
153 name, ok = QInputDialog.getText( |
145 self, |
154 self, |
146 self.tr("New Toolbar"), |
155 self.tr("New Toolbar"), |
147 self.tr("Toolbar Name:"), |
156 self.tr("Toolbar Name:"), |
148 QLineEdit.EchoMode.Normal) |
157 QLineEdit.EchoMode.Normal, |
|
158 ) |
149 if ok and name: |
159 if ok and name: |
150 if self.toolbarComboBox.findText(name) != -1: |
160 if self.toolbarComboBox.findText(name) != -1: |
151 # toolbar with this name already exists |
161 # toolbar with this name already exists |
152 EricMessageBox.critical( |
162 EricMessageBox.critical( |
153 self, |
163 self, |
154 self.tr("New Toolbar"), |
164 self.tr("New Toolbar"), |
155 self.tr( |
165 self.tr( |
156 """A toolbar with the name <b>{0}</b> already""" |
166 """A toolbar with the name <b>{0}</b> already""" """ exists.""" |
157 """ exists.""") |
167 ).format(name), |
158 .format(name)) |
168 ) |
159 return |
169 return |
160 |
170 |
161 tbItem = EricToolBarItem(None, [], False) |
171 tbItem = EricToolBarItem(None, [], False) |
162 tbItem.title = name |
172 tbItem.title = name |
163 tbItem.isChanged = True |
173 tbItem.isChanged = True |
164 self.__toolbarItems[id(tbItem)] = tbItem |
174 self.__toolbarItems[id(tbItem)] = tbItem |
165 self.__toolBarItemToWidgetActionID[id(tbItem)] = [] |
175 self.__toolBarItemToWidgetActionID[id(tbItem)] = [] |
166 self.toolbarComboBox.addItem(name, int(id(tbItem))) |
176 self.toolbarComboBox.addItem(name, int(id(tbItem))) |
167 self.toolbarComboBox.model().sort(0) |
177 self.toolbarComboBox.model().sort(0) |
168 self.toolbarComboBox.setCurrentIndex( |
178 self.toolbarComboBox.setCurrentIndex(self.toolbarComboBox.findText(name)) |
169 self.toolbarComboBox.findText(name)) |
179 |
170 |
|
171 @pyqtSlot() |
180 @pyqtSlot() |
172 def on_removeButton_clicked(self): |
181 def on_removeButton_clicked(self): |
173 """ |
182 """ |
174 Private slot to remove a custom toolbar. |
183 Private slot to remove a custom toolbar. |
175 """ |
184 """ |
176 name = self.toolbarComboBox.currentText() |
185 name = self.toolbarComboBox.currentText() |
177 res = EricMessageBox.yesNo( |
186 res = EricMessageBox.yesNo( |
178 self, |
187 self, |
179 self.tr("Remove Toolbar"), |
188 self.tr("Remove Toolbar"), |
180 self.tr( |
189 self.tr("""Should the toolbar <b>{0}</b> really be removed?""").format( |
181 """Should the toolbar <b>{0}</b> really be removed?""") |
190 name |
182 .format(name)) |
191 ), |
|
192 ) |
183 if res: |
193 if res: |
184 index = self.toolbarComboBox.currentIndex() |
194 index = self.toolbarComboBox.currentIndex() |
185 tbItemID = self.toolbarComboBox.itemData(index) |
195 tbItemID = self.toolbarComboBox.itemData(index) |
186 tbItem = self.__toolbarItems[tbItemID] |
196 tbItem = self.__toolbarItems[tbItemID] |
187 if ( |
197 if ( |
188 tbItem.toolBarId is not None and |
198 tbItem.toolBarId is not None |
189 tbItem.toolBarId not in self.__removedToolBarIDs |
199 and tbItem.toolBarId not in self.__removedToolBarIDs |
190 ): |
200 ): |
191 self.__removedToolBarIDs.append(tbItem.toolBarId) |
201 self.__removedToolBarIDs.append(tbItem.toolBarId) |
192 del self.__toolbarItems[tbItemID] |
202 del self.__toolbarItems[tbItemID] |
193 for widgetActionID in self.__toolBarItemToWidgetActionID[tbItemID]: |
203 for widgetActionID in self.__toolBarItemToWidgetActionID[tbItemID]: |
194 self.__widgetActionToToolBarItemID[widgetActionID] = None |
204 self.__widgetActionToToolBarItemID[widgetActionID] = None |
195 del self.__toolBarItemToWidgetActionID[tbItemID] |
205 del self.__toolBarItemToWidgetActionID[tbItemID] |
196 self.toolbarComboBox.removeItem(index) |
206 self.toolbarComboBox.removeItem(index) |
197 |
207 |
198 @pyqtSlot() |
208 @pyqtSlot() |
199 def on_renameButton_clicked(self): |
209 def on_renameButton_clicked(self): |
200 """ |
210 """ |
201 Private slot to rename a custom toolbar. |
211 Private slot to rename a custom toolbar. |
202 """ |
212 """ |
204 newName, ok = QInputDialog.getText( |
214 newName, ok = QInputDialog.getText( |
205 self, |
215 self, |
206 self.tr("Rename Toolbar"), |
216 self.tr("Rename Toolbar"), |
207 self.tr("New Toolbar Name:"), |
217 self.tr("New Toolbar Name:"), |
208 QLineEdit.EchoMode.Normal, |
218 QLineEdit.EchoMode.Normal, |
209 oldName) |
219 oldName, |
|
220 ) |
210 if ok and newName: |
221 if ok and newName: |
211 if oldName == newName: |
222 if oldName == newName: |
212 return |
223 return |
213 if self.toolbarComboBox.findText(newName) != -1: |
224 if self.toolbarComboBox.findText(newName) != -1: |
214 # toolbar with this name already exists |
225 # toolbar with this name already exists |
215 EricMessageBox.critical( |
226 EricMessageBox.critical( |
216 self, |
227 self, |
217 self.tr("Rename Toolbar"), |
228 self.tr("Rename Toolbar"), |
218 self.tr( |
229 self.tr( |
219 """A toolbar with the name <b>{0}</b> already""" |
230 """A toolbar with the name <b>{0}</b> already""" """ exists.""" |
220 """ exists.""") |
231 ).format(newName), |
221 .format(newName)) |
232 ) |
222 return |
233 return |
223 index = self.toolbarComboBox.currentIndex() |
234 index = self.toolbarComboBox.currentIndex() |
224 self.toolbarComboBox.setItemText(index, newName) |
235 self.toolbarComboBox.setItemText(index, newName) |
225 tbItem = self.__toolbarItems[self.toolbarComboBox.itemData(index)] |
236 tbItem = self.__toolbarItems[self.toolbarComboBox.itemData(index)] |
226 tbItem.title = newName |
237 tbItem.title = newName |
227 tbItem.isChanged = True |
238 tbItem.isChanged = True |
228 |
239 |
229 def __setupButtons(self): |
240 def __setupButtons(self): |
230 """ |
241 """ |
231 Private slot to set the buttons state. |
242 Private slot to set the buttons state. |
232 """ |
243 """ |
233 index = self.toolbarComboBox.currentIndex() |
244 index = self.toolbarComboBox.currentIndex() |
234 if index > -1: |
245 if index > -1: |
235 itemID = self.toolbarComboBox.itemData(index) |
246 itemID = self.toolbarComboBox.itemData(index) |
236 self.__currentToolBarItem = self.__toolbarItems[itemID] |
247 self.__currentToolBarItem = self.__toolbarItems[itemID] |
237 self.renameButton.setEnabled( |
248 self.renameButton.setEnabled(not self.__currentToolBarItem.isDefault) |
238 not self.__currentToolBarItem.isDefault) |
249 self.removeButton.setEnabled(not self.__currentToolBarItem.isDefault) |
239 self.removeButton.setEnabled( |
250 self.__restoreDefaultsButton.setEnabled(self.__currentToolBarItem.isDefault) |
240 not self.__currentToolBarItem.isDefault) |
|
241 self.__restoreDefaultsButton.setEnabled( |
|
242 self.__currentToolBarItem.isDefault) |
|
243 self.__resetButton.setEnabled( |
251 self.__resetButton.setEnabled( |
244 self.__currentToolBarItem.toolBarId is not None) |
252 self.__currentToolBarItem.toolBarId is not None |
245 |
253 ) |
|
254 |
246 row = self.toolbarActionsList.currentRow() |
255 row = self.toolbarActionsList.currentRow() |
247 self.upButton.setEnabled(row > 0) |
256 self.upButton.setEnabled(row > 0) |
248 self.downButton.setEnabled(row < self.toolbarActionsList.count() - 1) |
257 self.downButton.setEnabled(row < self.toolbarActionsList.count() - 1) |
249 self.leftButton.setEnabled(self.toolbarActionsList.count() > 0) |
258 self.leftButton.setEnabled(self.toolbarActionsList.count() > 0) |
250 rightEnable = ( |
259 rightEnable = ( |
251 self.actionsTree.currentItem().parent() is not None or |
260 self.actionsTree.currentItem().parent() is not None |
252 self.actionsTree.currentItem().text(0) == self.__separatorText |
261 or self.actionsTree.currentItem().text(0) == self.__separatorText |
253 ) |
262 ) |
254 self.rightButton.setEnabled(rightEnable) |
263 self.rightButton.setEnabled(rightEnable) |
255 |
264 |
256 @pyqtSlot(int) |
265 @pyqtSlot(int) |
257 def __toolbarComboBox_currentIndexChanged(self, index): |
266 def __toolbarComboBox_currentIndexChanged(self, index): |
258 """ |
267 """ |
259 Private slot called upon a selection of the current toolbar. |
268 Private slot called upon a selection of the current toolbar. |
260 |
269 |
261 @param index index of the new current toolbar (integer) |
270 @param index index of the new current toolbar (integer) |
262 """ |
271 """ |
263 itemID = self.toolbarComboBox.itemData(index) |
272 itemID = self.toolbarComboBox.itemData(index) |
264 self.__currentToolBarItem = self.__toolbarItems[itemID] |
273 self.__currentToolBarItem = self.__toolbarItems[itemID] |
265 self.toolbarActionsList.clear() |
274 self.toolbarActionsList.clear() |
269 item.setText(self.__separatorText) |
278 item.setText(self.__separatorText) |
270 else: |
279 else: |
271 action = self.__manager.actionById(actionID) |
280 action = self.__manager.actionById(actionID) |
272 item.setText(action.text()) |
281 item.setText(action.text()) |
273 item.setIcon(action.icon()) |
282 item.setIcon(action.icon()) |
274 item.setTextAlignment(Qt.AlignmentFlag.AlignLeft | |
283 item.setTextAlignment( |
275 Qt.AlignmentFlag.AlignVCenter) |
284 Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter |
|
285 ) |
276 item.setData(EricToolBarDialog.ActionIdRole, int(id(action))) |
286 item.setData(EricToolBarDialog.ActionIdRole, int(id(action))) |
277 item.setData(EricToolBarDialog.WidgetActionRole, False) |
287 item.setData(EricToolBarDialog.WidgetActionRole, False) |
278 if self.__manager.isWidgetAction(action): |
288 if self.__manager.isWidgetAction(action): |
279 item.setData(EricToolBarDialog.WidgetActionRole, True) |
289 item.setData(EricToolBarDialog.WidgetActionRole, True) |
280 item.setData(Qt.ItemDataRole.ForegroundRole, |
290 item.setData( |
281 QColor(Qt.GlobalColor.blue)) |
291 Qt.ItemDataRole.ForegroundRole, QColor(Qt.GlobalColor.blue) |
|
292 ) |
282 self.toolbarActionsList.setCurrentRow(0) |
293 self.toolbarActionsList.setCurrentRow(0) |
283 |
294 |
284 self.__setupButtons() |
295 self.__setupButtons() |
285 |
296 |
286 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
297 @pyqtSlot(QTreeWidgetItem, QTreeWidgetItem) |
287 def on_actionsTree_currentItemChanged(self, current, previous): |
298 def on_actionsTree_currentItemChanged(self, current, previous): |
288 """ |
299 """ |
289 Private slot called, when the currently selected action changes. |
300 Private slot called, when the currently selected action changes. |
290 |
301 |
291 @param current reference to the current item (QTreeWidgetItem) |
302 @param current reference to the current item (QTreeWidgetItem) |
292 @param previous reference to the previous current item |
303 @param previous reference to the previous current item |
293 (QTreeWidgetItem) |
304 (QTreeWidgetItem) |
294 """ |
305 """ |
295 self.__setupButtons() |
306 self.__setupButtons() |
296 |
307 |
297 @pyqtSlot(QListWidgetItem, QListWidgetItem) |
308 @pyqtSlot(QListWidgetItem, QListWidgetItem) |
298 def on_toolbarActionsList_currentItemChanged(self, current, previous): |
309 def on_toolbarActionsList_currentItemChanged(self, current, previous): |
299 """ |
310 """ |
300 Private slot to handle a change of the current item. |
311 Private slot to handle a change of the current item. |
301 |
312 |
302 @param current reference to the current item (QListWidgetItem) |
313 @param current reference to the current item (QListWidgetItem) |
303 @param previous reference to the previous current item |
314 @param previous reference to the previous current item |
304 (QListWidgetItem) |
315 (QListWidgetItem) |
305 """ |
316 """ |
306 self.__setupButtons() |
317 self.__setupButtons() |
307 |
318 |
308 @pyqtSlot() |
319 @pyqtSlot() |
309 def on_upButton_clicked(self): |
320 def on_upButton_clicked(self): |
310 """ |
321 """ |
311 Private slot used to move an action up in the list. |
322 Private slot used to move an action up in the list. |
312 """ |
323 """ |
313 row = self.toolbarActionsList.currentRow() |
324 row = self.toolbarActionsList.currentRow() |
314 if row == 0: |
325 if row == 0: |
315 # we're already at the top |
326 # we're already at the top |
316 return |
327 return |
317 |
328 |
318 actionID = self.__currentToolBarItem.actionIDs.pop(row) |
329 actionID = self.__currentToolBarItem.actionIDs.pop(row) |
319 self.__currentToolBarItem.actionIDs.insert(row - 1, actionID) |
330 self.__currentToolBarItem.actionIDs.insert(row - 1, actionID) |
320 self.__currentToolBarItem.isChanged = True |
331 self.__currentToolBarItem.isChanged = True |
321 itm = self.toolbarActionsList.takeItem(row) |
332 itm = self.toolbarActionsList.takeItem(row) |
322 self.toolbarActionsList.insertItem(row - 1, itm) |
333 self.toolbarActionsList.insertItem(row - 1, itm) |
323 self.toolbarActionsList.setCurrentItem(itm) |
334 self.toolbarActionsList.setCurrentItem(itm) |
324 self.__setupButtons() |
335 self.__setupButtons() |
325 |
336 |
326 @pyqtSlot() |
337 @pyqtSlot() |
327 def on_downButton_clicked(self): |
338 def on_downButton_clicked(self): |
328 """ |
339 """ |
329 Private slot used to move an action down in the list. |
340 Private slot used to move an action down in the list. |
330 """ |
341 """ |
331 row = self.toolbarActionsList.currentRow() |
342 row = self.toolbarActionsList.currentRow() |
332 if row == self.toolbarActionsList.count() - 1: |
343 if row == self.toolbarActionsList.count() - 1: |
333 # we're already at the end |
344 # we're already at the end |
334 return |
345 return |
335 |
346 |
336 actionID = self.__currentToolBarItem.actionIDs.pop(row) |
347 actionID = self.__currentToolBarItem.actionIDs.pop(row) |
337 self.__currentToolBarItem.actionIDs.insert(row + 1, actionID) |
348 self.__currentToolBarItem.actionIDs.insert(row + 1, actionID) |
338 self.__currentToolBarItem.isChanged = True |
349 self.__currentToolBarItem.isChanged = True |
339 itm = self.toolbarActionsList.takeItem(row) |
350 itm = self.toolbarActionsList.takeItem(row) |
340 self.toolbarActionsList.insertItem(row + 1, itm) |
351 self.toolbarActionsList.insertItem(row + 1, itm) |
341 self.toolbarActionsList.setCurrentItem(itm) |
352 self.toolbarActionsList.setCurrentItem(itm) |
342 self.__setupButtons() |
353 self.__setupButtons() |
343 |
354 |
344 @pyqtSlot() |
355 @pyqtSlot() |
345 def on_leftButton_clicked(self): |
356 def on_leftButton_clicked(self): |
346 """ |
357 """ |
347 Private slot to delete an action from the list. |
358 Private slot to delete an action from the list. |
348 """ |
359 """ |
349 row = self.toolbarActionsList.currentRow() |
360 row = self.toolbarActionsList.currentRow() |
350 actionID = self.__currentToolBarItem.actionIDs.pop(row) |
361 actionID = self.__currentToolBarItem.actionIDs.pop(row) |
351 self.__currentToolBarItem.isChanged = True |
362 self.__currentToolBarItem.isChanged = True |
352 if actionID in self.__widgetActionToToolBarItemID: |
363 if actionID in self.__widgetActionToToolBarItemID: |
353 self.__widgetActionToToolBarItemID[actionID] = None |
364 self.__widgetActionToToolBarItemID[actionID] = None |
354 self.__toolBarItemToWidgetActionID[ |
365 self.__toolBarItemToWidgetActionID[id(self.__currentToolBarItem)].remove( |
355 id(self.__currentToolBarItem)].remove(actionID) |
366 actionID |
|
367 ) |
356 itm = self.toolbarActionsList.takeItem(row) |
368 itm = self.toolbarActionsList.takeItem(row) |
357 del itm |
369 del itm |
358 self.toolbarActionsList.setCurrentRow(row) |
370 self.toolbarActionsList.setCurrentRow(row) |
359 self.__setupButtons() |
371 self.__setupButtons() |
360 |
372 |
361 @pyqtSlot() |
373 @pyqtSlot() |
362 def on_rightButton_clicked(self): |
374 def on_rightButton_clicked(self): |
363 """ |
375 """ |
364 Private slot to add an action to the list. |
376 Private slot to add an action to the list. |
365 """ |
377 """ |
366 row = self.toolbarActionsList.currentRow() + 1 |
378 row = self.toolbarActionsList.currentRow() + 1 |
367 |
379 |
368 item = QListWidgetItem() |
380 item = QListWidgetItem() |
369 if self.actionsTree.currentItem().text(0) == self.__separatorText: |
381 if self.actionsTree.currentItem().text(0) == self.__separatorText: |
370 item.setText(self.__separatorText) |
382 item.setText(self.__separatorText) |
371 actionID = None |
383 actionID = None |
372 else: |
384 else: |
373 actionID = self.actionsTree.currentItem().data( |
385 actionID = self.actionsTree.currentItem().data( |
374 0, EricToolBarDialog.ActionIdRole) |
386 0, EricToolBarDialog.ActionIdRole |
|
387 ) |
375 action = self.__manager.actionById(actionID) |
388 action = self.__manager.actionById(actionID) |
376 item.setText(action.text()) |
389 item.setText(action.text()) |
377 item.setIcon(action.icon()) |
390 item.setIcon(action.icon()) |
378 item.setTextAlignment(Qt.AlignmentFlag.AlignLeft | |
391 item.setTextAlignment( |
379 Qt.AlignmentFlag.AlignVCenter) |
392 Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter |
|
393 ) |
380 item.setData(EricToolBarDialog.ActionIdRole, int(id(action))) |
394 item.setData(EricToolBarDialog.ActionIdRole, int(id(action))) |
381 item.setData(EricToolBarDialog.WidgetActionRole, False) |
395 item.setData(EricToolBarDialog.WidgetActionRole, False) |
382 if self.__manager.isWidgetAction(action): |
396 if self.__manager.isWidgetAction(action): |
383 item.setData(EricToolBarDialog.WidgetActionRole, True) |
397 item.setData(EricToolBarDialog.WidgetActionRole, True) |
384 item.setData(Qt.ItemDataRole.ForegroundRole, |
398 item.setData( |
385 QColor(Qt.GlobalColor.blue)) |
399 Qt.ItemDataRole.ForegroundRole, QColor(Qt.GlobalColor.blue) |
|
400 ) |
386 oldTbItemID = self.__widgetActionToToolBarItemID[actionID] |
401 oldTbItemID = self.__widgetActionToToolBarItemID[actionID] |
387 if oldTbItemID is not None: |
402 if oldTbItemID is not None: |
388 self.__toolbarItems[oldTbItemID].actionIDs.remove(actionID) |
403 self.__toolbarItems[oldTbItemID].actionIDs.remove(actionID) |
389 self.__toolbarItems[oldTbItemID].isChanged = True |
404 self.__toolbarItems[oldTbItemID].isChanged = True |
390 self.__toolBarItemToWidgetActionID[oldTbItemID].remove( |
405 self.__toolBarItemToWidgetActionID[oldTbItemID].remove(actionID) |
391 actionID) |
|
392 self.__widgetActionToToolBarItemID[actionID] = id( |
406 self.__widgetActionToToolBarItemID[actionID] = id( |
393 self.__currentToolBarItem) |
407 self.__currentToolBarItem |
|
408 ) |
394 self.__toolBarItemToWidgetActionID[ |
409 self.__toolBarItemToWidgetActionID[ |
395 id(self.__currentToolBarItem)].append(actionID) |
410 id(self.__currentToolBarItem) |
|
411 ].append(actionID) |
396 self.toolbarActionsList.insertItem(row, item) |
412 self.toolbarActionsList.insertItem(row, item) |
397 self.__currentToolBarItem.actionIDs.insert(row, actionID) |
413 self.__currentToolBarItem.actionIDs.insert(row, actionID) |
398 self.__currentToolBarItem.isChanged = True |
414 self.__currentToolBarItem.isChanged = True |
399 self.toolbarActionsList.setCurrentRow(row) |
415 self.toolbarActionsList.setCurrentRow(row) |
400 self.__setupButtons() |
416 self.__setupButtons() |
401 |
417 |
402 @pyqtSlot(QAbstractButton) |
418 @pyqtSlot(QAbstractButton) |
403 def on_buttonBox_clicked(self, button): |
419 def on_buttonBox_clicked(self, button): |
404 """ |
420 """ |
405 Private slot called, when a button of the button box was clicked. |
421 Private slot called, when a button of the button box was clicked. |
406 |
422 |
407 @param button reference to the button clicked (QAbstractButton) |
423 @param button reference to the button clicked (QAbstractButton) |
408 """ |
424 """ |
409 if button == self.buttonBox.button( |
425 if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel): |
410 QDialogButtonBox.StandardButton.Cancel |
|
411 ): |
|
412 self.reject() |
426 self.reject() |
413 elif button == self.buttonBox.button( |
427 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Apply): |
414 QDialogButtonBox.StandardButton.Apply |
|
415 ): |
|
416 self.__saveToolBars() |
428 self.__saveToolBars() |
417 self.__setupButtons() |
429 self.__setupButtons() |
418 elif button == self.buttonBox.button( |
430 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Ok): |
419 QDialogButtonBox.StandardButton.Ok |
|
420 ): |
|
421 self.__saveToolBars() |
431 self.__saveToolBars() |
422 self.accept() |
432 self.accept() |
423 elif button == self.buttonBox.button( |
433 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Reset): |
424 QDialogButtonBox.StandardButton.Reset |
|
425 ): |
|
426 self.__resetCurrentToolbar() |
434 self.__resetCurrentToolbar() |
427 self.__setupButtons() |
435 self.__setupButtons() |
428 elif button == self.buttonBox.button( |
436 elif button == self.buttonBox.button( |
429 QDialogButtonBox.StandardButton.RestoreDefaults |
437 QDialogButtonBox.StandardButton.RestoreDefaults |
430 ): |
438 ): |
431 self.__restoreCurrentToolbarToDefault() |
439 self.__restoreCurrentToolbarToDefault() |
432 self.__setupButtons() |
440 self.__setupButtons() |
433 |
441 |
434 def __saveToolBars(self): |
442 def __saveToolBars(self): |
435 """ |
443 """ |
436 Private method to save the configured toolbars. |
444 Private method to save the configured toolbars. |
437 |
445 |
438 @exception RuntimeError raised to indicate an invalid action |
446 @exception RuntimeError raised to indicate an invalid action |
439 """ |
447 """ |
440 # step 1: remove toolbars marked for deletion |
448 # step 1: remove toolbars marked for deletion |
441 for tbID in self.__removedToolBarIDs: |
449 for tbID in self.__removedToolBarIDs: |
442 tb = self.__manager.toolBarById(tbID) |
450 tb = self.__manager.toolBarById(tbID) |
443 self.__manager.deleteToolBar(tb) |
451 self.__manager.deleteToolBar(tb) |
444 self.__removedToolBarIDs = [] |
452 self.__removedToolBarIDs = [] |
445 |
453 |
446 # step 2: save configured toolbars |
454 # step 2: save configured toolbars |
447 for tbItem in list(self.__toolbarItems.values()): |
455 for tbItem in list(self.__toolbarItems.values()): |
448 if not tbItem.isChanged: |
456 if not tbItem.isChanged: |
449 continue |
457 continue |
450 |
458 |
451 if tbItem.toolBarId is None: |
459 if tbItem.toolBarId is None: |
452 # new custom toolbar |
460 # new custom toolbar |
453 tb = self.__manager.createToolBar(tbItem.title) |
461 tb = self.__manager.createToolBar(tbItem.title) |
454 tbItem.toolBarId = id(tb) |
462 tbItem.toolBarId = id(tb) |
455 else: |
463 else: |
456 tb = self.__manager.toolBarById(tbItem.toolBarId) |
464 tb = self.__manager.toolBarById(tbItem.toolBarId) |
457 if not tbItem.isDefault and tbItem.title: |
465 if not tbItem.isDefault and tbItem.title: |
458 self.__manager.renameToolBar(tb, tbItem.title) |
466 self.__manager.renameToolBar(tb, tbItem.title) |
459 |
467 |
460 actions = [] |
468 actions = [] |
461 for actionID in tbItem.actionIDs: |
469 for actionID in tbItem.actionIDs: |
462 if actionID is None: |
470 if actionID is None: |
463 actions.append(None) |
471 actions.append(None) |
464 else: |
472 else: |
465 action = self.__manager.actionById(actionID) |
473 action = self.__manager.actionById(actionID) |
466 if action is None: |
474 if action is None: |
467 raise RuntimeError( |
475 raise RuntimeError( |
468 "No such action, id: 0x{0:x}".format(actionID)) |
476 "No such action, id: 0x{0:x}".format(actionID) |
|
477 ) |
469 actions.append(action) |
478 actions.append(action) |
470 self.__manager.setToolBar(tb, actions) |
479 self.__manager.setToolBar(tb, actions) |
471 tbItem.isChanged = False |
480 tbItem.isChanged = False |
472 |
481 |
473 def __restoreCurrentToolbar(self, actions): |
482 def __restoreCurrentToolbar(self, actions): |
474 """ |
483 """ |
475 Private methdo to restore the current toolbar to the given list of |
484 Private methdo to restore the current toolbar to the given list of |
476 actions. |
485 actions. |
477 |
486 |
478 @param actions list of actions to set for the current toolbar |
487 @param actions list of actions to set for the current toolbar |
479 (list of QAction) |
488 (list of QAction) |
480 """ |
489 """ |
481 tbItemID = id(self.__currentToolBarItem) |
490 tbItemID = id(self.__currentToolBarItem) |
482 for widgetActionID in self.__toolBarItemToWidgetActionID[tbItemID]: |
491 for widgetActionID in self.__toolBarItemToWidgetActionID[tbItemID]: |
483 self.__widgetActionToToolBarItemID[widgetActionID] = None |
492 self.__widgetActionToToolBarItemID[widgetActionID] = None |
484 self.__toolBarItemToWidgetActionID[tbItemID] = [] |
493 self.__toolBarItemToWidgetActionID[tbItemID] = [] |
485 self.__currentToolBarItem.actionIDs = [] |
494 self.__currentToolBarItem.actionIDs = [] |
486 |
495 |
487 for action in actions: |
496 for action in actions: |
488 if action is None: |
497 if action is None: |
489 self.__currentToolBarItem.actionIDs.append(None) |
498 self.__currentToolBarItem.actionIDs.append(None) |
490 else: |
499 else: |
491 actionID = id(action) |
500 actionID = id(action) |
492 self.__currentToolBarItem.actionIDs.append(actionID) |
501 self.__currentToolBarItem.actionIDs.append(actionID) |
493 if actionID in self.__widgetActionToToolBarItemID: |
502 if actionID in self.__widgetActionToToolBarItemID: |
494 oldTbItemID = self.__widgetActionToToolBarItemID[actionID] |
503 oldTbItemID = self.__widgetActionToToolBarItemID[actionID] |
495 if oldTbItemID is not None: |
504 if oldTbItemID is not None: |
496 self.__toolbarItems[oldTbItemID].actionIDs.remove( |
505 self.__toolbarItems[oldTbItemID].actionIDs.remove(actionID) |
497 actionID) |
|
498 self.__toolbarItems[oldTbItemID].isChanged = True |
506 self.__toolbarItems[oldTbItemID].isChanged = True |
499 self.__toolBarItemToWidgetActionID[oldTbItemID].remove( |
507 self.__toolBarItemToWidgetActionID[oldTbItemID].remove(actionID) |
500 actionID) |
|
501 self.__widgetActionToToolBarItemID[actionID] = tbItemID |
508 self.__widgetActionToToolBarItemID[actionID] = tbItemID |
502 self.__toolBarItemToWidgetActionID[tbItemID].append( |
509 self.__toolBarItemToWidgetActionID[tbItemID].append(actionID) |
503 actionID) |
510 self.__toolbarComboBox_currentIndexChanged(self.toolbarComboBox.currentIndex()) |
504 self.__toolbarComboBox_currentIndexChanged( |
511 |
505 self.toolbarComboBox.currentIndex()) |
|
506 |
|
507 def __resetCurrentToolbar(self): |
512 def __resetCurrentToolbar(self): |
508 """ |
513 """ |
509 Private method to revert all changes made to the current toolbar. |
514 Private method to revert all changes made to the current toolbar. |
510 """ |
515 """ |
511 tbID = self.__currentToolBarItem.toolBarId |
516 tbID = self.__currentToolBarItem.toolBarId |
512 actions = self.__manager.toolBarActions(tbID) |
517 actions = self.__manager.toolBarActions(tbID) |
513 self.__restoreCurrentToolbar(actions) |
518 self.__restoreCurrentToolbar(actions) |
514 self.__currentToolBarItem.isChanged = False |
519 self.__currentToolBarItem.isChanged = False |
515 |
520 |
516 def __restoreCurrentToolbarToDefault(self): |
521 def __restoreCurrentToolbarToDefault(self): |
517 """ |
522 """ |
518 Private method to set the current toolbar to its default configuration. |
523 Private method to set the current toolbar to its default configuration. |
519 """ |
524 """ |
520 if not self.__currentToolBarItem.isDefault: |
525 if not self.__currentToolBarItem.isDefault: |
521 return |
526 return |
522 |
527 |
523 tbID = self.__currentToolBarItem.toolBarId |
528 tbID = self.__currentToolBarItem.toolBarId |
524 actions = self.__manager.defaultToolBarActions(tbID) |
529 actions = self.__manager.defaultToolBarActions(tbID) |
525 self.__restoreCurrentToolbar(actions) |
530 self.__restoreCurrentToolbar(actions) |
526 self.__currentToolBarItem.isChanged = True |
531 self.__currentToolBarItem.isChanged = True |