设置主题事件。

This commit is contained in:
liteng 2018-06-16 22:12:41 +08:00
parent 51c7910404
commit 76089152ec
5 changed files with 45 additions and 9 deletions

View File

@ -8,7 +8,6 @@ import Toolbar from './editor/Toolbar';
import Menubar from './menu/Menubar';
import Panel from './panel/Panel';
import UI from './ui/UI';
import RemoveObjectCommand from './command/RemoveObjectCommand';
/**
* 应用程序

View File

@ -45,12 +45,8 @@ function Editor(app) {
Editor.prototype = {
setTheme: function (value) {
document.getElementById('theme').href = value;
this.signals.themeChanged.dispatch(value);
setTheme: function (value) { // 设置编辑器主题
this.app.call('setTheme', this, value);
},
//

View File

@ -11,6 +11,8 @@ import LoadFromHashEvent from './editor/LoadFromHashEvent';
import AutoSaveEvent from './editor/AutoSaveEvent';
import VREvent from './editor/VREvent';
import SetThemeEvent from './editor/SetThemeEvent';
/**
* 事件执行器
*/
@ -20,6 +22,7 @@ function EventDispatcher(app) {
this.addDomEventListener();
this.events = [
// Application中的事件
new DragOverEvent(this.app),
new DropEvent(this.app),
new KeyDownEvent(this.app),
@ -27,7 +30,10 @@ function EventDispatcher(app) {
//new MessageEvent(this.app),
new LoadFromHashEvent(this.app),
new AutoSaveEvent(this.app),
new VREvent(this.app)
new VREvent(this.app),
// Editor中的事件
new SetThemeEvent(this.app),
];
}

View File

@ -14,7 +14,10 @@ var EventList = [
'mousewheel',
'resize',
'dragover',
'drop'
'drop',
// editor事件
'setTheme', // 设置编辑器主题
];
export default EventList;

View File

@ -0,0 +1,32 @@
import BaseEvent from '../BaseEvent';
/**
* 设置主题事件
* @param {*} app
*/
function SetThemeEvent(app) {
BaseEvent.call(this, app);
}
SetThemeEvent.prototype = Object.create(BaseEvent.prototype);
SetThemeEvent.prototype.constructor = SetThemeEvent;
SetThemeEvent.prototype.start = function () {
var _this = this;
this.app.on('setTheme.' + this.id, function (theme) {
_this.onSetTheme(theme);
});
};
SetThemeEvent.prototype.stop = function () {
this.app.on('setTheme.' + this.id, null);
};
SetThemeEvent.prototype.onSetTheme = function (theme) {
var signals = this.app.editor.signals;
document.getElementById('theme').href = theme;
signals.themeChanged.dispatch(theme);
};
export default SetThemeEvent;