mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
Display Asterisk on Unsaved Documents (#392)
* ability to mark an open document as unsaved * unsaved detection now being triggered based on layer tree height * - rust implementation of unsaved markers - upgraded eslint * updated eslint in package.json * - Renamed GetOpenDocumentsList -> UpdateOpenDocumentsList - is not -> was not * changed hash to current identifier to better reflect its meaning * resolve some merge conflicts * removed console.log statement leftover from debuging
This commit is contained in:
@@ -28,7 +28,7 @@ pub enum DocumentsMessage {
|
||||
NewDocument,
|
||||
OpenDocument,
|
||||
OpenDocumentFile(String, String),
|
||||
GetOpenDocumentsList,
|
||||
UpdateOpenDocumentsList,
|
||||
NextDocument,
|
||||
PrevDocument,
|
||||
}
|
||||
@@ -55,9 +55,7 @@ impl DocumentsMessageHandler {
|
||||
|
||||
fn generate_new_document_name(&self) -> String {
|
||||
let mut doc_title_numbers = self
|
||||
.document_ids
|
||||
.iter()
|
||||
.filter_map(|id| self.documents.get(&id))
|
||||
.ordered_document_iterator()
|
||||
.map(|doc| {
|
||||
doc.name
|
||||
.rsplit_once(DEFAULT_DOCUMENT_NAME)
|
||||
@@ -85,7 +83,11 @@ impl DocumentsMessageHandler {
|
||||
self.documents.insert(self.document_id_counter, new_document);
|
||||
|
||||
// Send the new list of document tab names
|
||||
let open_documents = self.document_ids.iter().filter_map(|id| self.documents.get(&id).map(|doc| doc.name.clone())).collect::<Vec<String>>();
|
||||
let open_documents = self
|
||||
.document_ids
|
||||
.iter()
|
||||
.filter_map(|id| self.documents.get(&id).map(|doc| (doc.name.clone(), doc.is_saved())))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
responses.push_back(FrontendMessage::UpdateOpenDocumentsList { open_documents }.into());
|
||||
|
||||
@@ -96,6 +98,11 @@ impl DocumentsMessageHandler {
|
||||
responses.push_back(DocumentMessage::LayerChanged(layer.clone()).into());
|
||||
}
|
||||
}
|
||||
|
||||
// Returns an iterator over the open documents in order
|
||||
pub fn ordered_document_iterator(&self) -> impl Iterator<Item = &DocumentMessageHandler> {
|
||||
self.document_ids.iter().map(|id| self.documents.get(id).expect("document id was not found in the document hashmap"))
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for DocumentsMessageHandler {
|
||||
@@ -170,7 +177,7 @@ impl MessageHandler<DocumentsMessage, &InputPreprocessor> for DocumentsMessageHa
|
||||
};
|
||||
|
||||
// Send the new list of document tab names
|
||||
let open_documents = self.document_ids.iter().filter_map(|id| self.documents.get(&id).map(|doc| doc.name.clone())).collect();
|
||||
let open_documents = self.ordered_document_iterator().map(|doc| (doc.name.clone(), doc.is_saved())).collect();
|
||||
|
||||
// Update the list of new documents on the front end, active tab, and ensure that document renders
|
||||
responses.push_back(FrontendMessage::UpdateOpenDocumentsList { open_documents }.into());
|
||||
@@ -209,9 +216,9 @@ impl MessageHandler<DocumentsMessage, &InputPreprocessor> for DocumentsMessageHa
|
||||
),
|
||||
}
|
||||
}
|
||||
GetOpenDocumentsList => {
|
||||
UpdateOpenDocumentsList => {
|
||||
// Send the list of document tab names
|
||||
let open_documents = self.documents.values().map(|doc| doc.name.clone()).collect();
|
||||
let open_documents = self.ordered_document_iterator().map(|doc| (doc.name.clone(), doc.is_saved())).collect();
|
||||
responses.push_back(FrontendMessage::UpdateOpenDocumentsList { open_documents }.into());
|
||||
}
|
||||
NextDocument => {
|
||||
|
||||
Reference in New Issue
Block a user