Fix serialising document (#1526)

* Fix serialising document

* Remove unused import

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
0HyperCube 2023-12-20 22:58:04 +00:00 committed by GitHub
parent 92203f3576
commit 4733134b22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 29 deletions

View File

@ -72,8 +72,6 @@ pub struct DocumentMessageHandler {
pub commit_hash: String,
#[serde(default)]
pub collapsed: Vec<LayerNodeIdentifier>,
#[serde(default)]
pub selected: HashMap<Vec<LayerId>, bool>,
// Fields omitted from the saved document format
//
@ -114,7 +112,6 @@ impl Default for DocumentMessageHandler {
document_undo_history: VecDeque::new(),
document_redo_history: VecDeque::new(),
undo_in_progress: false,
selected: vec![(vec![], true)].into_iter().collect(),
layer_range_selection_reference: None,
navigation_handler: NavigationMessageHandler::default(),
overlays_message_handler: OverlaysMessageHandler::default(),
@ -223,7 +220,6 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
#[remain::unsorted]
PropertiesPanel(message) => {
let properties_panel_message_handler_data = PropertiesPanelMessageHandlerData {
selected_layers: &mut self.selected.iter().filter_map(|(path, selected)| selected.then_some(path.as_slice())),
node_graph_message_handler: &self.node_graph_handler,
executor,
document_name: self.name.as_str(),
@ -319,7 +315,7 @@ impl MessageHandler<DocumentMessage, DocumentInputs<'_>> for DocumentMessageHand
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: vec![id] });
}
DebugPrintDocument => {
info!("{:#?}\n{:#?}", self.network, self.selected);
info!("{:#?}", self.network);
}
DeleteLayer { layer_path } => {
responses.add(GraphOperationMessage::DeleteLayer { id: layer_path[0] });
@ -870,10 +866,6 @@ impl DocumentMessageHandler {
Ok(document)
}
pub fn selected_layers(&self) -> impl Iterator<Item = &[LayerId]> {
self.selected.iter().filter_map(|(path, selected)| selected.then_some(path.as_slice()))
}
/// Returns the bounding boxes for all visible layers.
pub fn bounding_boxes<'a>(&'a self) -> impl Iterator<Item = [DVec2; 2]> + 'a {
// TODO: Remove this function entirely?
@ -978,19 +970,11 @@ impl DocumentMessageHandler {
// Push the UpdateOpenDocumentsList message to the bus in order to update the save status of the open documents
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
let selected_paths: Vec<Vec<LayerId>> = self.selected_layers().map(|path| path.to_vec()).collect();
let Some(document) = self.document_undo_history.pop_back() else {
return;
};
// Update the currently displayed layer on the Properties panel if the selection changes after an undo action
// Also appropriately update the Properties panel if an undo action results in a layer being deleted
let prev_selected_paths: Vec<Vec<LayerId>> = self.selected.iter().filter_map(|(layer_id, selected)| selected.then_some(layer_id.clone())).collect();
if prev_selected_paths != selected_paths {
responses.add(BroadcastEvent::SelectionChanged);
}
let document_save = self.replace_document(document);
@ -1007,17 +991,9 @@ impl DocumentMessageHandler {
// Push the UpdateOpenDocumentsList message to the bus in order to update the save status of the open documents
responses.add(PortfolioMessage::UpdateOpenDocumentsList);
let selected_paths: Vec<Vec<LayerId>> = self.selected_layers().map(|path| path.to_vec()).collect();
let Some(document) = self.document_redo_history.pop_back() else { return };
// Update currently displayed layer on property panel if selection changes after redo action
// Also appropriately update property panel if redo action results in a layer being added
let next_selected_paths: Vec<Vec<LayerId>> = self.selected.iter().filter_map(|(layer_id, selected)| selected.then_some(layer_id.clone())).collect();
if next_selected_paths != selected_paths {
responses.add(BroadcastEvent::SelectionChanged);
}
let document_save = self.replace_document(document);
self.document_undo_history.push_back(document_save);

View File

@ -1,5 +1,4 @@
use crate::messages::portfolio::document::utility_types::document_metadata::DocumentMetadata;
use crate::messages::portfolio::document::utility_types::LayerId;
use crate::messages::prelude::NodeGraphMessageHandler;
use crate::node_graph_executor::NodeGraphExecutor;
@ -9,7 +8,6 @@ pub struct PropertiesPanelMessageHandlerData<'a> {
pub document_name: &'a str,
pub document_network: &'a mut NodeNetwork,
pub document_metadata: &'a mut DocumentMetadata,
pub selected_layers: &'a mut dyn Iterator<Item = &'a [LayerId]>,
pub node_graph_message_handler: &'a NodeGraphMessageHandler,
pub executor: &'a mut NodeGraphExecutor,
}