From ad0a40e512044ba9141781ca4bae3ed30f62eb2f Mon Sep 17 00:00:00 2001 From: George Atkinson Date: Mon, 14 Jun 2021 04:24:09 +0100 Subject: [PATCH] Multi-document management (create new document; tab switching) (#210) * Multi-docs WIP * Change to number * Add new document and switch documents * Remove keybind for previous document. Change keybind for next document. * Switch documents by clicking tabs * Remove keybind for previous document. Change keybind for next document. * multi-docs * Update package-lock.json * Hook up File>New to add new document * Remove console logs and empty lines. Start new documents from 2 instead of 1. * Fix formatting --- .../widgets/inputs/MenuBarInput.vue | 2 +- client/web/src/components/workspace/Panel.vue | 10 +++- .../src/components/workspace/Workspace.vue | 28 +++++++--- client/web/src/response-handler.ts | 24 +++++++++ client/web/wasm/src/document.rs | 10 ++++ client/web/wasm/src/wrappers.rs | 1 + core/editor/src/document/document_file.rs | 12 ++++- .../src/document/document_message_handler.rs | 52 ++++++++++++++++++- .../src/frontend/frontend_message_handler.rs | 3 ++ core/editor/src/input/input_mapper.rs | 2 + core/editor/src/input/keyboard.rs | 1 + 11 files changed, 133 insertions(+), 12 deletions(-) diff --git a/client/web/src/components/widgets/inputs/MenuBarInput.vue b/client/web/src/components/widgets/inputs/MenuBarInput.vue index 6fe09727..1def90c4 100644 --- a/client/web/src/components/widgets/inputs/MenuBarInput.vue +++ b/client/web/src/components/widgets/inputs/MenuBarInput.vue @@ -73,7 +73,7 @@ const menuEntries: MenuListEntries = [ ref: undefined, children: [ [ - { label: "New", icon: "File", shortcut: ["Ctrl", "N"] }, + { label: "New", icon: "File", shortcut: ["Ctrl", "N"], action: async () => (await wasm).new_document() }, { label: "Open…", shortcut: ["Ctrl", "O"] }, { label: "Open Recent", diff --git a/client/web/src/components/workspace/Panel.vue b/client/web/src/components/workspace/Panel.vue index acf42993..dc167abf 100644 --- a/client/web/src/components/workspace/Panel.vue +++ b/client/web/src/components/workspace/Panel.vue @@ -2,7 +2,7 @@
-
+
{{ tabLabel }}
@@ -144,6 +144,8 @@ import IconButton from "../widgets/buttons/IconButton.vue"; import PopoverButton, { PopoverButtonIcon } from "../widgets/buttons/PopoverButton.vue"; import { MenuDirection } from "../widgets/floating-menus/FloatingMenu.vue"; +const wasm = import("../../../wasm/pkg"); + export default defineComponent({ components: { Document, @@ -153,6 +155,12 @@ export default defineComponent({ IconButton, PopoverButton, }, + methods: { + async handleTabClick(tabIndex: number) { + const { select_document } = await wasm; + select_document(tabIndex); + }, + }, props: { tabMinWidths: { type: Boolean, default: false }, tabCloseButtons: { type: Boolean, default: false }, diff --git a/client/web/src/components/workspace/Workspace.vue b/client/web/src/components/workspace/Workspace.vue index 07c62a6b..2c966d55 100644 --- a/client/web/src/components/workspace/Workspace.vue +++ b/client/web/src/components/workspace/Workspace.vue @@ -1,13 +1,7 @@