mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(edit-names-vim) add
This commit is contained in:
parent
772b82857b
commit
c015ce6ce3
7 changed files with 119 additions and 44 deletions
|
|
@ -71,6 +71,7 @@ module.exports = {
|
|||
[modules + '/edit-file']: `${dirModules}/edit-file.js`,
|
||||
[modules + '/edit-file-vim']: `${dirModules}/edit-file-vim.js`,
|
||||
[modules + '/edit-names']: `${dirModules}/edit-names.js`,
|
||||
[modules + '/edit-names-vim']: `${dirModules}/edit-names-vim.js`,
|
||||
[modules + '/menu']: `${dirModules}/menu.js`,
|
||||
[modules + '/view']: `${dirModules}/view.js`,
|
||||
[modules + '/help']: `${dirModules}/help.js`,
|
||||
|
|
|
|||
3
HELP.md
3
HELP.md
|
|
@ -164,7 +164,8 @@ Hot keys
|
|||
| `Ctrl + r` | refresh
|
||||
| `Ctrl + d` | clear local storage
|
||||
| `Ctrl + a` | select all files in a panel
|
||||
| `Ctrl + m` | rename selected files
|
||||
| `Ctrl + m` | rename selected files in editor
|
||||
| `Shift + Ctrl + m` | rename selected files in vim mode of editor
|
||||
| `Ctrl + u` | swap panels
|
||||
| `Ctrl + F3` | sort by name
|
||||
| `Ctrl + F5` | sort by date
|
||||
|
|
|
|||
|
|
@ -411,7 +411,11 @@ function KeyProto() {
|
|||
|
||||
case Key.M:
|
||||
if (ctrlMeta) {
|
||||
CloudCmd.EditNames.show();
|
||||
if (shift)
|
||||
CloudCmd.EditNamesVim.show();
|
||||
else
|
||||
CloudCmd.EditNames.show();
|
||||
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,10 @@ CloudCmd.EditFile = function EditFileProto(callback) {
|
|||
}
|
||||
|
||||
EditFile.show = (options) => {
|
||||
const config = Object.assign({}, ConfigView, options);
|
||||
const config = {
|
||||
...ConfigView,
|
||||
...options,
|
||||
};
|
||||
|
||||
Images.show.load();
|
||||
|
||||
|
|
|
|||
55
client/modules/edit-names-vim.js
Normal file
55
client/modules/edit-names-vim.js
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
'use strict';
|
||||
|
||||
/* global CloudCmd */
|
||||
|
||||
const exec = require('execon');
|
||||
const Events = require('../dom/events');
|
||||
|
||||
const {Key} = CloudCmd;
|
||||
|
||||
CloudCmd.EditNamesVim = function EditNamesVimProto(callback) {
|
||||
const EditNamesVim = this;
|
||||
|
||||
const ConfigView = {
|
||||
bindKeys: false,
|
||||
beforeClose: () => {
|
||||
Events.rmKey(listener);
|
||||
CloudCmd.EditNames.isChanged();
|
||||
}
|
||||
};
|
||||
|
||||
function init(callback) {
|
||||
exec.series([
|
||||
CloudCmd.EditNames,
|
||||
callback || EditNamesVim.show,
|
||||
]);
|
||||
}
|
||||
|
||||
this.show = () => {
|
||||
Events.addKey(listener);
|
||||
|
||||
CloudCmd.EditNames
|
||||
.show(ConfigView)
|
||||
.getEditor()
|
||||
.setKeyMap('vim');
|
||||
};
|
||||
|
||||
this.hide = () => {
|
||||
CloudCmd.Edit.hide();
|
||||
};
|
||||
|
||||
function listener(event) {
|
||||
const {
|
||||
keyCode,
|
||||
shiftKey,
|
||||
} = event;
|
||||
|
||||
if (shiftKey && keyCode === Key.ESC) {
|
||||
event.preventDefault();
|
||||
EditNamesVim.hide();
|
||||
}
|
||||
}
|
||||
|
||||
init(callback);
|
||||
};
|
||||
|
||||
|
|
@ -3,11 +3,19 @@
|
|||
/* global CloudCmd, DOM */
|
||||
|
||||
const currify = require('currify/legacy');
|
||||
const store = require('fullstore/legacy');
|
||||
const squad = require('squad/legacy');
|
||||
const wraptile = require('wraptile/legacy');
|
||||
const exec = require('execon');
|
||||
const supermenu = require('supermenu');
|
||||
|
||||
const reject = Promise.reject.bind(Promise);
|
||||
|
||||
const call = currify((fn, callback) => {
|
||||
fn();
|
||||
callback();
|
||||
});
|
||||
|
||||
CloudCmd.EditNames = function EditNamesProto(callback) {
|
||||
const Info = DOM.CurrentInfo;
|
||||
const Dialog = DOM.Dialog;
|
||||
|
|
@ -15,47 +23,48 @@ CloudCmd.EditNames = function EditNamesProto(callback) {
|
|||
const TITLE = 'Edit Names';
|
||||
const alert = currify(Dialog.alert, TITLE);
|
||||
const refresh = currify(_refresh);
|
||||
const rename = currify(_rename);
|
||||
|
||||
let Menu;
|
||||
|
||||
const EditNames = this;
|
||||
const EditNames = exec.bind();
|
||||
const ConfigView = {
|
||||
beforeClose: () => {
|
||||
exec.ifExist(Menu, 'hide');
|
||||
isChanged();
|
||||
DOM.Events.remove('keydown', keyListener);
|
||||
EditNames.isChanged();
|
||||
}
|
||||
};
|
||||
|
||||
function init(callback) {
|
||||
let editor;
|
||||
const editor = store();
|
||||
|
||||
const getMainEditor = () => CloudCmd.Edit.getEditor();
|
||||
const getEditor = squad(editor, getMainEditor);
|
||||
const listeners = squad(setListeners, editor);
|
||||
|
||||
const show = callback ? exec : EditNames.show;
|
||||
|
||||
exec.series([
|
||||
CloudCmd.Edit,
|
||||
|
||||
(callback) => {
|
||||
editor = CloudCmd.Edit.getEditor();
|
||||
callback();
|
||||
},
|
||||
|
||||
(callback) => {
|
||||
setListeners(editor);
|
||||
callback();
|
||||
},
|
||||
|
||||
(callback) => {
|
||||
EditNames.show();
|
||||
callback();
|
||||
},
|
||||
call(getEditor),
|
||||
call(listeners),
|
||||
show,
|
||||
], callback);
|
||||
}
|
||||
|
||||
this.show = () => {
|
||||
EditNames.show = (options) => {
|
||||
const names = getActiveNames().join('\n');
|
||||
const config = {
|
||||
...ConfigView,
|
||||
...options,
|
||||
};
|
||||
|
||||
if (Info.name === '..' && names.length === 1)
|
||||
return Dialog.alert.noFiles(TITLE);
|
||||
|
||||
DOM.Events.addKey(keyListener);
|
||||
|
||||
CloudCmd.Edit
|
||||
.getEditor()
|
||||
.setValueFirst('edit-names', names)
|
||||
|
|
@ -63,9 +72,9 @@ CloudCmd.EditNames = function EditNamesProto(callback) {
|
|||
.setOption('keyMap', 'default')
|
||||
.disableKey();
|
||||
|
||||
DOM.Events.addKey(keyListener);
|
||||
|
||||
CloudCmd.Edit.show(ConfigView);
|
||||
CloudCmd.Edit.show(config);
|
||||
|
||||
return CloudCmd.Edit;
|
||||
};
|
||||
|
||||
function keyListener(event) {
|
||||
|
|
@ -84,7 +93,7 @@ CloudCmd.EditNames = function EditNamesProto(callback) {
|
|||
return DOM.getFilenames(DOM.getActiveFiles());
|
||||
}
|
||||
|
||||
this.hide = () => {
|
||||
EditNames.hide = () => {
|
||||
CloudCmd.Edit.hide();
|
||||
};
|
||||
|
||||
|
|
@ -130,18 +139,18 @@ CloudCmd.EditNames = function EditNamesProto(callback) {
|
|||
return root + dir;
|
||||
}
|
||||
|
||||
function rename(dir, from, to) {
|
||||
return (root) => {
|
||||
return fetch(CloudCmd.PREFIX + '/rename', {
|
||||
method: 'put',
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({
|
||||
from,
|
||||
to,
|
||||
dir: getDir(root, dir)
|
||||
})
|
||||
});
|
||||
};
|
||||
function _rename(path, from, to, root) {
|
||||
const dir = getDir(root, path);
|
||||
|
||||
return fetch(CloudCmd.PREFIX + '/rename', {
|
||||
method: 'put',
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({
|
||||
from,
|
||||
to,
|
||||
dir,
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function setMenu(event) {
|
||||
|
|
@ -201,18 +210,19 @@ CloudCmd.EditNames = function EditNamesProto(callback) {
|
|||
Menu.show(position.x, position.y);
|
||||
}
|
||||
|
||||
function isChanged() {
|
||||
EditNames.isChanged = () => {
|
||||
const editor = CloudCmd.Edit.getEditor();
|
||||
const msg = 'Apply new names?';
|
||||
|
||||
if (!editor.isChanged())
|
||||
return;
|
||||
|
||||
Dialog.confirm(TITLE, msg)
|
||||
.then(applyNames)
|
||||
.catch(EditNames.hide);
|
||||
}
|
||||
Dialog.confirm(TITLE, msg, {cancel: false})
|
||||
.then(applyNames);
|
||||
};
|
||||
|
||||
init(callback);
|
||||
setTimeout(wraptile(init, callback));
|
||||
|
||||
return EditNames;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
"edit-file",
|
||||
"edit-file-vim",
|
||||
"edit-names",
|
||||
"edit-names-vim",
|
||||
"menu",
|
||||
"view",
|
||||
"help",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue