Skip to content

Commit 0cc0835

Browse files
committed
Improve expose input and remove cancel/commit transaction messages
1 parent 532dc30 commit 0cc0835

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
@@ -400,15 +400,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
400400
responses.add(DocumentMessage::EnterNestedNetwork { node_id });
401401
}
402402
}
403-
NodeGraphMessage::ExposeInput {
404-
input_connector,
405-
set_to_exposed,
406-
start_transaction,
407-
} => {
408-
let InputConnector::Node { node_id, input_index } = input_connector else {
409-
log::error!("Cannot expose/hide export");
410-
return;
411-
};
403+
NodeGraphMessage::ExposeInput { node_id, input_index, exposed } => {
412404
let Some(node) = network_interface.document_node(&node_id, selection_network_path) else {
413405
log::error!("Could not find node {node_id} in NodeGraphMessage::ExposeInput");
414406
return;
@@ -418,38 +410,19 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
418410
return;
419411
};
420412

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

440-
// If this node's input is a value type, we set its chosen exposed state
415+
let new_exposed = exposed;
441416
if let NodeInput::Value { exposed, .. } = &mut node_input {
442-
*exposed = set_to_exposed;
417+
*exposed = new_exposed;
443418
}
419+
444420
responses.add(NodeGraphMessage::SetInput {
445421
input_connector: InputConnector::node(node_id, input_index),
446422
input: node_input,
447423
});
448424

449-
// Finish the history step
450-
responses.add(DocumentMessage::CommitTransaction);
451-
452-
// Update the graph UI and re-render
425+
// 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
453426
if graph_view_overlay_open {
454427
responses.add(PropertiesPanelMessage::Refresh);
455428
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
@@ -46,7 +46,7 @@ pub fn commit_value<T>(_: &T) -> Message {
4646
DocumentMessage::AddTransaction.into()
4747
}
4848

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

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
}
@@ -251,7 +250,6 @@ impl Fsm for FreehandToolFsmState {
251250
(FreehandToolFsmState::Ready, FreehandToolMessage::DragStart { append_to_selected }) => {
252251
responses.add(DocumentMessage::StartTransaction);
253252

254-
tool_data.dragged = false;
255253
tool_data.end_point = None;
256254
tool_data.weight = tool_options.line_weight;
257255

@@ -308,11 +306,7 @@ impl Fsm for FreehandToolFsmState {
308306
FreehandToolFsmState::Drawing
309307
}
310308
(FreehandToolFsmState::Drawing, FreehandToolMessage::DragStop) => {
311-
if tool_data.dragged {
312-
responses.add(DocumentMessage::CommitTransaction);
313-
} else {
314-
responses.add(DocumentMessage::EndTransaction);
315-
}
309+
responses.add(DocumentMessage::EndTransaction);
316310

317311
tool_data.end_point = None;
318312
tool_data.layer = None;
@@ -381,7 +375,6 @@ fn extend_path_with_next_segment(tool_data: &mut FreehandToolData, position: DVe
381375
});
382376
}
383377

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

0 commit comments

Comments
 (0)