simplified editor's options management
This commit is contained in:
@@ -749,6 +749,7 @@ def edit():
|
|||||||
return response.json({'file_hash': file_hash, 'saved_on': saved_on, 'functions': functions, 'controller': controller, 'application': request.args[0], 'highlight': highlight})
|
return response.json({'file_hash': file_hash, 'saved_on': saved_on, 'functions': functions, 'controller': controller, 'application': request.args[0], 'highlight': highlight})
|
||||||
else:
|
else:
|
||||||
file_details = dict(app=request.args[0],
|
file_details = dict(app=request.args[0],
|
||||||
|
editor_settings=preferences,
|
||||||
filename=filename,
|
filename=filename,
|
||||||
filetype=filetype,
|
filetype=filetype,
|
||||||
data=data,
|
data=data,
|
||||||
|
|||||||
@@ -51,17 +51,6 @@
|
|||||||
<link rel="stylesheet" href="{{=css_url}}/typeahead.js-bootstrap.css">
|
<link rel="stylesheet" href="{{=css_url}}/typeahead.js-bootstrap.css">
|
||||||
<link rel="stylesheet" href="{{=css_url}}/web2py-codemirror.css">
|
<link rel="stylesheet" href="{{=css_url}}/web2py-codemirror.css">
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var current_theme = "{{=editor_settings['theme']}}"; //Default theme
|
|
||||||
var current_editor = "{{=editor_settings['editor']}}"; //Default editor
|
|
||||||
{{if editor_settings['closetag'] == 'true':}}
|
|
||||||
var current_closetag = true; //Default closetag
|
|
||||||
{{else:}}
|
|
||||||
var current_closetag = false; //Default closetag
|
|
||||||
{{pass}}
|
|
||||||
var current_codefolding = {{=editor_settings['codefolding']}}; //Default codefolding
|
|
||||||
var current_indentwithtabs = {{=editor_settings['indentwithtabs']}};
|
|
||||||
var current_tabwidth = {{=editor_settings['tabwidth']}};
|
|
||||||
|
|
||||||
var current_font_incr = 0; // Default font-size, 0 means don't set
|
var current_font_incr = 0; // Default font-size, 0 means don't set
|
||||||
$(document).on('shown click', 'a[data-toggle="tab"]', function (e) {
|
$(document).on('shown click', 'a[data-toggle="tab"]', function (e) {
|
||||||
var tab_id = $(this).attr('href');
|
var tab_id = $(this).attr('href');
|
||||||
@@ -115,8 +104,8 @@ $(document).on('click', 'a.editor_filelink, a#editor_settingslink', function (e)
|
|||||||
});
|
});
|
||||||
|
|
||||||
/* This method updates all editors already instantiated with the selected preferences*/
|
/* This method updates all editors already instantiated with the selected preferences*/
|
||||||
function update_editor(config) {
|
function update_editor(preferences) {
|
||||||
var href = "{{="%s/theme/" % cm}}" + config.theme + ".css";
|
var href = "{{="%s/theme/" % cm}}" + preferences.theme + ".css";
|
||||||
var link = $("<link>");
|
var link = $("<link>");
|
||||||
link.attr({
|
link.attr({
|
||||||
type: 'text/css',
|
type: 'text/css',
|
||||||
@@ -124,8 +113,8 @@ function update_editor(config) {
|
|||||||
href: href
|
href: href
|
||||||
});
|
});
|
||||||
$("head").append( link );
|
$("head").append( link );
|
||||||
if ( config.editor != 'default'){
|
if ( preferences.editor != 'default'){
|
||||||
var src = "{{='%s/keymap/' % cm}}" + config.editor + ".js";
|
var src = "{{='%s/keymap/' % cm}}" + preferences.editor + ".js";
|
||||||
//var src = "/admin/static/codemirror/keymap/" + editor_name + ".js";
|
//var src = "/admin/static/codemirror/keymap/" + editor_name + ".js";
|
||||||
var script = $("<script>");
|
var script = $("<script>");
|
||||||
script.attr({
|
script.attr({
|
||||||
@@ -133,22 +122,16 @@ function update_editor(config) {
|
|||||||
});
|
});
|
||||||
$("head").append( script );
|
$("head").append( script );
|
||||||
}
|
}
|
||||||
current_theme = config.theme;
|
|
||||||
current_editor = config.editor;
|
|
||||||
current_codefolding = (config.codefolding === 'true');
|
|
||||||
current_closetag = (config.closetag === 'true');
|
|
||||||
current_indentwithtabs = (config.indentwithtabs === 'true');
|
|
||||||
current_tabwidth = parseInt(config.tabwidth);
|
|
||||||
|
|
||||||
$('textarea[name="data"]') .each(function(id, ta) {
|
$('textarea[name="data"]') .each(function(id, ta) {
|
||||||
editor = $(ta).data('editor');
|
editor = $(ta).data('editor');
|
||||||
editor.setOption("theme", current_theme);
|
editor.setOption("theme", preferences.theme);
|
||||||
editor.setOption("keyMap", current_editor);
|
editor.setOption("keyMap", preferences.editor);
|
||||||
editor.setOption("autoCloseTags", current_closetag);
|
editor.setOption("autoCloseTags", (preferences.closetag === 'true'));
|
||||||
editor.setOption("foldGutter", current_codefolding);
|
editor.setOption("foldGutter", (preferences.codefolding === 'true'));
|
||||||
editor.setOption("indentUnit", current_tabwidth);
|
editor.setOption("indentUnit", parseInt(preferences.tabwidth));
|
||||||
editor.setOption("tabSize", current_tabwidth);
|
editor.setOption("tabSize", parseInt(preferences.tabwidth));
|
||||||
editor.setOption("indentWithTabs", current_indentwithtabs);
|
editor.setOption("indentWithTabs", (preferences.indentwithtabs === 'true'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,16 +48,16 @@
|
|||||||
mode: { name: '{{=filetype}}'{{if filetype=='python':}},version: 2,singleLineStringErrors: false, {{pass}} },
|
mode: { name: '{{=filetype}}'{{if filetype=='python':}},version: 2,singleLineStringErrors: false, {{pass}} },
|
||||||
{{pass}}
|
{{pass}}
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
indentUnit: current_tabwidth,
|
indentUnit: {{=editor_settings['tabwidth']}},
|
||||||
indentWithTabs: current_indentwithtabs,
|
indentWithTabs: {{=editor_settings['indentwithtabs']}},
|
||||||
tabSize: current_tabwidth,
|
tabSize: {{=editor_settings['tabwidth']}},
|
||||||
styleActiveLine: true,
|
styleActiveLine: true,
|
||||||
autoCloseTags: current_closetag,
|
autoCloseTags: {{=editor_settings['closetag']}},
|
||||||
theme: current_theme,
|
theme: "{{=editor_settings['theme']}}",
|
||||||
lineWrapping: true,
|
lineWrapping: true,
|
||||||
foldGutter: current_codefolding,
|
foldGutter: {{=editor_settings['codefolding']}},
|
||||||
gutters: ["CodeMirror-linenumbers", "breakpoints", "CodeMirror-foldgutter"],
|
gutters: ["CodeMirror-linenumbers", "breakpoints", "CodeMirror-foldgutter"],
|
||||||
keyMap: current_editor,
|
keyMap: "{{=editor_settings['editor']}}",
|
||||||
matchBrackets: true,
|
matchBrackets: true,
|
||||||
autofocus: false,
|
autofocus: false,
|
||||||
height: "350px",
|
height: "350px",
|
||||||
|
|||||||
Reference in New Issue
Block a user