mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 15:28:04 +08:00
Save work periodically to reduce loss from crashes (#1580)
* Add auto saving * Fix autosave dispatching message but not saving document * Clamp set_timeout delay * Auto save all documents instead of only the active * Add with_editor to simplify code * Update consts * Simplify some more * Fix typo * Code review --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
@@ -76,3 +76,4 @@ pub const DEFAULT_FONT_STYLE: &str = "Normal (400)";
|
||||
pub const DEFAULT_DOCUMENT_NAME: &str = "Untitled Document";
|
||||
pub const FILE_SAVE_SUFFIX: &str = ".graphite";
|
||||
pub const MAX_UNDO_HISTORY_LEN: usize = 100; // TODO: Add this to user preferences
|
||||
pub const AUTO_SAVE_TIMEOUT_SECONDS: u64 = 15;
|
||||
|
||||
@@ -26,6 +26,7 @@ pub enum PortfolioMessage {
|
||||
message: DocumentMessage,
|
||||
},
|
||||
AutoSaveActiveDocument,
|
||||
AutoSaveAllDocuments,
|
||||
AutoSaveDocument {
|
||||
document_id: DocumentId,
|
||||
},
|
||||
|
||||
@@ -76,8 +76,16 @@ impl MessageHandler<PortfolioMessage, (&InputPreprocessorMessageHandler, &Prefer
|
||||
if let Some(document_id) = self.active_document_id {
|
||||
if let Some(document) = self.active_document_mut() {
|
||||
document.set_auto_save_state(true);
|
||||
responses.add(PortfolioMessage::AutoSaveDocument { document_id });
|
||||
}
|
||||
}
|
||||
}
|
||||
PortfolioMessage::AutoSaveAllDocuments => {
|
||||
for (document_id, document) in self.documents.iter_mut() {
|
||||
if !document.is_auto_saved() {
|
||||
document.set_auto_save_state(true);
|
||||
responses.add(PortfolioMessage::AutoSaveDocument { document_id: *document_id });
|
||||
}
|
||||
responses.add(PortfolioMessage::AutoSaveDocument { document_id });
|
||||
}
|
||||
}
|
||||
PortfolioMessage::AutoSaveDocument { document_id } => {
|
||||
|
||||
Reference in New Issue
Block a user