From e0146d57f79d5009e6c14541038b58984771621f Mon Sep 17 00:00:00 2001 From: kadir <30541839+auto-kad@users.noreply.github.com> Date: Sat, 28 Jan 2023 18:32:31 -0500 Subject: [PATCH] Update UI when deleting last point of shape with Path tool (#979) * Added new DocumentResponse variant * Update Operation::DeleteSelectedManipulatorPoints to update Layer Tree by delegating deletion to Operation::DeleteLayer. Also emits Operation::DeletedSelectedManipulatorPoints to let editor clear Properties panel * Update process_message() to deal with new DocumentResponse::DeletedSelectedManipulatorPoints match case. When this DocumentResponse is emitted, it clears the Properties panel. * Added Display trait implementation for DocumentResponse::DeletedSelectedManipulatorPoints. Updated imports in document_message_handler.rs to get the correct types for messages emitted from DocumentResponse::DeletedSelectedManipulatorPoints match case in process_message(). * Removed useless import. Capitalized comments for style consistency. * Updated messages emitted to clear Properties panel by emitting LayoutMessage::SendLayout's instead, which update the backend widget state * Revert inclusion of unused imports --------- Co-authored-by: Keavon Chambers --- document-legacy/src/document.rs | 14 ++++++++++---- document-legacy/src/response.rs | 2 ++ .../document/document_message_handler.rs | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/document-legacy/src/document.rs b/document-legacy/src/document.rs index 07f64175..e900aebf 100644 --- a/document-legacy/src/document.rs +++ b/document-legacy/src/document.rs @@ -1098,10 +1098,16 @@ impl Document { // Delete the layer if there are no longer any manipulator groups if (shape.manipulator_groups().len() - 1) == 0 { - self.delete(&layer_path)?; - responses.push(DocumentChanged); - responses.push(DocumentResponse::DeletedLayer { path: layer_path }); - return Ok(Some(responses)); + // Delegate deletion to DeleteLayer to update Layer Tree in frontend + match self.handle_operation(Operation::DeleteLayer { path: layer_path.clone() }, font_cache) { + Ok(Some(delete_responses)) => { + responses.extend(delete_responses); + responses.push(DocumentResponse::DeletedSelectedManipulatorPoints); + return Ok(Some(responses)); + } + Err(e) => error!("DocumentError: {:?}", e), + Ok(_) => {} + } } // If we still have manipulator groups, update the layer and thumbnails diff --git a/document-legacy/src/response.rs b/document-legacy/src/response.rs index 979ddddf..3d1537dd 100644 --- a/document-legacy/src/response.rs +++ b/document-legacy/src/response.rs @@ -21,6 +21,7 @@ pub enum DocumentResponse { LayerChanged { path: Vec, }, + DeletedSelectedManipulatorPoints, } impl fmt::Display for DocumentResponse { @@ -31,6 +32,7 @@ impl fmt::Display for DocumentResponse { DocumentResponse::CreatedLayer { .. } => write!(f, "CreatedLayer"), DocumentResponse::LayerChanged { .. } => write!(f, "LayerChanged"), DocumentResponse::DeletedLayer { .. } => write!(f, "DeleteLayer"), + DocumentResponse::DeletedSelectedManipulatorPoints { .. } => write!(f, "DeletedSelectedManipulatorPoints"), } } } diff --git a/editor/src/messages/portfolio/document/document_message_handler.rs b/editor/src/messages/portfolio/document/document_message_handler.rs index bcea8450..8972484e 100644 --- a/editor/src/messages/portfolio/document/document_message_handler.rs +++ b/editor/src/messages/portfolio/document/document_message_handler.rs @@ -143,6 +143,23 @@ impl MessageHandler responses.push_back(RenderDocument.into()), + DocumentResponse::DeletedSelectedManipulatorPoints => { + // Clear Properties panel after deleting all points by updating backend widget state. + responses.push_back( + LayoutMessage::SendLayout { + layout: Layout::WidgetLayout(WidgetLayout::new(vec![])), + layout_target: LayoutTarget::PropertiesOptions, + } + .into(), + ); + responses.push_back( + LayoutMessage::SendLayout { + layout: Layout::WidgetLayout(WidgetLayout::new(vec![])), + layout_target: LayoutTarget::PropertiesSections, + } + .into(), + ); + } }; responses.push_back(BroadcastEvent::DocumentIsDirty.into()); }