Add a keyboard shortcut to close active tab panel. #6572

This commit is contained in:
Rohit Bhati 2024-07-17 18:19:36 +05:30 committed by GitHub
parent 01cb1839f8
commit 9ee896aac4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 1 deletions

View File

@ -48,6 +48,8 @@ When using main browser window, the following keyboard shortcuts are available:
+----------------------------+--------------------+------------------------------------+
| Shift + Alt + ] | Shift + Option + ] | Tabbed panel forward |
+----------------------------+--------------------+------------------------------------+
| Shift + Alt + w | Shift + Ctrl + w | Close tab panel |
+----------------------------+--------------------+------------------------------------+
| Shift + Alt + l | Shift + Option + l | Tools main menu |
+----------------------------+--------------------+------------------------------------+
| Shift + Alt + v | Shift + Option + v | View data |

View File

@ -156,6 +156,21 @@ def register_browser_preferences(self):
fields=fields
)
self.preference.register(
'keyboard_shortcuts',
'close_tab_panel',
gettext('Close tab panel'),
'keyboardshortcut',
{
'alt': False,
'shift': True,
'control': True,
'key': {'key_code': 87, 'char': 'w'}
},
category_label=PREF_LABEL_KEYBOARD_SHORTCUTS,
fields=fields
)
self.preference.register(
'keyboard_shortcuts',
'tabbed_panel_forward',

View File

@ -15,6 +15,7 @@ import gettext from 'sources/gettext';
import pgWindow from 'sources/window';
import usePreferences from '../../../preferences/static/js/store';
const pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {};
pgBrowser.keyboardNavigation = pgBrowser.keyboardNavigation || {};
@ -51,6 +52,7 @@ _.extend(pgBrowser.keyboardNavigation, {
'direct_debugging': commonUtils.parseShortcutValue(prefStore.getPreferences('browser', 'direct_debugging')?.value),
'add_grid_row': commonUtils.parseShortcutValue(prefStore.getPreferences('browser', 'add_grid_row')?.value),
'open_quick_search': commonUtils.parseShortcutValue(prefStore.getPreferences('browser', 'open_quick_search')?.value),
'close_tab_panel': commonUtils.parseShortcutValue(prefStore.getPreferences('browser', 'close_tab_panel')?.value),
};
this.shortcutMethods = {
@ -59,7 +61,7 @@ _.extend(pgBrowser.keyboardNavigation, {
this.keyboardShortcut.object_shortcut, this.keyboardShortcut.tools_shortcut,
this.keyboardShortcut.help_shortcut],
}}, // Main menu
'bindRightPanel': {'shortcuts': [this.keyboardShortcut.tabbed_panel_backward, this.keyboardShortcut.tabbed_panel_forward]}, // Main window panels
'bindRightPanel': {'shortcuts': [this.keyboardShortcut.tabbed_panel_backward, this.keyboardShortcut.tabbed_panel_forward, this.keyboardShortcut.close_tab_panel]}, // Main window panels
'bindLeftTree': {'shortcuts': this.keyboardShortcut.left_tree_shortcut}, // Main menu,
'bindSubMenuQueryTool': {'shortcuts': this.keyboardShortcut.sub_menu_query_tool}, // Sub menu - Open Query Tool,
'bindSubMenuViewData': {'shortcuts': this.keyboardShortcut.sub_menu_view_data}, // Sub menu - Open View Data,
@ -189,6 +191,13 @@ _.extend(pgBrowser.keyboardNavigation, {
_focusTab: function(dockLayoutTabs, activeTabIdx, shortcut_obj, combo){
if (combo.key === shortcut_obj.tabbed_panel_backward) activeTabIdx = (activeTabIdx + dockLayoutTabs.length - 1) % dockLayoutTabs.length;
else if (combo.key === shortcut_obj.tabbed_panel_forward) activeTabIdx = (activeTabIdx + 1) % dockLayoutTabs.length;
else if (combo.key === shortcut_obj.close_tab_panel) {
const panelId = dockLayoutTabs[activeTabIdx].id?.slice(14);
if (panelId) {
pgAdmin.Browser.docker.close(panelId);
activeTabIdx = activeTabIdx % dockLayoutTabs.length;
}
}
dockLayoutTabs[activeTabIdx]?.click();
dockLayoutTabs[activeTabIdx]?.focus();
},