fixed merge
This commit is contained in:
@@ -11,9 +11,11 @@ import re
|
||||
from gluon.admin import *
|
||||
from gluon.fileutils import abspath, read_file, write_file
|
||||
from gluon.utils import web2py_uuid
|
||||
from gluon.tools import Config
|
||||
from glob import glob
|
||||
import shutil
|
||||
import platform
|
||||
|
||||
try:
|
||||
import git
|
||||
if git.__version__ < '0.3.1':
|
||||
@@ -559,6 +561,10 @@ def edit():
|
||||
""" File edit handler """
|
||||
# Load json only if it is ajax edited...
|
||||
app = get_app(request.vars.app)
|
||||
app_path = apath(app, r=request)
|
||||
editor_defaults={'theme':'web2py'}
|
||||
config = Config(os.path.join(app_path, 'settings.cfg'), section='editor', default_values=editor_defaults)
|
||||
preferences = config.read()
|
||||
|
||||
if not(request.ajax):
|
||||
# return the scaffolding, the rest will be through ajax requests
|
||||
@@ -572,7 +578,21 @@ def edit():
|
||||
for key in editarea_preferences:
|
||||
if key in globals():
|
||||
editarea_preferences[key] = globals()[key]
|
||||
return response.render ('default/edit.html', dict(app=request.args[0], editarea_preferences=editarea_preferences))
|
||||
return response.render ('default/edit.html', dict(app=request.args[0], editor_settings=preferences, editarea_preferences=editarea_preferences))
|
||||
|
||||
# show settings tab and save prefernces
|
||||
if 'settings' in request.vars:
|
||||
if request.post_vars: #save new preferences
|
||||
if config.save(request.post_vars.items()):
|
||||
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_theme('%s'); jQuery('a[href=#editor_settings] button.close').click();" % config.read()['theme']
|
||||
return
|
||||
else:
|
||||
details = {'filename':'settings', 'id':'editor_settings', 'force': False}
|
||||
details['plain_html'] = response.render('default/editor_settings.html', {'editor_settings':preferences})
|
||||
return response.json(details)
|
||||
|
||||
""" File edit handler """
|
||||
# Load json only if it is ajax edited...
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
.twitter-typeahead {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.twitter-typeahead .tt-query,
|
||||
.twitter-typeahead .tt-hint {
|
||||
margin-bottom: 0px;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
}}
|
||||
{{cm=URL('static','codemirror')}}
|
||||
<link rel="stylesheet" href="{{=cm}}/lib/codemirror.css">
|
||||
<link rel="stylesheet" href="{{=cm}}/theme/web2py.css">
|
||||
<link rel="stylesheet" href="{{="%s/theme/%s.css" % (cm, editor_settings['theme'])}}">
|
||||
<script src="{{=cm}}/lib/codemirror.js"></script>
|
||||
<script src="{{=cm}}/mode/clike/clike.js"></script>
|
||||
<script src="{{=cm}}/addon/edit/matchbrackets.js"></script>
|
||||
@@ -42,7 +42,7 @@
|
||||
<link rel="stylesheet" href="{{=URL('static/css','typeahead.js-bootstrap.css')}}">
|
||||
<link rel="stylesheet" href="{{=URL('static/css','web2py-codemirror.css')}}">
|
||||
<script type="text/javascript">
|
||||
var current_theme = "web2py"; //Default theme
|
||||
var current_theme = "{{=editor_settings['theme']}}"; //Default theme
|
||||
var current_font_incr = 0; // Default font-size, 0 means don't set
|
||||
jQuery(document).on('shown click', 'a[data-toggle="tab"]', function (e) {
|
||||
var tab_id = jQuery(this).attr('href');
|
||||
@@ -89,32 +89,27 @@ jQuery(document).on('click', '#restore', function (e) {
|
||||
});
|
||||
|
||||
// open the selected file
|
||||
jQuery(document).on('click', 'a.editor_filelink', function (e) {
|
||||
e.preventDefault();
|
||||
var url = jQuery(this).attr("href");
|
||||
load_file(url);
|
||||
jQuery(document).on('click', 'a.editor_filelink, a#editor_settingslink', function (e) {
|
||||
e.preventDefault();
|
||||
var url = jQuery(this).attr("href");
|
||||
load_file(url);
|
||||
});
|
||||
|
||||
// change the codemirror theme
|
||||
jQuery(document).on('click', '#themes a', function (e) {
|
||||
e.preventDefault();
|
||||
var href = jQuery(this).attr('href');
|
||||
var name = jQuery(this).text().replace('.css', '');
|
||||
var link = jQuery("<link>");
|
||||
link.attr({
|
||||
type: 'text/css',
|
||||
rel: 'stylesheet',
|
||||
href: href
|
||||
});
|
||||
jQuery("head").append( link );
|
||||
jQuery('textarea[name="data"]') .each(function(id, ta) {
|
||||
editor = jQuery(ta).data('editor');
|
||||
editor.setOption("theme", name);
|
||||
});
|
||||
jQuery('#themeName').html(name);
|
||||
current_theme = name;
|
||||
//#TODO save on session
|
||||
});
|
||||
function update_theme(name) {
|
||||
var href = "{{="%s/theme/" % cm}}" + name + ".css";
|
||||
var link = jQuery("<link>");
|
||||
link.attr({
|
||||
type: 'text/css',
|
||||
rel: 'stylesheet',
|
||||
href: href
|
||||
});
|
||||
jQuery("head").append( link );
|
||||
jQuery('textarea[name="data"]') .each(function(id, ta) {
|
||||
editor = jQuery(ta).data('editor');
|
||||
editor.setOption("theme", name);
|
||||
});
|
||||
current_theme = name;
|
||||
}
|
||||
|
||||
// incr/decr editor font-size
|
||||
jQuery(document).on('click', 'a.font_button', function (e) {
|
||||
@@ -165,16 +160,10 @@ jQuery(document).on('click', 'a.font_button', function (e) {
|
||||
|
||||
{{block sectionclass}}edit{{end}}
|
||||
|
||||
|
||||
<div class='row-fluid'>
|
||||
<div class="right controls btn-toolbar pull-right">
|
||||
<div class="dropdown btn-group pull-left">
|
||||
<a class="dropdown-toggle button btn" data-target="themes" data-toggle="dropdown" href="#" >Theme: <span id="themeName" style="color: #E8953C">Web2py</span> <span class="caret"></span></a>
|
||||
<ul class="dropdown-menu" role="menu" id="themes">
|
||||
{{for f in listfiles('admin', "static/codemirror/theme", regexp='.*\.css$' ):}}
|
||||
<li class=""><a href="{{=URL('static/codemirror/theme', f, host=True)}}">{{=f[:-4]}}</a></li>
|
||||
{{pass}}
|
||||
</ul>
|
||||
<div class="btn-group">
|
||||
<a class="button btn" onclick="jQuery('#files').toggle(); return false" href="#">Files toggle</a>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<a id="decr" class="button btn font_button">-</a>
|
||||
@@ -187,6 +176,7 @@ jQuery(document).on('click', 'a.font_button', function (e) {
|
||||
<a class="button btn" href="http://www.web2py.com/sqldesigner" target="_blank"><span>{{=T('online designer')}}</span></a>
|
||||
{{#pass}}
|
||||
<a class="button btn" href="http://www.web2py.com/examples/static/epydoc/index.html" target="_blank"><span>{{=T('docs')}}</span></a>
|
||||
<a class="button btn" title="{{=T('change editor settings')}}" id="editor_settingslink" href="{{=URL('default', 'edit', args=request.args, vars={'settings':True})}}"><i class="icon-cog"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
{{
|
||||
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$' )]}}
|
||||
<form id="editor_settings_form" class="form-horizontal">
|
||||
<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">
|
||||
<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");
|
||||
jQuery("#editor_settings_form").on('change', 'select, input', function (e) {
|
||||
jQuery("#editor_settings_form button[type=submit]").removeClass('disabled');
|
||||
});
|
||||
</script>
|
||||
@@ -22,6 +22,7 @@ import urllib
|
||||
import urllib2
|
||||
import Cookie
|
||||
import cStringIO
|
||||
import ConfigParser
|
||||
from email import MIMEBase, MIMEMultipart, MIMEText, Encoders, Header, message_from_string, Charset
|
||||
|
||||
from gluon.contenttype import contenttype
|
||||
@@ -5852,6 +5853,37 @@ class Wiki(object):
|
||||
request.post_vars.render = None
|
||||
return render(request.post_vars)
|
||||
|
||||
class Config(object):
|
||||
def __init__(
|
||||
self,
|
||||
filename,
|
||||
section,
|
||||
default_values={}
|
||||
):
|
||||
self.config = ConfigParser.ConfigParser(default_values)
|
||||
self.config.read(filename)
|
||||
if not self.config.has_section(section):
|
||||
self.config.add_section(section)
|
||||
self.section = section
|
||||
self.filename = filename
|
||||
|
||||
def read(self):
|
||||
if not( isinstance(current.session['settings_%s' % self.section], dict) ):
|
||||
settings = dict(self.config.items(self.section))
|
||||
else:
|
||||
settings = current.session['settings_%s' % self.section]
|
||||
return settings
|
||||
|
||||
def save(self, options):
|
||||
for option, value in options:
|
||||
self.config.set(self.section, option, value)
|
||||
try:
|
||||
self.config.write(open(self.filename, 'w'))
|
||||
result = True
|
||||
except:
|
||||
current.session['settings_%s' % self.section] = dict(self.config.items(self.section))
|
||||
result = False
|
||||
return result
|
||||
|
||||
if __name__ == '__main__':
|
||||
import doctest
|
||||
|
||||
Reference in New Issue
Block a user