From 0b0873262cc0cee819a56ae357d8fb4c3ecd8fa2 Mon Sep 17 00:00:00 2001 From: akshay1992kalbhor Date: Tue, 22 Jun 2021 14:28:02 +0530 Subject: [PATCH] Add support for closing document tabs (#215) * Can only remove last document successfully * Correctly update the layer tree panel * Remove comments * Add support for randomly closing docs * Create new doc after closing last doc * Update layer panel when creating new docs * Fix bug that crashed the program when first doc was closed * Refactor to make code simpler and increase readability * Add shortcut to close active doc (Shift + C) * Add a confirmation dialog box before closing tabs * New docs get the correct title * Remove comments and fix typos * Disable 'eslint-no-alert' * Refactor and fix document title bug * Rename the FrontendMessage and ReponseType for showing close confirmation modal * Change the message displayed in the close confirmation modal Co-authored-by: Keavon Chambers --- client/web/src/components/workspace/Panel.vue | 14 +++- .../src/components/workspace/Workspace.vue | 9 ++- client/web/src/response-handler.ts | 13 +++ client/web/wasm/src/document.rs | 5 ++ .../src/document/document_message_handler.rs | 79 ++++++++++++++++++- .../src/frontend/frontend_message_handler.rs | 2 + core/editor/src/input/input_mapper.rs | 1 + 7 files changed, 118 insertions(+), 5 deletions(-) diff --git a/client/web/src/components/workspace/Panel.vue b/client/web/src/components/workspace/Panel.vue index dc167abf7..5b59705a3 100644 --- a/client/web/src/components/workspace/Panel.vue +++ b/client/web/src/components/workspace/Panel.vue @@ -4,7 +4,7 @@
{{ tabLabel }} - +
@@ -143,6 +143,7 @@ import Minimap from "../panels/Minimap.vue"; import IconButton from "../widgets/buttons/IconButton.vue"; import PopoverButton, { PopoverButtonIcon } from "../widgets/buttons/PopoverButton.vue"; import { MenuDirection } from "../widgets/floating-menus/FloatingMenu.vue"; +import { ResponseType, registerResponseHandler, Response } from "../../response-handler"; const wasm = import("../../../wasm/pkg"); @@ -160,6 +161,17 @@ export default defineComponent({ const { select_document } = await wasm; select_document(tabIndex); }, + async closeTab(tabIndex: number) { + const { close_document } = await wasm; + // eslint-disable-next-line no-alert + const result = window.confirm("Closing this document will permanently discard all work. Continue?"); + if (result) close_document(tabIndex); + }, + }, + mounted() { + registerResponseHandler(ResponseType.PromptCloseConfirmationModal, (_responseData: Response) => { + this.closeTab(this.tabActiveIndex); + }); }, props: { tabMinWidths: { type: Boolean, default: false }, diff --git a/client/web/src/components/workspace/Workspace.vue b/client/web/src/components/workspace/Workspace.vue index 2c966d556..b7f3315e5 100644 --- a/client/web/src/components/workspace/Workspace.vue +++ b/client/web/src/components/workspace/Workspace.vue @@ -46,7 +46,7 @@