diff --git a/docs/en_US/images/preferences_sql_keyboard_shortcuts.png b/docs/en_US/images/preferences_sql_keyboard_shortcuts.png new file mode 100644 index 000000000..35c62c933 Binary files /dev/null and b/docs/en_US/images/preferences_sql_keyboard_shortcuts.png differ diff --git a/docs/en_US/keyboard_shortcuts.rst b/docs/en_US/keyboard_shortcuts.rst index af840addb..0de6aac24 100644 --- a/docs/en_US/keyboard_shortcuts.rst +++ b/docs/en_US/keyboard_shortcuts.rst @@ -91,7 +91,17 @@ When using the syntax-highlighting SQL editors, the following shortcuts are avai +--------------------------+------------------+-------------------------------------+ | Shift+Tab | Shift+Tab | Un-indent selected text | +--------------------------+------------------+-------------------------------------+ -| + y | + y | Copy SQL on history panel | +| Alt+G | Alt+G | Jump (to line:column) | ++--------------------------+------------------+-------------------------------------+ +| Ctrl+Space | Ctrl+Space | Auto-complete | ++--------------------------+------------------+-------------------------------------+ +| Ctrl+F | Cmd+F | Find | ++--------------------------+------------------+-------------------------------------+ +| Ctrl+G | Cmd+G | Find next | ++--------------------------+------------------+-------------------------------------+ +| Ctrl+Shift+G | Cmd+Shift+G | Find previous | ++--------------------------+------------------+-------------------------------------+ +| Ctrl+Shift+F | Cmd+Shift+F | Replace | +--------------------------+------------------+-------------------------------------+ @@ -110,17 +120,31 @@ When using the Query Tool, the following shortcuts are available: +--------------------------+--------------------+-----------------------------------+ | F8 | F8 | Execute query to CSV file | +--------------------------+--------------------+-----------------------------------+ -| Alt+G | Alt+G | Jump (to line:column) | +| + o | + o | Open file | +--------------------------+--------------------+-----------------------------------+ -| Ctrl+Space | Ctrl+Space | Auto-complete | +| + s | + s | Save file | +--------------------------+--------------------+-----------------------------------+ -| Ctrl+F | Cmd+F | Find | +| + n | + n | Find option drop down | +--------------------------+--------------------+-----------------------------------+ -| Ctrl+G | Cmd+G | Find next | +| + c | + c | Copy row(s) | +--------------------------+--------------------+-----------------------------------+ -| Ctrl+Shift+G | Cmd+Shift+G | Find previous | +| + p | + p | Paste row(s) | +--------------------------+--------------------+-----------------------------------+ -| Ctrl+Shift+F | Cmd+Shift+F | Replace | +| + d | + d | Delete row(s) | ++--------------------------+--------------------+-----------------------------------+ +| + f | + f | Filter dialog | ++--------------------------+--------------------+-----------------------------------+ +| + i | + i | Filter options drop down | ++--------------------------+--------------------+-----------------------------------+ +| + r | + r | Row limit | ++--------------------------+--------------------+-----------------------------------+ +| + q | + q | Cancel query | ++--------------------------+--------------------+-----------------------------------+ +| + l | + l | Clear option drop down | ++--------------------------+--------------------+-----------------------------------+ +| + x | + x | Execute option drop down | ++--------------------------+--------------------+-----------------------------------+ +| + t | + t | Display connection status | +--------------------------+--------------------+-----------------------------------+ | + y | + y | Copy SQL on history panel | +--------------------------+--------------------+-----------------------------------+ diff --git a/docs/en_US/preferences.rst b/docs/en_US/preferences.rst index 9a44a557a..1f2796116 100644 --- a/docs/en_US/preferences.rst +++ b/docs/en_US/preferences.rst @@ -190,6 +190,11 @@ Use the fields on the *Results grid* panel to specify your formatting preference * Use the *Result copy quote character* drop-down listbox to select the quote character for copied data. * Use the *Result copy quoting* drop-down listbox to select which type of fields require quoting; select *All*, *None*, or *Strings*. +Use the fields on the *Keyboard shortcuts* panel to configure shortcuts for the sql editor window navigation: + +.. image:: images/preferences_sql_keyboard_shortcuts.png + :alt: Preferences dialog sql keyboard shortcuts section + **The Storage Node** Expand the *Storage* node to specify your storage preferences. diff --git a/web/pgadmin/static/js/keyboard_shortcuts.js b/web/pgadmin/static/js/keyboard_shortcuts.js index 68b71c374..91e45cdff 100644 --- a/web/pgadmin/static/js/keyboard_shortcuts.js +++ b/web/pgadmin/static/js/keyboard_shortcuts.js @@ -1,11 +1,6 @@ import $ from 'jquery'; -const LEFT_ARROW_KEY = 37, - RIGHT_ARROW_KEY = 39, - F5_KEY = 116, - F7_KEY = 118, - F8_KEY = 119, - PERIOD_KEY = 190, +const PERIOD_KEY = 190, FWD_SLASH_KEY = 191, ESC_KEY = 27; @@ -115,23 +110,31 @@ function getInnerPanel($el, direction) { } /* Query tool: Keyboard Shortcuts handling */ -function keyboardShortcutsQueryTool(sqlEditorController, queryToolActions, event) { +function keyboardShortcutsQueryTool( + sqlEditorController, keyboardShortcutConfig, queryToolActions, event +) { if (sqlEditorController.isQueryRunning()) { return; } let keyCode = event.which || event.keyCode, panel_id; + let executeKeys = keyboardShortcutConfig['execute']; + let explainKeys = keyboardShortcutConfig['explain']; + let explainAnalyzeKeys = keyboardShortcutConfig['explain_analyze']; + let downloadCsvKeys = keyboardShortcutConfig['download_csv']; + let nextPanelKeys = keyboardShortcutConfig['move_next']; + let previousPanelKeys = keyboardShortcutConfig['move_previous']; - if (keyCode === F5_KEY) { - event.preventDefault(); - queryToolActions.executeQuery(sqlEditorController); - } else if (event.shiftKey && keyCode === F7_KEY) { + if (this.validateShortcutKeys(executeKeys, event)) { this._stopEventPropagation(event); - queryToolActions.explainAnalyze(sqlEditorController); - } else if (keyCode === F7_KEY) { + queryToolActions.executeQuery(sqlEditorController); + } else if (this.validateShortcutKeys(explainKeys, event)) { this._stopEventPropagation(event); queryToolActions.explain(sqlEditorController); - } else if (keyCode === F8_KEY) { - event.preventDefault(); + } else if (this.validateShortcutKeys(explainAnalyzeKeys, event)) { + this._stopEventPropagation(event); + queryToolActions.explainAnalyze(sqlEditorController); + } else if (this.validateShortcutKeys(downloadCsvKeys, event)) { + this._stopEventPropagation(event); queryToolActions.download(sqlEditorController); } else if (( (this.isMac() && event.metaKey) || @@ -151,21 +154,16 @@ function keyboardShortcutsQueryTool(sqlEditorController, queryToolActions, event ) && keyCode === PERIOD_KEY) { this._stopEventPropagation(event); queryToolActions.uncommentLineCode(sqlEditorController); - } else if (this.isAltShiftBoth(event) && keyCode === LEFT_ARROW_KEY) { - // Goto previous side panel - this._stopEventPropagation(event); - panel_id = this.getInnerPanel( - sqlEditorController.container, 'left' - ); - } else if (this.isAltShiftBoth(event) && keyCode === RIGHT_ARROW_KEY) { - // Goto next side panel - this._stopEventPropagation(event); - panel_id = this.getInnerPanel( - sqlEditorController.container, 'right' - ); } else if (keyCode == ESC_KEY) { queryToolActions.focusOut(sqlEditorController); + } else if(this.validateShortcutKeys(nextPanelKeys, event)) { + this._stopEventPropagation(event); + panel_id = this.getInnerPanel(sqlEditorController.container, 'right'); + } else if(this.validateShortcutKeys(previousPanelKeys, event)) { + this._stopEventPropagation(event); + panel_id = this.getInnerPanel(sqlEditorController.container, 'left'); } + return panel_id; } diff --git a/web/pgadmin/static/js/sqleditor/query_tool_actions.js b/web/pgadmin/static/js/sqleditor/query_tool_actions.js index 01d19215f..9e8e45055 100644 --- a/web/pgadmin/static/js/sqleditor/query_tool_actions.js +++ b/web/pgadmin/static/js/sqleditor/query_tool_actions.js @@ -114,10 +114,56 @@ let queryToolActions = { ); }, - focusOut: function() { + focusOut: function () { document.activeElement.blur(); window.top.document.activeElement.blur(); }, + + getKeyboardShortcuts: function (sqlEditorController) { + let executeQueryPref = window.top.pgAdmin.Browser.get_preference( + 'sqleditor', 'execute_query'); + let explainQueryPref = window.top.pgAdmin.Browser.get_preference( + 'sqleditor', 'explain_query'); + let explainAnalyzeQueryPref = window.top.pgAdmin.Browser.get_preference( + 'sqleditor', 'explain_analyze_query'); + let downloadCsvPref = window.top.pgAdmin.Browser.get_preference( + 'sqleditor', 'download_csv'); + let nextPanelPerf = window.top.pgAdmin.Browser.get_preference( + 'sqleditor', 'move_next'); + let previousPanelPerf = window.top.pgAdmin.Browser.get_preference( + 'sqleditor', 'move_previous'); + + if(!executeQueryPref && sqlEditorController.handler.is_new_browser_tab) { + executeQueryPref = window.opener.pgAdmin.Browser.get_preference( + 'sqleditor', 'execute_query' + ), + explainQueryPref = window.opener.pgAdmin.Browser.get_preference( + 'sqleditor', 'explain_query' + ), + explainAnalyzeQueryPref = window.opener.pgAdmin.Browser.get_preference( + 'sqleditor', 'explain_analyze_query' + ), + downloadCsvPref = window.opener.pgAdmin.Browser.get_preference( + 'sqleditor', 'download_csv' + ), + nextPanelPerf = window.opener.pgAdmin.Browser.get_preference( + 'sqleditor', 'move_next' + ), + previousPanelPerf = window.opener.pgAdmin.Browser.get_preference( + 'sqleditor', 'move_previous' + ); + } + + return { + 'execute': executeQueryPref.value, + 'explain': explainQueryPref.value, + 'explain_analyze': explainAnalyzeQueryPref.value, + 'download_csv': downloadCsvPref.value, + 'move_next': nextPanelPerf.value, + 'move_previous': previousPanelPerf.value, + }; + + }, }; module.exports = queryToolActions; diff --git a/web/pgadmin/tools/datagrid/__init__.py b/web/pgadmin/tools/datagrid/__init__.py index a3d113251..9b188042a 100644 --- a/web/pgadmin/tools/datagrid/__init__.py +++ b/web/pgadmin/tools/datagrid/__init__.py @@ -28,6 +28,8 @@ from pgadmin.utils.preferences import Preferences from pgadmin.model import Server from pgadmin.utils.driver import get_driver from pgadmin.utils.exception import ConnectionLost +from pgadmin.tools.sqleditor.utils.query_tool_preferences import \ + get_query_tool_keyboard_shortcuts, get_text_representation_of_shortcut class DataGridModule(PgAdminModule): @@ -287,6 +289,7 @@ def panel(trans_id, is_query_tool, editor_title): url_params['obj_id'] = trans_obj.obj_id display_connection_status = pref.preference('connection_status').get() + queryToolShortcuts = get_query_tool_keyboard_shortcuts() return render_template( "datagrid/index.html", @@ -306,7 +309,10 @@ def panel(trans_id, is_query_tool, editor_title): # before passing it to html template. prompt_save_changes='true' if prompt_save_changes else 'false', display_connection_status=display_connection_status, - url_params=json.dumps(url_params) + url_params=json.dumps(url_params), + key=queryToolShortcuts.get('keys'), + shortcuts=queryToolShortcuts.get('shortcuts'), + get_shortcut_text=get_text_representation_of_shortcut ) diff --git a/web/pgadmin/tools/datagrid/templates/datagrid/index.html b/web/pgadmin/tools/datagrid/templates/datagrid/index.html index 73c8ba05e..2f3bb0578 100644 --- a/web/pgadmin/tools/datagrid/templates/datagrid/index.html +++ b/web/pgadmin/tools/datagrid/templates/datagrid/index.html @@ -28,14 +28,19 @@