{{
  def listfiles(app, dir, regexp='.*\.py$'):
      files = sorted(
         listdir(apath('%(app)s/%(dir)s/' % {'app':app, 'dir':dir}, r=request), regexp))
      files = [x.replace('\\', '/') for x in files if not x.endswith('.bak')]
      return files
}}
{{themes = [f[:-4] for f in listfiles('admin', "static/codemirror/theme", regexp='.*\.css$' )]}}
{{editors = ['default', 'vim', 'emacs']}}

<form id="editor_settings_form" class="form-horizontal" action="">
	<div class="control-group">
		<label class="control-label" for="selectTheme">{{=T('Theme')}}</label>
		<div class="controls">{{=SELECT(themes, value=editor_settings['theme'], _name="theme" )}}</div>
	</div>
	<div class="control-group">
		<label class="control-label" for="selectEditor">{{=T('Editor')}}</label>
		<div class="controls">{{=SELECT(editors, value=editor_settings['editor'], _name="editor" )}}</div>
	</div>
	<div class="control-group">
		<label class="control-label" for="closeTag">{{=T('Enable Close-Tag')}}</label>
		<div class="controls">{{=stateWidget("closetag", value=editor_settings['closetag'])}}</div>
	</div>
	<div class="control-group">
		<label class="control-label" for="codefolding">{{=T('Enable Code Folding')}}</label>
		<div class="controls">{{=stateWidget("codefolding", value=editor_settings['codefolding'])}}</div>
	</div>
	<div class="control-group">
		<label class="control-label" for="tabwidth">{{=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="indentwithtabs">{{=T('Indent with tabs')}}</label>
		<div class="controls">{{=stateWidget("indentwithtabs", value=editor_settings['indentwithtabs'])}}</div>
	</div>
    <div class="control-group">
        <label class="control-label" for="linenumbers">{{=T('Display line numbers')}}</label>
        <div class="controls">{{=stateWidget("linenumbers", value=editor_settings['linenumbers'])}}</div>
    </div>
    <div class="control-group">
        <label class="control-label" for="highlightline">{{=T('Highlight current line')}}</label>
        <div class="controls">{{=stateWidget("highlightline", value=editor_settings['highlightline'])}}</div>
    </div>
	<div class="control-group">
		<div class="controls"><button type="submit" class="disabled btn btn-primary">{{=T('Save')}}</button></div>
	</div>
</form>
<script>
$.web2py.trap_form("{{=URL('default', 'edit', args=request.args, vars={'settings':True})}}", "editor_settings");
$("#editor_settings_form").on('change', 'select, input', function (e) {
	$("#editor_settings_form button[type=submit]").removeClass('disabled');
});
</script>
