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...
|
||||
app = get_app(request.vars.app)
|
||||
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'),
|
||||
section='editor', default_values=editor_defaults)
|
||||
preferences = config.read()
|
||||
@@ -580,7 +580,7 @@ def edit():
|
||||
response.headers["web2py-component-flash"] = T('Preferences saved correctly')
|
||||
else:
|
||||
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
|
||||
else:
|
||||
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
|
||||
{{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
|
||||
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);
|
||||
});
|
||||
|
||||
function update_editor(editor_theme, editor_name, editor_closetag, editor_codefolding) {
|
||||
var href = "{{="%s/theme/" % cm}}" + editor_theme + ".css";
|
||||
function update_editor(config) {
|
||||
var href = "{{="%s/theme/" % cm}}" + config.theme + ".css";
|
||||
var link = jQuery("<link>");
|
||||
link.attr({
|
||||
type: 'text/css',
|
||||
@@ -119,8 +121,8 @@ function update_editor(editor_theme, editor_name, editor_closetag, editor_codefo
|
||||
href: href
|
||||
});
|
||||
jQuery("head").append( link );
|
||||
if (editor_name !='default'){
|
||||
var src = "{{='%s/keymap/' % cm}}" + editor_name + ".js";
|
||||
if ( config.editor != 'default'){
|
||||
var src = "{{='%s/keymap/' % cm}}" + config.editor + ".js";
|
||||
//var src = "/admin/static/codemirror/keymap/" + editor_name + ".js";
|
||||
var script = jQuery("<script>");
|
||||
script.attr({
|
||||
@@ -128,16 +130,22 @@ function update_editor(editor_theme, editor_name, editor_closetag, editor_codefo
|
||||
});
|
||||
jQuery("head").append( script );
|
||||
}
|
||||
current_theme = editor_theme;
|
||||
current_editor = editor_name;
|
||||
current_codefolding = editor_codefolding;
|
||||
current_closetag = editor_closetag;
|
||||
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);
|
||||
|
||||
jQuery('textarea[name="data"]') .each(function(id, ta) {
|
||||
editor = jQuery(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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -48,11 +48,12 @@
|
||||
mode: { name: '{{=filetype}}'{{if filetype=='python':}},version: 2,singleLineStringErrors: false, {{pass}} },
|
||||
{{pass}}
|
||||
lineNumbers: true,
|
||||
indentUnit: 4,
|
||||
indentUnit: current_tabwidth,
|
||||
indentWithTabs: current_indentwithtabs,
|
||||
tabSize: current_tabwidth,
|
||||
styleActiveLine: true,
|
||||
autoCloseTags: current_closetag,
|
||||
theme: current_theme,
|
||||
tabMode: "shift",
|
||||
lineWrapping: true,
|
||||
foldGutter: current_codefolding,
|
||||
gutters: ["CodeMirror-linenumbers", "breakpoints", "CodeMirror-foldgutter"],
|
||||
|
||||
@@ -26,6 +26,14 @@
|
||||
<label class="control-label" for="codefolding">{{=T('Enable Code Folding')}}</label>
|
||||
<div class="controls">{{=SELECT(booleanOptions, value=editor_settings['codefolding'], _name="codefolding" )}}</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="controls"><button type="submit" class="disabled btn btn-primary">{{=T('Save')}}</button></div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user