mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(dialog) cancel -> tryToCatch
This commit is contained in:
parent
7e98ad725d
commit
ef38bd7aa3
7 changed files with 58 additions and 47 deletions
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const tryToCatch = require('try-to-catch/legacy');
|
||||
|
||||
const {
|
||||
alert,
|
||||
prompt,
|
||||
|
|
@ -14,9 +15,9 @@ module.exports.alert = (...a) => alert(title, ...a, {
|
|||
cancel: false,
|
||||
});
|
||||
|
||||
module.exports.prompt = (...a) => prompt(title, ...a);
|
||||
module.exports.confirm = (...a) => confirm(title, ...a);
|
||||
module.exports.progress = (...a) => progress(title, ...a);
|
||||
module.exports.prompt = (...a) => tryToCatch(prompt, title, ...a);
|
||||
module.exports.confirm = (...a) => tryToCatch(confirm, title, ...a);
|
||||
module.exports.progress = (...a) => tryToCatch(progress, title, ...a);
|
||||
|
||||
module.exports.alert.noFiles = () => {
|
||||
return alert(title, 'No files selected!', {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
const itype = require('itype/legacy');
|
||||
const exec = require('execon');
|
||||
const jonny = require('jonny/legacy');
|
||||
const tryToCatch = require('try-to-catch/legacy');
|
||||
|
||||
const Util = require('../../common/util');
|
||||
const callbackify = require('../../common/callbackify');
|
||||
|
|
@ -100,9 +99,9 @@ function CmdProto() {
|
|||
|
||||
const name = getName();
|
||||
|
||||
const [, newName] = await tryToCatch(Dialog.prompt, msg, name);
|
||||
const [cancel, newName] = await Dialog.prompt(msg, name);
|
||||
|
||||
if (!newName)
|
||||
if (cancel)
|
||||
return;
|
||||
|
||||
const path = (type) => {
|
||||
|
|
@ -753,9 +752,9 @@ function CmdProto() {
|
|||
if (from === '..')
|
||||
return Dialog.alert.noFiles();
|
||||
|
||||
const [e, to] = await tryToCatch(Dialog.prompt, 'Rename', from);
|
||||
const [cancel, to] = await Dialog.prompt('Rename', from);
|
||||
|
||||
if (e)
|
||||
if (cancel)
|
||||
return;
|
||||
|
||||
const isExist = !!DOM.getCurrentByName(to);
|
||||
|
|
@ -856,18 +855,22 @@ function CmdProto() {
|
|||
return '.tar.gz';
|
||||
};
|
||||
|
||||
this.goToDirectory = () => {
|
||||
this.goToDirectory = async () => {
|
||||
const msg = 'Go to directory:';
|
||||
const path = CurrentInfo.dirPath;
|
||||
const {Dialog} = DOM;
|
||||
const cancel = false;
|
||||
const setPath = (path) => ({
|
||||
path,
|
||||
});
|
||||
const {dirPath} = CurrentInfo;
|
||||
|
||||
Dialog.prompt(msg, path, {cancel})
|
||||
.then(setPath)
|
||||
.then(CloudCmd.loadDir);
|
||||
const [
|
||||
cancel,
|
||||
path = dirPath,
|
||||
] = await Dialog.prompt(msg, path);
|
||||
|
||||
if (cancel)
|
||||
return;
|
||||
|
||||
CloudCmd.loadDir({
|
||||
path
|
||||
});
|
||||
},
|
||||
|
||||
this.duplicatePanel = () => {
|
||||
|
|
|
|||
|
|
@ -16,12 +16,15 @@ module.exports = async (msg, files) => {
|
|||
|
||||
const allMsg = `Specify file type for ${msg} selection`;
|
||||
|
||||
const type = await prompt(allMsg, SelectType);
|
||||
/* eslint require-atomic-updates: 0 */
|
||||
const [cancel, type] = await prompt(allMsg, SelectType);
|
||||
|
||||
if (cancel)
|
||||
return;
|
||||
|
||||
SelectType = type;
|
||||
|
||||
const regExp = getRegExp(type);
|
||||
|
||||
let matches = 0;
|
||||
|
||||
for (const current of files) {
|
||||
|
|
|
|||
|
|
@ -180,17 +180,18 @@ function setMsgChanged(name) {
|
|||
|
||||
module.exports.isChanged = isChanged;
|
||||
|
||||
function isChanged() {
|
||||
async function isChanged() {
|
||||
const editor = CloudCmd.Edit.getEditor();
|
||||
const is = editor.isChanged();
|
||||
|
||||
if (!is)
|
||||
return;
|
||||
|
||||
const cancel = false;
|
||||
Dialog.confirm(MSG_CHANGED, {cancel})
|
||||
.then(() => {
|
||||
editor.save();
|
||||
});
|
||||
const [cancel] = await Dialog.confirm(MSG_CHANGED);
|
||||
|
||||
if (cancel)
|
||||
return;
|
||||
|
||||
editor.save();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
CloudCmd.EditNames = exports;
|
||||
|
||||
const smalltalk = require('smalltalk');
|
||||
const currify = require('currify/legacy');
|
||||
const exec = require('execon');
|
||||
const supermenu = require('supermenu');
|
||||
|
|
@ -69,7 +70,7 @@ function keyListener(event) {
|
|||
EditNames.hide();
|
||||
|
||||
else if (ctrlMeta && event.keyCode === Key.P)
|
||||
Dialog
|
||||
smalltalk
|
||||
.prompt('Apply pattern:', '[n][e]', {cancel: false})
|
||||
.then(applyPattern);
|
||||
|
||||
|
|
|
|||
|
|
@ -255,7 +255,7 @@ Operation.extract = () => {
|
|||
*
|
||||
* @currentFile
|
||||
*/
|
||||
function promptDelete() {
|
||||
async function promptDelete() {
|
||||
if (noFilesCheck())
|
||||
return;
|
||||
|
||||
|
|
@ -291,11 +291,12 @@ function promptDelete() {
|
|||
msg = msgAsk + msgSel + type + name + '?';
|
||||
}
|
||||
|
||||
const cancel = false;
|
||||
const [cancel] = await Dialog.confirm(msg);
|
||||
|
||||
Dialog.confirm(msg, {cancel}).then(() => {
|
||||
deleteSilent(files);
|
||||
});
|
||||
if (cancel)
|
||||
return;
|
||||
|
||||
deleteSilent(files);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -380,9 +381,12 @@ function _processFiles(options, data) {
|
|||
const title = isCopy ? 'Copy' : 'Rename/Move';
|
||||
const operation = isCopy ? copyFn : moveFn;
|
||||
|
||||
if (shouldAsk && config(option))
|
||||
return message(title, to, names.map(encode))
|
||||
.then(ask);
|
||||
if (shouldAsk && config(option)) {
|
||||
const [cancel, to] = message(title, to, names.map(encode));
|
||||
|
||||
if (!cancel)
|
||||
ask(to);
|
||||
}
|
||||
|
||||
ask(to);
|
||||
|
||||
|
|
@ -492,7 +496,7 @@ function twopack(operation, type) {
|
|||
});
|
||||
}
|
||||
|
||||
function message(msg, to, names) {
|
||||
async function message(msg, to, names) {
|
||||
const n = names.length;
|
||||
const [name] = names;
|
||||
|
||||
|
|
@ -505,9 +509,7 @@ function message(msg, to, names) {
|
|||
|
||||
msg += ' to';
|
||||
|
||||
const cancel = false;
|
||||
|
||||
return Dialog.prompt(msg, to, {cancel});
|
||||
return Dialog.prompt(msg, to);
|
||||
}
|
||||
|
||||
function load(callback) {
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ module.exports = (options) => (emitter) => {
|
|||
callback();
|
||||
},
|
||||
|
||||
error: (error) => {
|
||||
error: async (error) => {
|
||||
lastError = error;
|
||||
|
||||
if (noContinue) {
|
||||
|
|
@ -71,13 +71,13 @@ module.exports = (options) => (emitter) => {
|
|||
return;
|
||||
}
|
||||
|
||||
Dialog.confirm(error + '\n Continue?')
|
||||
.then(() => {
|
||||
emitter.continue();
|
||||
}, () => {
|
||||
emitter.abort();
|
||||
progress.remove();
|
||||
});
|
||||
const [cancel] = await Dialog.confirm(error + '\n Continue?');
|
||||
|
||||
if (!cancel)
|
||||
emitter.continue();
|
||||
|
||||
emitter.abort();
|
||||
progress.remove();
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue