From 3a012945aeb9d8638cf56e04d8f583d4cc2f5bb2 Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Fri, 6 Mar 2015 15:51:30 +0200 Subject: [PATCH] User can choose to use Enter instead of Ctrl+Enter to execute queries. Implements RFE #1570, part 2. Signed-off-by: Dan Ungureanu --- js/console.js | 40 +++++++++++++++++++++++++++++++++---- libraries/Console.class.php | 7 ++++++- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/js/console.js b/js/console.js index 687c78e98c..3d95e7a234 100644 --- a/js/console.js +++ b/js/console.js @@ -107,6 +107,9 @@ var PMA_console = { if(tempConfig.currentQuery === true) { $('#pma_console_options input[name=current_query]').prop('checked', true); } + if(tempConfig.enterExecutes === true) { + $('#pma_console_options input[name=enter_executes]').prop('checked', true); + } } else { $('#pma_console_options input[name=current_query]').prop('checked', true); } @@ -164,9 +167,14 @@ var PMA_console = { $('#pma_console_options input[name=always_expand]').prop('checked', false); $('#pma_console_options input[name=start_history]').prop('checked', false); $('#pma_console_options input[name=current_query]').prop('checked', true); + $('#pma_console_options input[name=enter_executes]').prop('checked', false); PMA_console.updateConfig(); }); + $('#pma_console_options input[name=enter_executes]').change(function() { + PMA_consoleMessages.showInstructions(PMA_console.config.enterExecutes); + }); + $(document).ajaxComplete(function (event, xhr) { try { var data = $.parseJSON(xhr.responseText); @@ -386,7 +394,8 @@ var PMA_console = { PMA_console.config = { alwaysExpand: $('#pma_console_options input[name=always_expand]').prop('checked'), startHistory: $('#pma_console_options input[name=start_history]').prop('checked'), - currentQuery: $('#pma_console_options input[name=current_query]').prop('checked') + currentQuery: $('#pma_console_options input[name=current_query]').prop('checked'), + enterExecutes: $('#pma_console_options input[name=enter_executes]').prop('checked') }; $.cookie('pma_console_config', JSON.stringify(PMA_console.config)); }, @@ -594,13 +603,22 @@ var PMA_consoleInput = { }, /** * Mousedown event handler for bind to input - * Shortcut is Ctrl+Enter key + * Shortcut is Ctrl+Enter key or just ENTER, depending on console's + * configuration. * * @return void */ _keydown: function(event) { - if(event.ctrlKey && event.keyCode === 13) { - PMA_consoleInput.execute(); + if (PMA_console.config.enterExecutes) { + // Enter, but not in combination with Shift (which writes a new line). + if (!event.shiftKey && event.keyCode === 13) { + PMA_consoleInput.execute(); + } + } else { + // Ctrl+Enter + if (event.ctrlKey && event.keyCode === 13) { + PMA_consoleInput.execute(); + } } }, /** @@ -733,6 +751,19 @@ var PMA_consoleMessages = { return $query.text(); } }, + /** + * Used to show the correct message depending on which key + * combination executes the query (Ctrl+Enter or Enter). + * + * @param bool enterExecutes Only Enter has to be pressed to execute query. + * @return void + */ + showInstructions: function(enterExecutes) { + enterExecutes = +enterExecutes || 0; // conversion to int + var $welcomeMsg = $('#pma_console .content .console_message_container .message.welcome span'); + $welcomeMsg.children('[id^=instructions]').hide(); + $welcomeMsg.children('#instructions-' + enterExecutes).show(); + }, /** * Used for log new message * @@ -928,6 +959,7 @@ var PMA_consoleMessages = { if(PMA_console.config.startHistory) { PMA_consoleMessages.showHistory(); } + PMA_consoleMessages.showInstructions(PMA_console.config.enterExecutes); } }; diff --git a/libraries/Console.class.php b/libraries/Console.class.php index 0b4fd50fdf..1da0c229c1 100644 --- a/libraries/Console.class.php +++ b/libraries/Console.class.php @@ -215,7 +215,10 @@ class PMA_Console $output .= '
'; $output .= '
' . '
' - . __('Press Ctrl+Enter to execute query') + . '' + . __('Press Ctrl+Enter to execute query') . '' + . '' + . __('Press Enter to execute query') . '' . '
'; // History support @@ -310,6 +313,8 @@ class PMA_Console . __('Show query history at start') . '
' . '
' + . '
' . '
'; $output .= '
'; // Options card