Skip to content

Commit 4022836

Browse files
adamgerhantKeavon
authored andcommitted
Improve expose input and remove cancel/commit transaction messages
1 parent c2730bd commit 4022836

File tree

7 files changed

+45
-79
lines changed

7 files changed

+45
-79
lines changed

editor/src/messages/portfolio/document/document_message.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ pub enum DocumentMessage {
182182
AddTransaction,
183183
StartTransaction,
184184
EndTransaction,
185-
CommitTransaction,
186-
CancelTransaction,
187185
AbortTransaction,
188186
RepeatedAbortTransaction {
189187
undo_count: usize,

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,46 +1292,28 @@ impl MessageHandler<DocumentMessage, DocumentMessageContext<'_>> for DocumentMes
12921292
responses.add_front(NodeGraphMessage::RunDocumentGraph);
12931293
}
12941294
DocumentMessage::AddTransaction => {
1295-
// Reverse order since they are added to the front
1296-
responses.add_front(DocumentMessage::CommitTransaction);
1297-
responses.add_front(DocumentMessage::StartTransaction);
1295+
self.start_transaction(responses);
1296+
self.commit_transaction(responses);
12981297
}
12991298
// 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.
13001299
DocumentMessage::StartTransaction => {
1301-
self.network_interface.start_transaction();
1302-
let network_interface_clone = self.network_interface.clone();
1303-
self.document_undo_history.push_back(network_interface_clone);
1304-
if self.document_undo_history.len() > crate::consts::MAX_UNDO_HISTORY_LEN {
1305-
self.document_undo_history.pop_front();
1306-
}
1307-
// Push the UpdateOpenDocumentsList message to the bus in order to update the save status of the open documents
1308-
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
1300+
self.start_transaction(responses);
13091301
}
13101302
// Commits the transaction if the network was mutated since the transaction started, otherwise it cancels the transaction
13111303
DocumentMessage::EndTransaction => match self.network_interface.transaction_status() {
13121304
TransactionStatus::Started => {
1313-
responses.add_front(DocumentMessage::CancelTransaction);
1305+
self.network_interface.finish_transaction();
1306+
self.document_undo_history.pop_back();
13141307
}
13151308
TransactionStatus::Modified => {
1316-
responses.add_front(DocumentMessage::CommitTransaction);
1309+
self.commit_transaction(responses);
13171310
}
13181311
TransactionStatus::Finished => {}
13191312
},
1320-
DocumentMessage::CancelTransaction => {
1321-
self.network_interface.finish_transaction();
1322-
self.document_undo_history.pop_back();
1323-
}
1324-
DocumentMessage::CommitTransaction => {
1325-
if self.network_interface.transaction_status() == TransactionStatus::Finished {
1326-
return;
1327-
}
1328-
self.network_interface.finish_transaction();
1329-
self.document_redo_history.clear();
1330-
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
1331-
}
13321313
DocumentMessage::AbortTransaction => match self.network_interface.transaction_status() {
13331314
TransactionStatus::Started => {
1334-
responses.add_front(DocumentMessage::CancelTransaction);
1315+
self.network_interface.finish_transaction();
1316+
self.document_undo_history.pop_back();
13351317
}
13361318
TransactionStatus::Modified => {
13371319
responses.add(DocumentMessage::RepeatedAbortTransaction { undo_count: 1 });
@@ -1829,6 +1811,26 @@ impl DocumentMessageHandler {
18291811
val.unwrap()
18301812
}
18311813

1814+
pub fn start_transaction(&mut self, responses: &mut VecDeque<Message>) {
1815+
self.network_interface.start_transaction();
1816+
let network_interface_clone = self.network_interface.clone();
1817+
self.document_undo_history.push_back(network_interface_clone);
1818+
if self.document_undo_history.len() > crate::consts::MAX_UNDO_HISTORY_LEN {
1819+
self.document_undo_history.pop_front();
1820+
}
1821+
// Push the UpdateOpenDocumentsList message to the bus in order to update the save status of the open documents
1822+
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
1823+
}
1824+
1825+
pub fn commit_transaction(&mut self, responses: &mut VecDeque<Message>) {
1826+
if self.network_interface.transaction_status() == TransactionStatus::Finished {
1827+
return;
1828+
}
1829+
self.network_interface.finish_transaction();
1830+
self.document_redo_history.clear();
1831+
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
1832+
}
1833+
18321834
pub fn deserialize_document(serialized_content: &str) -> Result<Self, EditorError> {
18331835
let document_message_handler = serde_json::from_str::<DocumentMessageHandler>(serialized_content)
18341836
.or_else(|e| {

editor/src/messages/portfolio/document/node_graph/node_graph_message.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ pub enum NodeGraphMessage {
6363
EnterNestedNetwork,
6464
DuplicateSelectedNodes,
6565
ExposeInput {
66-
input_connector: InputConnector,
67-
set_to_exposed: bool,
68-
start_transaction: bool,
66+
node_id: NodeId,
67+
input_index: usize,
68+
exposed: bool,
6969
},
7070
ExposeEncapsulatingPrimaryInput {
7171
exposed: bool,

editor/src/messages/portfolio/document/node_graph/node_graph_message_handler.rs

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -403,15 +403,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
403403
responses.add(DocumentMessage::EnterNestedNetwork { node_id });
404404
}
405405
}
406-
NodeGraphMessage::ExposeInput {
407-
input_connector,
408-
set_to_exposed,
409-
start_transaction,
410-
} => {
411-
let InputConnector::Node { node_id, input_index } = input_connector else {
412-
log::error!("Cannot expose/hide export");
413-
return;
414-
};
406+
NodeGraphMessage::ExposeInput { node_id, input_index, exposed } => {
415407
let Some(node) = network_interface.document_node(&node_id, selection_network_path) else {
416408
log::error!("Could not find node {node_id} in NodeGraphMessage::ExposeInput");
417409
return;
@@ -421,38 +413,19 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
421413
return;
422414
};
423415

424-
// If we're un-exposing an input that is not a value, then disconnect it. This will convert it to a value input,
425-
// so we can come back to handle this message again to set the exposed value in the second run-through.
426-
if !set_to_exposed && node_input.as_value().is_none() {
427-
// Reversed order because we are pushing front
428-
responses.add_front(NodeGraphMessage::ExposeInput {
429-
input_connector,
430-
set_to_exposed,
431-
start_transaction: false,
432-
});
433-
responses.add_front(NodeGraphMessage::DisconnectInput { input_connector });
434-
responses.add_front(DocumentMessage::StartTransaction);
435-
return;
436-
}
437-
438-
// 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
439-
if start_transaction {
440-
responses.add_front(DocumentMessage::StartTransaction);
441-
}
416+
responses.add(DocumentMessage::AddTransaction);
442417

443-
// If this node's input is a value type, we set its chosen exposed state
418+
let new_exposed = exposed;
444419
if let NodeInput::Value { exposed, .. } = &mut node_input {
445-
*exposed = set_to_exposed;
420+
*exposed = new_exposed;
446421
}
422+
447423
responses.add(NodeGraphMessage::SetInput {
448424
input_connector: InputConnector::node(node_id, input_index),
449425
input: node_input,
450426
});
451427

452-
// Finish the history step
453-
responses.add(DocumentMessage::CommitTransaction);
454-
455-
// Update the graph UI and re-render
428+
// Update the graph UI and re-render if the graph is open, if the graph is closed then open the graph and zoom in on the input
456429
if graph_view_overlay_open {
457430
responses.add(PropertiesPanelMessage::Refresh);
458431
responses.add(NodeGraphMessage::SendGraph);

editor/src/messages/portfolio/document/node_graph/node_properties.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn commit_value<T>(_: &T) -> Message {
4747
DocumentMessage::AddTransaction.into()
4848
}
4949

50-
pub fn expose_widget(node_id: NodeId, index: usize, data_type: FrontendGraphDataType, exposed: bool) -> WidgetInstance {
50+
pub fn expose_widget(node_id: NodeId, input_index: usize, data_type: FrontendGraphDataType, exposed: bool) -> WidgetInstance {
5151
ParameterExposeButton::new()
5252
.exposed(exposed)
5353
.data_type(data_type)
@@ -58,9 +58,9 @@ pub fn expose_widget(node_id: NodeId, index: usize, data_type: FrontendGraphData
5858
})
5959
.on_update(move |_parameter| Message::Batched {
6060
messages: Box::new([NodeGraphMessage::ExposeInput {
61-
input_connector: InputConnector::node(node_id, index),
62-
set_to_exposed: !exposed,
63-
start_transaction: true,
61+
node_id,
62+
input_index,
63+
exposed: !exposed,
6464
}
6565
.into()]),
6666
})

editor/src/messages/portfolio/document/utility_types/network_interface.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3800,8 +3800,8 @@ impl NodeNetworkInterface {
38003800
return;
38013801
};
38023802

3803-
// When changing a NodeInput::Node to a NodeInput::Node, the input should first be disconnected to ensure proper side effects
3804-
if (matches!(previous_input, NodeInput::Node { .. }) && matches!(new_input, NodeInput::Node { .. })) {
3803+
// When changing a NodeInput::Node to another input, the input should first be disconnected to ensure proper side effects
3804+
if matches!(previous_input, NodeInput::Node { .. }) {
38053805
self.disconnect_input(input_connector, network_path);
38063806
self.set_input(input_connector, new_input, network_path);
38073807
return;
@@ -3856,7 +3856,7 @@ impl NodeNetworkInterface {
38563856
return;
38573857
}
38583858

3859-
// It is necessary to ensure the grpah is acyclic before calling `self.position` as it sometimes crashes with cyclic graphs #3227
3859+
// It is necessary to ensure the graph is acyclic before calling `self.position` as it sometimes crashes with cyclic graphs #3227
38603860
let previous_metadata = match &previous_input {
38613861
NodeInput::Node { node_id, .. } => self.position(node_id, network_path).map(|position| (*node_id, position)),
38623862
_ => None,

editor/src/messages/tool/tool_messages/freehand_tool.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ impl ToolTransition for FreehandTool {
214214
#[derive(Clone, Debug, Default)]
215215
struct FreehandToolData {
216216
end_point: Option<(DVec2, PointId)>,
217-
dragged: bool,
218217
weight: f64,
219218
layer: Option<LayerNodeIdentifier>,
220219
}
@@ -250,7 +249,6 @@ impl Fsm for FreehandToolFsmState {
250249
(FreehandToolFsmState::Ready, FreehandToolMessage::DragStart { append_to_selected }) => {
251250
responses.add(DocumentMessage::StartTransaction);
252251

253-
tool_data.dragged = false;
254252
tool_data.end_point = None;
255253
tool_data.weight = tool_options.line_weight;
256254

@@ -307,11 +305,7 @@ impl Fsm for FreehandToolFsmState {
307305
FreehandToolFsmState::Drawing
308306
}
309307
(FreehandToolFsmState::Drawing, FreehandToolMessage::DragStop) => {
310-
if tool_data.dragged {
311-
responses.add(DocumentMessage::CommitTransaction);
312-
} else {
313-
responses.add(DocumentMessage::EndTransaction);
314-
}
308+
responses.add(DocumentMessage::EndTransaction);
315309

316310
tool_data.end_point = None;
317311
tool_data.layer = None;
@@ -380,7 +374,6 @@ fn extend_path_with_next_segment(tool_data: &mut FreehandToolData, position: DVe
380374
});
381375
}
382376

383-
tool_data.dragged = true;
384377
tool_data.end_point = Some((position, id));
385378
}
386379

0 commit comments

Comments
 (0)