diff --git a/editor/src/communication/dispatcher.rs b/editor/src/communication/dispatcher.rs index 34f881e5..1367d136 100644 --- a/editor/src/communication/dispatcher.rs +++ b/editor/src/communication/dispatcher.rs @@ -24,8 +24,8 @@ pub struct Dispatcher { const SIDE_EFFECT_FREE_MESSAGES: &[MessageDiscriminant] = &[ MessageDiscriminant::Portfolio(PortfolioMessageDiscriminant::Document(DocumentMessageDiscriminant::RenderDocument)), MessageDiscriminant::Portfolio(PortfolioMessageDiscriminant::Document(DocumentMessageDiscriminant::FolderChanged)), - MessageDiscriminant::Frontend(FrontendMessageDiscriminant::UpdateLayer), - MessageDiscriminant::Frontend(FrontendMessageDiscriminant::DisplayFolderTreeStructure), + MessageDiscriminant::Frontend(FrontendMessageDiscriminant::UpdateDocumentLayer), + MessageDiscriminant::Frontend(FrontendMessageDiscriminant::DisplayDocumentLayerTreeStructure), MessageDiscriminant::Frontend(FrontendMessageDiscriminant::UpdateOpenDocumentsList), MessageDiscriminant::Tool(ToolMessageDiscriminant::DocumentIsDirty), ]; @@ -78,7 +78,7 @@ impl Dispatcher { if log::max_level() == log::LevelFilter::Trace && !(matches!( message, - InputPreprocessor(_) | Frontend(FrontendMessage::SetCanvasZoom { .. }) | Frontend(FrontendMessage::SetCanvasRotation { .. }) + InputPreprocessor(_) | Frontend(FrontendMessage::UpdateCanvasZoom { .. }) | Frontend(FrontendMessage::UpdateCanvasRotation { .. }) ) || MessageDiscriminant::from(message).local_name().ends_with("MouseMove")) { log::trace!("Message: {:?}", message); diff --git a/editor/src/document/artboard_message_handler.rs b/editor/src/document/artboard_message_handler.rs index a113b7e0..017bc79d 100644 --- a/editor/src/document/artboard_message_handler.rs +++ b/editor/src/document/artboard_message_handler.rs @@ -68,14 +68,14 @@ impl MessageHandler"##.to_string(), } .into(), ) } else { responses.push_back( - FrontendMessage::UpdateArtboards { + FrontendMessage::UpdateDocumentArtboards { svg: self.artboards_graphene_document.render_root(ViewMode::Normal), } .into(), diff --git a/editor/src/document/document_message_handler.rs b/editor/src/document/document_message_handler.rs index c9e99052..e4587d21 100644 --- a/editor/src/document/document_message_handler.rs +++ b/editor/src/document/document_message_handler.rs @@ -243,7 +243,7 @@ impl DocumentMessageHandler { if let Some(layer) = self.layer_metadata.get_mut(path) { layer.selected = true; let data = self.layer_panel_entry(path.to_vec()).ok()?; - (!path.is_empty()).then(|| FrontendMessage::UpdateLayer { data }.into()) + (!path.is_empty()).then(|| FrontendMessage::UpdateDocumentLayer { data }.into()) } else { log::warn!("Tried to select non existing layer {:?}", path); None @@ -594,7 +594,7 @@ impl MessageHandler for DocumentMessageHand false => self.name.clone() + FILE_EXPORT_SUFFIX, }; responses.push_back( - FrontendMessage::ExportDocument { + FrontendMessage::TriggerFileDownload { document: format!( r#"{}{}"#, bbox[0].x, @@ -620,7 +620,7 @@ impl MessageHandler for DocumentMessageHand false => self.name.clone() + FILE_SAVE_SUFFIX, }; responses.push_back( - FrontendMessage::SaveDocument { + FrontendMessage::TriggerFileDownload { document: self.serialize_document(), name, } @@ -830,11 +830,11 @@ impl MessageHandler for DocumentMessageHand } DocumentStructureChanged => { let data_buffer: RawBuffer = self.serialize_root().into(); - responses.push_back(FrontendMessage::DisplayFolderTreeStructure { data_buffer }.into()) + responses.push_back(FrontendMessage::DisplayDocumentLayerTreeStructure { data_buffer }.into()) } LayerChanged(path) => { if let Ok(layer_entry) = self.layer_panel_entry(path) { - responses.push_back(FrontendMessage::UpdateLayer { data: layer_entry }.into()); + responses.push_back(FrontendMessage::UpdateDocumentLayer { data: layer_entry }.into()); } } DispatchOperation(op) => match self.graphene_document.handle_operation(&op) { @@ -866,7 +866,7 @@ impl MessageHandler for DocumentMessageHand }, RenderDocument => { responses.push_back( - FrontendMessage::UpdateArtwork { + FrontendMessage::UpdateDocumentArtwork { svg: self.graphene_document.render_root(self.view_mode), } .into(), @@ -892,7 +892,7 @@ impl MessageHandler for DocumentMessageHand let ruler_origin = self.graphene_document.root.transform.transform_point2(DVec2::ZERO); responses.push_back( - FrontendMessage::UpdateScrollbars { + FrontendMessage::UpdateDocumentScrollbars { position: scrollbar_position.into(), size: scrollbar_size.into(), multiplier: scrollbar_multiplier.into(), @@ -901,7 +901,7 @@ impl MessageHandler for DocumentMessageHand ); responses.push_back( - FrontendMessage::UpdateRulers { + FrontendMessage::UpdateDocumentRulers { origin: ruler_origin.into(), spacing: ruler_spacing, interval: ruler_interval, diff --git a/editor/src/document/movement_handler.rs b/editor/src/document/movement_handler.rs index aebf5301..f5c9e6ac 100644 --- a/editor/src/document/movement_handler.rs +++ b/editor/src/document/movement_handler.rs @@ -235,7 +235,7 @@ impl MessageHandler for Moveme } SetCanvasZoom(new) => { self.zoom = new.clamp(VIEWPORT_ZOOM_SCALE_MIN, VIEWPORT_ZOOM_SCALE_MAX); - responses.push_back(FrontendMessage::SetCanvasZoom { new_zoom: self.snapped_scale() }.into()); + responses.push_back(FrontendMessage::UpdateCanvasZoom { factor: self.snapped_scale() }.into()); responses.push_back(ToolMessage::DocumentIsDirty.into()); responses.push_back(DocumentMessage::DirtyRenderDocumentInOutlineView.into()); self.create_document_transform(&ipp.viewport_bounds, responses); @@ -275,7 +275,7 @@ impl MessageHandler for Moveme self.tilt = new_radians; self.create_document_transform(&ipp.viewport_bounds, responses); responses.push_back(ToolMessage::DocumentIsDirty.into()); - responses.push_back(FrontendMessage::SetCanvasRotation { new_radians: self.snapped_angle() }.into()); + responses.push_back(FrontendMessage::UpdateCanvasRotation { angle_radians: self.snapped_angle() }.into()); } FitViewportToBounds { bounds: [bounds_corner_a, bounds_corner_b], @@ -301,7 +301,7 @@ impl MessageHandler for Moveme self.zoom = 1. } - responses.push_back(FrontendMessage::SetCanvasZoom { new_zoom: self.zoom }.into()); + responses.push_back(FrontendMessage::UpdateCanvasZoom { factor: self.zoom }.into()); responses.push_back(ToolMessage::DocumentIsDirty.into()); responses.push_back(DocumentMessage::DirtyRenderDocumentInOutlineView.into()); self.create_document_transform(&ipp.viewport_bounds, responses); diff --git a/editor/src/document/overlay_message_handler.rs b/editor/src/document/overlay_message_handler.rs index 27d62641..b42064e2 100644 --- a/editor/src/document/overlay_message_handler.rs +++ b/editor/src/document/overlay_message_handler.rs @@ -41,7 +41,7 @@ impl MessageHandler>(), ); @@ -181,7 +181,7 @@ impl MessageHandler for PortfolioMessageHa use PortfolioMessage::*; match message { RequestAboutGraphiteDialog => { - responses.push_back(FrontendMessage::DisplayAboutGraphiteDialog.into()); + responses.push_back(FrontendMessage::DisplayDialogAboutGraphite.into()); } Document(message) => self.active_document_mut().process_action(message, ipp, responses), SelectDocument(id) => { @@ -190,7 +190,7 @@ impl MessageHandler for PortfolioMessageHa responses.push_back(PortfolioMessage::AutoSaveDocument(self.active_document_id).into()); } self.active_document_id = id; - responses.push_back(FrontendMessage::SetActiveDocument { document_id: id }.into()); + responses.push_back(FrontendMessage::UpdateActiveDocument { document_id: id }.into()); responses.push_back(RenderDocument.into()); responses.push_back(DocumentMessage::DocumentStructureChanged.into()); for layer in self.active_document().layer_metadata.keys() { @@ -259,8 +259,8 @@ impl MessageHandler for PortfolioMessageHa .collect::>(); responses.push_back(FrontendMessage::UpdateOpenDocumentsList { open_documents }.into()); - responses.push_back(FrontendMessage::SetActiveDocument { document_id: self.active_document_id }.into()); - responses.push_back(FrontendMessage::RemoveAutoSaveDocument { document_id: id }.into()); + responses.push_back(FrontendMessage::UpdateActiveDocument { document_id: self.active_document_id }.into()); + responses.push_back(FrontendMessage::TriggerIndexedDbRemoveDocument { document_id: id }.into()); responses.push_back(RenderDocument.into()); responses.push_back(DocumentMessage::DocumentStructureChanged.into()); for layer in self.active_document().layer_metadata.keys() { @@ -275,7 +275,7 @@ impl MessageHandler for PortfolioMessageHa self.load_document(new_document, document_id, false, responses); } OpenDocument => { - responses.push_back(FrontendMessage::OpenDocumentBrowse.into()); + responses.push_back(FrontendMessage::TriggerFileUpload.into()); } OpenDocumentFile(document_name, document) => { responses.push_back( @@ -301,7 +301,7 @@ impl MessageHandler for PortfolioMessageHa self.load_document(document, document_id, true, responses); } Err(e) => responses.push_back( - FrontendMessage::DisplayError { + FrontendMessage::DisplayDialogError { title: "Failed to open document".to_string(), description: e.to_string(), } @@ -327,7 +327,7 @@ impl MessageHandler for PortfolioMessageHa AutoSaveDocument(id) => { let document = self.documents.get(&id).unwrap(); responses.push_back( - FrontendMessage::AutoSaveDocument { + FrontendMessage::TriggerIndexedDbWriteDocument { document: document.serialize_document(), details: FrontendDocumentDetails { is_saved: document.is_saved(), diff --git a/editor/src/frontend/frontend_message_handler.rs b/editor/src/frontend/frontend_message_handler.rs index 412715c1..e1b17e25 100644 --- a/editor/src/frontend/frontend_message_handler.rs +++ b/editor/src/frontend/frontend_message_handler.rs @@ -15,28 +15,30 @@ pub struct FrontendDocumentDetails { #[impl_message(Message, Frontend)] #[derive(PartialEq, Clone, Deserialize, Serialize, Debug)] pub enum FrontendMessage { - DisplayFolderTreeStructure { data_buffer: RawBuffer }, - SetActiveTool { tool_name: String, tool_options: Option }, - SetActiveDocument { document_id: u64 }, + // Display prefix: make the frontend show something, like a dialog + // Update prefix: give the frontend a new value or state for it to use + // Trigger prefix: cause a browser API to do something + DisplayDocumentLayerTreeStructure { data_buffer: RawBuffer }, + UpdateActiveTool { tool_name: String, tool_options: Option }, + UpdateActiveDocument { document_id: u64 }, UpdateOpenDocumentsList { open_documents: Vec }, UpdateInputHints { hint_data: HintData }, - DisplayError { title: String, description: String }, - DisplayPanic { panic_info: String, title: String, description: String }, + DisplayDialogError { title: String, description: String }, + DisplayDialogPanic { panic_info: String, title: String, description: String }, DisplayConfirmationToCloseDocument { document_id: u64 }, DisplayConfirmationToCloseAllDocuments, - DisplayAboutGraphiteDialog, - UpdateLayer { data: LayerPanelEntry }, - UpdateArtwork { svg: String }, - UpdateOverlays { svg: String }, - UpdateArtboards { svg: String }, - UpdateScrollbars { position: (f64, f64), size: (f64, f64), multiplier: (f64, f64) }, - UpdateRulers { origin: (f64, f64), spacing: f64, interval: f64 }, - ExportDocument { document: String, name: String }, - SaveDocument { document: String, name: String }, - AutoSaveDocument { document: String, details: FrontendDocumentDetails, version: String }, - RemoveAutoSaveDocument { document_id: u64 }, - OpenDocumentBrowse, + DisplayDialogAboutGraphite, + UpdateDocumentLayer { data: LayerPanelEntry }, + UpdateDocumentArtwork { svg: String }, + UpdateDocumentOverlays { svg: String }, + UpdateDocumentArtboards { svg: String }, + UpdateDocumentScrollbars { position: (f64, f64), size: (f64, f64), multiplier: (f64, f64) }, + UpdateDocumentRulers { origin: (f64, f64), spacing: f64, interval: f64 }, + TriggerFileUpload, + TriggerFileDownload { document: String, name: String }, + TriggerIndexedDbWriteDocument { document: String, details: FrontendDocumentDetails, version: String }, + TriggerIndexedDbRemoveDocument { document_id: u64 }, UpdateWorkingColors { primary: Color, secondary: Color }, - SetCanvasZoom { new_zoom: f64 }, - SetCanvasRotation { new_radians: f64 }, + UpdateCanvasZoom { factor: f64 }, + UpdateCanvasRotation { angle_radians: f64 }, } diff --git a/editor/src/input/input_mapper.rs b/editor/src/input/input_mapper.rs index 1fc87a8c..d1286839 100644 --- a/editor/src/input/input_mapper.rs +++ b/editor/src/input/input_mapper.rs @@ -219,7 +219,7 @@ impl Default for Mapping { entry! {action=ToolMessage::ResetColors, key_down=KeyX, modifiers=[KeyShift, KeyControl]}, entry! {action=ToolMessage::SwapColors, key_down=KeyX, modifiers=[KeyShift]}, // Editor Actions - entry! {action=FrontendMessage::OpenDocumentBrowse, key_down=KeyO, modifiers=[KeyControl]}, + entry! {action=FrontendMessage::TriggerFileUpload, key_down=KeyO, modifiers=[KeyControl]}, // Document Actions entry! {action=PortfolioMessage::Paste(User), key_down=KeyV, modifiers=[KeyControl]}, entry! {action=DocumentMessage::Redo, key_down=KeyZ, modifiers=[KeyControl, KeyShift]}, diff --git a/editor/src/tool/tool_message_handler.rs b/editor/src/tool/tool_message_handler.rs index b67294b4..563a95a0 100644 --- a/editor/src/tool/tool_message_handler.rs +++ b/editor/src/tool/tool_message_handler.rs @@ -105,7 +105,7 @@ impl MessageHandler // Notify the frontend about the new active tool to be displayed let tool_name = new_tool.to_string(); let tool_options = self.tool_state.document_tool_data.tool_options.get(&new_tool).copied(); - responses.push_back(FrontendMessage::SetActiveTool { tool_name, tool_options }.into()); + responses.push_back(FrontendMessage::UpdateActiveTool { tool_name, tool_options }.into()); } DocumentIsDirty => { // Send the DocumentIsDirty message to the active tool's sub-tool message handler diff --git a/frontend/src/components/panels/Document.vue b/frontend/src/components/panels/Document.vue index 0e8c19a4..9153c6cb 100644 --- a/frontend/src/components/panels/Document.vue +++ b/frontend/src/components/panels/Document.vue @@ -251,7 +251,17 @@