25 |
25 |
26 class ShortcutsDialog(QDialog, Ui_ShortcutsDialog): |
26 class ShortcutsDialog(QDialog, Ui_ShortcutsDialog): |
27 """ |
27 """ |
28 Class implementing a dialog for the configuration of eric's keyboard |
28 Class implementing a dialog for the configuration of eric's keyboard |
29 shortcuts. |
29 shortcuts. |
30 |
30 |
31 @signal updateShortcuts() emitted when the user pressed the dialogs OK |
31 @signal updateShortcuts() emitted when the user pressed the dialogs OK |
32 button |
32 button |
33 """ |
33 """ |
|
34 |
34 updateShortcuts = pyqtSignal() |
35 updateShortcuts = pyqtSignal() |
35 |
36 |
36 objectNameRole = Qt.ItemDataRole.UserRole |
37 objectNameRole = Qt.ItemDataRole.UserRole |
37 noCheckRole = Qt.ItemDataRole.UserRole + 1 |
38 noCheckRole = Qt.ItemDataRole.UserRole + 1 |
38 objectTypeRole = Qt.ItemDataRole.UserRole + 2 |
39 objectTypeRole = Qt.ItemDataRole.UserRole + 2 |
39 |
40 |
40 def __init__(self, parent=None): |
41 def __init__(self, parent=None): |
41 """ |
42 """ |
42 Constructor |
43 Constructor |
43 |
44 |
44 @param parent parent widget of this dialog |
45 @param parent parent widget of this dialog |
45 @type QWidget |
46 @type QWidget |
46 """ |
47 """ |
47 super().__init__(parent) |
48 super().__init__(parent) |
48 self.setupUi(self) |
49 self.setupUi(self) |
49 self.setWindowFlags(Qt.WindowType.Window) |
50 self.setWindowFlags(Qt.WindowType.Window) |
50 |
51 |
51 self.__helpViewer = None |
52 self.__helpViewer = None |
52 |
53 |
53 self.shortcutsList.headerItem().setText( |
54 self.shortcutsList.headerItem().setText(self.shortcutsList.columnCount(), "") |
54 self.shortcutsList.columnCount(), "") |
55 self.shortcutsList.header().setSortIndicator(0, Qt.SortOrder.AscendingOrder) |
55 self.shortcutsList.header().setSortIndicator( |
56 |
56 0, Qt.SortOrder.AscendingOrder) |
|
57 |
|
58 from .ShortcutDialog import ShortcutDialog |
57 from .ShortcutDialog import ShortcutDialog |
|
58 |
59 self.shortcutDialog = ShortcutDialog() |
59 self.shortcutDialog = ShortcutDialog() |
60 self.shortcutDialog.shortcutChanged.connect(self.__shortcutChanged) |
60 self.shortcutDialog.shortcutChanged.connect(self.__shortcutChanged) |
61 |
61 |
62 def __resort(self): |
62 def __resort(self): |
63 """ |
63 """ |
64 Private method to resort the tree. |
64 Private method to resort the tree. |
65 """ |
65 """ |
66 self.shortcutsList.sortItems( |
66 self.shortcutsList.sortItems( |
67 self.shortcutsList.sortColumn(), |
67 self.shortcutsList.sortColumn(), |
68 self.shortcutsList.header().sortIndicatorOrder()) |
68 self.shortcutsList.header().sortIndicatorOrder(), |
69 |
69 ) |
|
70 |
70 def __resizeColumns(self): |
71 def __resizeColumns(self): |
71 """ |
72 """ |
72 Private method to resize the list columns. |
73 Private method to resize the list columns. |
73 """ |
74 """ |
74 self.shortcutsList.header().resizeSections( |
75 self.shortcutsList.header().resizeSections( |
75 QHeaderView.ResizeMode.ResizeToContents) |
76 QHeaderView.ResizeMode.ResizeToContents |
|
77 ) |
76 self.shortcutsList.header().setStretchLastSection(True) |
78 self.shortcutsList.header().setStretchLastSection(True) |
77 |
79 |
78 def __generateCategoryItem(self, title): |
80 def __generateCategoryItem(self, title): |
79 """ |
81 """ |
80 Private method to generate a category item. |
82 Private method to generate a category item. |
81 |
83 |
82 @param title title for the item (string) |
84 @param title title for the item (string) |
83 @return reference to the category item (QTreeWidgetItem) |
85 @return reference to the category item (QTreeWidgetItem) |
84 """ |
86 """ |
85 itm = QTreeWidgetItem(self.shortcutsList, [title]) |
87 itm = QTreeWidgetItem(self.shortcutsList, [title]) |
86 itm.setExpanded(True) |
88 itm.setExpanded(True) |
87 return itm |
89 return itm |
88 |
90 |
89 def __generateShortcutItem(self, category, action, |
91 def __generateShortcutItem(self, category, action, noCheck=False, objectType=""): |
90 noCheck=False, objectType=""): |
|
91 """ |
92 """ |
92 Private method to generate a keyboard shortcut item. |
93 Private method to generate a keyboard shortcut item. |
93 |
94 |
94 @param category reference to the category item (QTreeWidgetItem) |
95 @param category reference to the category item (QTreeWidgetItem) |
95 @param action reference to the keyboard action (EricAction) |
96 @param action reference to the keyboard action (EricAction) |
96 @param noCheck flag indicating that no uniqueness check should |
97 @param noCheck flag indicating that no uniqueness check should |
97 be performed (boolean) |
98 be performed (boolean) |
98 @param objectType type of the object (string). Objects of the same |
99 @param objectType type of the object (string). Objects of the same |
99 type are not checked for duplicate shortcuts. |
100 type are not checked for duplicate shortcuts. |
100 """ |
101 """ |
101 itm = QTreeWidgetItem( |
102 itm = QTreeWidgetItem( |
102 category, |
103 category, |
103 [action.iconText(), action.shortcut().toString(), |
104 [ |
104 action.alternateShortcut().toString()]) |
105 action.iconText(), |
|
106 action.shortcut().toString(), |
|
107 action.alternateShortcut().toString(), |
|
108 ], |
|
109 ) |
105 itm.setIcon(0, action.icon()) |
110 itm.setIcon(0, action.icon()) |
106 itm.setData(0, self.objectNameRole, action.objectName()) |
111 itm.setData(0, self.objectNameRole, action.objectName()) |
107 itm.setData(0, self.noCheckRole, noCheck) |
112 itm.setData(0, self.noCheckRole, noCheck) |
108 if objectType: |
113 if objectType: |
109 itm.setData(0, self.objectTypeRole, objectType) |
114 itm.setData(0, self.objectTypeRole, objectType) |
110 else: |
115 else: |
111 itm.setData(0, self.objectTypeRole, None) |
116 itm.setData(0, self.objectTypeRole, None) |
112 |
117 |
113 def populate(self, helpViewer=None): |
118 def populate(self, helpViewer=None): |
114 """ |
119 """ |
115 Public method to populate the dialog. |
120 Public method to populate the dialog. |
116 |
121 |
117 @param helpViewer reference to the help window object |
122 @param helpViewer reference to the help window object |
118 """ |
123 """ |
119 self.searchEdit.clear() |
124 self.searchEdit.clear() |
120 self.searchEdit.setFocus() |
125 self.searchEdit.setFocus() |
121 self.shortcutsList.clear() |
126 self.shortcutsList.clear() |
122 self.actionButton.setChecked(True) |
127 self.actionButton.setChecked(True) |
123 |
128 |
124 self.__helpViewer = helpViewer |
129 self.__helpViewer = helpViewer |
125 |
130 |
126 if helpViewer is None: |
131 if helpViewer is None: |
127 # let the plugin manager create on demand plugin objects |
132 # let the plugin manager create on demand plugin objects |
128 pm = ericApp().getObject("PluginManager") |
133 pm = ericApp().getObject("PluginManager") |
129 pm.initOnDemandPlugins() |
134 pm.initOnDemandPlugins() |
130 |
135 |
131 # populate the various lists |
136 # populate the various lists |
132 self.projectItem = self.__generateCategoryItem(self.tr("Project")) |
137 self.projectItem = self.__generateCategoryItem(self.tr("Project")) |
133 for act in ericApp().getObject("Project").getActions(): |
138 for act in ericApp().getObject("Project").getActions(): |
134 self.__generateShortcutItem(self.projectItem, act) |
139 self.__generateShortcutItem(self.projectItem, act) |
135 |
140 |
136 self.uiItem = self.__generateCategoryItem(self.tr("General")) |
141 self.uiItem = self.__generateCategoryItem(self.tr("General")) |
137 for act in ericApp().getObject("UserInterface").getActions('ui'): |
142 for act in ericApp().getObject("UserInterface").getActions("ui"): |
138 self.__generateShortcutItem(self.uiItem, act) |
143 self.__generateShortcutItem(self.uiItem, act) |
139 |
144 |
140 self.wizardsItem = self.__generateCategoryItem(self.tr("Wizards")) |
145 self.wizardsItem = self.__generateCategoryItem(self.tr("Wizards")) |
141 for act in ( |
146 for act in ericApp().getObject("UserInterface").getActions("wizards"): |
142 ericApp().getObject("UserInterface").getActions('wizards') |
|
143 ): |
|
144 self.__generateShortcutItem(self.wizardsItem, act) |
147 self.__generateShortcutItem(self.wizardsItem, act) |
145 |
148 |
146 self.debugItem = self.__generateCategoryItem(self.tr("Debug")) |
149 self.debugItem = self.__generateCategoryItem(self.tr("Debug")) |
147 for act in ericApp().getObject("DebugUI").getActions(): |
150 for act in ericApp().getObject("DebugUI").getActions(): |
148 self.__generateShortcutItem(self.debugItem, act) |
151 self.__generateShortcutItem(self.debugItem, act) |
149 |
152 |
150 self.editItem = self.__generateCategoryItem(self.tr("Edit")) |
153 self.editItem = self.__generateCategoryItem(self.tr("Edit")) |
151 for act in ericApp().getObject("ViewManager").getActions('edit'): |
154 for act in ericApp().getObject("ViewManager").getActions("edit"): |
152 self.__generateShortcutItem(self.editItem, act) |
155 self.__generateShortcutItem(self.editItem, act) |
153 |
156 |
154 self.fileItem = self.__generateCategoryItem(self.tr("File")) |
157 self.fileItem = self.__generateCategoryItem(self.tr("File")) |
155 for act in ericApp().getObject("ViewManager").getActions('file'): |
158 for act in ericApp().getObject("ViewManager").getActions("file"): |
156 self.__generateShortcutItem(self.fileItem, act) |
159 self.__generateShortcutItem(self.fileItem, act) |
157 |
160 |
158 self.searchItem = self.__generateCategoryItem(self.tr("Search")) |
161 self.searchItem = self.__generateCategoryItem(self.tr("Search")) |
159 for act in ericApp().getObject("ViewManager").getActions('search'): |
162 for act in ericApp().getObject("ViewManager").getActions("search"): |
160 self.__generateShortcutItem(self.searchItem, act) |
163 self.__generateShortcutItem(self.searchItem, act) |
161 |
164 |
162 self.viewItem = self.__generateCategoryItem(self.tr("View")) |
165 self.viewItem = self.__generateCategoryItem(self.tr("View")) |
163 for act in ericApp().getObject("ViewManager").getActions('view'): |
166 for act in ericApp().getObject("ViewManager").getActions("view"): |
164 self.__generateShortcutItem(self.viewItem, act) |
167 self.__generateShortcutItem(self.viewItem, act) |
165 |
168 |
166 self.macroItem = self.__generateCategoryItem(self.tr("Macro")) |
169 self.macroItem = self.__generateCategoryItem(self.tr("Macro")) |
167 for act in ericApp().getObject("ViewManager").getActions('macro'): |
170 for act in ericApp().getObject("ViewManager").getActions("macro"): |
168 self.__generateShortcutItem(self.macroItem, act) |
171 self.__generateShortcutItem(self.macroItem, act) |
169 |
172 |
170 self.bookmarkItem = self.__generateCategoryItem( |
173 self.bookmarkItem = self.__generateCategoryItem(self.tr("Bookmarks")) |
171 self.tr("Bookmarks")) |
174 for act in ericApp().getObject("ViewManager").getActions("bookmark"): |
172 for act in ( |
|
173 ericApp().getObject("ViewManager").getActions('bookmark') |
|
174 ): |
|
175 self.__generateShortcutItem(self.bookmarkItem, act) |
175 self.__generateShortcutItem(self.bookmarkItem, act) |
176 |
176 |
177 self.spellingItem = self.__generateCategoryItem( |
177 self.spellingItem = self.__generateCategoryItem(self.tr("Spelling")) |
178 self.tr("Spelling")) |
178 for act in ericApp().getObject("ViewManager").getActions("spelling"): |
179 for act in ( |
|
180 ericApp().getObject("ViewManager").getActions('spelling') |
|
181 ): |
|
182 self.__generateShortcutItem(self.spellingItem, act) |
179 self.__generateShortcutItem(self.spellingItem, act) |
183 |
180 |
184 actions = ericApp().getObject("ViewManager").getActions('window') |
181 actions = ericApp().getObject("ViewManager").getActions("window") |
185 if actions: |
182 if actions: |
186 self.windowItem = self.__generateCategoryItem( |
183 self.windowItem = self.__generateCategoryItem(self.tr("Window")) |
187 self.tr("Window")) |
|
188 for act in actions: |
184 for act in actions: |
189 self.__generateShortcutItem(self.windowItem, act) |
185 self.__generateShortcutItem(self.windowItem, act) |
190 |
186 |
191 self.pluginCategoryItems = [] |
187 self.pluginCategoryItems = [] |
192 for category, ref in ericApp().getPluginObjects(): |
188 for category, ref in ericApp().getPluginObjects(): |
193 if hasattr(ref, "getActions"): |
189 if hasattr(ref, "getActions"): |
194 categoryItem = self.__generateCategoryItem(category) |
190 categoryItem = self.__generateCategoryItem(category) |
195 objectType = ericApp().getPluginObjectType(category) |
191 objectType = ericApp().getPluginObjectType(category) |
196 for act in ref.getActions(): |
192 for act in ref.getActions(): |
197 self.__generateShortcutItem(categoryItem, act, |
193 self.__generateShortcutItem( |
198 objectType=objectType) |
194 categoryItem, act, objectType=objectType |
|
195 ) |
199 self.pluginCategoryItems.append(categoryItem) |
196 self.pluginCategoryItems.append(categoryItem) |
200 |
197 |
201 else: |
198 else: |
202 self.helpViewerItem = self.__generateCategoryItem( |
199 self.helpViewerItem = self.__generateCategoryItem( |
203 self.tr("eric Web Browser")) |
200 self.tr("eric Web Browser") |
|
201 ) |
204 for act in helpViewer.getActions(): |
202 for act in helpViewer.getActions(): |
205 self.__generateShortcutItem(self.helpViewerItem, act, True) |
203 self.__generateShortcutItem(self.helpViewerItem, act, True) |
206 |
204 |
207 self.__resort() |
205 self.__resort() |
208 self.__resizeColumns() |
206 self.__resizeColumns() |
209 |
207 |
210 self.__editTopItem = None |
208 self.__editTopItem = None |
211 |
209 |
212 def on_shortcutsList_itemDoubleClicked(self, itm, column): |
210 def on_shortcutsList_itemDoubleClicked(self, itm, column): |
213 """ |
211 """ |
214 Private slot to handle a double click in the shortcuts list. |
212 Private slot to handle a double click in the shortcuts list. |
215 |
213 |
216 @param itm the list item that was double clicked (QTreeWidgetItem) |
214 @param itm the list item that was double clicked (QTreeWidgetItem) |
217 @param column the list item was double clicked in (integer) |
215 @param column the list item was double clicked in (integer) |
218 """ |
216 """ |
219 if itm.childCount(): |
217 if itm.childCount(): |
220 return |
218 return |
221 |
219 |
222 self.__editTopItem = itm.parent() |
220 self.__editTopItem = itm.parent() |
223 |
221 |
224 self.shortcutDialog.setKeys( |
222 self.shortcutDialog.setKeys( |
225 QKeySequence(itm.text(1)), |
223 QKeySequence(itm.text(1)), |
226 QKeySequence(itm.text(2)), |
224 QKeySequence(itm.text(2)), |
227 itm.data(0, self.noCheckRole), |
225 itm.data(0, self.noCheckRole), |
228 itm.data(0, self.objectTypeRole)) |
226 itm.data(0, self.objectTypeRole), |
|
227 ) |
229 self.shortcutDialog.show() |
228 self.shortcutDialog.show() |
230 |
229 |
231 def on_shortcutsList_itemClicked(self, itm, column): |
230 def on_shortcutsList_itemClicked(self, itm, column): |
232 """ |
231 """ |
233 Private slot to handle a click in the shortcuts list. |
232 Private slot to handle a click in the shortcuts list. |
234 |
233 |
235 @param itm the list item that was clicked (QTreeWidgetItem) |
234 @param itm the list item that was clicked (QTreeWidgetItem) |
236 @param column the list item was clicked in (integer) |
235 @param column the list item was clicked in (integer) |
237 """ |
236 """ |
238 if itm.childCount() or column not in [1, 2]: |
237 if itm.childCount() or column not in [1, 2]: |
239 return |
238 return |
240 |
239 |
241 self.shortcutsList.openPersistentEditor(itm, column) |
240 self.shortcutsList.openPersistentEditor(itm, column) |
242 |
241 |
243 def on_shortcutsList_itemChanged(self, itm, column): |
242 def on_shortcutsList_itemChanged(self, itm, column): |
244 """ |
243 """ |
245 Private slot to handle the edit of a shortcut key. |
244 Private slot to handle the edit of a shortcut key. |
246 |
245 |
247 @param itm reference to the item changed (QTreeWidgetItem) |
246 @param itm reference to the item changed (QTreeWidgetItem) |
248 @param column column changed (integer) |
247 @param column column changed (integer) |
249 """ |
248 """ |
250 if column != 0: |
249 if column != 0: |
251 keystr = itm.text(column).title() |
250 keystr = itm.text(column).title() |
252 if ( |
251 if not itm.data(0, self.noCheckRole) and not self.__checkShortcut( |
253 not itm.data(0, self.noCheckRole) and |
252 QKeySequence(keystr), itm.data(0, self.objectTypeRole), itm.parent() |
254 not self.__checkShortcut(QKeySequence(keystr), |
|
255 itm.data(0, self.objectTypeRole), |
|
256 itm.parent()) |
|
257 ): |
253 ): |
258 itm.setText(column, "") |
254 itm.setText(column, "") |
259 else: |
255 else: |
260 itm.setText(column, keystr) |
256 itm.setText(column, keystr) |
261 self.shortcutsList.closePersistentEditor(itm, column) |
257 self.shortcutsList.closePersistentEditor(itm, column) |
262 |
258 |
263 def __shortcutChanged(self, keysequence, altKeysequence, noCheck, |
259 def __shortcutChanged(self, keysequence, altKeysequence, noCheck, objectType): |
264 objectType): |
|
265 """ |
260 """ |
266 Private slot to handle the shortcutChanged signal of the shortcut |
261 Private slot to handle the shortcutChanged signal of the shortcut |
267 dialog. |
262 dialog. |
268 |
263 |
269 @param keysequence the keysequence of the changed action (QKeySequence) |
264 @param keysequence the keysequence of the changed action (QKeySequence) |
270 @param altKeysequence the alternative keysequence of the changed |
265 @param altKeysequence the alternative keysequence of the changed |
271 action (QKeySequence) |
266 action (QKeySequence) |
272 @param noCheck flag indicating that no uniqueness check should |
267 @param noCheck flag indicating that no uniqueness check should |
273 be performed (boolean) |
268 be performed (boolean) |
274 @param objectType type of the object (string). |
269 @param objectType type of the object (string). |
275 """ |
270 """ |
276 if ( |
271 if not noCheck and ( |
277 not noCheck and |
272 not self.__checkShortcut(keysequence, objectType, self.__editTopItem) |
278 (not self.__checkShortcut( |
273 or not self.__checkShortcut(altKeysequence, objectType, self.__editTopItem) |
279 keysequence, objectType, self.__editTopItem) or |
|
280 not self.__checkShortcut( |
|
281 altKeysequence, objectType, self.__editTopItem)) |
|
282 ): |
274 ): |
283 return |
275 return |
284 |
276 |
285 self.shortcutsList.currentItem().setText(1, keysequence.toString()) |
277 self.shortcutsList.currentItem().setText(1, keysequence.toString()) |
286 self.shortcutsList.currentItem().setText(2, altKeysequence.toString()) |
278 self.shortcutsList.currentItem().setText(2, altKeysequence.toString()) |
287 |
279 |
288 self.__resort() |
280 self.__resort() |
289 self.__resizeColumns() |
281 self.__resizeColumns() |
290 |
282 |
291 def __checkShortcut(self, keysequence, objectType, origTopItem): |
283 def __checkShortcut(self, keysequence, objectType, origTopItem): |
292 """ |
284 """ |
293 Private method to check a keysequence for uniqueness. |
285 Private method to check a keysequence for uniqueness. |
294 |
286 |
295 @param keysequence the keysequence to check (QKeySequence) |
287 @param keysequence the keysequence to check (QKeySequence) |
296 @param objectType type of the object (string). Entries with the same |
288 @param objectType type of the object (string). Entries with the same |
297 object type are not checked for uniqueness. |
289 object type are not checked for uniqueness. |
298 @param origTopItem refrence to the parent of the item to be checked |
290 @param origTopItem refrence to the parent of the item to be checked |
299 (QTreeWidgetItem) |
291 (QTreeWidgetItem) |
300 @return flag indicating uniqueness (boolean) |
292 @return flag indicating uniqueness (boolean) |
301 """ |
293 """ |
302 if keysequence.isEmpty(): |
294 if keysequence.isEmpty(): |
303 return True |
295 return True |
304 |
296 |
305 keystr = keysequence.toString() |
297 keystr = keysequence.toString() |
306 keyname = self.shortcutsList.currentItem().text(0) |
298 keyname = self.shortcutsList.currentItem().text(0) |
307 for topIndex in range(self.shortcutsList.topLevelItemCount()): |
299 for topIndex in range(self.shortcutsList.topLevelItemCount()): |
308 topItem = self.shortcutsList.topLevelItem(topIndex) |
300 topItem = self.shortcutsList.topLevelItem(topIndex) |
309 for index in range(topItem.childCount()): |
301 for index in range(topItem.childCount()): |
310 itm = topItem.child(index) |
302 itm = topItem.child(index) |
311 |
303 |
312 # 1. shall a check be performed? |
304 # 1. shall a check be performed? |
313 if itm.data(0, self.noCheckRole): |
305 if itm.data(0, self.noCheckRole): |
314 continue |
306 continue |
315 |
307 |
316 # 2. check object type |
308 # 2. check object type |
317 itmObjectType = itm.data(0, self.objectTypeRole) |
309 itmObjectType = itm.data(0, self.objectTypeRole) |
318 if ( |
310 if ( |
319 itmObjectType and |
311 itmObjectType |
320 itmObjectType == objectType and |
312 and itmObjectType == objectType |
321 topItem != origTopItem |
313 and topItem != origTopItem |
322 ): |
314 ): |
323 continue |
315 continue |
324 |
316 |
325 # 3. check key name |
317 # 3. check key name |
326 if itm.text(0) != keyname: |
318 if itm.text(0) != keyname: |
327 for col in [1, 2]: |
319 for col in [1, 2]: |
328 # check against primary, then alternative binding |
320 # check against primary, then alternative binding |
329 itmseq = itm.text(col) |
321 itmseq = itm.text(col) |
333 self, |
325 self, |
334 self.tr("Edit shortcuts"), |
326 self.tr("Edit shortcuts"), |
335 self.tr( |
327 self.tr( |
336 """<p><b>{0}</b> has already been""" |
328 """<p><b>{0}</b> has already been""" |
337 """ allocated to the <b>{1}</b> action. """ |
329 """ allocated to the <b>{1}</b> action. """ |
338 """Remove this binding?</p>""") |
330 """Remove this binding?</p>""" |
339 .format(keystr, itm.text(0)), |
331 ).format(keystr, itm.text(0)), |
340 icon=EricMessageBox.Warning) |
332 icon=EricMessageBox.Warning, |
|
333 ) |
341 if res: |
334 if res: |
342 itm.setText(col, "") |
335 itm.setText(col, "") |
343 return True |
336 return True |
344 else: |
337 else: |
345 return False |
338 return False |
346 |
339 |
347 if not itmseq: |
340 if not itmseq: |
348 continue |
341 continue |
349 |
342 |
350 # step 2: check if shortcut hides an already allocated |
343 # step 2: check if shortcut hides an already allocated |
351 if itmseq.startswith("{0}+".format(keystr)): |
344 if itmseq.startswith("{0}+".format(keystr)): |
352 res = EricMessageBox.yesNo( |
345 res = EricMessageBox.yesNo( |
353 self, |
346 self, |
354 self.tr("Edit shortcuts"), |
347 self.tr("Edit shortcuts"), |
355 self.tr( |
348 self.tr( |
356 """<p><b>{0}</b> hides the <b>{1}</b>""" |
349 """<p><b>{0}</b> hides the <b>{1}</b>""" |
357 """ action. Remove this binding?</p>""") |
350 """ action. Remove this binding?</p>""" |
358 .format(keystr, itm.text(0)), |
351 ).format(keystr, itm.text(0)), |
359 icon=EricMessageBox.Warning) |
352 icon=EricMessageBox.Warning, |
|
353 ) |
360 if res: |
354 if res: |
361 itm.setText(col, "") |
355 itm.setText(col, "") |
362 return True |
356 return True |
363 else: |
357 else: |
364 return False |
358 return False |
365 |
359 |
366 # step 3: check if shortcut is hidden by an |
360 # step 3: check if shortcut is hidden by an |
367 # already allocated |
361 # already allocated |
368 if keystr.startswith("{0}+".format(itmseq)): |
362 if keystr.startswith("{0}+".format(itmseq)): |
369 res = EricMessageBox.yesNo( |
363 res = EricMessageBox.yesNo( |
370 self, |
364 self, |
371 self.tr("Edit shortcuts"), |
365 self.tr("Edit shortcuts"), |
372 self.tr( |
366 self.tr( |
373 """<p><b>{0}</b> is hidden by the """ |
367 """<p><b>{0}</b> is hidden by the """ |
374 """<b>{1}</b> action. """ |
368 """<b>{1}</b> action. """ |
375 """Remove this binding?</p>""") |
369 """Remove this binding?</p>""" |
376 .format(keystr, itm.text(0)), |
370 ).format(keystr, itm.text(0)), |
377 icon=EricMessageBox.Warning) |
371 icon=EricMessageBox.Warning, |
|
372 ) |
378 if res: |
373 if res: |
379 itm.setText(col, "") |
374 itm.setText(col, "") |
380 return True |
375 return True |
381 else: |
376 else: |
382 return False |
377 return False |
383 |
378 |
384 return True |
379 return True |
385 |
380 |
386 def __saveCategoryActions(self, category, actions): |
381 def __saveCategoryActions(self, category, actions): |
387 """ |
382 """ |
388 Private method to save the actions for a category. |
383 Private method to save the actions for a category. |
389 |
384 |
390 @param category reference to the category item (QTreeWidgetItem) |
385 @param category reference to the category item (QTreeWidgetItem) |
391 @param actions list of actions for the category (list of EricAction) |
386 @param actions list of actions for the category (list of EricAction) |
392 """ |
387 """ |
393 for index in range(category.childCount()): |
388 for index in range(category.childCount()): |
394 itm = category.child(index) |
389 itm = category.child(index) |
395 txt = itm.data(0, self.objectNameRole) |
390 txt = itm.data(0, self.objectNameRole) |
396 for act in actions: |
391 for act in actions: |
397 if txt == act.objectName(): |
392 if txt == act.objectName(): |
398 act.setShortcut(QKeySequence(itm.text(1))) |
393 act.setShortcut(QKeySequence(itm.text(1))) |
399 act.setAlternateShortcut( |
394 act.setAlternateShortcut( |
400 QKeySequence(itm.text(2)), removeEmpty=True) |
395 QKeySequence(itm.text(2)), removeEmpty=True |
|
396 ) |
401 break |
397 break |
402 |
398 |
403 def on_buttonBox_accepted(self): |
399 def on_buttonBox_accepted(self): |
404 """ |
400 """ |
405 Private slot to handle the OK button press. |
401 Private slot to handle the OK button press. |
406 """ |
402 """ |
407 if self.__helpViewer is None: |
403 if self.__helpViewer is None: |
408 self.__saveCategoryActions( |
404 self.__saveCategoryActions( |
409 self.projectItem, |
405 self.projectItem, ericApp().getObject("Project").getActions() |
410 ericApp().getObject("Project").getActions()) |
406 ) |
411 self.__saveCategoryActions( |
407 self.__saveCategoryActions( |
412 self.uiItem, |
408 self.uiItem, ericApp().getObject("UserInterface").getActions("ui") |
413 ericApp().getObject("UserInterface").getActions('ui')) |
409 ) |
414 self.__saveCategoryActions( |
410 self.__saveCategoryActions( |
415 self.wizardsItem, |
411 self.wizardsItem, |
416 ericApp().getObject("UserInterface").getActions('wizards')) |
412 ericApp().getObject("UserInterface").getActions("wizards"), |
417 self.__saveCategoryActions( |
413 ) |
418 self.debugItem, |
414 self.__saveCategoryActions( |
419 ericApp().getObject("DebugUI").getActions()) |
415 self.debugItem, ericApp().getObject("DebugUI").getActions() |
420 self.__saveCategoryActions( |
416 ) |
421 self.editItem, |
417 self.__saveCategoryActions( |
422 ericApp().getObject("ViewManager").getActions('edit')) |
418 self.editItem, ericApp().getObject("ViewManager").getActions("edit") |
423 self.__saveCategoryActions( |
419 ) |
424 self.fileItem, |
420 self.__saveCategoryActions( |
425 ericApp().getObject("ViewManager").getActions('file')) |
421 self.fileItem, ericApp().getObject("ViewManager").getActions("file") |
426 self.__saveCategoryActions( |
422 ) |
427 self.searchItem, |
423 self.__saveCategoryActions( |
428 ericApp().getObject("ViewManager").getActions('search')) |
424 self.searchItem, ericApp().getObject("ViewManager").getActions("search") |
429 self.__saveCategoryActions( |
425 ) |
430 self.viewItem, |
426 self.__saveCategoryActions( |
431 ericApp().getObject("ViewManager").getActions('view')) |
427 self.viewItem, ericApp().getObject("ViewManager").getActions("view") |
432 self.__saveCategoryActions( |
428 ) |
433 self.macroItem, |
429 self.__saveCategoryActions( |
434 ericApp().getObject("ViewManager").getActions('macro')) |
430 self.macroItem, ericApp().getObject("ViewManager").getActions("macro") |
|
431 ) |
435 self.__saveCategoryActions( |
432 self.__saveCategoryActions( |
436 self.bookmarkItem, |
433 self.bookmarkItem, |
437 ericApp().getObject("ViewManager").getActions('bookmark')) |
434 ericApp().getObject("ViewManager").getActions("bookmark"), |
|
435 ) |
438 self.__saveCategoryActions( |
436 self.__saveCategoryActions( |
439 self.spellingItem, |
437 self.spellingItem, |
440 ericApp().getObject("ViewManager").getActions('spelling')) |
438 ericApp().getObject("ViewManager").getActions("spelling"), |
441 |
439 ) |
442 actions = ericApp().getObject("ViewManager").getActions('window') |
440 |
|
441 actions = ericApp().getObject("ViewManager").getActions("window") |
443 if actions: |
442 if actions: |
444 self.__saveCategoryActions(self.windowItem, actions) |
443 self.__saveCategoryActions(self.windowItem, actions) |
445 |
444 |
446 for categoryItem in self.pluginCategoryItems: |
445 for categoryItem in self.pluginCategoryItems: |
447 category = categoryItem.text(0) |
446 category = categoryItem.text(0) |
448 ref = ericApp().getPluginObject(category) |
447 ref = ericApp().getPluginObject(category) |
449 if ref is not None and hasattr(ref, "getActions"): |
448 if ref is not None and hasattr(ref, "getActions"): |
450 self.__saveCategoryActions(categoryItem, ref.getActions()) |
449 self.__saveCategoryActions(categoryItem, ref.getActions()) |
451 |
450 |
452 Shortcuts.saveShortcuts() |
451 Shortcuts.saveShortcuts() |
453 |
452 |
454 else: |
453 else: |
455 self.__saveCategoryActions( |
454 self.__saveCategoryActions( |
456 self.helpViewerItem, self.__helpViewer.getActions()) |
455 self.helpViewerItem, self.__helpViewer.getActions() |
|
456 ) |
457 Shortcuts.saveShortcuts(helpViewer=self.__helpViewer) |
457 Shortcuts.saveShortcuts(helpViewer=self.__helpViewer) |
458 |
458 |
459 Preferences.syncPreferences() |
459 Preferences.syncPreferences() |
460 |
460 |
461 self.updateShortcuts.emit() |
461 self.updateShortcuts.emit() |
462 self.hide() |
462 self.hide() |
463 |
463 |
464 @pyqtSlot(str) |
464 @pyqtSlot(str) |
465 def on_searchEdit_textChanged(self, txt): |
465 def on_searchEdit_textChanged(self, txt): |
466 """ |
466 """ |
467 Private slot called, when the text in the search edit changes. |
467 Private slot called, when the text in the search edit changes. |
468 |
468 |
469 @param txt text of the search edit (string) |
469 @param txt text of the search edit (string) |
470 """ |
470 """ |
471 rx = re.compile(re.escape(txt), re.IGNORECASE) |
471 rx = re.compile(re.escape(txt), re.IGNORECASE) |
472 for topIndex in range(self.shortcutsList.topLevelItemCount()): |
472 for topIndex in range(self.shortcutsList.topLevelItemCount()): |
473 topItem = self.shortcutsList.topLevelItem(topIndex) |
473 topItem = self.shortcutsList.topLevelItem(topIndex) |
474 childHiddenCount = 0 |
474 childHiddenCount = 0 |
475 for index in range(topItem.childCount()): |
475 for index in range(topItem.childCount()): |
476 itm = topItem.child(index) |
476 itm = topItem.child(index) |
477 if ( |
477 if txt and ( |
478 txt and ( |
478 (self.actionButton.isChecked() and rx.search(itm.text(0)) is None) |
479 (self.actionButton.isChecked() and |
479 or ( |
480 rx.search(itm.text(0)) is None) or |
480 self.shortcutButton.isChecked() |
481 (self.shortcutButton.isChecked() and |
481 and txt.lower() not in itm.text(1).lower() |
482 txt.lower() not in itm.text(1).lower() and |
482 and txt.lower() not in itm.text(2).lower() |
483 txt.lower() not in itm.text(2).lower()) |
|
484 ) |
483 ) |
485 ): |
484 ): |
486 itm.setHidden(True) |
485 itm.setHidden(True) |
487 childHiddenCount += 1 |
486 childHiddenCount += 1 |
488 else: |
487 else: |
489 itm.setHidden(False) |
488 itm.setHidden(False) |
490 topItem.setHidden(childHiddenCount == topItem.childCount()) |
489 topItem.setHidden(childHiddenCount == topItem.childCount()) |
491 |
490 |
492 @pyqtSlot(bool) |
491 @pyqtSlot(bool) |
493 def on_actionButton_toggled(self, checked): |
492 def on_actionButton_toggled(self, checked): |
494 """ |
493 """ |
495 Private slot called, when the action radio button is toggled. |
494 Private slot called, when the action radio button is toggled. |
496 |
495 |
497 @param checked state of the action radio button (boolean) |
496 @param checked state of the action radio button (boolean) |
498 """ |
497 """ |
499 if checked: |
498 if checked: |
500 self.on_searchEdit_textChanged(self.searchEdit.text()) |
499 self.on_searchEdit_textChanged(self.searchEdit.text()) |
501 |
500 |
502 @pyqtSlot(bool) |
501 @pyqtSlot(bool) |
503 def on_shortcutButton_toggled(self, checked): |
502 def on_shortcutButton_toggled(self, checked): |
504 """ |
503 """ |
505 Private slot called, when the shortcuts radio button is toggled. |
504 Private slot called, when the shortcuts radio button is toggled. |
506 |
505 |
507 @param checked state of the shortcuts radio button (boolean) |
506 @param checked state of the shortcuts radio button (boolean) |
508 """ |
507 """ |
509 if checked: |
508 if checked: |
510 self.on_searchEdit_textChanged(self.searchEdit.text()) |
509 self.on_searchEdit_textChanged(self.searchEdit.text()) |