Merge pull request #267 from ilvalle/fix-editor
Tab width (new option in editor settings)
This commit is contained in:
@@ -563,7 +563,7 @@ def edit():
|
|||||||
# Load json only if it is ajax edited...
|
# Load json only if it is ajax edited...
|
||||||
app = get_app(request.vars.app)
|
app = get_app(request.vars.app)
|
||||||
app_path = apath(app, r=request)
|
app_path = apath(app, r=request)
|
||||||
editor_defaults={'theme':'web2py', 'editor': 'default', 'closetag': 'true', 'codefolding': 'false'}
|
editor_defaults={'theme':'web2py', 'editor': 'default', 'closetag': 'true', 'codefolding': 'false', 'tabwidth':'4', 'indentwithtabs':'false'}
|
||||||
config = Config(os.path.join(request.folder, 'settings.cfg'),
|
config = Config(os.path.join(request.folder, 'settings.cfg'),
|
||||||
section='editor', default_values=editor_defaults)
|
section='editor', default_values=editor_defaults)
|
||||||
preferences = config.read()
|
preferences = config.read()
|
||||||
@@ -580,7 +580,7 @@ def edit():
|
|||||||
response.headers["web2py-component-flash"] = T('Preferences saved correctly')
|
response.headers["web2py-component-flash"] = T('Preferences saved correctly')
|
||||||
else:
|
else:
|
||||||
response.headers["web2py-component-flash"] = T('Preferences saved on session only')
|
response.headers["web2py-component-flash"] = T('Preferences saved on session only')
|
||||||
response.headers["web2py-component-command"] = "update_editor('%(theme)s', '%(editor)s', %(closetag)s, %(codefolding)s);jQuery('a[href=#editor_settings] button.close').click();" % (config.read())
|
response.headers["web2py-component-command"] = "update_editor(%s);jQuery('a[href=#editor_settings] button.close').click();" % response.json(config.read())
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
details = {'filename':'settings', 'id':'editor_settings', 'force': False}
|
details = {'filename':'settings', 'id':'editor_settings', 'force': False}
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ var current_editor = "{{=editor_settings['editor']}}"; //Default editor
|
|||||||
var current_closetag = false; //Default closetag
|
var current_closetag = false; //Default closetag
|
||||||
{{pass}}
|
{{pass}}
|
||||||
var current_codefolding = {{=editor_settings['codefolding']}}; //Default codefolding
|
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
|
||||||
jQuery(document).on('shown click', 'a[data-toggle="tab"]', function (e) {
|
jQuery(document).on('shown click', 'a[data-toggle="tab"]', function (e) {
|
||||||
@@ -110,8 +112,8 @@ jQuery(document).on('click', 'a.editor_filelink, a#editor_settingslink', functio
|
|||||||
load_file(url);
|
load_file(url);
|
||||||
});
|
});
|
||||||
|
|
||||||
function update_editor(editor_theme, editor_name, editor_closetag, editor_codefolding) {
|
function update_editor(config) {
|
||||||
var href = "{{="%s/theme/" % cm}}" + editor_theme + ".css";
|
var href = "{{="%s/theme/" % cm}}" + config.theme + ".css";
|
||||||
var link = jQuery("<link>");
|
var link = jQuery("<link>");
|
||||||
link.attr({
|
link.attr({
|
||||||
type: 'text/css',
|
type: 'text/css',
|
||||||
@@ -119,8 +121,8 @@ function update_editor(editor_theme, editor_name, editor_closetag, editor_codefo
|
|||||||
href: href
|
href: href
|
||||||
});
|
});
|
||||||
jQuery("head").append( link );
|
jQuery("head").append( link );
|
||||||
if (editor_name !='default'){
|
if ( config.editor != 'default'){
|
||||||
var src = "{{='%s/keymap/' % cm}}" + editor_name + ".js";
|
var src = "{{='%s/keymap/' % cm}}" + config.editor + ".js";
|
||||||
//var src = "/admin/static/codemirror/keymap/" + editor_name + ".js";
|
//var src = "/admin/static/codemirror/keymap/" + editor_name + ".js";
|
||||||
var script = jQuery("<script>");
|
var script = jQuery("<script>");
|
||||||
script.attr({
|
script.attr({
|
||||||
@@ -128,16 +130,22 @@ function update_editor(editor_theme, editor_name, editor_closetag, editor_codefo
|
|||||||
});
|
});
|
||||||
jQuery("head").append( script );
|
jQuery("head").append( script );
|
||||||
}
|
}
|
||||||
current_theme = editor_theme;
|
current_theme = config.theme;
|
||||||
current_editor = editor_name;
|
current_editor = config.editor;
|
||||||
current_codefolding = editor_codefolding;
|
current_codefolding = (config.codefolding === 'true');
|
||||||
current_closetag = editor_closetag;
|
current_closetag = (config.closetag === 'true');
|
||||||
|
current_indentwithtabs = (config.indentwithtabs === 'true');
|
||||||
|
current_tabwidth = parseInt(config.tabwidth);
|
||||||
|
|
||||||
jQuery('textarea[name="data"]') .each(function(id, ta) {
|
jQuery('textarea[name="data"]') .each(function(id, ta) {
|
||||||
editor = jQuery(ta).data('editor');
|
editor = jQuery(ta).data('editor');
|
||||||
editor.setOption("theme", current_theme);
|
editor.setOption("theme", current_theme);
|
||||||
editor.setOption("keyMap", current_editor);
|
editor.setOption("keyMap", current_editor);
|
||||||
editor.setOption("autoCloseTags", current_closetag);
|
editor.setOption("autoCloseTags", current_closetag);
|
||||||
editor.setOption("foldGutter", current_codefolding);
|
editor.setOption("foldGutter", current_codefolding);
|
||||||
|
editor.setOption("indentUnit", current_tabwidth);
|
||||||
|
editor.setOption("tabSize", current_tabwidth);
|
||||||
|
editor.setOption("indentWithTabs", current_indentwithtabs);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,11 +48,12 @@
|
|||||||
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: 4,
|
indentUnit: current_tabwidth,
|
||||||
|
indentWithTabs: current_indentwithtabs,
|
||||||
|
tabSize: current_tabwidth,
|
||||||
styleActiveLine: true,
|
styleActiveLine: true,
|
||||||
autoCloseTags: current_closetag,
|
autoCloseTags: current_closetag,
|
||||||
theme: current_theme,
|
theme: current_theme,
|
||||||
tabMode: "shift",
|
|
||||||
lineWrapping: true,
|
lineWrapping: true,
|
||||||
foldGutter: current_codefolding,
|
foldGutter: current_codefolding,
|
||||||
gutters: ["CodeMirror-linenumbers", "breakpoints", "CodeMirror-foldgutter"],
|
gutters: ["CodeMirror-linenumbers", "breakpoints", "CodeMirror-foldgutter"],
|
||||||
|
|||||||
@@ -26,6 +26,14 @@
|
|||||||
<label class="control-label" for="codefolding">{{=T('Enable Code Folding')}}</label>
|
<label class="control-label" for="codefolding">{{=T('Enable Code Folding')}}</label>
|
||||||
<div class="controls">{{=SELECT(booleanOptions, value=editor_settings['codefolding'], _name="codefolding" )}}</div>
|
<div class="controls">{{=SELECT(booleanOptions, value=editor_settings['codefolding'], _name="codefolding" )}}</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label" for="codefolding">{{=T('Tab width (# characters)')}}</label>
|
||||||
|
<div class="controls">{{=SELECT(range(1,9, 1), value=editor_settings['tabwidth'], _name="tabwidth" )}}</div>
|
||||||
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label" for="codefolding">{{=T('Indent with tabs')}}</label>
|
||||||
|
<div class="controls">{{=SELECT(booleanOptions, value=editor_settings['indentwithtabs'], _name="indentwithtabs" )}}</div>
|
||||||
|
</div>
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<div class="controls"><button type="submit" class="disabled btn btn-primary">{{=T('Save')}}</button></div>
|
<div class="controls"><button type="submit" class="disabled btn btn-primary">{{=T('Save')}}</button></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user