add options for theme and mode

This commit is contained in:
nightwing 2013-12-04 01:48:18 +04:00
commit 10e2c3049c
3 changed files with 20 additions and 7 deletions

View file

@ -2534,6 +2534,10 @@ config.defineOptions(EditSession.prototype, "session", {
set: function(val) {this.doc.setNewLineMode(val)}, set: function(val) {this.doc.setNewLineMode(val)},
get: function() {return this.doc.getNewLineMode()}, get: function() {return this.doc.getNewLineMode()},
handlesSet: true handlesSet: true
},
mode: {
set: function(val) { this.setMode(val) },
get: function() { return this.$modeId }
} }
}); });

View file

@ -248,7 +248,7 @@ var Editor = function(renderer, session) {
this.setKeyboardHandler = function(keyboardHandler) { this.setKeyboardHandler = function(keyboardHandler) {
if (!keyboardHandler) { if (!keyboardHandler) {
this.keyBinding.setKeyboardHandler(null); this.keyBinding.setKeyboardHandler(null);
} else if (typeof keyboardHandler == "string") { } else if (typeof keyboardHandler === "string") {
this.$keybindingId = keyboardHandler; this.$keybindingId = keyboardHandler;
var _self = this; var _self = this;
config.loadModule(["keybinding", keyboardHandler], function(module) { config.loadModule(["keybinding", keyboardHandler], function(module) {
@ -2424,6 +2424,7 @@ config.defineOptions(Editor.prototype, "editor", {
minLines: "renderer", minLines: "renderer",
scrollPastEnd: "renderer", scrollPastEnd: "renderer",
fixedWidthGutter: "renderer", fixedWidthGutter: "renderer",
theme: "renderer",
scrollSpeed: "$mouseHandler", scrollSpeed: "$mouseHandler",
dragDelay: "$mouseHandler", dragDelay: "$mouseHandler",
@ -2437,7 +2438,8 @@ config.defineOptions(Editor.prototype, "editor", {
useSoftTabs: "session", useSoftTabs: "session",
tabSize: "session", tabSize: "session",
wrap: "session", wrap: "session",
foldStyle: "session" foldStyle: "session",
mode: "session"
}); });
exports.Editor = Editor; exports.Editor = Editor;

View file

@ -49,6 +49,7 @@ dom.importCssString(editorCss, "ace_editor");
/** /**
* The class that is responsible for drawing everything you see on the screen! * The class that is responsible for drawing everything you see on the screen!
* @related editor.renderer
* @class VirtualRenderer * @class VirtualRenderer
**/ **/
@ -1469,18 +1470,18 @@ var VirtualRenderer = function(container, theme) {
**/ **/
this.setTheme = function(theme, cb) { this.setTheme = function(theme, cb) {
var _self = this; var _self = this;
this.$themeValue = theme; this.$themeId = theme;
_self._dispatchEvent('themeChange',{theme:theme}); _self._dispatchEvent('themeChange',{theme:theme});
if (!theme || typeof theme == "string") { if (!theme || typeof theme == "string") {
var moduleName = theme || "ace/theme/textmate"; var moduleName = theme || this.$options.theme.initialValue;
config.loadModule(["theme", moduleName], afterLoad); config.loadModule(["theme", moduleName], afterLoad);
} else { } else {
afterLoad(theme); afterLoad(theme);
} }
function afterLoad(module) { function afterLoad(module) {
if (_self.$themeValue != theme) if (_self.$themeId != theme)
return cb && cb(); return cb && cb();
if (!module.cssClass) if (!module.cssClass)
return; return;
@ -1507,7 +1508,7 @@ var VirtualRenderer = function(container, theme) {
// force re-measure of the gutter width // force re-measure of the gutter width
if (_self.$size) { if (_self.$size) {
_self.$size.width = 0; _self.$size.width = 0;
_self.onResize(); _self.$updateSizeAsync();
} }
_self._dispatchEvent('themeLoaded', {theme:module}); _self._dispatchEvent('themeLoaded', {theme:module});
@ -1520,7 +1521,7 @@ var VirtualRenderer = function(container, theme) {
* @returns {String} * @returns {String}
**/ **/
this.getTheme = function() { this.getTheme = function() {
return this.$themeValue; return this.$themeId;
}; };
// Methods allows to add / remove CSS classnames to the editor element. // Methods allows to add / remove CSS classnames to the editor element.
@ -1688,6 +1689,12 @@ config.defineOptions(VirtualRenderer.prototype, "renderer", {
this.$gutterLayer.$fixedWidth = !!val; this.$gutterLayer.$fixedWidth = !!val;
this.$loop.schedule(this.CHANGE_GUTTER); this.$loop.schedule(this.CHANGE_GUTTER);
} }
},
theme: {
set: function(val) { this.setTheme(val) },
get: function() { return this.$themeId || this.theme; },
initialValue: "./theme/textmate",
handlesSet: true
} }
}); });