Fix sorting of message enum variants

This commit is contained in:
Keavon Chambers 2022-01-16 13:21:05 -08:00
parent b17432b1c4
commit 3038d72226
25 changed files with 254 additions and 111 deletions

View file

@ -58,6 +58,8 @@ impl Dispatcher {
// Process the action by forwarding it to the relevant message handler, or saving the FrontendMessage to be sent to the frontend // Process the action by forwarding it to the relevant message handler, or saving the FrontendMessage to be sent to the frontend
#[remain::sorted] #[remain::sorted]
match message { match message {
#[remain::unsorted]
NoOp => {}
Frontend(message) => { Frontend(message) => {
// `FrontendMessage`s are saved and will be sent to the frontend after the message queue is done being processed // `FrontendMessage`s are saved and will be sent to the frontend after the message queue is done being processed
self.responses.push(message); self.responses.push(message);
@ -74,7 +76,6 @@ impl Dispatcher {
InputPreprocessor(message) => { InputPreprocessor(message) => {
self.message_handlers.input_preprocessor_message_handler.process_action(message, (), &mut self.message_queue); self.message_handlers.input_preprocessor_message_handler.process_action(message, (), &mut self.message_queue);
} }
NoOp => {}
Portfolio(message) => { Portfolio(message) => {
self.message_handlers self.message_handlers
.portfolio_message_handler .portfolio_message_handler

View file

@ -20,6 +20,8 @@ where
#[impl_message] #[impl_message]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Message { pub enum Message {
#[remain::unsorted]
NoOp,
#[child] #[child]
Frontend(FrontendMessage), Frontend(FrontendMessage),
#[child] #[child]
@ -28,7 +30,6 @@ pub enum Message {
InputMapper(InputMapperMessage), InputMapper(InputMapperMessage),
#[child] #[child]
InputPreprocessor(InputPreprocessorMessage), InputPreprocessor(InputPreprocessorMessage),
NoOp,
#[child] #[child]
Portfolio(PortfolioMessage), Portfolio(PortfolioMessage),
#[child] #[child]

View file

@ -8,8 +8,17 @@ use serde::{Deserialize, Serialize};
#[impl_message(Message, DocumentMessage, Artboard)] #[impl_message(Message, DocumentMessage, Artboard)]
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
pub enum ArtboardMessage { pub enum ArtboardMessage {
AddArtboard { top: f64, left: f64, height: f64, width: f64 }, // Sub-messages
#[remain::unsorted]
DispatchOperation(Box<DocumentOperation>), DispatchOperation(Box<DocumentOperation>),
// Messages
AddArtboard {
top: f64,
left: f64,
height: f64,
width: f64,
},
RenderArtboards, RenderArtboards,
} }

View file

@ -1,5 +1,3 @@
use super::layer_panel::LayerMetadata;
use crate::input::InputPreprocessorMessageHandler;
use crate::message_prelude::*; use crate::message_prelude::*;
use graphene::color::Color; use graphene::color::Color;
@ -23,14 +21,21 @@ impl ArtboardMessageHandler {
} }
} }
impl MessageHandler<ArtboardMessage, (&mut LayerMetadata, &GrapheneDocument, &InputPreprocessorMessageHandler)> for ArtboardMessageHandler { impl MessageHandler<ArtboardMessage, ()> for ArtboardMessageHandler {
#[remain::check] #[remain::check]
fn process_action(&mut self, message: ArtboardMessage, _data: (&mut LayerMetadata, &GrapheneDocument, &InputPreprocessorMessageHandler), responses: &mut VecDeque<Message>) { fn process_action(&mut self, message: ArtboardMessage, _: (), responses: &mut VecDeque<Message>) {
use ArtboardMessage::*; use ArtboardMessage::*;
// let (layer_metadata, document, ipp) = data;
#[remain::sorted] #[remain::sorted]
match message { match message {
// Sub-messages
#[remain::unsorted]
DispatchOperation(operation) => match self.artboards_graphene_document.handle_operation(&operation) {
Ok(_) => (),
Err(e) => log::error!("Artboard Error: {:?}", e),
},
// Messages
AddArtboard { top, left, height, width } => { AddArtboard { top, left, height, width } => {
let artboard_id = generate_uuid(); let artboard_id = generate_uuid();
self.artboard_ids.push(artboard_id); self.artboard_ids.push(artboard_id);
@ -50,10 +55,6 @@ impl MessageHandler<ArtboardMessage, (&mut LayerMetadata, &GrapheneDocument, &In
responses.push_back(DocumentMessage::RenderDocument.into()); responses.push_back(DocumentMessage::RenderDocument.into());
} }
DispatchOperation(operation) => match self.artboards_graphene_document.handle_operation(&operation) {
Ok(_) => (),
Err(e) => log::error!("Artboard Error: {:?}", e),
},
RenderArtboards => { RenderArtboards => {
// Render an infinite canvas if there are no artboards // Render an infinite canvas if there are no artboards
if self.artboard_ids.is_empty() { if self.artboard_ids.is_empty() {

View file

@ -13,6 +13,23 @@ use serde::{Deserialize, Serialize};
#[impl_message(Message, PortfolioMessage, Document)] #[impl_message(Message, PortfolioMessage, Document)]
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
pub enum DocumentMessage { pub enum DocumentMessage {
// Sub-messages
#[remain::unsorted]
DispatchOperation(Box<DocumentOperation>),
#[remain::unsorted]
#[child]
Artboard(ArtboardMessage),
#[remain::unsorted]
#[child]
Movement(MovementMessage),
#[remain::unsorted]
#[child]
Overlays(OverlaysMessage),
#[remain::unsorted]
#[child]
TransformLayers(TransformLayerMessage),
// Messages
AbortTransaction, AbortTransaction,
AddSelectedLayers { AddSelectedLayers {
additional_layers: Vec<Vec<LayerId>>, additional_layers: Vec<Vec<LayerId>>,
@ -21,8 +38,6 @@ pub enum DocumentMessage {
axis: AlignAxis, axis: AlignAxis,
aggregate: AlignAggregate, aggregate: AlignAggregate,
}, },
#[child]
Artboard(ArtboardMessage),
CommitTransaction, CommitTransaction,
CreateEmptyFolder { CreateEmptyFolder {
container_path: Vec<LayerId>, container_path: Vec<LayerId>,
@ -35,7 +50,6 @@ pub enum DocumentMessage {
DeselectAllLayers, DeselectAllLayers,
DirtyRenderDocument, DirtyRenderDocument,
DirtyRenderDocumentInOutlineView, DirtyRenderDocumentInOutlineView,
DispatchOperation(Box<DocumentOperation>),
DocumentHistoryBackward, DocumentHistoryBackward,
DocumentHistoryForward, DocumentHistoryForward,
DocumentStructureChanged, DocumentStructureChanged,
@ -51,8 +65,6 @@ pub enum DocumentMessage {
LayerChanged { LayerChanged {
affected_layer_path: Vec<LayerId>, affected_layer_path: Vec<LayerId>,
}, },
#[child]
Movement(MovementMessage),
MoveSelectedLayersTo { MoveSelectedLayersTo {
folder_path: Vec<LayerId>, folder_path: Vec<LayerId>,
insert_index: isize, insert_index: isize,
@ -61,8 +73,6 @@ pub enum DocumentMessage {
delta_x: f64, delta_x: f64,
delta_y: f64, delta_y: f64,
}, },
#[child]
Overlays(OverlaysMessage),
Redo, Redo,
RenameLayer { RenameLayer {
layer_path: Vec<LayerId>, layer_path: Vec<LayerId>,
@ -110,8 +120,6 @@ pub enum DocumentMessage {
ToggleLayerVisibility { ToggleLayerVisibility {
layer_path: Vec<LayerId>, layer_path: Vec<LayerId>,
}, },
#[child]
TransformLayers(TransformLayerMessage),
Undo, Undo,
UngroupLayers { UngroupLayers {
folder_path: Vec<LayerId>, folder_path: Vec<LayerId>,

View file

@ -445,6 +445,60 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
#[remain::sorted] #[remain::sorted]
match message { match message {
// Sub-messages
#[remain::unsorted]
DispatchOperation(op) => match self.graphene_document.handle_operation(&op) {
Ok(Some(document_responses)) => {
for response in document_responses {
match &response {
DocumentResponse::FolderChanged { path } => responses.push_back(FolderChanged { affected_folder_path: path.clone() }.into()),
DocumentResponse::DeletedLayer { path } => {
self.layer_metadata.remove(path);
}
DocumentResponse::LayerChanged { path } => responses.push_back(LayerChanged { affected_layer_path: path.clone() }.into()),
DocumentResponse::CreatedLayer { path } => {
if self.layer_metadata.contains_key(path) {
log::warn!("CreatedLayer overrides existing layer metadata.");
}
self.layer_metadata.insert(path.clone(), LayerMetadata::new(false));
responses.push_back(LayerChanged { affected_layer_path: path.clone() }.into());
self.layer_range_selection_reference = path.clone();
responses.push_back(
AddSelectedLayers {
additional_layers: vec![path.clone()],
}
.into(),
);
}
DocumentResponse::DocumentChanged => responses.push_back(RenderDocument.into()),
};
responses.push_back(ToolMessage::DocumentIsDirty.into());
}
}
Err(e) => log::error!("DocumentError: {:?}", e),
Ok(_) => (),
},
#[remain::unsorted]
Artboard(message) => {
self.artboard_message_handler.process_action(message, (), responses);
}
#[remain::unsorted]
Movement(message) => {
self.movement_handler.process_action(message, (&self.graphene_document, ipp), responses);
}
#[remain::unsorted]
Overlays(message) => {
self.overlays_message_handler.process_action(message, self.overlays_visible, responses);
// responses.push_back(OverlaysMessage::RenderOverlays.into());
}
#[remain::unsorted]
TransformLayers(message) => {
self.transform_layer_handler
.process_action(message, (&mut self.layer_metadata, &mut self.graphene_document, ipp), responses);
}
// Messages
AbortTransaction => { AbortTransaction => {
self.undo(responses).unwrap_or_else(|e| log::warn!("{}", e)); self.undo(responses).unwrap_or_else(|e| log::warn!("{}", e));
responses.extend([RenderDocument.into(), DocumentStructureChanged.into()]); responses.extend([RenderDocument.into(), DocumentStructureChanged.into()]);
@ -494,13 +548,6 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
responses.push_back(ToolMessage::DocumentIsDirty.into()); responses.push_back(ToolMessage::DocumentIsDirty.into());
} }
} }
Artboard(message) => {
self.artboard_message_handler.process_action(
message,
(Self::layer_metadata_mut_no_borrow_self(&mut self.layer_metadata, &[]), &self.graphene_document, ipp),
responses,
);
}
CommitTransaction => (), CommitTransaction => (),
CreateEmptyFolder { mut container_path } => { CreateEmptyFolder { mut container_path } => {
let id = generate_uuid(); let id = generate_uuid();
@ -542,38 +589,6 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
responses.push_front(DocumentMessage::DirtyRenderDocument.into()); responses.push_front(DocumentMessage::DirtyRenderDocument.into());
} }
} }
DispatchOperation(op) => match self.graphene_document.handle_operation(&op) {
Ok(Some(document_responses)) => {
for response in document_responses {
match &response {
DocumentResponse::FolderChanged { path } => responses.push_back(FolderChanged { affected_folder_path: path.clone() }.into()),
DocumentResponse::DeletedLayer { path } => {
self.layer_metadata.remove(path);
}
DocumentResponse::LayerChanged { path } => responses.push_back(LayerChanged { affected_layer_path: path.clone() }.into()),
DocumentResponse::CreatedLayer { path } => {
if self.layer_metadata.contains_key(path) {
log::warn!("CreatedLayer overrides existing layer metadata.");
}
self.layer_metadata.insert(path.clone(), LayerMetadata::new(false));
responses.push_back(LayerChanged { affected_layer_path: path.clone() }.into());
self.layer_range_selection_reference = path.clone();
responses.push_back(
AddSelectedLayers {
additional_layers: vec![path.clone()],
}
.into(),
);
}
DocumentResponse::DocumentChanged => responses.push_back(RenderDocument.into()),
};
responses.push_back(ToolMessage::DocumentIsDirty.into());
}
}
Err(e) => log::error!("DocumentError: {:?}", e),
Ok(_) => (),
},
DocumentHistoryBackward => self.undo(responses).unwrap_or_else(|e| log::warn!("{}", e)), DocumentHistoryBackward => self.undo(responses).unwrap_or_else(|e| log::warn!("{}", e)),
DocumentHistoryForward => self.redo(responses).unwrap_or_else(|e| log::warn!("{}", e)), DocumentHistoryForward => self.redo(responses).unwrap_or_else(|e| log::warn!("{}", e)),
DocumentStructureChanged => { DocumentStructureChanged => {
@ -671,7 +686,6 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
responses.push_back(FrontendMessage::UpdateDocumentLayer { data: layer_entry }.into()); responses.push_back(FrontendMessage::UpdateDocumentLayer { data: layer_entry }.into());
} }
} }
Movement(message) => self.movement_handler.process_action(message, (&self.graphene_document, ipp), responses),
MoveSelectedLayersTo { folder_path, insert_index } => { MoveSelectedLayersTo { folder_path, insert_index } => {
let selected_layers = self.selected_layers().collect::<Vec<_>>(); let selected_layers = self.selected_layers().collect::<Vec<_>>();
@ -704,10 +718,6 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
} }
responses.push_back(ToolMessage::DocumentIsDirty.into()); responses.push_back(ToolMessage::DocumentIsDirty.into());
} }
Overlays(message) => {
self.overlays_message_handler.process_action(message, self.overlays_visible, responses);
// responses.push_back(OverlaysMessage::RenderOverlays.into());
}
Redo => { Redo => {
responses.push_back(SelectMessage::Abort.into()); responses.push_back(SelectMessage::Abort.into());
responses.push_back(DocumentHistoryForward.into()); responses.push_back(DocumentHistoryForward.into());
@ -938,9 +948,6 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
responses.push_back(DocumentOperation::ToggleLayerVisibility { path: layer_path }.into()); responses.push_back(DocumentOperation::ToggleLayerVisibility { path: layer_path }.into());
responses.push_back(ToolMessage::DocumentIsDirty.into()); responses.push_back(ToolMessage::DocumentIsDirty.into());
} }
TransformLayers(message) => self
.transform_layer_handler
.process_action(message, (&mut self.layer_metadata, &mut self.graphene_document, ipp), responses),
Undo => { Undo => {
responses.push_back(SelectMessage::Abort.into()); responses.push_back(SelectMessage::Abort.into());
responses.push_back(DocumentHistoryBackward.into()); responses.push_back(DocumentHistoryBackward.into());

View file

@ -8,8 +8,12 @@ use serde::{Deserialize, Serialize};
#[impl_message(Message, DocumentMessage, Overlays)] #[impl_message(Message, DocumentMessage, Overlays)]
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
pub enum OverlaysMessage { pub enum OverlaysMessage {
ClearAllOverlays, // Sub-messages
#[remain::unsorted]
DispatchOperation(Box<DocumentOperation>), DispatchOperation(Box<DocumentOperation>),
// Messages
ClearAllOverlays,
Rerender, Rerender,
} }

View file

@ -15,11 +15,15 @@ impl MessageHandler<OverlaysMessage, bool> for OverlaysMessageHandler {
#[remain::sorted] #[remain::sorted]
match message { match message {
ClearAllOverlays => todo!(), // Sub-messages
#[remain::unsorted]
DispatchOperation(operation) => match self.overlays_graphene_document.handle_operation(&operation) { DispatchOperation(operation) => match self.overlays_graphene_document.handle_operation(&operation) {
Ok(_) => (), Ok(_) => (),
Err(e) => log::error!("OverlaysError: {:?}", e), Err(e) => log::error!("OverlaysError: {:?}", e),
}, },
// Messages
ClearAllOverlays => todo!(),
Rerender => (), Rerender => (),
} }

View file

@ -9,6 +9,12 @@ use serde::{Deserialize, Serialize};
#[impl_message(Message, Portfolio)] #[impl_message(Message, Portfolio)]
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
pub enum PortfolioMessage { pub enum PortfolioMessage {
// Sub-messages
#[remain::unsorted]
#[child]
Document(DocumentMessage),
// Messages
AutoSaveActiveDocument, AutoSaveActiveDocument,
AutoSaveDocument { AutoSaveDocument {
document_id: u64, document_id: u64,
@ -28,12 +34,13 @@ pub enum PortfolioMessage {
Cut { Cut {
clipboard: Clipboard, clipboard: Clipboard,
}, },
#[child]
Document(DocumentMessage),
NewDocument, NewDocument,
NextDocument, NextDocument,
OpenDocument, OpenDocument,
OpenDocumentFile(String, String), OpenDocumentFile {
document_name: String,
document_serialized_content: String,
},
OpenDocumentFileWithId { OpenDocumentFileWithId {
document_id: u64, document_id: u64,
document_name: String, document_name: String,

View file

@ -130,6 +130,11 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessorMessageHandler> for Port
#[remain::sorted] #[remain::sorted]
match message { match message {
// Sub-messages
#[remain::unsorted]
Document(message) => self.active_document_mut().process_action(message, ipp, responses),
// Messages
AutoSaveActiveDocument => responses.push_back(PortfolioMessage::AutoSaveDocument { document_id: self.active_document_id }.into()), AutoSaveActiveDocument => responses.push_back(PortfolioMessage::AutoSaveDocument { document_id: self.active_document_id }.into()),
AutoSaveDocument { document_id } => { AutoSaveDocument { document_id } => {
let document = self.documents.get(&document_id).unwrap(); let document = self.documents.get(&document_id).unwrap();
@ -235,7 +240,6 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessorMessageHandler> for Port
responses.push_back(Copy { clipboard }.into()); responses.push_back(Copy { clipboard }.into());
responses.push_back(DeleteSelectedLayers.into()); responses.push_back(DeleteSelectedLayers.into());
} }
Document(message) => self.active_document_mut().process_action(message, ipp, responses),
NewDocument => { NewDocument => {
let name = self.generate_new_document_name(); let name = self.generate_new_document_name();
let new_document = DocumentMessageHandler::with_name(name, ipp); let new_document = DocumentMessageHandler::with_name(name, ipp);
@ -252,7 +256,10 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessorMessageHandler> for Port
OpenDocument => { OpenDocument => {
responses.push_back(FrontendMessage::TriggerFileUpload.into()); responses.push_back(FrontendMessage::TriggerFileUpload.into());
} }
OpenDocumentFile(document_name, document_serialized_content) => { OpenDocumentFile {
document_name,
document_serialized_content,
} => {
responses.push_back( responses.push_back(
PortfolioMessage::OpenDocumentFileWithId { PortfolioMessage::OpenDocumentFileWithId {
document_id: generate_uuid(), document_id: generate_uuid(),

View file

@ -7,10 +7,15 @@ use serde::{Deserialize, Serialize};
#[impl_message(Message, InputMapper)] #[impl_message(Message, InputMapper)]
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
pub enum InputMapperMessage { pub enum InputMapperMessage {
// Sub-messages
#[remain::unsorted]
#[child] #[child]
KeyDown(Key), KeyDown(Key),
#[remain::unsorted]
#[child] #[child]
KeyUp(Key), KeyUp(Key),
// Messages
MouseScroll, MouseScroll,
PointerMove, PointerMove,
} }

View file

@ -10,32 +10,49 @@ use serde::{Deserialize, Serialize};
#[impl_message(Message, Tool)] #[impl_message(Message, Tool)]
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
pub enum ToolMessage { pub enum ToolMessage {
// Sub-messages
#[remain::unsorted]
#[child]
Crop(CropMessage),
#[remain::unsorted]
#[child]
Ellipse(EllipseMessage),
#[remain::unsorted]
#[child]
Eyedropper(EyedropperMessage),
#[remain::unsorted]
#[child]
Fill(FillMessage),
#[remain::unsorted]
#[child]
Line(LineMessage),
#[remain::unsorted]
#[child]
Navigate(NavigateMessage),
#[remain::unsorted]
#[child]
Path(PathMessage),
#[remain::unsorted]
#[child]
Pen(PenMessage),
#[remain::unsorted]
#[child]
Rectangle(RectangleMessage),
#[remain::unsorted]
#[child]
Select(SelectMessage),
#[remain::unsorted]
#[child]
Shape(ShapeMessage),
// Messages
#[remain::unsorted]
NoOp,
ActivateTool { ActivateTool {
tool_type: ToolType, tool_type: ToolType,
}, },
#[child]
Crop(CropMessage),
DocumentIsDirty, DocumentIsDirty,
#[child]
Ellipse(EllipseMessage),
#[child]
Eyedropper(EyedropperMessage),
#[child]
Fill(FillMessage),
#[child]
Line(LineMessage),
#[child]
Navigate(NavigateMessage),
NoOp,
#[child]
Path(PathMessage),
#[child]
Pen(PenMessage),
#[child]
Rectangle(RectangleMessage),
ResetColors, ResetColors,
#[child]
Select(SelectMessage),
SelectPrimaryColor { SelectPrimaryColor {
color: Color, color: Color,
}, },
@ -46,8 +63,6 @@ pub enum ToolMessage {
tool_type: ToolType, tool_type: ToolType,
tool_options: ToolOptions, tool_options: ToolOptions,
}, },
#[child]
Shape(ShapeMessage),
SwapColors, SwapColors,
UpdateCursor, UpdateCursor,
UpdateHints, UpdateHints,

View file

@ -20,6 +20,7 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, &InputPreprocessorMes
let (document, input) = data; let (document, input) = data;
#[remain::sorted] #[remain::sorted]
match message { match message {
// Messages
ActivateTool { tool_type } => { ActivateTool { tool_type } => {
let tool_data = &mut self.tool_state.tool_data; let tool_data = &mut self.tool_state.tool_data;
let document_data = &self.tool_state.document_tool_data; let document_data = &self.tool_state.document_tool_data;
@ -101,6 +102,9 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, &InputPreprocessorMes
update_working_colors(document_data, responses); update_working_colors(document_data, responses);
} }
// Sub-messages
#[remain::unsorted]
tool_message => { tool_message => {
let tool_type = match &tool_message { let tool_type = match &tool_message {
UpdateCursor | UpdateHints => self.tool_state.tool_data.active_tool_type, UpdateCursor | UpdateHints => self.tool_state.tool_data.active_tool_type,

View file

@ -10,6 +10,11 @@ pub struct Crop;
#[impl_message(Message, ToolMessage, Crop)] #[impl_message(Message, ToolMessage, Crop)]
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
pub enum CropMessage { pub enum CropMessage {
// Standard messages
// #[remain::unsorted]
// Abort,
// Tool-specific messages
MouseMove, MouseMove,
} }

View file

@ -23,10 +23,17 @@ pub struct Ellipse {
#[impl_message(Message, ToolMessage, Ellipse)] #[impl_message(Message, ToolMessage, Ellipse)]
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
pub enum EllipseMessage { pub enum EllipseMessage {
// Standard messages
#[remain::unsorted]
Abort, Abort,
// Tool-specific messages
DragStart, DragStart,
DragStop, DragStop,
Resize { center: Key, lock_ratio: Key }, Resize {
center: Key,
lock_ratio: Key,
},
} }
impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for Ellipse { impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for Ellipse {

View file

@ -23,7 +23,11 @@ pub struct Eyedropper {
#[impl_message(Message, ToolMessage, Eyedropper)] #[impl_message(Message, ToolMessage, Eyedropper)]
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
pub enum EyedropperMessage { pub enum EyedropperMessage {
// Standard messages
#[remain::unsorted]
Abort, Abort,
// Tool-specific messages
LeftMouseDown, LeftMouseDown,
RightMouseDown, RightMouseDown,
} }

View file

@ -23,7 +23,11 @@ pub struct Fill {
#[impl_message(Message, ToolMessage, Fill)] #[impl_message(Message, ToolMessage, Fill)]
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
pub enum FillMessage { pub enum FillMessage {
// Standard messages
#[remain::unsorted]
Abort, Abort,
// Tool-specific messages
LeftMouseDown, LeftMouseDown,
RightMouseDown, RightMouseDown,
} }

View file

@ -26,10 +26,18 @@ pub struct Line {
#[impl_message(Message, ToolMessage, Line)] #[impl_message(Message, ToolMessage, Line)]
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
pub enum LineMessage { pub enum LineMessage {
// Standard messages
#[remain::unsorted]
Abort, Abort,
// Tool-specific messages
DragStart, DragStart,
DragStop, DragStop,
Redraw { center: Key, lock_angle: Key, snap_angle: Key }, Redraw {
center: Key,
lock_angle: Key,
snap_angle: Key,
},
} }
impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for Line { impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for Line {

View file

@ -19,9 +19,18 @@ pub struct Navigate {
#[impl_message(Message, ToolMessage, Navigate)] #[impl_message(Message, ToolMessage, Navigate)]
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
pub enum NavigateMessage { pub enum NavigateMessage {
// Standard messages
#[remain::unsorted]
Abort, Abort,
ClickZoom { zoom_in: bool },
MouseMove { snap_angle: Key, snap_zoom: Key }, // Tool-specific messages
ClickZoom {
zoom_in: bool,
},
MouseMove {
snap_angle: Key,
snap_zoom: Key,
},
RotateCanvasBegin, RotateCanvasBegin,
TransformCanvasEnd, TransformCanvasEnd,
TranslateCanvasBegin, TranslateCanvasBegin,

View file

@ -27,9 +27,12 @@ pub struct Path {
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
pub enum PathMessage { pub enum PathMessage {
// Standard messages // Standard messages
#[remain::unsorted]
Abort, Abort,
#[remain::unsorted]
DocumentIsDirty, DocumentIsDirty,
// Tool-specific messages
DragStart, DragStart,
DragStop, DragStop,
PointerMove, PointerMove,

View file

@ -24,7 +24,11 @@ pub struct Pen {
#[impl_message(Message, ToolMessage, Pen)] #[impl_message(Message, ToolMessage, Pen)]
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
pub enum PenMessage { pub enum PenMessage {
// Standard messages
#[remain::unsorted]
Abort, Abort,
// Tool-specific messages
Confirm, Confirm,
DragStart, DragStart,
DragStop, DragStop,

View file

@ -23,10 +23,17 @@ pub struct Rectangle {
#[impl_message(Message, ToolMessage, Rectangle)] #[impl_message(Message, ToolMessage, Rectangle)]
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
pub enum RectangleMessage { pub enum RectangleMessage {
// Standard messages
#[remain::unsorted]
Abort, Abort,
// Tool-specific messages
DragStart, DragStart,
DragStop, DragStop,
Resize { center: Key, lock_ratio: Key }, Resize {
center: Key,
lock_ratio: Key,
},
} }
impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for Rectangle { impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for Rectangle {

View file

@ -24,21 +24,30 @@ pub struct Select {
data: SelectToolData, data: SelectToolData,
} }
// #[remain::sorted] // https://github.com/dtolnay/remain/issues/16 #[remain::sorted]
#[impl_message(Message, ToolMessage, Select)] #[impl_message(Message, ToolMessage, Select)]
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
pub enum SelectMessage { pub enum SelectMessage {
// Standard messages // Standard messages
#[remain::unsorted]
Abort, Abort,
#[remain::unsorted]
DocumentIsDirty, DocumentIsDirty,
DragStart { add_to_selection: Key }, // Tool-specific messages
Align {
axis: AlignAxis,
aggregate: AlignAggregate,
},
DragStart {
add_to_selection: Key,
},
DragStop, DragStop,
MouseMove { snap_angle: Key },
Align { axis: AlignAxis, aggregate: AlignAggregate },
FlipHorizontal, FlipHorizontal,
FlipVertical, FlipVertical,
MouseMove {
snap_angle: Key,
},
} }
impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for Select { impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for Select {

View file

@ -24,10 +24,17 @@ pub struct Shape {
#[impl_message(Message, ToolMessage, Shape)] #[impl_message(Message, ToolMessage, Shape)]
#[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)] #[derive(PartialEq, Clone, Debug, Hash, Serialize, Deserialize)]
pub enum ShapeMessage { pub enum ShapeMessage {
// Standard messages
#[remain::unsorted]
Abort, Abort,
// Tool-specific messages
DragStart, DragStart,
DragStop, DragStop,
Resize { center: Key, lock_ratio: Key }, Resize {
center: Key,
lock_ratio: Key,
},
} }
impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for Shape { impl<'a> MessageHandler<ToolMessage, ToolActionHandlerData<'a>> for Shape {

View file

@ -164,8 +164,11 @@ impl JsEditorHandle {
self.dispatch(message); self.dispatch(message);
} }
pub fn open_document_file(&self, name: String, content: String) { pub fn open_document_file(&self, document_name: String, document_serialized_content: String) {
let message = PortfolioMessage::OpenDocumentFile(name, content); let message = PortfolioMessage::OpenDocumentFile {
document_name,
document_serialized_content,
};
self.dispatch(message); self.dispatch(message);
} }