diff --git a/client/web/src/components/workspace/Workspace.vue b/client/web/src/components/workspace/Workspace.vue index 500de8cc..97f04e71 100644 --- a/client/web/src/components/workspace/Workspace.vue +++ b/client/web/src/components/workspace/Workspace.vue @@ -51,6 +51,8 @@ import LayoutRow from "../layout/LayoutRow.vue"; import LayoutCol from "../layout/LayoutCol.vue"; import Panel from "./Panel.vue"; +const wasm = import("@/../wasm/pkg"); + export default defineComponent({ components: { LayoutRow, @@ -69,12 +71,14 @@ export default defineComponent({ const documentData = responseData as SetActiveDocument; if (documentData) this.activeDocument = documentData.document_index; }); + + (async () => (await wasm).get_open_documents_list())(); }, data() { return { activeDocument: 0, - documents: ["Untitled Document"], // TODO: start as an empty list + documents: [] as Array, }; }, }); diff --git a/client/web/wasm/src/document.rs b/client/web/wasm/src/document.rs index fa28625e..2c80a6d5 100644 --- a/client/web/wasm/src/document.rs +++ b/client/web/wasm/src/document.rs @@ -28,6 +28,11 @@ pub fn select_document(document: usize) -> Result<(), JsValue> { EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::SelectDocument(document)).map_err(convert_error)) } +#[wasm_bindgen] +pub fn get_open_documents_list() -> Result<(), JsValue> { + EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::GetOpenDocumentsList).map_err(convert_error)) +} + #[wasm_bindgen] pub fn new_document() -> Result<(), JsValue> { EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::NewDocument).map_err(convert_error)) diff --git a/core/editor/src/document/document_message_handler.rs b/core/editor/src/document/document_message_handler.rs index 5aa3f791..62421312 100644 --- a/core/editor/src/document/document_message_handler.rs +++ b/core/editor/src/document/document_message_handler.rs @@ -35,6 +35,7 @@ pub enum DocumentMessage { CloseAllDocumentsWithConfirmation, CloseAllDocuments, NewDocument, + GetOpenDocumentsList, NextDocument, PrevDocument, ExportDocument, @@ -303,6 +304,11 @@ impl MessageHandler for DocumentMessageHand ); responses.push_back(SelectDocument(self.active_document_index).into()); } + GetOpenDocumentsList => { + // Send the list of document tab names + let open_documents = self.documents.iter().map(|doc| doc.name.clone()).collect(); + responses.push_back(FrontendMessage::UpdateOpenDocumentsList { open_documents }.into()); + } NextDocument => { let id = (self.active_document_index + 1) % self.documents.len(); responses.push_back(SelectDocument(id).into());