mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-25 03:58:12 +08:00
Improve history states (#932)
* Add some more history states
* Fix undo whilst drawing
* Paste image history
* Toggle output and preview history
* Code review nits
* Remove extra '{'
* Fix typo
* Fix about.toml
Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Keavon Chambers
parent
6e142627a3
commit
2bcc3d3baf
@@ -187,6 +187,7 @@ pub enum DocumentMessage {
|
||||
toggle_angle: bool,
|
||||
},
|
||||
Undo,
|
||||
UndoFinished,
|
||||
UngroupLayers {
|
||||
folder_path: Vec<LayerId>,
|
||||
},
|
||||
|
||||
@@ -53,6 +53,9 @@ pub struct DocumentMessageHandler {
|
||||
pub document_undo_history: VecDeque<DocumentSave>,
|
||||
#[serde(skip)]
|
||||
pub document_redo_history: VecDeque<DocumentSave>,
|
||||
/// Don't allow aborting transactions whilst undoing to avoid #559
|
||||
#[serde(skip)]
|
||||
undo_in_progress: bool,
|
||||
|
||||
#[serde(with = "vectorize_layer_metadata")]
|
||||
pub layer_metadata: HashMap<Vec<LayerId>, LayerMetadata>,
|
||||
@@ -85,6 +88,7 @@ impl Default for DocumentMessageHandler {
|
||||
|
||||
document_undo_history: VecDeque::new(),
|
||||
document_redo_history: VecDeque::new(),
|
||||
undo_in_progress: false,
|
||||
|
||||
layer_metadata: vec![(vec![], LayerMetadata::new(true))].into_iter().collect(),
|
||||
layer_range_selection_reference: Vec::new(),
|
||||
@@ -190,8 +194,10 @@ impl MessageHandler<DocumentMessage, (u64, &InputPreprocessorMessageHandler, &Pe
|
||||
|
||||
// Messages
|
||||
AbortTransaction => {
|
||||
self.undo(responses).unwrap_or_else(|e| warn!("{}", e));
|
||||
responses.extend([RenderDocument.into(), DocumentStructureChanged.into()]);
|
||||
if !self.undo_in_progress {
|
||||
self.undo(responses).unwrap_or_else(|e| warn!("{}", e));
|
||||
responses.extend([RenderDocument.into(), DocumentStructureChanged.into()]);
|
||||
}
|
||||
}
|
||||
AddSelectedLayers { additional_layers } => {
|
||||
for layer_path in &additional_layers {
|
||||
@@ -509,7 +515,7 @@ impl MessageHandler<DocumentMessage, (u64, &InputPreprocessorMessageHandler, &Pe
|
||||
// Set a random seed input
|
||||
responses.push_back(
|
||||
NodeGraphMessage::SetInputValue {
|
||||
node: *imaginate_node.last().unwrap(),
|
||||
node_id: *imaginate_node.last().unwrap(),
|
||||
input_index: 1,
|
||||
value: graph_craft::document::value::TaggedValue::F64((generate_uuid() >> 1) as f64),
|
||||
}
|
||||
@@ -541,6 +547,8 @@ impl MessageHandler<DocumentMessage, (u64, &InputPreprocessorMessageHandler, &Pe
|
||||
responses.push_back(BroadcastEvent::DocumentIsDirty.into());
|
||||
}
|
||||
PasteImage { mime, image_data, mouse } => {
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
|
||||
let path = vec![generate_uuid()];
|
||||
responses.push_back(
|
||||
DocumentOperation::AddImage {
|
||||
@@ -833,12 +841,15 @@ impl MessageHandler<DocumentMessage, (u64, &InputPreprocessorMessageHandler, &Pe
|
||||
);
|
||||
}
|
||||
Undo => {
|
||||
self.undo_in_progress = true;
|
||||
responses.push_back(BroadcastEvent::ToolAbort.into());
|
||||
responses.push_back(DocumentHistoryBackward.into());
|
||||
responses.push_back(BroadcastEvent::DocumentIsDirty.into());
|
||||
responses.push_back(RenderDocument.into());
|
||||
responses.push_back(FolderChanged { affected_folder_path: vec![] }.into());
|
||||
responses.push_back(UndoFinished.into());
|
||||
}
|
||||
UndoFinished => self.undo_in_progress = false,
|
||||
UngroupLayers { folder_path } => {
|
||||
// Select all the children of the folder
|
||||
let select = self.document_legacy.folder_children_paths(&folder_path);
|
||||
@@ -1353,6 +1364,8 @@ impl DocumentMessageHandler {
|
||||
responses.push_back(DocumentMessage::LayerChanged { affected_layer_path: layer.clone() }.into())
|
||||
}
|
||||
|
||||
responses.push_back(NodeGraphMessage::SendGraph.into());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
None => Err(EditorError::NoTransactionInProgress),
|
||||
@@ -1391,6 +1404,8 @@ impl DocumentMessageHandler {
|
||||
responses.push_back(DocumentMessage::LayerChanged { affected_layer_path: layer.clone() }.into())
|
||||
}
|
||||
|
||||
responses.push_back(NodeGraphMessage::SendGraph.into());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
None => Err(EditorError::NoTransactionInProgress),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use crate::messages::prelude::*;
|
||||
|
||||
use document_legacy::LayerId;
|
||||
use graph_craft::document::{value::TaggedValue, NodeId};
|
||||
use graph_craft::document::value::TaggedValue;
|
||||
use graph_craft::document::{DocumentNode, NodeId, NodeInput};
|
||||
|
||||
#[remain::sorted]
|
||||
#[impl_message(Message, DocumentMessage, NodeGraph)]
|
||||
@@ -43,6 +44,10 @@ pub enum NodeGraphMessage {
|
||||
input_index: usize,
|
||||
new_exposed: bool,
|
||||
},
|
||||
InsertNode {
|
||||
node_id: NodeId,
|
||||
document_node: DocumentNode,
|
||||
},
|
||||
MoveSelectedNodes {
|
||||
displacement_x: i32,
|
||||
displacement_y: i32,
|
||||
@@ -56,14 +61,20 @@ pub enum NodeGraphMessage {
|
||||
SelectNodes {
|
||||
nodes: Vec<NodeId>,
|
||||
},
|
||||
SendGraph,
|
||||
SetDrawing {
|
||||
new_drawing: bool,
|
||||
},
|
||||
SetInputValue {
|
||||
node: NodeId,
|
||||
node_id: NodeId,
|
||||
input_index: usize,
|
||||
value: TaggedValue,
|
||||
},
|
||||
SetNodeInput {
|
||||
node_id: NodeId,
|
||||
input_index: usize,
|
||||
input: NodeInput,
|
||||
},
|
||||
SetQualifiedInputValue {
|
||||
layer_path: Vec<LayerId>,
|
||||
node_path: Vec<NodeId>,
|
||||
@@ -74,7 +85,11 @@ pub enum NodeGraphMessage {
|
||||
node_id: NodeId,
|
||||
},
|
||||
ToggleHidden,
|
||||
ToggleHiddenImpl,
|
||||
TogglePreview {
|
||||
node_id: NodeId,
|
||||
},
|
||||
TogglePreviewImpl {
|
||||
node_id: NodeId,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -125,6 +125,16 @@ impl NodeGraphMessageHandler {
|
||||
})
|
||||
}
|
||||
|
||||
/// Get the active graph_craft NodeNetwork struct
|
||||
fn get_active_network<'a>(&self, document: &'a Document) -> Option<&'a graph_craft::document::NodeNetwork> {
|
||||
let mut network = self.get_root_network(document);
|
||||
|
||||
for segement in &self.nested_path {
|
||||
network = network.and_then(|network| network.nodes.get(segement)).and_then(|node| node.implementation.get_network());
|
||||
}
|
||||
network
|
||||
}
|
||||
|
||||
/// Get the active graph_craft NodeNetwork struct
|
||||
fn get_active_network_mut<'a>(&self, document: &'a mut Document) -> Option<&'a mut graph_craft::document::NodeNetwork> {
|
||||
let mut network = self.get_root_network_mut(document);
|
||||
@@ -179,7 +189,7 @@ impl NodeGraphMessageHandler {
|
||||
|
||||
/// Updates the buttons for disable and preview
|
||||
fn update_selection_action_buttons(&mut self, document: &mut Document, responses: &mut VecDeque<Message>) {
|
||||
if let Some(network) = self.get_active_network_mut(document) {
|
||||
if let Some(network) = self.get_active_network(document) {
|
||||
let mut widgets = Vec::new();
|
||||
|
||||
// Don't allow disabling input or output nodes
|
||||
@@ -281,7 +291,7 @@ impl NodeGraphMessageHandler {
|
||||
|
||||
let mut nodes = Vec::new();
|
||||
for (id, node) in &network.nodes {
|
||||
let Some(node_type) = document_node_types::resolve_document_node_type(&node.name) else{
|
||||
let Some(node_type) = document_node_types::resolve_document_node_type(&node.name) else {
|
||||
warn!("Node '{}' does not exist in library", node.name);
|
||||
continue
|
||||
};
|
||||
@@ -406,7 +416,6 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
|
||||
if let Some(_old_layer_path) = self.layer_path.take() {
|
||||
responses.push_back(FrontendMessage::UpdateNodeGraphVisibility { visible: false }.into());
|
||||
responses.push_back(PropertiesPanelMessage::ResendActiveProperties.into());
|
||||
// TODO: Close UI and clean up old node graph
|
||||
}
|
||||
}
|
||||
NodeGraphMessage::ConnectNodesByLink {
|
||||
@@ -415,26 +424,30 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
|
||||
input_node_connector_index,
|
||||
} => {
|
||||
log::debug!("Connect primary output from node {output_node} to input of index {input_node_connector_index} on node {input_node}.");
|
||||
let node_id = input_node;
|
||||
|
||||
let Some(network) = self.get_active_network_mut(document) else {
|
||||
let Some(network) = self.get_active_network(document) else {
|
||||
error!("No network");
|
||||
return;
|
||||
};
|
||||
let Some(input_node) = network.nodes.get_mut(&input_node) else {
|
||||
let Some(input_node) = network.nodes.get(&input_node) else {
|
||||
error!("No to");
|
||||
return;
|
||||
};
|
||||
let Some((actual_index, _)) = input_node.inputs.iter().enumerate().filter(|input|input.1.is_exposed()).nth(input_node_connector_index) else {
|
||||
let Some((input_index, _)) = input_node.inputs.iter().enumerate().filter(|input|input.1.is_exposed()).nth(input_node_connector_index) else {
|
||||
error!("Failed to find actual index of connector indes {input_node_connector_index} on node {input_node:#?}");
|
||||
return;
|
||||
};
|
||||
input_node.inputs[actual_index] = NodeInput::Node(output_node);
|
||||
|
||||
Self::send_graph(network, responses);
|
||||
responses.push_back(DocumentMessage::NodeGraphFrameGenerate.into());
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
|
||||
let input = NodeInput::Node(output_node);
|
||||
responses.push_back(NodeGraphMessage::SetNodeInput { node_id, input_index, input }.into());
|
||||
|
||||
responses.push_back(NodeGraphMessage::SendGraph.into());
|
||||
}
|
||||
NodeGraphMessage::Copy => {
|
||||
let Some(network) = self.get_active_network_mut(document) else {
|
||||
let Some(network) = self.get_active_network(document) else {
|
||||
error!("No network");
|
||||
return;
|
||||
};
|
||||
@@ -451,12 +464,8 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
|
||||
}
|
||||
NodeGraphMessage::CreateNode { node_id, node_type, x, y } => {
|
||||
let node_id = node_id.unwrap_or_else(crate::application::generate_uuid);
|
||||
let Some(network) = self.get_active_network_mut(document) else{
|
||||
warn!("No network");
|
||||
return;
|
||||
};
|
||||
|
||||
let Some(document_node_type) = document_node_types::resolve_document_node_type(&node_type) else{
|
||||
let Some(document_node_type) = document_node_types::resolve_document_node_type(&node_type) else {
|
||||
responses.push_back(DialogMessage::DisplayDialogError { title: "Cannot insert node".to_string(), description: format!("The document node '{node_type}' does not exist in the document node list") }.into());
|
||||
return;
|
||||
};
|
||||
@@ -481,17 +490,18 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
network.nodes.insert(
|
||||
node_id,
|
||||
DocumentNode {
|
||||
name: node_type.clone(),
|
||||
inputs: document_node_type.inputs.iter().map(|input| input.default.clone()).collect(),
|
||||
// TODO: Allow inserting nodes that contain other nodes.
|
||||
implementation: DocumentNodeImplementation::Network(inner_network),
|
||||
metadata: graph_craft::document::DocumentNodeMetadata { position: (x, y).into() },
|
||||
},
|
||||
);
|
||||
Self::send_graph(network, responses);
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
|
||||
let document_node = DocumentNode {
|
||||
name: node_type.clone(),
|
||||
inputs: document_node_type.inputs.iter().map(|input| input.default.clone()).collect(),
|
||||
// TODO: Allow inserting nodes that contain other nodes.
|
||||
implementation: DocumentNodeImplementation::Network(inner_network),
|
||||
metadata: graph_craft::document::DocumentNodeMetadata { position: (x, y).into() },
|
||||
};
|
||||
responses.push_back(NodeGraphMessage::InsertNode { node_id, document_node }.into());
|
||||
|
||||
responses.push_back(NodeGraphMessage::SendGraph.into());
|
||||
}
|
||||
NodeGraphMessage::Cut => {
|
||||
responses.push_back(NodeGraphMessage::Copy.into());
|
||||
@@ -499,32 +509,26 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
|
||||
}
|
||||
NodeGraphMessage::DeleteNode { node_id } => {
|
||||
if let Some(network) = self.get_active_network_mut(document) {
|
||||
if self.remove_node(network, node_id) {
|
||||
Self::send_graph(network, responses);
|
||||
responses.push_back(DocumentMessage::NodeGraphFrameGenerate.into());
|
||||
}
|
||||
self.remove_node(network, node_id);
|
||||
}
|
||||
self.update_selected(document, responses);
|
||||
}
|
||||
NodeGraphMessage::DeleteSelectedNodes => {
|
||||
if let Some(network) = self.get_active_network_mut(document) {
|
||||
let mut modified = false;
|
||||
for node_id in self.selected_nodes.clone() {
|
||||
modified = modified || self.remove_node(network, node_id);
|
||||
}
|
||||
if modified {
|
||||
Self::send_graph(network, responses);
|
||||
responses.push_back(DocumentMessage::NodeGraphFrameGenerate.into());
|
||||
}
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
|
||||
for node_id in self.selected_nodes.clone() {
|
||||
responses.push_back(NodeGraphMessage::DeleteNode { node_id }.into());
|
||||
}
|
||||
self.update_selected(document, responses);
|
||||
|
||||
responses.push_back(NodeGraphMessage::SendGraph.into());
|
||||
responses.push_back(DocumentMessage::NodeGraphFrameGenerate.into());
|
||||
}
|
||||
NodeGraphMessage::DisconnectNodes { node_id, input_index } => {
|
||||
let Some(network) = self.get_active_network_mut(document) else {
|
||||
let Some(network) = self.get_active_network(document) else {
|
||||
warn!("No network");
|
||||
return;
|
||||
};
|
||||
let Some(node) = network.nodes.get_mut(&node_id) else {
|
||||
let Some(node) = network.nodes.get(&node_id) else {
|
||||
warn!("Invalid node");
|
||||
return;
|
||||
};
|
||||
@@ -532,37 +536,46 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
|
||||
warn!("Node {} not in library", node.name);
|
||||
return;
|
||||
};
|
||||
node.inputs[input_index] = node_type.inputs[input_index].default.clone();
|
||||
Self::send_graph(network, responses);
|
||||
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
|
||||
let input = node_type.inputs[input_index].default.clone();
|
||||
responses.push_back(NodeGraphMessage::SetNodeInput { node_id, input_index, input }.into());
|
||||
|
||||
responses.push_back(NodeGraphMessage::SendGraph.into());
|
||||
}
|
||||
NodeGraphMessage::DoubleClickNode { node } => {
|
||||
self.selected_nodes.clear();
|
||||
if let Some(network) = self.get_active_network_mut(document) {
|
||||
if let Some(network) = self.get_active_network(document) {
|
||||
if network.nodes.get(&node).and_then(|node| node.implementation.get_network()).is_some() {
|
||||
self.nested_path.push(node);
|
||||
}
|
||||
}
|
||||
if let Some(network) = self.get_active_network_mut(document) {
|
||||
if let Some(network) = self.get_active_network(document) {
|
||||
Self::send_graph(network, responses);
|
||||
}
|
||||
self.collect_nested_addresses(document, responses);
|
||||
self.update_selected(document, responses);
|
||||
}
|
||||
NodeGraphMessage::DuplicateSelectedNodes => {
|
||||
if let Some(network) = self.get_active_network_mut(document) {
|
||||
if let Some(network) = self.get_active_network(document) {
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
|
||||
let new_ids = &self.selected_nodes.iter().map(|&id| (id, crate::application::generate_uuid())).collect();
|
||||
self.selected_nodes.clear();
|
||||
|
||||
// Copy the selected nodes
|
||||
let copied_nodes = Self::copy_nodes(network, new_ids).collect::<Vec<_>>();
|
||||
for (new_id, mut node) in copied_nodes {
|
||||
for (node_id, mut document_node) in copied_nodes {
|
||||
// Shift duplicated node
|
||||
node.metadata.position += IVec2::splat(2);
|
||||
document_node.metadata.position += IVec2::splat(2);
|
||||
|
||||
// Add new node to the list
|
||||
self.selected_nodes.push(new_id);
|
||||
network.nodes.insert(new_id, node);
|
||||
self.selected_nodes.push(node_id);
|
||||
|
||||
// Insert new node into graph
|
||||
responses.push_back(NodeGraphMessage::InsertNode { node_id, document_node }.into());
|
||||
}
|
||||
|
||||
Self::send_graph(network, responses);
|
||||
self.update_selected(document, responses);
|
||||
}
|
||||
@@ -572,38 +585,48 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
|
||||
for _ in 0..depth_of_nesting {
|
||||
self.nested_path.pop();
|
||||
}
|
||||
if let Some(network) = self.get_active_network_mut(document) {
|
||||
if let Some(network) = self.get_active_network(document) {
|
||||
Self::send_graph(network, responses);
|
||||
}
|
||||
self.collect_nested_addresses(document, responses);
|
||||
self.update_selected(document, responses);
|
||||
}
|
||||
NodeGraphMessage::ExposeInput { node_id, input_index, new_exposed } => {
|
||||
let Some(network) = self.get_active_network_mut(document) else{
|
||||
let Some(network) = self.get_active_network(document) else {
|
||||
warn!("No network");
|
||||
return;
|
||||
};
|
||||
|
||||
let Some(node) = network.nodes.get_mut(&node_id) else {
|
||||
let Some(node) = network.nodes.get(&node_id) else {
|
||||
warn!("No node");
|
||||
return;
|
||||
};
|
||||
|
||||
if let NodeInput::Value { exposed, .. } = &mut node.inputs[input_index] {
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
|
||||
let mut input = node.inputs[input_index].clone();
|
||||
if let NodeInput::Value { exposed, .. } = &mut input {
|
||||
*exposed = new_exposed;
|
||||
} else if let Some(node_type) = document_node_types::resolve_document_node_type(&node.name) {
|
||||
if let NodeInput::Value { tagged_value, .. } = &node_type.inputs[input_index].default {
|
||||
node.inputs[input_index] = NodeInput::Value {
|
||||
input = NodeInput::Value {
|
||||
tagged_value: tagged_value.clone(),
|
||||
exposed: new_exposed,
|
||||
};
|
||||
}
|
||||
}
|
||||
Self::send_graph(network, responses);
|
||||
responses.push_back(NodeGraphMessage::SetNodeInput { node_id, input_index, input }.into());
|
||||
|
||||
responses.push_back(NodeGraphMessage::SendGraph.into());
|
||||
responses.push_back(PropertiesPanelMessage::ResendActiveProperties.into());
|
||||
}
|
||||
NodeGraphMessage::InsertNode { node_id, document_node } => {
|
||||
if let Some(network) = self.get_active_network_mut(document) {
|
||||
network.nodes.insert(node_id, document_node);
|
||||
}
|
||||
}
|
||||
NodeGraphMessage::MoveSelectedNodes { displacement_x, displacement_y } => {
|
||||
let Some(network) = self.get_active_network_mut(document) else{
|
||||
let Some(network) = self.get_active_network_mut(document) else {
|
||||
warn!("No network");
|
||||
return;
|
||||
};
|
||||
@@ -621,11 +644,9 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(_old_layer_path) = self.layer_path.replace(layer_path) {
|
||||
// TODO: Necessary cleanup of old node graph
|
||||
}
|
||||
self.layer_path = Some(layer_path);
|
||||
|
||||
if let Some(network) = self.get_active_network_mut(document) {
|
||||
if let Some(network) = self.get_active_network(document) {
|
||||
self.selected_nodes.clear();
|
||||
responses.push_back(FrontendMessage::UpdateNodeGraphVisibility { visible: true }.into());
|
||||
|
||||
@@ -638,7 +659,7 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
|
||||
self.update_selected(document, responses);
|
||||
}
|
||||
NodeGraphMessage::PasteNodes { serialized_nodes } => {
|
||||
let Some(network) = self.get_active_network_mut(document) else{
|
||||
let Some(network) = self.get_active_network(document) else {
|
||||
warn!("No network");
|
||||
return;
|
||||
};
|
||||
@@ -660,31 +681,38 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
|
||||
shift += IVec2::splat(2);
|
||||
}
|
||||
|
||||
self.selected_nodes.clear();
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
|
||||
let new_ids: HashMap<_, _> = data.iter().map(|&(id, _)| (id, crate::application::generate_uuid())).collect();
|
||||
for (old_id, mut node) in data {
|
||||
for (old_id, mut document_node) in data {
|
||||
// Shift copied node
|
||||
node.metadata.position += shift;
|
||||
document_node.metadata.position += shift;
|
||||
|
||||
// Get the new, non-conflicting id
|
||||
let new_id = *new_ids.get(&old_id).unwrap();
|
||||
let node_id = *new_ids.get(&old_id).unwrap();
|
||||
document_node = document_node.map_ids(Self::default_node_input, &new_ids);
|
||||
|
||||
// Insert node into network
|
||||
network.nodes.insert(new_id, node.map_ids(Self::default_node_input, &new_ids));
|
||||
|
||||
// Select the newly pasted node
|
||||
self.selected_nodes.push(new_id);
|
||||
responses.push_back(NodeGraphMessage::InsertNode { node_id, document_node }.into());
|
||||
}
|
||||
|
||||
Self::send_graph(network, responses);
|
||||
self.update_selected(document, responses);
|
||||
let nodes = new_ids.values().copied().collect();
|
||||
responses.push_back(NodeGraphMessage::SelectNodes { nodes }.into());
|
||||
|
||||
responses.push_back(NodeGraphMessage::SendGraph.into());
|
||||
}
|
||||
NodeGraphMessage::SelectNodes { nodes } => {
|
||||
self.selected_nodes = nodes;
|
||||
self.update_selection_action_buttons(document, responses);
|
||||
self.update_selected(document, responses);
|
||||
responses.push_back(PropertiesPanelMessage::ResendActiveProperties.into());
|
||||
}
|
||||
NodeGraphMessage::SendGraph => {
|
||||
if let Some(network) = self.get_active_network(document) {
|
||||
Self::send_graph(network, responses);
|
||||
responses.push_back(DocumentMessage::NodeGraphFrameGenerate.into());
|
||||
}
|
||||
}
|
||||
NodeGraphMessage::SetDrawing { new_drawing } => {
|
||||
let selected: Vec<_> = selected.collect();
|
||||
// Check if we stopped drawing a node graph frame
|
||||
@@ -704,14 +732,13 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
|
||||
}
|
||||
self.is_drawing_node_graph_frame = new_drawing
|
||||
}
|
||||
NodeGraphMessage::SetInputValue { node, input_index, value } => {
|
||||
if let Some(network) = self.get_active_network_mut(document) {
|
||||
if let Some(node) = network.nodes.get_mut(&node) {
|
||||
// Extend number of inputs if not already large enough
|
||||
if input_index >= node.inputs.len() {
|
||||
node.inputs.extend(((node.inputs.len() - 1)..input_index).map(|_| NodeInput::Network));
|
||||
}
|
||||
node.inputs[input_index] = NodeInput::Value { tagged_value: value, exposed: false };
|
||||
NodeGraphMessage::SetInputValue { node_id, input_index, value } => {
|
||||
if let Some(network) = self.get_active_network(document) {
|
||||
if let Some(node) = network.nodes.get(&node_id) {
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
|
||||
let input = NodeInput::Value { tagged_value: value, exposed: false };
|
||||
responses.push_back(NodeGraphMessage::SetNodeInput { node_id, input_index, input }.into());
|
||||
responses.push_back(PropertiesPanelMessage::ResendActiveProperties.into());
|
||||
if node.name != "Imaginate" || input_index == 0 {
|
||||
responses.push_back(DocumentMessage::NodeGraphFrameGenerate.into());
|
||||
@@ -719,6 +746,13 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
|
||||
}
|
||||
}
|
||||
}
|
||||
NodeGraphMessage::SetNodeInput { node_id, input_index, input } => {
|
||||
if let Some(network) = self.get_active_network_mut(document) {
|
||||
if let Some(node) = network.nodes.get_mut(&node_id) {
|
||||
node.inputs[input_index] = input
|
||||
}
|
||||
}
|
||||
}
|
||||
NodeGraphMessage::SetQualifiedInputValue {
|
||||
layer_path,
|
||||
node_path,
|
||||
@@ -750,7 +784,7 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
|
||||
}
|
||||
}
|
||||
NodeGraphMessage::ShiftNode { node_id } => {
|
||||
let Some(network) = self.get_active_network_mut(document) else{
|
||||
let Some(network) = self.get_active_network_mut(document) else {
|
||||
warn!("No network");
|
||||
return;
|
||||
};
|
||||
@@ -794,9 +828,13 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
|
||||
stack.extend(outwards_links.get(&id).unwrap_or(&Vec::new()).iter().copied())
|
||||
}
|
||||
}
|
||||
Self::send_graph(network, responses);
|
||||
responses.push_back(NodeGraphMessage::SendGraph.into());
|
||||
}
|
||||
NodeGraphMessage::ToggleHidden => {
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
responses.push_back(NodeGraphMessage::ToggleHiddenImpl.into());
|
||||
}
|
||||
NodeGraphMessage::ToggleHiddenImpl => {
|
||||
if let Some(network) = self.get_active_network_mut(document) {
|
||||
// Check if any of the selected nodes are hidden
|
||||
if self.selected_nodes.iter().any(|id| network.disabled.contains(id)) {
|
||||
@@ -813,6 +851,10 @@ impl MessageHandler<NodeGraphMessage, (&mut Document, &mut dyn Iterator<Item = &
|
||||
responses.push_back(DocumentMessage::NodeGraphFrameGenerate.into());
|
||||
}
|
||||
NodeGraphMessage::TogglePreview { node_id } => {
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
responses.push_back(NodeGraphMessage::TogglePreviewImpl { node_id }.into());
|
||||
}
|
||||
NodeGraphMessage::TogglePreviewImpl { node_id } => {
|
||||
if let Some(network) = self.get_active_network_mut(document) {
|
||||
// Check if the node is not already
|
||||
if network.output != node_id {
|
||||
|
||||
+4
-4
@@ -21,7 +21,7 @@ pub fn string_properties(text: impl Into<String>) -> Vec<LayoutGroup> {
|
||||
fn update_value<T, F: Fn(&T) -> TaggedValue + 'static + Send + Sync>(value: F, node_id: NodeId, input_index: usize) -> WidgetCallback<T> {
|
||||
WidgetCallback::new(move |input_value: &T| {
|
||||
NodeGraphMessage::SetInputValue {
|
||||
node: node_id,
|
||||
node_id,
|
||||
input_index,
|
||||
value: value(input_value),
|
||||
}
|
||||
@@ -398,13 +398,13 @@ pub fn imaginate_properties(document_node: &DocumentNode, node_id: NodeId, conte
|
||||
LayoutGroup::Row { widgets }.with_tooltip("Connection status to the server that computes generated images")
|
||||
};
|
||||
|
||||
let &NodeInput::Value {tagged_value: TaggedValue::ImaginateStatus( imaginate_status),..} = status_value else{
|
||||
let &NodeInput::Value {tagged_value: TaggedValue::ImaginateStatus( imaginate_status),..} = status_value else {
|
||||
panic!("Invalid status input")
|
||||
};
|
||||
let NodeInput::Value {tagged_value: TaggedValue::RcImage( cached_data),..} = cached_value else{
|
||||
let NodeInput::Value {tagged_value: TaggedValue::RcImage( cached_data),..} = cached_value else {
|
||||
panic!("Invalid cached image input")
|
||||
};
|
||||
let &NodeInput::Value {tagged_value: TaggedValue::F64( percent_complete),..} = complete_value else{
|
||||
let &NodeInput::Value {tagged_value: TaggedValue::F64( percent_complete),..} = complete_value else {
|
||||
panic!("Invalid percent complete input")
|
||||
};
|
||||
let use_base_image = if let &NodeInput::Value {
|
||||
|
||||
+24
-10
@@ -92,7 +92,7 @@ impl<'a> MessageHandler<PropertiesPanelMessage, (&PersistentData, PropertiesPane
|
||||
ModifyFont { font_family, font_style, size } => {
|
||||
let (path, _) = self.active_selection.clone().expect("Received update for properties panel with no active layer");
|
||||
|
||||
responses.push_back(self.create_document_operation(Operation::ModifyFont { path, font_family, font_style, size }));
|
||||
self.create_document_operation(Operation::ModifyFont { path, font_family, font_style, size }, true, responses);
|
||||
responses.push_back(ResendActiveProperties.into());
|
||||
}
|
||||
ModifyTransform { value, transform_op } => {
|
||||
@@ -101,33 +101,34 @@ impl<'a> MessageHandler<PropertiesPanelMessage, (&PersistentData, PropertiesPane
|
||||
|
||||
let transform = apply_transform_operation(layer, transform_op, value, &persistent_data.font_cache);
|
||||
|
||||
responses.push_back(self.create_document_operation(Operation::SetLayerTransform { path: path.clone(), transform }));
|
||||
self.create_document_operation(Operation::SetLayerTransform { path: path.clone(), transform }, true, responses);
|
||||
}
|
||||
ModifyName { name } => {
|
||||
let (path, _) = self.active_selection.clone().expect("Received update for properties panel with no active layer");
|
||||
responses.push_back(self.create_document_operation(Operation::SetLayerName { path, name }))
|
||||
self.create_document_operation(Operation::SetLayerName { path, name }, true, responses);
|
||||
}
|
||||
ModifyPreserveAspect { preserve_aspect } => {
|
||||
let (layer_path, _) = self.active_selection.clone().expect("Received update for properties panel with no active layer");
|
||||
responses.push_back(self.create_document_operation(Operation::SetLayerPreserveAspect { layer_path, preserve_aspect }))
|
||||
self.create_document_operation(Operation::SetLayerPreserveAspect { layer_path, preserve_aspect }, true, responses);
|
||||
}
|
||||
ModifyFill { fill } => {
|
||||
let (path, _) = self.active_selection.clone().expect("Received update for properties panel with no active layer");
|
||||
responses.push_back(self.create_document_operation(Operation::SetLayerFill { path, fill }));
|
||||
self.create_document_operation(Operation::SetLayerFill { path, fill }, true, responses);
|
||||
}
|
||||
ModifyStroke { stroke } => {
|
||||
let (path, _) = self.active_selection.clone().expect("Received update for properties panel with no active layer");
|
||||
responses.push_back(self.create_document_operation(Operation::SetLayerStroke { path, stroke }))
|
||||
self.create_document_operation(Operation::SetLayerStroke { path, stroke }, true, responses);
|
||||
}
|
||||
ModifyText { new_text } => {
|
||||
let (path, _) = self.active_selection.clone().expect("Received update for properties panel with no active layer");
|
||||
responses.push_back(Operation::SetTextContent { path, new_text }.into())
|
||||
self.create_document_operation(Operation::SetTextContent { path, new_text }, true, responses);
|
||||
}
|
||||
SetPivot { new_position } => {
|
||||
let (layer_path, _) = self.active_selection.clone().expect("Received update for properties panel with no active layer");
|
||||
let position: Option<glam::DVec2> = new_position.into();
|
||||
let pivot = position.unwrap().into();
|
||||
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
responses.push_back(Operation::SetPivot { layer_path, pivot }.into());
|
||||
}
|
||||
CheckSelectedWasUpdated { path } => {
|
||||
@@ -187,11 +188,24 @@ impl PropertiesPanelMessageHandler {
|
||||
matches!((last_active_path_id, last_modified), (Some(active_last), Some(modified_last)) if active_last == modified_last)
|
||||
}
|
||||
|
||||
fn create_document_operation(&self, operation: Operation) -> Message {
|
||||
fn create_document_operation(&self, operation: Operation, commit_history: bool, responses: &mut VecDeque<Message>) {
|
||||
let (_, target_document) = self.active_selection.as_ref().unwrap();
|
||||
match *target_document {
|
||||
TargetDocument::Artboard => ArtboardMessage::DispatchOperation(Box::new(operation)).into(),
|
||||
TargetDocument::Artwork => DocumentMessage::DispatchOperation(Box::new(operation)).into(),
|
||||
TargetDocument::Artboard => {
|
||||
// Commit history is not respected as the artboard document is not saved in the history system.
|
||||
|
||||
// Dispatch the relevant operation to the artboard document
|
||||
responses.push_back(ArtboardMessage::DispatchOperation(Box::new(operation)).into())
|
||||
}
|
||||
TargetDocument::Artwork => {
|
||||
// Commit to history before the modification
|
||||
if commit_history {
|
||||
responses.push_back(DocumentMessage::StartTransaction.into());
|
||||
}
|
||||
|
||||
// Dispatch the relevant operation to the main document
|
||||
responses.push_back(DocumentMessage::DispatchOperation(Box::new(operation)).into());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user