mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-01 13:58:12 +08:00
Properly handle pen tool undo and redo (#1587)
feat: properly handle pen tool undo and redo
This commit is contained in:
@@ -630,6 +630,7 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
|
|||||||
Redo => {
|
Redo => {
|
||||||
responses.add(SelectToolMessage::Abort);
|
responses.add(SelectToolMessage::Abort);
|
||||||
responses.add(DocumentMessage::DocumentHistoryForward);
|
responses.add(DocumentMessage::DocumentHistoryForward);
|
||||||
|
responses.add(ToolMessage::Redo);
|
||||||
responses.add(OverlaysMessage::Draw);
|
responses.add(OverlaysMessage::Draw);
|
||||||
}
|
}
|
||||||
RenameDocument { new_name } => {
|
RenameDocument { new_name } => {
|
||||||
@@ -806,10 +807,11 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
|
|||||||
}
|
}
|
||||||
Undo => {
|
Undo => {
|
||||||
self.undo_in_progress = true;
|
self.undo_in_progress = true;
|
||||||
responses.add(BroadcastEvent::ToolAbort);
|
|
||||||
responses.add(DocumentMessage::DocumentHistoryBackward);
|
responses.add(DocumentMessage::DocumentHistoryBackward);
|
||||||
responses.add(OverlaysMessage::Draw);
|
responses.add(OverlaysMessage::Draw);
|
||||||
responses.add(DocumentMessage::UndoFinished);
|
responses.add(DocumentMessage::UndoFinished);
|
||||||
|
responses.add(ToolMessage::Undo);
|
||||||
}
|
}
|
||||||
UndoFinished => self.undo_in_progress = false,
|
UndoFinished => self.undo_in_progress = false,
|
||||||
UngroupSelectedLayers => {
|
UngroupSelectedLayers => {
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ pub enum ToolMessage {
|
|||||||
},
|
},
|
||||||
DeactivateTools,
|
DeactivateTools,
|
||||||
InitTools,
|
InitTools,
|
||||||
|
Redo,
|
||||||
RefreshToolOptions,
|
RefreshToolOptions,
|
||||||
ResetColors,
|
ResetColors,
|
||||||
SelectPrimaryColor {
|
SelectPrimaryColor {
|
||||||
@@ -136,6 +137,7 @@ pub enum ToolMessage {
|
|||||||
color: Color,
|
color: Color,
|
||||||
},
|
},
|
||||||
SwapColors,
|
SwapColors,
|
||||||
|
Undo,
|
||||||
UpdateCursor,
|
UpdateCursor,
|
||||||
UpdateHints,
|
UpdateHints,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,6 +177,15 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, DocumentId, &InputPre
|
|||||||
tool_data.active_tool_mut().process_message(ToolMessage::UpdateHints, responses, &mut data);
|
tool_data.active_tool_mut().process_message(ToolMessage::UpdateHints, responses, &mut data);
|
||||||
tool_data.active_tool_mut().process_message(ToolMessage::UpdateCursor, responses, &mut data);
|
tool_data.active_tool_mut().process_message(ToolMessage::UpdateCursor, responses, &mut data);
|
||||||
}
|
}
|
||||||
|
ToolMessage::Redo => {
|
||||||
|
let tool_data = &mut self.tool_state.tool_data;
|
||||||
|
match tool_data.active_tool_type {
|
||||||
|
ToolType::Pen => {
|
||||||
|
responses.add(PenToolMessage::Redo);
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
ToolMessage::RefreshToolOptions => {
|
ToolMessage::RefreshToolOptions => {
|
||||||
let tool_data = &mut self.tool_state.tool_data;
|
let tool_data = &mut self.tool_state.tool_data;
|
||||||
tool_data.tools.get(&tool_data.active_tool_type).unwrap().send_layout(responses, LayoutTarget::ToolOptions);
|
tool_data.tools.get(&tool_data.active_tool_type).unwrap().send_layout(responses, LayoutTarget::ToolOptions);
|
||||||
@@ -221,6 +230,17 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, DocumentId, &InputPre
|
|||||||
|
|
||||||
document_data.update_working_colors(responses); // TODO: Make this an event
|
document_data.update_working_colors(responses); // TODO: Make this an event
|
||||||
}
|
}
|
||||||
|
ToolMessage::Undo => {
|
||||||
|
let tool_data = &mut self.tool_state.tool_data;
|
||||||
|
match tool_data.active_tool_type {
|
||||||
|
ToolType::Pen => {
|
||||||
|
responses.add(PenToolMessage::Undo);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
responses.add(BroadcastEvent::ToolAbort);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Sub-messages
|
// Sub-messages
|
||||||
#[remain::unsorted]
|
#[remain::unsorted]
|
||||||
@@ -282,6 +302,7 @@ impl MessageHandler<ToolMessage, (&DocumentMessageHandler, DocumentId, &InputPre
|
|||||||
SelectRandomPrimaryColor,
|
SelectRandomPrimaryColor,
|
||||||
ResetColors,
|
ResetColors,
|
||||||
SwapColors,
|
SwapColors,
|
||||||
|
Undo,
|
||||||
);
|
);
|
||||||
list.extend(self.tool_state.tool_data.active_tool().actions());
|
list.extend(self.tool_state.tool_data.active_tool().actions());
|
||||||
list.extend(self.transform_layer_handler.actions());
|
list.extend(self.transform_layer_handler.actions());
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ pub enum PenToolMessage {
|
|||||||
break_handle: Key,
|
break_handle: Key,
|
||||||
lock_angle: Key,
|
lock_angle: Key,
|
||||||
},
|
},
|
||||||
|
Redo,
|
||||||
Undo,
|
Undo,
|
||||||
UpdateOptions(PenOptionsUpdate),
|
UpdateOptions(PenOptionsUpdate),
|
||||||
}
|
}
|
||||||
@@ -198,6 +199,17 @@ struct ModifierState {
|
|||||||
lock_angle: bool,
|
lock_angle: bool,
|
||||||
break_handle: bool,
|
break_handle: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ModifierState {
|
||||||
|
fn default() -> Self {
|
||||||
|
ModifierState {
|
||||||
|
snap_angle: false,
|
||||||
|
lock_angle: false,
|
||||||
|
break_handle: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
struct PenToolData {
|
struct PenToolData {
|
||||||
weight: f64,
|
weight: f64,
|
||||||
@@ -665,6 +677,7 @@ impl Fsm for PenToolFsmState {
|
|||||||
PenToolFsmState::DraggingHandle
|
PenToolFsmState::DraggingHandle
|
||||||
}
|
}
|
||||||
(PenToolFsmState::PlacingAnchor, PenToolMessage::DragStart) => {
|
(PenToolFsmState::PlacingAnchor, PenToolMessage::DragStart) => {
|
||||||
|
responses.add(DocumentMessage::StartTransaction);
|
||||||
tool_data.check_break(document, transform, responses);
|
tool_data.check_break(document, transform, responses);
|
||||||
PenToolFsmState::DraggingHandle
|
PenToolFsmState::DraggingHandle
|
||||||
}
|
}
|
||||||
@@ -713,6 +726,12 @@ impl Fsm for PenToolFsmState {
|
|||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
(PenToolFsmState::DraggingHandle | PenToolFsmState::PlacingAnchor, PenToolMessage::Undo) => tool_data
|
||||||
|
.place_anchor(SnapData::new(document, input), transform, input.mouse.position, ModifierState::default(), responses)
|
||||||
|
.unwrap_or(PenToolFsmState::PlacingAnchor),
|
||||||
|
(_, PenToolMessage::Redo) => tool_data
|
||||||
|
.place_anchor(SnapData::new(document, input), transform, input.mouse.position, ModifierState::default(), responses)
|
||||||
|
.unwrap_or(PenToolFsmState::PlacingAnchor),
|
||||||
_ => self,
|
_ => self,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user