mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
Standardize FrontendMessage message names
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -68,14 +68,14 @@ impl MessageHandler<ArtboardMessage, (&mut LayerMetadata, &GrapheneDocument, &In
|
||||
// Render an infinite canvas if there are no artboards
|
||||
if self.artboard_ids.is_empty() {
|
||||
responses.push_back(
|
||||
FrontendMessage::UpdateArtboards {
|
||||
FrontendMessage::UpdateDocumentArtboards {
|
||||
svg: r##"<rect width="100%" height="100%" fill="#ffffff" />"##.to_string(),
|
||||
}
|
||||
.into(),
|
||||
)
|
||||
} else {
|
||||
responses.push_back(
|
||||
FrontendMessage::UpdateArtboards {
|
||||
FrontendMessage::UpdateDocumentArtboards {
|
||||
svg: self.artboards_graphene_document.render_root(ViewMode::Normal),
|
||||
}
|
||||
.into(),
|
||||
|
||||
@@ -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<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
||||
false => self.name.clone() + FILE_EXPORT_SUFFIX,
|
||||
};
|
||||
responses.push_back(
|
||||
FrontendMessage::ExportDocument {
|
||||
FrontendMessage::TriggerFileDownload {
|
||||
document: format!(
|
||||
r#"<svg xmlns="http://www.w3.org/2000/svg" viewBox="{} {} {} {}">{}{}</svg>"#,
|
||||
bbox[0].x,
|
||||
@@ -620,7 +620,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> 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<DocumentMessage, &InputPreprocessor> 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<DocumentMessage, &InputPreprocessor> 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<DocumentMessage, &InputPreprocessor> 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<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
||||
);
|
||||
|
||||
responses.push_back(
|
||||
FrontendMessage::UpdateRulers {
|
||||
FrontendMessage::UpdateDocumentRulers {
|
||||
origin: ruler_origin.into(),
|
||||
spacing: ruler_spacing,
|
||||
interval: ruler_interval,
|
||||
|
||||
@@ -235,7 +235,7 @@ impl MessageHandler<MovementMessage, (&Document, &InputPreprocessor)> 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<MovementMessage, (&Document, &InputPreprocessor)> 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<MovementMessage, (&Document, &InputPreprocessor)> 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);
|
||||
|
||||
@@ -41,7 +41,7 @@ impl MessageHandler<OverlayMessage, (&mut LayerMetadata, &Document, &InputPrepro
|
||||
|
||||
// Render overlays
|
||||
responses.push_back(
|
||||
FrontendMessage::UpdateOverlays {
|
||||
FrontendMessage::UpdateDocumentOverlays {
|
||||
svg: self.overlays_graphene_document.render_root(ViewMode::Normal),
|
||||
}
|
||||
.into(),
|
||||
|
||||
@@ -124,7 +124,7 @@ impl PortfolioMessageHandler {
|
||||
.layer_metadata
|
||||
.keys()
|
||||
.filter_map(|path| new_document.layer_panel_entry_from_path(path))
|
||||
.map(|entry| FrontendMessage::UpdateLayer { data: entry }.into())
|
||||
.map(|entry| FrontendMessage::UpdateDocumentLayer { data: entry }.into())
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
|
||||
@@ -181,7 +181,7 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessor> 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<PortfolioMessage, &InputPreprocessor> 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<PortfolioMessage, &InputPreprocessor> for PortfolioMessageHa
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
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<PortfolioMessage, &InputPreprocessor> 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<PortfolioMessage, &InputPreprocessor> 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<PortfolioMessage, &InputPreprocessor> 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(),
|
||||
|
||||
@@ -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<ToolOptions> },
|
||||
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<ToolOptions> },
|
||||
UpdateActiveDocument { document_id: u64 },
|
||||
UpdateOpenDocumentsList { open_documents: Vec<FrontendDocumentDetails> },
|
||||
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 },
|
||||
}
|
||||
|
||||
@@ -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]},
|
||||
|
||||
@@ -105,7 +105,7 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, &InputPreprocessor)>
|
||||
// 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
|
||||
|
||||
Reference in New Issue
Block a user