diff --git a/editor/src/messages/portfolio/document/document_message.rs b/editor/src/messages/portfolio/document/document_message.rs index 6c66a027..67ee5aa7 100644 --- a/editor/src/messages/portfolio/document/document_message.rs +++ b/editor/src/messages/portfolio/document/document_message.rs @@ -47,6 +47,7 @@ pub enum DocumentMessage { aggregate: AlignAggregate, }, BooleanOperation(BooleanOperationType), + ClearLayerTree, CommitTransaction, CreateEmptyFolder { container_path: Vec, diff --git a/editor/src/messages/portfolio/document/document_message_handler.rs b/editor/src/messages/portfolio/document/document_message_handler.rs index 8c90ff27..a7a86d8d 100644 --- a/editor/src/messages/portfolio/document/document_message_handler.rs +++ b/editor/src/messages/portfolio/document/document_message_handler.rs @@ -243,6 +243,20 @@ impl MessageHandler { + // Send an empty layer tree + let data_buffer: RawBuffer = Self::default().serialize_root().into(); + responses.push_back(FrontendMessage::UpdateDocumentLayerTreeStructure { data_buffer }.into()); + + // Clear the options bar + responses.push_back( + LayoutMessage::SendLayout { + layout: Layout::WidgetLayout(Default::default()), + layout_target: LayoutTarget::LayerTreeOptions, + } + .into(), + ); + } CommitTransaction => (), CreateEmptyFolder { mut container_path } => { let id = generate_uuid(); diff --git a/editor/src/messages/portfolio/portfolio_message.rs b/editor/src/messages/portfolio/portfolio_message.rs index 7e2b8f55..bae83bfa 100644 --- a/editor/src/messages/portfolio/portfolio_message.rs +++ b/editor/src/messages/portfolio/portfolio_message.rs @@ -45,6 +45,9 @@ pub enum PortfolioMessage { Cut { clipboard: Clipboard, }, + DeleteDocument { + document_id: u64, + }, DestroyAllDocuments, FontLoaded { font_family: String, diff --git a/editor/src/messages/portfolio/portfolio_message_handler.rs b/editor/src/messages/portfolio/portfolio_message_handler.rs index 1abfdc23..5950ec67 100644 --- a/editor/src/messages/portfolio/portfolio_message_handler.rs +++ b/editor/src/messages/portfolio/portfolio_message_handler.rs @@ -91,6 +91,10 @@ impl MessageHandler { - let document_index = self.document_index(document_id); - self.documents.remove(&document_id); - self.document_ids.remove(document_index); - - if self.document_ids.is_empty() { - self.active_document_id = None; - } else if self.active_document_id.is_some() { - let document_id = if document_index == self.document_ids.len() { - // If we closed the last document take the one previous (same as last) - *self.document_ids.last().unwrap() - } else { - // Move to the next tab - self.document_ids[document_index] - }; - responses.push_back(PortfolioMessage::SelectDocument { document_id }.into()); + // Is this the last document? + if self.documents.len() == 1 && self.document_ids[0] == document_id { + // Clear properties panel and layer tree + responses.push_back(PropertiesPanelMessage::ClearSelection.into()); + responses.push_back(DocumentMessage::ClearLayerTree.into()); } + // Actually delete the document (delay to delete document is required to let the document and properties panel messages above get processed) + responses.push_back(PortfolioMessage::DeleteDocument { document_id }.into()); // Send the new list of document tab names responses.push_back(PortfolioMessage::UpdateOpenDocumentsList.into()); @@ -178,6 +174,24 @@ impl MessageHandler { + let document_index = self.document_index(document_id); + self.documents.remove(&document_id); + self.document_ids.remove(document_index); + + if self.document_ids.is_empty() { + self.active_document_id = None; + } else if self.active_document_id.is_some() { + let document_id = if document_index == self.document_ids.len() { + // If we closed the last document take the one previous (same as last) + *self.document_ids.last().unwrap() + } else { + // Move to the next tab + self.document_ids[document_index] + }; + responses.push_back(PortfolioMessage::SelectDocument { document_id }.into()); + } + } PortfolioMessage::DestroyAllDocuments => { // Empty the list of internal document data self.documents.clear();