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})
|
||||
else:
|
||||
file_details = dict(app=request.args[0],
|
||||
editor_settings=preferences,
|
||||
filename=filename,
|
||||
filetype=filetype,
|
||||
data=data,
|
||||
|
||||
@@ -51,17 +51,6 @@
|
||||
<link rel="stylesheet" href="{{=css_url}}/typeahead.js-bootstrap.css">
|
||||
<link rel="stylesheet" href="{{=css_url}}/web2py-codemirror.css">
|
||||
<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
|
||||
$(document).on('shown click', 'a[data-toggle="tab"]', function (e) {
|
||||
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*/
|
||||
function update_editor(config) {
|
||||
var href = "{{="%s/theme/" % cm}}" + config.theme + ".css";
|
||||
function update_editor(preferences) {
|
||||
var href = "{{="%s/theme/" % cm}}" + preferences.theme + ".css";
|
||||
var link = $("<link>");
|
||||
link.attr({
|
||||
type: 'text/css',
|
||||
@@ -124,8 +113,8 @@ function update_editor(config) {
|
||||
href: href
|
||||
});
|
||||
$("head").append( link );
|
||||
if ( config.editor != 'default'){
|
||||
var src = "{{='%s/keymap/' % cm}}" + config.editor + ".js";
|
||||
if ( preferences.editor != 'default'){
|
||||
var src = "{{='%s/keymap/' % cm}}" + preferences.editor + ".js";
|
||||
//var src = "/admin/static/codemirror/keymap/" + editor_name + ".js";
|
||||
var script = $("<script>");
|
||||
script.attr({
|
||||
@@ -133,22 +122,16 @@ function update_editor(config) {
|
||||
});
|
||||
$("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) {
|
||||
editor = $(ta).data('editor');
|
||||
editor.setOption("theme", current_theme);
|
||||
editor.setOption("keyMap", current_editor);
|
||||
editor.setOption("autoCloseTags", current_closetag);
|
||||
editor.setOption("foldGutter", current_codefolding);
|
||||
editor.setOption("indentUnit", current_tabwidth);
|
||||
editor.setOption("tabSize", current_tabwidth);
|
||||
editor.setOption("indentWithTabs", current_indentwithtabs);
|
||||
editor.setOption("theme", preferences.theme);
|
||||
editor.setOption("keyMap", preferences.editor);
|
||||
editor.setOption("autoCloseTags", (preferences.closetag === 'true'));
|
||||
editor.setOption("foldGutter", (preferences.codefolding === 'true'));
|
||||
editor.setOption("indentUnit", parseInt(preferences.tabwidth));
|
||||
editor.setOption("tabSize", parseInt(preferences.tabwidth));
|
||||
editor.setOption("indentWithTabs", (preferences.indentwithtabs === 'true'));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -48,16 +48,16 @@
|
||||
mode: { name: '{{=filetype}}'{{if filetype=='python':}},version: 2,singleLineStringErrors: false, {{pass}} },
|
||||
{{pass}}
|
||||
lineNumbers: true,
|
||||
indentUnit: current_tabwidth,
|
||||
indentWithTabs: current_indentwithtabs,
|
||||
tabSize: current_tabwidth,
|
||||
indentUnit: {{=editor_settings['tabwidth']}},
|
||||
indentWithTabs: {{=editor_settings['indentwithtabs']}},
|
||||
tabSize: {{=editor_settings['tabwidth']}},
|
||||
styleActiveLine: true,
|
||||
autoCloseTags: current_closetag,
|
||||
theme: current_theme,
|
||||
autoCloseTags: {{=editor_settings['closetag']}},
|
||||
theme: "{{=editor_settings['theme']}}",
|
||||
lineWrapping: true,
|
||||
foldGutter: current_codefolding,
|
||||
foldGutter: {{=editor_settings['codefolding']}},
|
||||
gutters: ["CodeMirror-linenumbers", "breakpoints", "CodeMirror-foldgutter"],
|
||||
keyMap: current_editor,
|
||||
keyMap: "{{=editor_settings['editor']}}",
|
||||
matchBrackets: true,
|
||||
autofocus: false,
|
||||
height: "350px",
|
||||
|
||||
Reference in New Issue
Block a user