mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-29 06:28:12 +08:00
Make frontend request tab list on initialization
This commit is contained in:
@@ -51,6 +51,8 @@ import LayoutRow from "../layout/LayoutRow.vue";
|
|||||||
import LayoutCol from "../layout/LayoutCol.vue";
|
import LayoutCol from "../layout/LayoutCol.vue";
|
||||||
import Panel from "./Panel.vue";
|
import Panel from "./Panel.vue";
|
||||||
|
|
||||||
|
const wasm = import("@/../wasm/pkg");
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: {
|
components: {
|
||||||
LayoutRow,
|
LayoutRow,
|
||||||
@@ -69,12 +71,14 @@ export default defineComponent({
|
|||||||
const documentData = responseData as SetActiveDocument;
|
const documentData = responseData as SetActiveDocument;
|
||||||
if (documentData) this.activeDocument = documentData.document_index;
|
if (documentData) this.activeDocument = documentData.document_index;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
(async () => (await wasm).get_open_documents_list())();
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
activeDocument: 0,
|
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))
|
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]
|
#[wasm_bindgen]
|
||||||
pub fn new_document() -> Result<(), JsValue> {
|
pub fn new_document() -> Result<(), JsValue> {
|
||||||
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::NewDocument).map_err(convert_error))
|
EDITOR_STATE.with(|editor| editor.borrow_mut().handle_message(DocumentMessage::NewDocument).map_err(convert_error))
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ pub enum DocumentMessage {
|
|||||||
CloseAllDocumentsWithConfirmation,
|
CloseAllDocumentsWithConfirmation,
|
||||||
CloseAllDocuments,
|
CloseAllDocuments,
|
||||||
NewDocument,
|
NewDocument,
|
||||||
|
GetOpenDocumentsList,
|
||||||
NextDocument,
|
NextDocument,
|
||||||
PrevDocument,
|
PrevDocument,
|
||||||
ExportDocument,
|
ExportDocument,
|
||||||
@@ -303,6 +304,11 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
|||||||
);
|
);
|
||||||
responses.push_back(SelectDocument(self.active_document_index).into());
|
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 => {
|
NextDocument => {
|
||||||
let id = (self.active_document_index + 1) % self.documents.len();
|
let id = (self.active_document_index + 1) % self.documents.len();
|
||||||
responses.push_back(SelectDocument(id).into());
|
responses.push_back(SelectDocument(id).into());
|
||||||
|
|||||||
Reference in New Issue
Block a user