Trait biodivine_sketchbook::app::state::StackSession
source · pub trait StackSession: SessionState {
// Required methods
fn process_message(
&mut self,
message: &SessionMessage,
) -> Result<(Option<SessionMessage>, Option<StateChange>), DynError>;
fn id(&self) -> &str;
fn undo_stack(&self) -> &UndoStack;
fn undo_stack_mut(&mut self) -> &mut UndoStack;
// Provided methods
fn perform_action(
&mut self,
action: &UserAction,
) -> Result<StateChange, DynError> { ... }
fn perform_categorized_action(
&mut self,
action: &UserAction,
ignore_stack: bool,
) -> Result<StateChange, DynError> { ... }
fn append_stack_updates(&self, state_changes: &mut Vec<Event>) { ... }
}
Expand description
A Session with a UndoStack with events.
Sessions perform user actions, or communicate with different sessions via messages.
Required Methods§
sourcefn process_message(
&mut self,
message: &SessionMessage,
) -> Result<(Option<SessionMessage>, Option<StateChange>), DynError>
fn process_message( &mut self, message: &SessionMessage, ) -> Result<(Option<SessionMessage>, Option<StateChange>), DynError>
Process a message sent to this session state object.
Depending on the message, an optional “response” SessionMessage might be returned. This will be sent to the sender of the original message. Similarly, if the processing of the message caused some changes to the state, an optional “refresh” SessionMessage should be returned to then update the frontend.
sourcefn id(&self) -> &str
fn id(&self) -> &str
Returns the string identifier of this particular session. Each session identifier must be unique within the application.
sourcefn undo_stack(&self) -> &UndoStack
fn undo_stack(&self) -> &UndoStack
Returns an immutable reference to session’s undo stack.
sourcefn undo_stack_mut(&mut self) -> &mut UndoStack
fn undo_stack_mut(&mut self) -> &mut UndoStack
Returns a mutable reference to session’s undo stack.
Provided Methods§
sourcefn perform_action(
&mut self,
action: &UserAction,
) -> Result<StateChange, DynError>
fn perform_action( &mut self, action: &UserAction, ) -> Result<StateChange, DynError>
Perform a user action on this session state object. This usually involves propagating the events to the internal SessionState objects and collecting the results into a single StateChange entry.
In this top-level method, we explicitly test for undo-stack actions. Once that is done, the processing continues via StackSession::perform_categorized_action.
sourcefn perform_categorized_action(
&mut self,
action: &UserAction,
ignore_stack: bool,
) -> Result<StateChange, DynError>
fn perform_categorized_action( &mut self, action: &UserAction, ignore_stack: bool, ) -> Result<StateChange, DynError>
Perform a user action on this session state object, with additional information whether the action should bypass the undo-redo stack.
This method assumes the action was already categorized into one of undo
(stack should be
bypassed) or regular
(goes to the undo stack).
If you want to run the full process including categorizing the action, use StackSession::perform_action.