feature(dialog) cancel -> tryToCatch

This commit is contained in:
coderaiser 2019-05-22 12:59:06 +03:00
parent 7e98ad725d
commit ef38bd7aa3
7 changed files with 58 additions and 47 deletions

View file

@ -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) {

View file

@ -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();
},
};