diff --git a/client/dom/dialog.js b/client/dom/dialog.js index 904e9f4f..13b36b2a 100644 --- a/client/dom/dialog.js +++ b/client/dom/dialog.js @@ -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!', { diff --git a/client/dom/index.js b/client/dom/index.js index e89891bc..e731c893 100644 --- a/client/dom/index.js +++ b/client/dom/index.js @@ -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 = () => { diff --git a/client/dom/select-by-pattern.js b/client/dom/select-by-pattern.js index 32469b34..b64a77dd 100644 --- a/client/dom/select-by-pattern.js +++ b/client/dom/select-by-pattern.js @@ -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) { diff --git a/client/modules/edit-file.js b/client/modules/edit-file.js index a91f901c..941b88d1 100644 --- a/client/modules/edit-file.js +++ b/client/modules/edit-file.js @@ -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(); } diff --git a/client/modules/edit-names.js b/client/modules/edit-names.js index 117cb49d..90bfc59a 100644 --- a/client/modules/edit-names.js +++ b/client/modules/edit-names.js @@ -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); diff --git a/client/modules/operation/index.js b/client/modules/operation/index.js index cbbd82e2..875f3ddb 100644 --- a/client/modules/operation/index.js +++ b/client/modules/operation/index.js @@ -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) { diff --git a/client/modules/operation/set-listeners.js b/client/modules/operation/set-listeners.js index 71d7b64e..2b773050 100644 --- a/client/modules/operation/set-listeners.js +++ b/client/modules/operation/set-listeners.js @@ -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(); }, };