mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-18 07:48:02 +08:00
Implement IndexedDB document auto-save (#422)
* removed all use of document indicies * -add u64 support for wasm bridge * fixed rust formating * Cleaned up FrontendDocumentState in js-messages * Tiny tweaks from code review * - moved more of closeDocumentWithConfirmation to rust - updated serde_wasm_bindgen to add feature flag * working initial auto save impl * auto save is a lifetime file * - cargo fmt - fixc error message - move document version constant * code review round 1 * generate seed for uuid in js when wasm is initialized * Resolve PR feedback * Further address PR feedback * Fix failing test Co-authored-by: Keavon Chambers <keavon@keavon.com> Co-authored-by: otdavies <oliver@psyfer.io>
This commit is contained in:
@@ -5,6 +5,7 @@ pub use super::layer_panel::*;
|
||||
use super::movement_handler::{MovementMessage, MovementMessageHandler};
|
||||
use super::transform_layer_handler::{TransformLayerMessage, TransformLayerMessageHandler};
|
||||
|
||||
use crate::consts::DEFAULT_DOCUMENT_NAME;
|
||||
use crate::consts::{ASYMPTOTIC_EFFECT, FILE_EXPORT_SUFFIX, FILE_SAVE_SUFFIX, SCALE_EFFECT, SCROLLBAR_SPACING};
|
||||
use crate::input::InputPreprocessor;
|
||||
use crate::message_prelude::*;
|
||||
@@ -186,6 +187,13 @@ impl DocumentMessageHandler {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_unmodified_default(&self) -> bool {
|
||||
self.serialize_root().len() == Self::default().serialize_root().len()
|
||||
&& self.document_undo_history.len() == 0
|
||||
&& self.document_redo_history.len() == 0
|
||||
&& self.name.starts_with(DEFAULT_DOCUMENT_NAME)
|
||||
}
|
||||
|
||||
fn select_layer(&mut self, path: &[LayerId]) -> Option<Message> {
|
||||
if self.graphene_document.layer(path).ok()?.overlay {
|
||||
return None;
|
||||
@@ -413,6 +421,14 @@ impl DocumentMessageHandler {
|
||||
self.current_identifier() == self.saved_document_identifier
|
||||
}
|
||||
|
||||
pub fn set_save_state(&mut self, is_saved: bool) {
|
||||
if is_saved {
|
||||
self.saved_document_identifier = self.current_identifier();
|
||||
} else {
|
||||
self.saved_document_identifier = generate_uuid();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn layer_panel_entry(&mut self, path: Vec<LayerId>) -> Result<LayerPanelEntry, EditorError> {
|
||||
let data: LayerData = *layer_data(&mut self.layer_data, &path);
|
||||
let layer = self.graphene_document.layer(&path)?;
|
||||
@@ -493,7 +509,8 @@ impl MessageHandler<DocumentMessage, &InputPreprocessor> for DocumentMessageHand
|
||||
)
|
||||
}
|
||||
SaveDocument => {
|
||||
self.saved_document_identifier = self.current_identifier();
|
||||
self.set_save_state(true);
|
||||
responses.push_back(DocumentsMessage::AutoSaveActiveDocument.into());
|
||||
// Update the save status of the just saved document
|
||||
responses.push_back(DocumentsMessage::UpdateOpenDocumentsList.into());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user