Skip to content

Commit e708588

Browse files
committed
Standardize FrontendMessage message names
1 parent 0b4934b commit e708588

17 files changed

Lines changed: 154 additions & 152 deletions

editor/src/communication/dispatcher.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ pub struct Dispatcher {
2424
const SIDE_EFFECT_FREE_MESSAGES: &[MessageDiscriminant] = &[
2525
MessageDiscriminant::Portfolio(PortfolioMessageDiscriminant::Document(DocumentMessageDiscriminant::RenderDocument)),
2626
MessageDiscriminant::Portfolio(PortfolioMessageDiscriminant::Document(DocumentMessageDiscriminant::FolderChanged)),
27-
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::UpdateLayer),
28-
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::DisplayFolderTreeStructure),
27+
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::UpdateDocumentLayer),
28+
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::DisplayDocumentLayerTreeStructure),
2929
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::UpdateOpenDocumentsList),
3030
MessageDiscriminant::Tool(ToolMessageDiscriminant::DocumentIsDirty),
3131
];
@@ -78,7 +78,7 @@ impl Dispatcher {
7878
if log::max_level() == log::LevelFilter::Trace
7979
&& !(matches!(
8080
message,
81-
InputPreprocessor(_) | Frontend(FrontendMessage::SetCanvasZoom { .. }) | Frontend(FrontendMessage::SetCanvasRotation { .. })
81+
InputPreprocessor(_) | Frontend(FrontendMessage::UpdateCanvasZoom { .. }) | Frontend(FrontendMessage::UpdateCanvasRotation { .. })
8282
) || MessageDiscriminant::from(message).local_name().ends_with("MouseMove"))
8383
{
8484
log::trace!("Message: {:?}", message);

editor/src/document/artboard_message_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@ impl MessageHandler<ArtboardMessage, (&mut LayerMetadata, &GrapheneDocument, &In
6868
// Render an infinite canvas if there are no artboards
6969
if self.artboard_ids.is_empty() {
7070
responses.push_back(
71-
FrontendMessage::UpdateArtboards {
71+
FrontendMessage::UpdateDocumentArtboards {
7272
svg: r##"<rect width="100%" height="100%" fill="#ffffff" />"##.to_string(),
7373
}
7474
.into(),
7575
)
7676
} else {
7777
responses.push_back(
78-
FrontendMessage::UpdateArtboards {
78+
FrontendMessage::UpdateDocumentArtboards {
7979
svg: self.artboards_graphene_document.render_root(ViewMode::Normal),
8080
}
8181
.into(),

editor/src/document/document_message_handler.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl DocumentMessageHandler {
243243
if let Some(layer) = self.layer_metadata.get_mut(path) {
244244
layer.selected = true;
245245
let data = self.layer_panel_entry(path.to_vec()).ok()?;
246-
(!path.is_empty()).then(|| FrontendMessage::UpdateLayer { data }.into())
246+
(!path.is_empty()).then(|| FrontendMessage::UpdateDocumentLayer { data }.into())
247247
} else {
248248
log::warn!("Tried to select non existing layer {:?}", path);
249249
None
@@ -594,7 +594,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
594594
false => self.name.clone() + FILE_EXPORT_SUFFIX,
595595
};
596596
responses.push_back(
597-
FrontendMessage::ExportDocument {
597+
FrontendMessage::TriggerFileDownload {
598598
document: format!(
599599
r#"<svg xmlns="http://www.w3.org/2000/svg" viewBox="{} {} {} {}">{}{}</svg>"#,
600600
bbox[0].x,
@@ -620,7 +620,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
620620
false => self.name.clone() + FILE_SAVE_SUFFIX,
621621
};
622622
responses.push_back(
623-
FrontendMessage::SaveDocument {
623+
FrontendMessage::TriggerFileDownload {
624624
document: self.serialize_document(),
625625
name,
626626
}
@@ -830,11 +830,11 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
830830
}
831831
DocumentStructureChanged => {
832832
let data_buffer: RawBuffer = self.serialize_root().into();
833-
responses.push_back(FrontendMessage::DisplayFolderTreeStructure { data_buffer }.into())
833+
responses.push_back(FrontendMessage::DisplayDocumentLayerTreeStructure { data_buffer }.into())
834834
}
835835
LayerChanged(path) => {
836836
if let Ok(layer_entry) = self.layer_panel_entry(path) {
837-
responses.push_back(FrontendMessage::UpdateLayer { data: layer_entry }.into());
837+
responses.push_back(FrontendMessage::UpdateDocumentLayer { data: layer_entry }.into());
838838
}
839839
}
840840
DispatchOperation(op) => match self.graphene_document.handle_operation(&op) {
@@ -866,7 +866,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
866866
},
867867
RenderDocument => {
868868
responses.push_back(
869-
FrontendMessage::UpdateArtwork {
869+
FrontendMessage::UpdateDocumentArtwork {
870870
svg: self.graphene_document.render_root(self.view_mode),
871871
}
872872
.into(),
@@ -892,7 +892,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
892892
let ruler_origin = self.graphene_document.root.transform.transform_point2(DVec2::ZERO);
893893

894894
responses.push_back(
895-
FrontendMessage::UpdateScrollbars {
895+
FrontendMessage::UpdateDocumentScrollbars {
896896
position: scrollbar_position.into(),
897897
size: scrollbar_size.into(),
898898
multiplier: scrollbar_multiplier.into(),
@@ -901,7 +901,7 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
901901
);
902902

903903
responses.push_back(
904-
FrontendMessage::UpdateRulers {
904+
FrontendMessage::UpdateDocumentRulers {
905905
origin: ruler_origin.into(),
906906
spacing: ruler_spacing,
907907
interval: ruler_interval,

editor/src/document/movement_handler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl MessageHandler<MovementMessage, (&Document, &InputPreprocessor)> for Moveme
235235
}
236236
SetCanvasZoom(new) => {
237237
self.zoom = new.clamp(VIEWPORT_ZOOM_SCALE_MIN, VIEWPORT_ZOOM_SCALE_MAX);
238-
responses.push_back(FrontendMessage::SetCanvasZoom { new_zoom: self.snapped_scale() }.into());
238+
responses.push_back(FrontendMessage::UpdateCanvasZoom { factor: self.snapped_scale() }.into());
239239
responses.push_back(ToolMessage::DocumentIsDirty.into());
240240
responses.push_back(DocumentMessage::DirtyRenderDocumentInOutlineView.into());
241241
self.create_document_transform(&ipp.viewport_bounds, responses);
@@ -275,7 +275,7 @@ impl MessageHandler<MovementMessage, (&Document, &InputPreprocessor)> for Moveme
275275
self.tilt = new_radians;
276276
self.create_document_transform(&ipp.viewport_bounds, responses);
277277
responses.push_back(ToolMessage::DocumentIsDirty.into());
278-
responses.push_back(FrontendMessage::SetCanvasRotation { new_radians: self.snapped_angle() }.into());
278+
responses.push_back(FrontendMessage::UpdateCanvasRotation { angle_radians: self.snapped_angle() }.into());
279279
}
280280
FitViewportToBounds {
281281
bounds: [bounds_corner_a, bounds_corner_b],
@@ -301,7 +301,7 @@ impl MessageHandler<MovementMessage, (&Document, &InputPreprocessor)> for Moveme
301301
self.zoom = 1.
302302
}
303303

304-
responses.push_back(FrontendMessage::SetCanvasZoom { new_zoom: self.zoom }.into());
304+
responses.push_back(FrontendMessage::UpdateCanvasZoom { factor: self.zoom }.into());
305305
responses.push_back(ToolMessage::DocumentIsDirty.into());
306306
responses.push_back(DocumentMessage::DirtyRenderDocumentInOutlineView.into());
307307
self.create_document_transform(&ipp.viewport_bounds, responses);

editor/src/document/overlay_message_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl MessageHandler<OverlayMessage, (&mut LayerMetadata, &Document, &InputPrepro
4141

4242
// Render overlays
4343
responses.push_back(
44-
FrontendMessage::UpdateOverlays {
44+
FrontendMessage::UpdateDocumentOverlays {
4545
svg: self.overlays_graphene_document.render_root(ViewMode::Normal),
4646
}
4747
.into(),

editor/src/document/portfolio_message_handler.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl PortfolioMessageHandler {
124124
.layer_metadata
125125
.keys()
126126
.filter_map(|path| new_document.layer_panel_entry_from_path(path))
127-
.map(|entry| FrontendMessage::UpdateLayer { data: entry }.into())
127+
.map(|entry| FrontendMessage::UpdateDocumentLayer { data: entry }.into())
128128
.collect::<Vec<_>>(),
129129
);
130130

@@ -181,7 +181,7 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessor> for PortfolioMessageHa
181181
use PortfolioMessage::*;
182182
match message {
183183
RequestAboutGraphiteDialog => {
184-
responses.push_back(FrontendMessage::DisplayAboutGraphiteDialog.into());
184+
responses.push_back(FrontendMessage::DisplayDialogAboutGraphite.into());
185185
}
186186
Document(message) => self.active_document_mut().process_action(message, ipp, responses),
187187
SelectDocument(id) => {
@@ -190,7 +190,7 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessor> for PortfolioMessageHa
190190
responses.push_back(PortfolioMessage::AutoSaveDocument(self.active_document_id).into());
191191
}
192192
self.active_document_id = id;
193-
responses.push_back(FrontendMessage::SetActiveDocument { document_id: id }.into());
193+
responses.push_back(FrontendMessage::UpdateActiveDocument { document_id: id }.into());
194194
responses.push_back(RenderDocument.into());
195195
responses.push_back(DocumentMessage::DocumentStructureChanged.into());
196196
for layer in self.active_document().layer_metadata.keys() {
@@ -259,8 +259,8 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessor> for PortfolioMessageHa
259259
.collect::<Vec<_>>();
260260

261261
responses.push_back(FrontendMessage::UpdateOpenDocumentsList { open_documents }.into());
262-
responses.push_back(FrontendMessage::SetActiveDocument { document_id: self.active_document_id }.into());
263-
responses.push_back(FrontendMessage::RemoveAutoSaveDocument { document_id: id }.into());
262+
responses.push_back(FrontendMessage::UpdateActiveDocument { document_id: self.active_document_id }.into());
263+
responses.push_back(FrontendMessage::TriggerIndexedDbRemoveDocument { document_id: id }.into());
264264
responses.push_back(RenderDocument.into());
265265
responses.push_back(DocumentMessage::DocumentStructureChanged.into());
266266
for layer in self.active_document().layer_metadata.keys() {
@@ -275,7 +275,7 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessor> for PortfolioMessageHa
275275
self.load_document(new_document, document_id, false, responses);
276276
}
277277
OpenDocument => {
278-
responses.push_back(FrontendMessage::OpenDocumentBrowse.into());
278+
responses.push_back(FrontendMessage::TriggerFileUpload.into());
279279
}
280280
OpenDocumentFile(document_name, document) => {
281281
responses.push_back(
@@ -301,7 +301,7 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessor> for PortfolioMessageHa
301301
self.load_document(document, document_id, true, responses);
302302
}
303303
Err(e) => responses.push_back(
304-
FrontendMessage::DisplayError {
304+
FrontendMessage::DisplayDialogError {
305305
title: "Failed to open document".to_string(),
306306
description: e.to_string(),
307307
}
@@ -327,7 +327,7 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessor> for PortfolioMessageHa
327327
AutoSaveDocument(id) => {
328328
let document = self.documents.get(&id).unwrap();
329329
responses.push_back(
330-
FrontendMessage::AutoSaveDocument {
330+
FrontendMessage::TriggerIndexedDbWriteDocument {
331331
document: document.serialize_document(),
332332
details: FrontendDocumentDetails {
333333
is_saved: document.is_saved(),

editor/src/frontend/frontend_message_handler.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,30 @@ pub struct FrontendDocumentDetails {
1515
#[impl_message(Message, Frontend)]
1616
#[derive(PartialEq, Clone, Deserialize, Serialize, Debug)]
1717
pub enum FrontendMessage {
18-
DisplayFolderTreeStructure { data_buffer: RawBuffer },
19-
SetActiveTool { tool_name: String, tool_options: Option<ToolOptions> },
20-
SetActiveDocument { document_id: u64 },
18+
// Display prefix: make the frontend show something, like a dialog
19+
// Update prefix: give the frontend a new value or state for it to use
20+
// Trigger prefix: cause a browser API to do something
21+
DisplayDocumentLayerTreeStructure { data_buffer: RawBuffer },
22+
UpdateActiveTool { tool_name: String, tool_options: Option<ToolOptions> },
23+
UpdateActiveDocument { document_id: u64 },
2124
UpdateOpenDocumentsList { open_documents: Vec<FrontendDocumentDetails> },
2225
UpdateInputHints { hint_data: HintData },
23-
DisplayError { title: String, description: String },
24-
DisplayPanic { panic_info: String, title: String, description: String },
26+
DisplayDialogError { title: String, description: String },
27+
DisplayDialogPanic { panic_info: String, title: String, description: String },
2528
DisplayConfirmationToCloseDocument { document_id: u64 },
2629
DisplayConfirmationToCloseAllDocuments,
27-
DisplayAboutGraphiteDialog,
28-
UpdateLayer { data: LayerPanelEntry },
29-
UpdateArtwork { svg: String },
30-
UpdateOverlays { svg: String },
31-
UpdateArtboards { svg: String },
32-
UpdateScrollbars { position: (f64, f64), size: (f64, f64), multiplier: (f64, f64) },
33-
UpdateRulers { origin: (f64, f64), spacing: f64, interval: f64 },
34-
ExportDocument { document: String, name: String },
35-
SaveDocument { document: String, name: String },
36-
AutoSaveDocument { document: String, details: FrontendDocumentDetails, version: String },
37-
RemoveAutoSaveDocument { document_id: u64 },
38-
OpenDocumentBrowse,
30+
DisplayDialogAboutGraphite,
31+
UpdateDocumentLayer { data: LayerPanelEntry },
32+
UpdateDocumentArtwork { svg: String },
33+
UpdateDocumentOverlays { svg: String },
34+
UpdateDocumentArtboards { svg: String },
35+
UpdateDocumentScrollbars { position: (f64, f64), size: (f64, f64), multiplier: (f64, f64) },
36+
UpdateDocumentRulers { origin: (f64, f64), spacing: f64, interval: f64 },
37+
TriggerFileUpload,
38+
TriggerFileDownload { document: String, name: String },
39+
TriggerIndexedDbWriteDocument { document: String, details: FrontendDocumentDetails, version: String },
40+
TriggerIndexedDbRemoveDocument { document_id: u64 },
3941
UpdateWorkingColors { primary: Color, secondary: Color },
40-
SetCanvasZoom { new_zoom: f64 },
41-
SetCanvasRotation { new_radians: f64 },
42+
UpdateCanvasZoom { factor: f64 },
43+
UpdateCanvasRotation { angle_radians: f64 },
4244
}

editor/src/input/input_mapper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl Default for Mapping {
219219
entry! {action=ToolMessage::ResetColors, key_down=KeyX, modifiers=[KeyShift, KeyControl]},
220220
entry! {action=ToolMessage::SwapColors, key_down=KeyX, modifiers=[KeyShift]},
221221
// Editor Actions
222-
entry! {action=FrontendMessage::OpenDocumentBrowse, key_down=KeyO, modifiers=[KeyControl]},
222+
entry! {action=FrontendMessage::TriggerFileUpload, key_down=KeyO, modifiers=[KeyControl]},
223223
// Document Actions
224224
entry! {action=PortfolioMessage::Paste(User), key_down=KeyV, modifiers=[KeyControl]},
225225
entry! {action=DocumentMessage::Redo, key_down=KeyZ, modifiers=[KeyControl, KeyShift]},

editor/src/tool/tool_message_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, &InputPreprocessor)>
105105
// Notify the frontend about the new active tool to be displayed
106106
let tool_name = new_tool.to_string();
107107
let tool_options = self.tool_state.document_tool_data.tool_options.get(&new_tool).copied();
108-
responses.push_back(FrontendMessage::SetActiveTool { tool_name, tool_options }.into());
108+
responses.push_back(FrontendMessage::UpdateActiveTool { tool_name, tool_options }.into());
109109
}
110110
DocumentIsDirty => {
111111
// Send the DocumentIsDirty message to the active tool's sub-tool message handler

frontend/src/components/panels/Document.vue

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,17 @@
251251
<script lang="ts">
252252
import { defineComponent } from "vue";
253253
254-
import { UpdateArtwork, UpdateOverlays, UpdateScrollbars, UpdateRulers, SetActiveTool, SetCanvasZoom, SetCanvasRotation, ToolName, UpdateArtboards } from "@/dispatcher/js-messages";
254+
import {
255+
UpdateDocumentArtwork,
256+
UpdateDocumentOverlays,
257+
UpdateDocumentScrollbars,
258+
UpdateDocumentRulers,
259+
UpdateActiveTool,
260+
UpdateCanvasZoom,
261+
UpdateCanvasRotation,
262+
ToolName,
263+
UpdateDocumentArtboards,
264+
} from "@/dispatcher/js-messages";
255265
256266
import LayoutCol from "@/components/layout/LayoutCol.vue";
257267
import LayoutRow from "@/components/layout/LayoutRow.vue";
@@ -330,41 +340,41 @@ export default defineComponent({
330340
},
331341
},
332342
mounted() {
333-
this.editor.dispatcher.subscribeJsMessage(UpdateArtwork, (UpdateArtwork) => {
334-
this.artworkSvg = UpdateArtwork.svg;
343+
this.editor.dispatcher.subscribeJsMessage(UpdateDocumentArtwork, (UpdateDocumentArtwork) => {
344+
this.artworkSvg = UpdateDocumentArtwork.svg;
335345
});
336346
337-
this.editor.dispatcher.subscribeJsMessage(UpdateOverlays, (updateOverlays) => {
338-
this.overlaysSvg = updateOverlays.svg;
347+
this.editor.dispatcher.subscribeJsMessage(UpdateDocumentOverlays, (updateDocumentOverlays) => {
348+
this.overlaysSvg = updateDocumentOverlays.svg;
339349
});
340350
341-
this.editor.dispatcher.subscribeJsMessage(UpdateArtboards, (updateArtboards) => {
342-
this.artboardSvg = updateArtboards.svg;
351+
this.editor.dispatcher.subscribeJsMessage(UpdateDocumentArtboards, (updateDocumentArtboards) => {
352+
this.artboardSvg = updateDocumentArtboards.svg;
343353
});
344354
345-
this.editor.dispatcher.subscribeJsMessage(UpdateScrollbars, (updateScrollbars) => {
346-
this.scrollbarPos = updateScrollbars.position;
347-
this.scrollbarSize = updateScrollbars.size;
348-
this.scrollbarMultiplier = updateScrollbars.multiplier;
355+
this.editor.dispatcher.subscribeJsMessage(UpdateDocumentScrollbars, (updateDocumentScrollbars) => {
356+
this.scrollbarPos = updateDocumentScrollbars.position;
357+
this.scrollbarSize = updateDocumentScrollbars.size;
358+
this.scrollbarMultiplier = updateDocumentScrollbars.multiplier;
349359
});
350360
351-
this.editor.dispatcher.subscribeJsMessage(UpdateRulers, (updateRulers) => {
352-
this.rulerOrigin = updateRulers.origin;
353-
this.rulerSpacing = updateRulers.spacing;
354-
this.rulerInterval = updateRulers.interval;
361+
this.editor.dispatcher.subscribeJsMessage(UpdateDocumentRulers, (updateDocumentRulers) => {
362+
this.rulerOrigin = updateDocumentRulers.origin;
363+
this.rulerSpacing = updateDocumentRulers.spacing;
364+
this.rulerInterval = updateDocumentRulers.interval;
355365
});
356366
357-
this.editor.dispatcher.subscribeJsMessage(SetActiveTool, (setActiveTool) => {
358-
this.activeTool = setActiveTool.tool_name;
359-
this.activeToolOptions = setActiveTool.tool_options;
367+
this.editor.dispatcher.subscribeJsMessage(UpdateActiveTool, (updateActiveTool) => {
368+
this.activeTool = updateActiveTool.tool_name;
369+
this.activeToolOptions = updateActiveTool.tool_options;
360370
});
361371
362-
this.editor.dispatcher.subscribeJsMessage(SetCanvasZoom, (setCanvasZoom) => {
363-
this.documentZoom = setCanvasZoom.new_zoom * 100;
372+
this.editor.dispatcher.subscribeJsMessage(UpdateCanvasZoom, (updateCanvasZoom) => {
373+
this.documentZoom = updateCanvasZoom.factor * 100;
364374
});
365375
366-
this.editor.dispatcher.subscribeJsMessage(SetCanvasRotation, (setCanvasRotation) => {
367-
const newRotation = setCanvasRotation.new_radians * (180 / Math.PI);
376+
this.editor.dispatcher.subscribeJsMessage(UpdateCanvasRotation, (updateCanvasRotation) => {
377+
const newRotation = updateCanvasRotation.angle_radians * (180 / Math.PI);
368378
this.documentRotation = (360 + (newRotation % 360)) % 360;
369379
});
370380

0 commit comments

Comments
 (0)