diff --git a/client/edit.js b/client/edit.js index 52b92e1ae7..cbf8f11625 100644 --- a/client/edit.js +++ b/client/edit.js @@ -1,4 +1,4 @@ -var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format; +var CloudCmd, Util, DOM, CloudFunc; (function(CloudCmd, Util, DOM) { 'use strict'; @@ -6,22 +6,18 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format; CloudCmd.Edit = EditProto; function EditProto(callback) { - var Name = 'Edit', - Loading = true, - - Dialog = DOM.Dialog, - + var Name = 'Edit'; + var Loading = true; + + var Dialog = DOM.Dialog, exec = Util.exec, - Edit = this, - - Menu, + Element, - EditorName = 'edward', + EditorName = 'edward', editor, - TITLE = 'Edit', + TITLE = 'Edit', - Element, ConfigView = { afterShow: function() { editor @@ -39,8 +35,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format; function(callback) { loadFiles(element, callback); }, - callback - ]); + ], callback); } function createElement() { @@ -54,6 +49,8 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format; notAppend: true }); + Element = element; + return element; } @@ -63,8 +60,6 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format; } function initConfig(config, options) { - var config = {}; - Util.copyObj(config, ConfigView); if (!options) @@ -78,7 +73,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format; config.afterShow = function() { afterShow(); options.afterShow(); - } + }; } return config; @@ -95,6 +90,10 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format; return editor; }; + this.getElement = function() { + return Element; + } + this.hide = function() { CloudCmd.View.hide(); }; diff --git a/client/edit-file.js b/client/filedit.js similarity index 58% rename from client/edit-file.js rename to client/filedit.js index 08ae58f20d..96695f13a4 100644 --- a/client/edit-file.js +++ b/client/filedit.js @@ -3,27 +3,21 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format; (function(CloudCmd, Util, DOM) { 'use strict'; - CloudCmd.Edit = EditProto; - - function EditProto(callback) { - var Name = 'Edit', - Loading = true, - - Info = DOM.CurrentInfo, - Dialog = DOM.Dialog, - - exec = Util.exec, - - Menu, - - EditorName = 'edward', - editor, + CloudCmd.Filedit = function FileditProto(callback) { + var Name = 'EditFile'; + var Loading = true; + + var Info = DOM.CurrentInfo; + var Dialog = DOM.Dialog; + var exec = Util.exec; + var Filedit = this; + + var Menu, TITLE = 'Edit', Images = DOM.Images, MSG_CHANGED, - Element, ConfigView = { beforeClose: function() { exec.ifExist(Menu, 'hide'); @@ -32,45 +26,32 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format; }; function init(callback) { - var element = createElement(); - - DOM.Events.addOnce('contextmenu', element, setMenu); + var editor; exec.series([ - CloudCmd.View, CloudCmd.Edit, - getConfig, + function(callback) { + editor = CloudCmd.Edit.getEditor(); + callback(); + }, function(callback) { authCheck(editor); callback(); }, + + function(callback) { + setListeners(editor) + callback(); + }, function(callback) { - CloudCmd.Edit - .create(element) - .show(callback); + Filedit.show(callback); }, ]); } - function createElement() { - var element = DOM.load({ - name : 'div', - style : - 'width : 100%;' + - 'height : 100%;' + - 'font-family: "Droid Sans Mono";' + - 'position : absolute;', - notAppend : true - }); - - return element; - } - this.show = function() { Images.show.load(); - var editor = CloudCmd.Edit.getEditor(); - Info.getData(function(error, data) { var path = Info.path; var isDir = Info.isDir; @@ -82,31 +63,30 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format; if (error) return Images.hide(); - editor.setValueFirst(path, data); - setMsgChanged(name); - editor + CloudCmd.Edit + .getEditor() + .setValueFirst(path, data) .setModeForPath(name) .setOption('fontSize', 16); - CloudCmd.View.show(Element, ConfigView); + CloudCmd.Edit.show(ConfigView); }); }; this.hide = function() { - CloudCmd.View.hide(); + CloudCmd.Edit.hide(); }; - this.create = function(element) { - Element = element; + function setListeners(editor) { + var element = CloudCmd.Edit.getElement(); + + DOM.Events.addOnce('contextmenu', element, setMenu); editor.on('save', function(value) { - var size = Format.size(value); - DOM.setCurrentSize(size); + DOM.setCurrentSize(Format.size(value)); }); - - return this; }; function authCheck(spawn) { @@ -124,42 +104,6 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format; }); } - function getConfig(callback) { - DOM.Files.get('config', function(error, config) { - if (error) - Dialog.alert(TITLE, error); - else if (config.editor) - EditorName = config.editor; - - callback(); - }); - } - - function loadFiles(element, callback) { - var prefix = CloudCmd.PREFIX, - prefixName = prefix + '/' + EditorName, - url = prefixName + '/' + EditorName + '.js'; - - Util.time(Name + ' load'); - - DOM.load.js(url, function() { - var word = window[EditorName], - options = { - maxSize : CloudFunc.MAX_FILE_SIZE, - prefix : prefixName, - socketPath : prefix - }; - - word(element, options, function(ed) { - Util.timeEnd(Name + ' load'); - editor = ed; - Loading = false; - - exec(callback); - }); - }); - } - function setMenu(event) { var position = { x: event.clientX, @@ -169,18 +113,21 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format; event.preventDefault(); !Menu && DOM.loadRemote('menu', function(error) { - var noFocus, - options = { - beforeShow: function(params) { - params.x -= 18; - params.y -= 27; - }, - - afterClick: function() { - !noFocus && editor.focus(); - } - }, - menuData = { + var noFocus; + var options = { + beforeShow: function(params) { + params.x -= 18; + params.y -= 27; + }, + + afterClick: function() { + !noFocus && editor.focus(); + } + }; + + var editor = CloudCmd.Edit.getEditor(); + + var menuData = { 'Save Ctrl+S' : function() { editor.save(); }, @@ -210,7 +157,7 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format; editor.minify(); }, 'Close Esc' : function() { - Edit.hide(); + Filedit.hide(); } }; @@ -220,7 +167,9 @@ var CloudCmd, Util, DOM, CloudFunc, MenuIO, Format; if (Menu || !MenuIO) return; - Menu = new MenuIO(Element, options, menuData); + var element = CloudCmd.Edit.getElement(); + + Menu = new MenuIO(element, options, menuData); Menu.show(position.x, position.y); }); } diff --git a/client/key.js b/client/key.js index 447fcf62b2..080ced1f64 100644 --- a/client/key.js +++ b/client/key.js @@ -294,7 +294,7 @@ var CloudCmd, Util, DOM; break; case Key.F4: - CloudCmd.Edit.show(); + CloudCmd.Filedit.show(); event.preventDefault(); break; diff --git a/client/listeners.js b/client/listeners.js index 7d2a8e3f8d..159a323e38 100644 --- a/client/listeners.js +++ b/client/listeners.js @@ -53,7 +53,7 @@ var Util, DOM, CloudFunc, CloudCmd; 'f1' : CloudCmd.Help.show, 'f2' : DOM.renameCurrent, 'f3' : CloudCmd.View.show, - 'f4' : CloudCmd.Edit.show, + 'f4' : CloudCmd.EditFile.show, 'f5' : operation('copy'), 'f6' : operation('move'), 'f7' : DOM.promptNewDir, diff --git a/json/modules.json b/json/modules.json index 203e8ea090..205d03bed7 100644 --- a/json/modules.json +++ b/json/modules.json @@ -1,5 +1,6 @@ [ "edit", + "filedit", "menu", "view", "help", @@ -8,7 +9,7 @@ "contact", "upload", "operation", - "konsole", + "konsole", "cloud", [{ "name": "remote", "data": [{