From fad48b0d0980576c2621472c27f05f8e09366918 Mon Sep 17 00:00:00 2001 From: Mike Sawka Date: Mon, 8 Jan 2024 22:59:17 -0800 Subject: [PATCH] bind cmd-w to delete a screen (with a confirm message). also fix 'esc' so it closes the alert modal with a 'cancel' (#215) --- src/app/common/modals/modals.tsx | 4 ++-- src/app/common/modals/settings.tsx | 4 ++-- src/model/model.ts | 23 +++++++++++++++++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/app/common/modals/modals.tsx b/src/app/common/modals/modals.tsx index 7b15fda7..7d995d73 100644 --- a/src/app/common/modals/modals.tsx +++ b/src/app/common/modals/modals.tsx @@ -235,10 +235,10 @@ class AlertModal extends React.Component<{}, {}> { - + - + diff --git a/src/app/common/modals/settings.tsx b/src/app/common/modals/settings.tsx index e02117eb..3718a838 100644 --- a/src/app/common/modals/settings.tsx +++ b/src/app/common/modals/settings.tsx @@ -228,7 +228,7 @@ class ScreenSettingsModal extends React.Component<{}, {}> { return; } if (this.screen.getScreenLines().lines.length == 0) { - GlobalCommandRunner.screenDelete(this.screenId); + GlobalCommandRunner.screenDelete(this.screenId, false); GlobalModel.modalsModel.popModal(); return; } @@ -238,7 +238,7 @@ class ScreenSettingsModal extends React.Component<{}, {}> { if (!result) { return; } - let prtn = GlobalCommandRunner.screenDelete(this.screenId); + let prtn = GlobalCommandRunner.screenDelete(this.screenId, false); commandRtnHandler(prtn, this.errorMessage); GlobalModel.modalsModel.popModal(); }); diff --git a/src/model/model.ts b/src/model/model.ts index a85f9724..8a8cb7fa 100644 --- a/src/model/model.ts +++ b/src/model/model.ts @@ -200,6 +200,7 @@ type ElectronApi = { onLCmd: (callback: (mods: KeyModsType) => void) => void; onHCmd: (callback: (mods: KeyModsType) => void) => void; onPCmd: (callback: (mods: KeyModsType) => void) => void; + onWCmd: (callback: (mods: KeyModsType) => void) => void; onMenuItemAbout: (callback: () => void) => void; onMetaArrowUp: (callback: () => void) => void; onMetaArrowDown: (callback: () => void) => void; @@ -3216,6 +3217,7 @@ class Model { getApi().onLCmd(this.onLCmd.bind(this)); getApi().onHCmd(this.onHCmd.bind(this)); getApi().onPCmd(this.onPCmd.bind(this)); + getApi().onWCmd(this.onWCmd.bind(this)); getApi().onMenuItemAbout(this.onMenuItemAbout.bind(this)); getApi().onMetaArrowUp(this.onMetaArrowUp.bind(this)); getApi().onMetaArrowDown(this.onMetaArrowDown.bind(this)); @@ -3460,6 +3462,23 @@ class Model { return true; } + onWCmd(e: any, mods: KeyModsType) { + let activeScreen = this.getActiveScreen(); + if (activeScreen == null) { + return; + } + let rtnp = this.showAlert({ + message: "Are you sure you want to delete this screen?", + confirm: true, + }); + rtnp.then((result) => { + if (!result) { + return; + } + GlobalCommandRunner.screenDelete(activeScreen.screenId, true); + }); + } + clearModals(): boolean { let didSomething = false; mobx.action(() => { @@ -4395,8 +4414,8 @@ class CommandRunner { ); } - screenDelete(screenId: string): Promise { - return GlobalModel.submitCommand("screen", "delete", [screenId], { nohist: "1" }, false); + screenDelete(screenId: string, interactive: boolean): Promise { + return GlobalModel.submitCommand("screen", "delete", [screenId], { nohist: "1" }, interactive); } screenWebShare(screenId: string, shouldShare: boolean): Promise {