From a3271da77201ecbe763735e9f6a2dba37a73141c Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 8 Aug 2017 12:22:43 +0300 Subject: [PATCH] feature(cloudcmd) add emitter --- client/client.js | 13 ++++++++++++- client/dom/index.js | 21 +++++++++++++-------- client/modules/konsole.js | 10 ++++++++-- package.json | 1 + 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/client/client.js b/client/client.js index d2292e222d..fb7199ebba 100644 --- a/client/client.js +++ b/client/client.js @@ -1,6 +1,8 @@ 'use strict'; 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'); @@ -15,6 +17,8 @@ const { /* global Util, DOM */ +inherits(CloudCmdProto, Emitify); + module.exports = new CloudCmdProto(Util, DOM); function CloudCmdProto(Util, DOM) { @@ -29,6 +33,8 @@ function CloudCmdProto(Util, DOM) { console.log(str); }; + Emitify.call(this); + const CloudCmd = this; const Info = DOM.CurrentInfo; const Storage = DOM.Storage; @@ -254,6 +260,7 @@ function CloudCmdProto(Util, DOM) { } DOM.setCurrentFile(current); + CloudCmd.execFromModule(module, 'show'); }; @@ -313,6 +320,8 @@ function CloudCmdProto(Util, DOM) { function baseInit(callback) { const files = DOM.getFiles(); + CloudCmd.on('current-file', DOM.updateCurrentInfo); + /* выделяем строку с первым файлом */ if (files) DOM.setCurrentFile(files[0], { @@ -510,10 +519,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); diff --git a/client/dom/index.js b/client/dom/index.js index 2c972186e7..7e62326149 100644 --- a/client/dom/index.js +++ b/client/dom/index.js @@ -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; }; @@ -1031,7 +1031,6 @@ function CmdProto() { return; DOM.setCurrentName(to, current); - Cmd.updateCurrentInfo(current); Storage.remove(dirPath); if (isExist) @@ -1062,7 +1061,7 @@ function CmdProto() { }; /* scroll on one page*/ - this.scrollByPages = (element, pPages) => { + this.scrollByPages = (element, pPages) => { var ret = element && element.scrollByPages && pPages; if (ret) @@ -1072,7 +1071,11 @@ function CmdProto() { }; this.changePanel = () => { + const Info = CurrentInfo; let panel = DOM.getPanel(); + + CloudCmd.emit('passive-dir', Info.dirPath); + const panelPassive = DOM.getPanel({ active: false }); @@ -1110,6 +1113,8 @@ function CmdProto() { history: true }); + CloudCmd.emit('active-dir', Info.dirPath); + return DOM; }; diff --git a/client/modules/konsole.js b/client/modules/konsole.js index dbcf92a64c..14af2a02f8 100644 --- a/client/modules/konsole.js +++ b/client/modules/konsole.js @@ -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,13 +67,14 @@ function ConsoleProto() { PASSIVE_DIR: DOM.getNotCurrentDirPath.bind(DOM), CURRENT_NAME: DOM.getCurrentName.bind(DOM), CURRENT_PATH: () => { - return DOM.CurrentInfo.path; + return Info.path; } }; } function create(callback) { const options = { + cwd: Info.dirPath, env: getEnv(), prefix: getPrefix(), socketPath: CloudCmd.PREFIX, @@ -77,6 +82,7 @@ function ConsoleProto() { Console(Element, options, (spawn) => { spawn.on('connect', exec.with(authCheck, spawn)); + exec(callback); }); diff --git a/package.json b/package.json index 4423d0045b..228d5219be 100644 --- a/package.json +++ b/package.json @@ -171,6 +171,7 @@ "html-looks-like": "^1.0.2", "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",