Add preferences to enable brace matching and brace closing in the SQL editors. Fixes #2513

This commit is contained in:
Murtuza Zabuawala 2017-06-27 09:57:38 -04:00 committed by Dave Page
parent a87ee6d059
commit 1b49bb8b22
8 changed files with 62 additions and 18 deletions

View File

@ -549,6 +549,12 @@ def browser_js():
editor_wrap_code_pref = prefs.preference('wrap_code')
editor_wrap_code = editor_wrap_code_pref.get()
brace_matching_pref = prefs.preference('brace_matching')
brace_matching = brace_matching_pref.get()
insert_pair_brackets_perf = prefs.preference('insert_pair_brackets')
insert_pair_brackets = insert_pair_brackets_perf.get()
for submodule in current_blueprint.submodules:
snippets.extend(submodule.jssnippets)
return make_response(
@ -561,6 +567,8 @@ def browser_js():
editor_tab_size=editor_tab_size,
editor_use_spaces=editor_use_spaces,
editor_wrap_code=editor_wrap_code,
editor_brace_matching=brace_matching,
editor_insert_pair_brackets=insert_pair_brackets,
_=gettext
),
200, {'Content-Type': 'application/x-javascript'})

View File

@ -7,7 +7,8 @@ define(
'pgadmin.alertifyjs', 'pgadmin.browser.messages',
'pgadmin.browser.menu', 'pgadmin.browser.panel',
'pgadmin.browser.error', 'pgadmin.browser.frame',
'pgadmin.browser.node', 'pgadmin.browser.collection'
'pgadmin.browser.node', 'pgadmin.browser.collection',
'codemirror/addon/edit/matchbrackets', 'codemirror/addon/edit/closebrackets'
], function(
gettext, url_for, require, $, _, S, Bootstrap, pgAdmin, Alertify,
CodeMirror, checkNodeVisibility
@ -388,7 +389,9 @@ define(
readOnly: true,
extraKeys: pgAdmin.Browser.editor_shortcut_keys,
tabSize: pgAdmin.Browser.editor_options.tabSize,
lineWrapping: pgAdmin.Browser.editor_options.wrapCode
lineWrapping: pgAdmin.Browser.editor_options.wrapCode,
autoCloseBrackets: pgAdmin.Browser.editor_options.insert_pair_brackets,
matchBrackets: pgAdmin.Browser.editor_options.brace_matching
});
setTimeout(function() {
@ -1834,7 +1837,9 @@ define(
},
editor_options: {
tabSize: '{{ editor_tab_size }}',
wrapCode: '{{ editor_wrap_code }}' == 'True'
wrapCode: '{{ editor_wrap_code }}' == 'True',
insert_pair_brackets: '{{ editor_insert_pair_brackets }}' == 'True',
brace_matching: '{{ editor_brace_matching }}' == 'True'
}
});

View File

