mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 14:18:04 +08:00
Update the parameter expose button in the Properties panel and fix undo history when it's clicked
This commit is contained in:
@@ -159,6 +159,7 @@ pub enum DocumentMessage {
|
||||
SetViewMode {
|
||||
view_mode: ViewMode,
|
||||
},
|
||||
AddTransaction,
|
||||
StartTransaction,
|
||||
EndTransaction,
|
||||
CommitTransaction,
|
||||
@@ -166,7 +167,6 @@ pub enum DocumentMessage {
|
||||
RepeatedAbortTransaction {
|
||||
undo_count: usize,
|
||||
},
|
||||
AddTransaction,
|
||||
ToggleLayerExpansion {
|
||||
id: NodeId,
|
||||
recursive: bool,
|
||||
|
||||
@@ -1155,6 +1155,11 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
|
||||
self.view_mode = view_mode;
|
||||
responses.add_front(NodeGraphMessage::RunDocumentGraph);
|
||||
}
|
||||
DocumentMessage::AddTransaction => {
|
||||
// Reverse order since they are added to the front
|
||||
responses.add_front(DocumentMessage::CommitTransaction);
|
||||
responses.add_front(DocumentMessage::StartTransaction);
|
||||
}
|
||||
// Note: A transaction should never be started in a scope that mutates the network interface, since it will only be run after that scope ends.
|
||||
DocumentMessage::StartTransaction => {
|
||||
self.network_interface.start_transaction();
|
||||
@@ -1198,11 +1203,6 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
|
||||
self.network_interface.finish_transaction();
|
||||
responses.add(OverlaysMessage::Draw);
|
||||
}
|
||||
DocumentMessage::AddTransaction => {
|
||||
// Reverse order since they are added to the front
|
||||
responses.add_front(DocumentMessage::CommitTransaction);
|
||||
responses.add_front(DocumentMessage::StartTransaction);
|
||||
}
|
||||
DocumentMessage::ToggleLayerExpansion { id, recursive } => {
|
||||
let layer = LayerNodeIdentifier::new(id, &self.network_interface, &[]);
|
||||
let metadata = self.metadata();
|
||||
|
||||
@@ -58,7 +58,8 @@ pub enum NodeGraphMessage {
|
||||
DuplicateSelectedNodes,
|
||||
ExposeInput {
|
||||
input_connector: InputConnector,
|
||||
new_exposed: bool,
|
||||
set_to_exposed: bool,
|
||||
start_transaction: bool,
|
||||
},
|
||||
InsertNode {
|
||||
node_id: NodeId,
|
||||
|
||||
@@ -315,7 +315,11 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||
responses.add(DocumentMessage::EnterNestedNetwork { node_id });
|
||||
}
|
||||
}
|
||||
NodeGraphMessage::ExposeInput { input_connector, new_exposed } => {
|
||||
NodeGraphMessage::ExposeInput {
|
||||
input_connector,
|
||||
set_to_exposed,
|
||||
start_transaction,
|
||||
} => {
|
||||
let InputConnector::Node { node_id, input_index } = input_connector else {
|
||||
log::error!("Cannot expose/hide export");
|
||||
return;
|
||||
@@ -324,26 +328,43 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
|
||||
log::error!("Could not find node {node_id} in NodeGraphMessage::ExposeInput");
|
||||
return;
|
||||
};
|
||||
let Some(mut input) = node.inputs.get(input_index).cloned() else {
|
||||
let Some(mut node_input) = node.inputs.get(input_index).cloned() else {
|
||||
log::error!("Could not find input {input_index} in NodeGraphMessage::ExposeInput");
|
||||
return;
|
||||
};
|
||||
if let NodeInput::Value { exposed, .. } = &mut input {
|
||||
*exposed = new_exposed;
|
||||
} else if !new_exposed {
|
||||
// If hiding an input that is not a value, then disconnect it. This will convert it to a value input.
|
||||
responses.add(NodeGraphMessage::DisconnectInput { input_connector });
|
||||
responses.add(NodeGraphMessage::ExposeInput { input_connector, new_exposed });
|
||||
|
||||
// If we're un-exposing an input that is not a value, then disconnect it. This will convert it to a value input,
|
||||
// so we can come back to handle this message again to set the exposed value in the second run-through.
|
||||
if !set_to_exposed && node_input.as_value().is_none() {
|
||||
// Reversed order because we are pushing front
|
||||
responses.add_front(NodeGraphMessage::ExposeInput {
|
||||
input_connector,
|
||||
set_to_exposed,
|
||||
start_transaction: false,
|
||||
});
|
||||
responses.add_front(NodeGraphMessage::DisconnectInput { input_connector });
|
||||
responses.add_front(DocumentMessage::StartTransaction);
|
||||
return;
|
||||
}
|
||||
|
||||
responses.add(DocumentMessage::AddTransaction);
|
||||
// Add a history step, but only do so if we didn't already start a transaction in the first run-through of this message in the above code
|
||||
if start_transaction {
|
||||
responses.add_front(DocumentMessage::StartTransaction);
|
||||
}
|
||||
|
||||
// If this node's input is a value type, we set its chosen exposed state
|
||||
if let NodeInput::Value { exposed, .. } = &mut node_input {
|
||||
*exposed = set_to_exposed;
|
||||
}
|
||||
responses.add(NodeGraphMessage::SetInput {
|
||||
input_connector: InputConnector::node(node_id, input_index),
|
||||
input,
|
||||
input: node_input,
|
||||
});
|
||||
|
||||
// Finish the history step
|
||||
responses.add(DocumentMessage::CommitTransaction);
|
||||
|
||||
// Update the graph UI and re-render
|
||||
responses.add(PropertiesPanelMessage::Refresh);
|
||||
responses.add(NodeGraphMessage::SendGraph);
|
||||
responses.add(NodeGraphMessage::RunDocumentGraph);
|
||||
|
||||
@@ -52,11 +52,12 @@ pub fn expose_widget(node_id: NodeId, index: usize, data_type: FrontendGraphData
|
||||
ParameterExposeButton::new()
|
||||
.exposed(exposed)
|
||||
.data_type(data_type)
|
||||
.tooltip("Expose this parameter input in node graph")
|
||||
.tooltip("Expose this parameter as a node input in the graph")
|
||||
.on_update(move |_parameter| {
|
||||
NodeGraphMessage::ExposeInput {
|
||||
input_connector: InputConnector::node(node_id, index),
|
||||
new_exposed: !exposed,
|
||||
set_to_exposed: !exposed,
|
||||
start_transaction: true,
|
||||
}
|
||||
.into()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user