From 4a97f6e64d607cdfc2fcfee19a1b89009c69fdfb Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Thu, 10 Jan 2013 18:40:31 +0100 Subject: [PATCH] Save All with more than one document would crash --- .../DocumentWindow/src/DocumentController.mm | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Frameworks/DocumentWindow/src/DocumentController.mm b/Frameworks/DocumentWindow/src/DocumentController.mm index b9008cb4..59c3f488 100644 --- a/Frameworks/DocumentWindow/src/DocumentController.mm +++ b/Frameworks/DocumentWindow/src/DocumentController.mm @@ -705,17 +705,19 @@ namespace { struct save_callback_t : document_save_callback_t { - save_callback_t (DocumentController* self) : _self(self) { } + save_callback_t (DocumentController* self, size_t count) : _self(self), _count(count) { } void did_save_document (document::document_ptr document, bool flag, std::string const& message, oak::uuid_t const& filter) { if(flag) [_self documentDidChange:document]; - delete this; + if(--_count == 0 || !flag) + delete this; } private: __weak DocumentController* _self; + size_t _count; }; } @@ -723,7 +725,7 @@ namespace { if([self selectedDocument]->path() != NULL_STR) { - [DocumentSaveHelper trySaveDocument:[self selectedDocument] forWindow:self.window defaultDirectory:nil andCallback:new save_callback_t(self)]; + [DocumentSaveHelper trySaveDocument:[self selectedDocument] forWindow:self.window defaultDirectory:nil andCallback:new save_callback_t(self, 1)]; } else { @@ -758,7 +760,7 @@ namespace self.documents = newDocuments; } - [DocumentSaveHelper trySaveDocument:self.selectedDocument forWindow:self.window defaultDirectory:nil andCallback:new save_callback_t(self)]; + [DocumentSaveHelper trySaveDocument:self.selectedDocument forWindow:self.window defaultDirectory:nil andCallback:new save_callback_t(self, 1)]; [self updatePathDependentProperties]; }]; } @@ -775,7 +777,7 @@ namespace return; [self selectedDocument]->set_path(to_s(path)); [self selectedDocument]->set_disk_encoding(encoding); - [DocumentSaveHelper trySaveDocument:self.selectedDocument forWindow:self.window defaultDirectory:nil andCallback:new save_callback_t(self)]; + [DocumentSaveHelper trySaveDocument:self.selectedDocument forWindow:self.window defaultDirectory:nil andCallback:new save_callback_t(self, 1)]; [self updatePathDependentProperties]; }]; } @@ -788,7 +790,7 @@ namespace if((*document)->is_modified()) documentsToSave.push_back(*document); } - [DocumentSaveHelper trySaveDocuments:documentsToSave forWindow:self.window defaultDirectory:self.untitledSavePath andCallback:new save_callback_t(self)]; + [DocumentSaveHelper trySaveDocuments:documentsToSave forWindow:self.window defaultDirectory:self.untitledSavePath andCallback:new save_callback_t(self, documentsToSave.size())]; } // ================