Make frontend request tab list on initialization
This commit is contained in:
parent
e7699bbcbd
commit
37e6335557
|
|
@ -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<string>,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ pub enum DocumentMessage {
|
|||
CloseAllDocumentsWithConfirmation,
|
||||
CloseAllDocuments,
|
||||
NewDocument,
|
||||
GetOpenDocumentsList,
|
||||
NextDocument,
|
||||
PrevDocument,
|
||||
ExportDocument,
|
||||
|
|
@ -303,6 +304,11 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> 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());
|
||||
|
|
|
|||
Loading…
Reference in New Issue