Fix sorting of message enum variants

This commit is contained in:
Keavon Chambers
2022-01-16 13:21:05 -08:00
parent 1a4ab0733b
commit 841f34e797
25 changed files with 254 additions and 111 deletions

View File

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

View File

@@ -1,5 +1,3 @@
use super::layer_panel::LayerMetadata;
use crate::input::InputPreprocessorMessageHandler;
use crate::message_prelude::*;
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]
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::*;
// let (layer_metadata, document, ipp) = data;
#[remain::sorted]
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 } => {
let artboard_id = generate_uuid();
self.artboard_ids.push(artboard_id);
@@ -50,10 +55,6 @@ impl MessageHandler<ArtboardMessage, (&mut LayerMetadata, &GrapheneDocument, &In
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 => {
// Render an infinite canvas if there are no artboards
if self.artboard_ids.is_empty() {

View File

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

View File

@@ -445,6 +445,60 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
#[remain::sorted]
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 => {
self.undo(responses).unwrap_or_else(|e| log::warn!("{}", e));
responses.extend([RenderDocument.into(), DocumentStructureChanged.into()]);
@@ -494,13 +548,6 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
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 => (),
CreateEmptyFolder { mut container_path } => {
let id = generate_uuid();
@@ -542,38 +589,6 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
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)),
DocumentHistoryForward => self.redo(responses).unwrap_or_else(|e| log::warn!("{}", e)),
DocumentStructureChanged => {
@@ -671,7 +686,6 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
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 } => {
let selected_layers = self.selected_layers().collect::<Vec<_>>();
@@ -704,10 +718,6 @@ impl MessageHandler<DocumentMessage, &InputPreprocessorMessageHandler> for Docum
}
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 => {
responses.push_back(SelectMessage::Abort.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(ToolMessage::DocumentIsDirty.into());
}
TransformLayers(message) => self
.transform_layer_handler
.process_action(message, (&mut self.layer_metadata, &mut self.graphene_document, ipp), responses),
Undo => {
responses.push_back(SelectMessage::Abort.into());
responses.push_back(DocumentHistoryBackward.into());

View File

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

View File

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

View File

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

View File

@@ -130,6 +130,11 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessorMessageHandler> for Port
#[remain::sorted]
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()),
AutoSaveDocument { document_id } => {
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(DeleteSelectedLayers.into());
}
Document(message) => self.active_document_mut().process_action(message, ipp, responses),
NewDocument => {
let name = self.generate_new_document_name();
let new_document = DocumentMessageHandler::with_name(name, ipp);
@@ -252,7 +256,10 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessorMessageHandler> for Port
OpenDocument => {
responses.push_back(FrontendMessage::TriggerFileUpload.into());
}
OpenDocumentFile(document_name, document_serialized_content) => {
OpenDocumentFile {
document_name,
document_serialized_content,
} => {
responses.push_back(
PortfolioMessage::OpenDocumentFileWithId {
document_id: generate_uuid(),