mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-20 01:47:35 +00:00
feature(cloudcmd) add emitter
This commit is contained in:
parent
92960e7f8a
commit
3817ee7ae2
4 changed files with 41 additions and 13 deletions
|
|
@ -3,6 +3,8 @@
|
|||
/* global Util, DOM */
|
||||
|
||||
const itype = require('itype/legacy');
|
||||
const emitify = require('emitify/legacy');
|
||||
const inherits = require('inherits');
|
||||
const rendy = require('rendy');
|
||||
const exec = require('execon');
|
||||
const Images = require('./dom/images');
|
||||
|
|
@ -16,6 +18,10 @@ const {
|
|||
buildFromJSON,
|
||||
} = require('../common/cloudfunc');
|
||||
|
||||
/* global Util, DOM */
|
||||
|
||||
inherits(CloudCmdProto, Emitify);
|
||||
|
||||
module.exports = new CloudCmdProto(Util, DOM);
|
||||
|
||||
function CloudCmdProto(Util, DOM) {
|
||||
|
|
@ -24,12 +30,14 @@ function CloudCmdProto(Util, DOM) {
|
|||
let Listeners;
|
||||
|
||||
const log = (str) => {
|
||||
if (Debug)
|
||||
console.log(str);
|
||||
if (!Debug)
|
||||
return;
|
||||
|
||||
return str;
|
||||
console.log(str);
|
||||
};
|
||||
|
||||
Emitify.call(this);
|
||||
|
||||
const CloudCmd = this;
|
||||
const Info = DOM.CurrentInfo;
|
||||
const Storage = DOM.Storage;
|
||||
|
|
@ -251,6 +259,7 @@ function CloudCmdProto(Util, DOM) {
|
|||
}
|
||||
|
||||
DOM.setCurrentFile(current);
|
||||
|
||||
CloudCmd.execFromModule(module, 'show');
|
||||
};
|
||||
|
||||
|
|
@ -310,6 +319,8 @@ function CloudCmdProto(Util, DOM) {
|
|||
function baseInit(callback) {
|
||||
const files = DOM.getFiles();
|
||||
|
||||
CloudCmd.on('current-file', DOM.updateCurrentInfo);
|
||||
|
||||
/* выделяем строку с первым файлом */
|
||||
if (files)
|
||||
DOM.setCurrentFile(files[0], {
|
||||
|
|
@ -507,10 +518,12 @@ function CloudCmdProto(Util, DOM) {
|
|||
|
||||
if (!current)
|
||||
current = DOM.getFiles(panel)[0];
|
||||
|
||||
|
||||
DOM.setCurrentFile(current, {
|
||||
history: history
|
||||
});
|
||||
|
||||
CloudCmd.emit('active-dir', Info.dirPath);
|
||||
}
|
||||
|
||||
exec(callback);
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ function CmdProto() {
|
|||
* get current direcotory path
|
||||
*/
|
||||
this.getCurrentDirPath = (panel = DOM.getPanel()) => {
|
||||
const path = DOM.getByDataName('js-path', panel);
|
||||
const path = DOM.getByDataName('js-path', panel);
|
||||
const ret = path && path.textContent;
|
||||
|
||||
return ret;
|
||||
|
|
@ -473,17 +473,17 @@ function CmdProto() {
|
|||
* to prevent default behavior
|
||||
*/
|
||||
if (!o || o.history !== false) {
|
||||
if (path !== '/')
|
||||
path = FS + path;
|
||||
|
||||
DOM.setHistory(path, null, path);
|
||||
const historyPath = path === '/' ? path : FS + path;
|
||||
DOM.setHistory(historyPath, null, historyPath);
|
||||
}
|
||||
}
|
||||
|
||||
/* scrolling to current file */
|
||||
DOM.scrollIntoViewIfNeeded(currentFile, CENTER);
|
||||
|
||||
Cmd.updateCurrentInfo(currentFile);
|
||||
CloudCmd.emit('current-file', currentFile);
|
||||
CloudCmd.emit('current-path', path);
|
||||
CloudCmd.emit('current-name', DOM.getCurrentName(currentFile));
|
||||
|
||||
return DOM;
|
||||
};
|
||||
|
|
@ -996,7 +996,6 @@ function CmdProto() {
|
|||
return;
|
||||
|
||||
DOM.setCurrentName(to, current);
|
||||
Cmd.updateCurrentInfo(current);
|
||||
Storage.remove(dirPath);
|
||||
|
||||
if (isExist)
|
||||
|
|
@ -1029,7 +1028,11 @@ function CmdProto() {
|
|||
};
|
||||
|
||||
this.changePanel = () => {
|
||||
const Info = CurrentInfo;
|
||||
let panel = DOM.getPanel();
|
||||
|
||||
CloudCmd.emit('passive-dir', Info.dirPath);
|
||||
|
||||
const panelPassive = DOM.getPanel({
|
||||
active: false
|
||||
});
|
||||
|
|
@ -1067,6 +1070,8 @@ function CmdProto() {
|
|||
history: true
|
||||
});
|
||||
|
||||
CloudCmd.emit('active-dir', Info.dirPath);
|
||||
|
||||
return DOM;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,12 @@
|
|||
/* global Console */
|
||||
|
||||
const exec = require('execon');
|
||||
const currify = require('currify/legacy');
|
||||
const Images = require('../dom/images');
|
||||
const {Dialog} = DOM;
|
||||
const {
|
||||
Dialog,
|
||||
CurrentInfo:Info,
|
||||
} = DOM;
|
||||
|
||||
CloudCmd.Konsole = ConsoleProto;
|
||||
|
||||
|
|
@ -63,7 +67,7 @@ function ConsoleProto() {
|
|||
PASSIVE_DIR: DOM.getNotCurrentDirPath.bind(DOM),
|
||||
CURRENT_NAME: DOM.getCurrentName.bind(DOM),
|
||||
CURRENT_PATH: () => {
|
||||
return DOM.CurrentInfo.path;
|
||||
return Info.path;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -77,6 +81,7 @@ function ConsoleProto() {
|
|||
|
||||
Console(Element, options, (spawn) => {
|
||||
spawn.on('connect', exec.with(authCheck, spawn));
|
||||
|
||||
exec(callback);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -178,6 +178,11 @@
|
|||
"html-looks-like": "^1.0.2",
|
||||
"html-webpack-plugin": "^3.0.4",
|
||||
"limier": "^2.0.0",
|
||||
"html-webpack-exclude-assets-plugin": "^0.0.5",
|
||||
"html-webpack-plugin": "^2.29.0",
|
||||
"inherits": "^2.0.3",
|
||||
"jscs": "^3.0.1",
|
||||
"jshint": "^2.8.0",
|
||||
"minor": "^1.2.2",
|
||||
"mkdirp": "^0.5.1",
|
||||
"mock-require": "^3.0.1",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue