mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-25 17:48:12 +08:00
* Feat: implement the hierarchical tree for visualization * rename HierarchicalTree trait function * feat: change the HierarchicalTree from String to DebugMessageTree struct * Nits * feat: impliment proc macro to extract field from messagedata structs * update the hierarchical-tree for hanlder data * feat: added message handler struct to hierarchical tree * feat: add the line number to message handler struct * feat: added handler path to tree and NITS * clean the white spaces in type string * fixes some white spaces * feat: added path to message enum in hierarchical tree * feat: add file creation of hierarchical message system tree * cleanup * Code review * Add todo comment for deferred change --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
64 lines
1.9 KiB
Rust
64 lines
1.9 KiB
Rust
pub use crate::dispatcher::*;
|
|
use crate::messages::prelude::*;
|
|
|
|
/// Implements a message handler struct for a separate message struct.
|
|
/// - The first generic argument (`M`) is that message struct type, representing a message enum variant to be matched and handled in `process_message()`.
|
|
/// - The second generic argument (`D`) is the type of data that can be passed along by the caller to `process_message()`.
|
|
pub trait MessageHandler<M: ToDiscriminant, D>
|
|
where
|
|
M::Discriminant: AsMessage,
|
|
<M::Discriminant as TransitiveChild>::TopParent: TransitiveChild<Parent = <M::Discriminant as TransitiveChild>::TopParent, TopParent = <M::Discriminant as TransitiveChild>::TopParent> + AsMessage,
|
|
{
|
|
/// Return true if the Action is consumed.
|
|
fn process_message(&mut self, message: M, responses: &mut VecDeque<Message>, data: D);
|
|
|
|
fn actions(&self) -> ActionList;
|
|
}
|
|
|
|
pub type ActionList = Vec<Vec<MessageDiscriminant>>;
|
|
|
|
pub trait AsMessage: TransitiveChild
|
|
where
|
|
Self::TopParent: TransitiveChild<Parent = Self::TopParent, TopParent = Self::TopParent> + AsMessage,
|
|
{
|
|
fn local_name(self) -> String;
|
|
fn global_name(self) -> String {
|
|
<Self as Into<Self::TopParent>>::into(self).local_name()
|
|
}
|
|
}
|
|
|
|
// TODO: Add Send + Sync requirement
|
|
// Use something like rw locks for synchronization
|
|
pub trait MessageHandlerData {}
|
|
|
|
pub trait ToDiscriminant {
|
|
type Discriminant;
|
|
|
|
fn to_discriminant(&self) -> Self::Discriminant;
|
|
}
|
|
|
|
pub trait TransitiveChild: Into<Self::Parent> + Into<Self::TopParent> {
|
|
type TopParent;
|
|
type Parent;
|
|
}
|
|
|
|
pub trait Hint {
|
|
fn hints(&self) -> HashMap<String, String>;
|
|
}
|
|
|
|
pub trait HierarchicalTree {
|
|
fn build_message_tree() -> DebugMessageTree;
|
|
|
|
fn message_handler_data_str() -> MessageData {
|
|
MessageData::new(String::new(), Vec::new(), "")
|
|
}
|
|
|
|
fn message_handler_str() -> MessageData {
|
|
MessageData::new(String::new(), Vec::new(), "")
|
|
}
|
|
|
|
fn path() -> &'static str {
|
|
""
|
|
}
|
|
}
|