3 return function(sandbox) {
\r
5 function addTab(title, slug, view) {
\r
6 sandbox.getModule('tabsManager').addTab(title, slug, view);
\r
9 /* Events handling */
\r
13 eventHandlers.skelton = {
\r
15 sandbox.getModule('tabsManager').start();
\r
17 'cmd.save': function() {
\r
18 var editorSlugs = ['visual', 'source'];
\r
19 var slug = sandbox.getModule('tabsManager').getCurrentSlug();
\r
20 if(_.contains(editorSlugs, slug)) {
\r
21 var editor = sandbox.getModule(slug+'Editor');
\r
22 if(editor.isDirty()) {
\r
23 sandbox.getModule('data').commitDocument(editor.getDocument(), slug + '_edit');
\r
24 editor.setDirty(false);
\r
27 sandbox.getModule('data').saveDocument();
\r
31 eventHandlers.tabsManager = {
\r
33 sandbox.getModule('skelton').setMainView(sandbox.getModule('tabsManager').getView());
\r
34 _.each(['visualEditor', 'sourceEditor'], function(moduleName) {
\r
35 sandbox.getModule(moduleName).start();
\r
38 leaving: function(slug) {
\r
39 if(slug === 'source' || slug === 'visual') {
\r
40 var editor = sandbox.getModule(slug+'Editor');
\r
41 if(editor.isDirty()) {
\r
42 sandbox.getModule('data').commitDocument(editor.getDocument(), slug + '_edit');
\r
43 editor.setDirty(false);
\r
47 showed: function(slug) {
\r
48 if(slug === 'visual')
\r
49 sandbox.getModule('visualEditor').onShowed();
\r
53 eventHandlers.sourceEditor = {
\r
55 addTab(gettext('Source'), 'source', sandbox.getModule('sourceEditor').getView());
\r
56 sandbox.getModule('sourceEditor').setDocument(sandbox.getModule('data').getDocument());
\r
60 eventHandlers.visualEditor = {
\r
62 sandbox.getModule('visualEditor').setDocument(sandbox.getModule('data').getDocument());
\r
63 addTab(gettext('Visual'), 'visual', sandbox.getModule('visualEditor').getView());
\r
68 eventHandlers.data = {
\r
70 sandbox.getModule('skelton').start();
\r
72 documentChanged: function(document, reason) {
\r
73 var slug = (reason === 'visual_edit' ? 'source' : 'visual');
\r
74 sandbox.getModule(slug+'Editor').setDocument(document);
\r
76 savingStarted: function() {
\r
77 sandbox.getModule('skelton').deactivateCommand('save');
\r
78 sandbox.getModule('skelton').showMessage(gettext('Saving...'));
\r
80 savingEnded: function(status) {
\r
81 sandbox.getModule('skelton').activateCommand('save');
\r
82 sandbox.getModule('skelton').clearMessage();
\r
91 sandbox.getModule('data').start();
\r
93 handleEvent: function(moduleName, eventName, args) {
\r
94 if(eventHandlers[moduleName] && eventHandlers[moduleName][eventName]) {
\r
95 eventHandlers[moduleName][eventName].apply(eventHandlers, args);
\r