@ -5,7 +5,8 @@
define([
'sources/gettext', 'underscore', 'underscore.string', 'jquery',
'backbone', 'backform', 'backgrid', 'codemirror', 'pgadmin.backgrid',
'codemirror/mode/sql/sql', 'select2'
'codemirror/mode/sql/sql', 'select2', 'codemirror/addon/edit/matchbrackets',
'codemirror/addon/edit/closebrackets'
],
function(gettext, _, S, $, Backbone, Backform, Backgrid, CodeMirror) {
// Export global even in AMD case in case this script is loaded with
@ -1405,7 +1406,9 @@
readOnly: true,
extraKeys: pgAdmin.Browser.editor_shortcut_keys,
tabSize: pgAdmin.Browser.editor_options.tabSize,
lineWrapping: pgAdmin.Browser.editor_options.wrapCode
lineWrapping: pgAdmin.Browser.editor_options.wrapCode,
autoCloseBrackets: pgAdmin.Browser.editor_options.insert_pair_brackets,
matchBrackets: pgAdmin.Browser.editor_options.brace_matching
});
/*
@ -2014,10 +2017,12 @@
self.sqlCtrl = CodeMirror.fromTextArea(
(self.$el.find("textarea")[0]), {
lineNumbers: true,
mode: "text/x-sql",
mode: "text/x-pgsql",
extraKeys: pgAdmin.Browser.editor_shortcut_keys,
tabSize: pgAdmin.Browser.editor_options.tabSize,
lineWrapping: pgAdmin.Browser.editor_options.wrapCode
lineWrapping: pgAdmin.Browser.editor_options.wrapCode,
autoCloseBrackets: pgAdmin.Browser.editor_options.insert_pair_brackets,
matchBrackets: pgAdmin.Browser.editor_options.brace_matching
});
// Disable editor

View File

@ -56,6 +56,7 @@
<link type="text/css" rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.overrides.css') }}"/>
<link type="text/css" rel="stylesheet" href="{{ url_for('static', filename='css/aci_tree.overrides.css') }}"/>
<link type="text/css" rel="stylesheet" href="{{ url_for('static', filename='css/select2.overrides.css') }}"/>
<link type="text/css" rel="stylesheet" href="{{ url_for('static', filename='css/codemirror.overrides.css') }}"/>
<link type="text/css" rel="stylesheet" href="{{ url_for('static', filename='css/pgadmin.css') }}"/>
<link type="text/css" rel="stylesheet" href="{{ url_for('static', filename='css/pgadmin.style.css') }}"/>
{% block css_link %}{% endblock %}

View File

@ -1,6 +1,8 @@
define([
'sources/gettext', 'sources/url_for', 'jquery','alertify', 'pgadmin','codemirror',
'sources/sqleditor_utils', 'pgadmin.browser', 'wcdocker'
'sources/sqleditor_utils', 'pgadmin.browser', 'wcdocker',
'codemirror/addon/edit/matchbrackets', 'codemirror/addon/edit/closebrackets'
], function(gettext, url_for, $, alertify, pgAdmin, codemirror, sqlEditorUtils) {
// Some scripts do export their object in the window only.
// Generally the one, which do no have AMD support.
@ -263,13 +265,13 @@ define([
// Apply CodeMirror to filter text area.
this.filter_obj = CodeMirror.fromTextArea($sql_filter.get(0), {
lineNumbers: true,
lineWrapping: true,
matchBrackets: true,
indentUnit: 4,
mode: "text/x-pgsql",
extraKeys: pgBrowser.editor_shortcut_keys,
tabSize: pgBrowser.editor_options.tabSize,
lineWrapping: pgAdmin.Browser.editor_options.wrapCode
lineWrapping: pgAdmin.Browser.editor_options.wrapCode,
autoCloseBrackets: pgAdmin.Browser.editor_options.insert_pair_brackets,
matchBrackets: pgAdmin.Browser.editor_options.brace_matching
});
},

View File

@ -4,7 +4,9 @@ define([
'pgadmin.tools.debugger.ui', 'wcdocker', 'pgadmin.backform',
'pgadmin.backgrid', 'codemirror/addon/selection/active-line',
'codemirror/addon/fold/foldgutter', 'codemirror/addon/fold/foldcode',
'pgadmin-sqlfoldcode'
'pgadmin-sqlfoldcode', 'codemirror/addon/edit/matchbrackets',
'codemirror/addon/edit/closebrackets',
], function(
gettext, $, _, S, Alertify, pgAdmin, pgBrowser, Backbone, Backgrid,
CodeMirror, Backform, debug_function_again
@ -1605,7 +1607,9 @@ define([
readOnly: true,
extraKeys: pgAdmin.Browser.editor_shortcut_keys,
tabSize: pgAdmin.Browser.editor_options.tabSize,
lineWrapping: pgAdmin.Browser.editor_options.wrapCode
lineWrapping: pgAdmin.Browser.editor_options.wrapCode,
autoCloseBrackets: pgAdmin.Browser.editor_options.insert_pair_brackets,
matchBrackets: pgAdmin.Browser.editor_options.brace_matching
});
// On loading the docker, register the callbacks

View File

@ -190,9 +190,24 @@ class SqlEditorModule(PgAdminModule):
'Options', 'wrap_code',
gettext("Line wrapping?"), 'boolean', False,
category_label=gettext('Options'),
help_str=gettext('Specifies whether or not to wrap SQL code in editor.')
help_str=gettext('Specifies whether or not to wrap SQL code in the editor.')
)
self.insert_pair_brackets = self.preference.register(
'Options', 'insert_pair_brackets',
gettext("Insert bracket pairs?"), 'boolean', True,
category_label=gettext('Options'),
help_str=gettext('Specifies whether or not to insert paired brackets in the editor.')
)
self.brace_matching = self.preference.register(
'Options', 'brace_matching',
gettext("Brace matching?"), 'boolean', True,
category_label=gettext('Options'),
help_str=gettext('Specifies whether or not to highlight matched braces in the editor.')
)
blueprint = SqlEditorModule(MODULE_NAME, __name__, static_url_path='/static')

View File

@ -25,6 +25,8 @@ define([
'codemirror/addon/search/search',
'codemirror/addon/search/searchcursor',
'codemirror/addon/search/jump-to-line',
'codemirror/addon/edit/matchbrackets',
'codemirror/addon/edit/closebrackets',
'backgrid.sizeable.columns',
'slick.pgadmin.formatters',
@ -111,7 +113,6 @@ define([
$('.editor-title').text(_.unescape(self.editor_title));
self.filter_obj = CodeMirror.fromTextArea(filter.get(0), {
lineNumbers: true,
matchBrackets: true,
indentUnit: 4,
mode: "text/x-pgsql",
foldOptions: {
@ -124,7 +125,9 @@ define([
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
extraKeys: pgBrowser.editor_shortcut_keys,
tabSize: pgAdmin.Browser.editor_options.tabSize,
lineWrapping: pgAdmin.Browser.editor_options.wrapCode
lineWrapping: pgAdmin.Browser.editor_options.wrapCode,
autoCloseBrackets: pgAdmin.Browser.editor_options.insert_pair_brackets,
matchBrackets: pgAdmin.Browser.editor_options.brace_matching
});
// Create main wcDocker instance
@ -154,7 +157,6 @@ define([
self.query_tool_obj = CodeMirror.fromTextArea(text_container.get(0), {
lineNumbers: true,
matchBrackets: true,
indentUnit: 4,
styleSelectedText: true,
mode: "text/x-pgsql",
@ -169,7 +171,9 @@ define([
extraKeys: pgBrowser.editor_shortcut_keys,
tabSize: pgAdmin.Browser.editor_options.tabSize,
lineWrapping: pgAdmin.Browser.editor_options.wrapCode,
scrollbarStyle: 'simple'
scrollbarStyle: 'simple',
autoCloseBrackets: pgAdmin.Browser.editor_options.insert_pair_brackets,
matchBrackets: pgAdmin.Browser.editor_options.brace_matching
});
// Refresh Code mirror on SQL panel resize to