From 88ae04572cf9cc76e8492015f86243ff54622044 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Thu, 9 May 2013 11:41:19 +0700 Subject: [PATCH] =?UTF-8?q?Handle=20=E2=80=9Cdid-save=E2=80=9D=20bundle=20?= =?UTF-8?q?item=20callback=20in=20OakTextView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While it’s easier to execute bundle items from a text view, it doesn’t work when saving documents that are not in the current text view. This is an intermediate refactoring step — handling should (likely) end up in the DocumentSaveHelper class, but we need to improve dealing with command execution first, and by having the callback piggyback on the normal performBundleItem: method, we (temporarily) limit the code which use the command execution API, making refactoring easier. --- .../DocumentWindow/src/DocumentSaveHelper.mm | 6 +++++- Frameworks/OakTextView/src/OakTextView.mm | 15 +++++++++++++++ Frameworks/document/src/document.cc | 7 ------- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Frameworks/DocumentWindow/src/DocumentSaveHelper.mm b/Frameworks/DocumentWindow/src/DocumentSaveHelper.mm index 9e5bdc7b..cff648db 100644 --- a/Frameworks/DocumentWindow/src/DocumentSaveHelper.mm +++ b/Frameworks/DocumentWindow/src/DocumentSaveHelper.mm @@ -204,7 +204,11 @@ namespace - (void)didSaveDocument:(document::document_ptr const&)aDocument success:(BOOL)flag error:(std::string const&)aMessage usingFilter:(oak::uuid_t const&)aFilter { D(DBF_DocumentController_SaveHelper, bug("‘%s’, success %s, user abort %s\n", aDocument->path().c_str(), BSTR(flag), BSTR(self.userAbort));); - if(!flag && !self.userAbort) + if(flag) + { + [[NSNotificationCenter defaultCenter] postNotificationName:@"OakDocumentNotificationDidSave" object:self userInfo:@{ @"window" : self.window }]; + } + else if(!self.userAbort) { [self.window.attachedSheet orderOut:self]; if(aFilter) diff --git a/Frameworks/OakTextView/src/OakTextView.mm b/Frameworks/OakTextView/src/OakTextView.mm index 3737d847..8baa3b2f 100644 --- a/Frameworks/OakTextView/src/OakTextView.mm +++ b/Frameworks/OakTextView/src/OakTextView.mm @@ -524,6 +524,7 @@ static std::string shell_quote (std::vector paths) [self registerForDraggedTypes:[[self class] dropTypes]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(documentWillSave:) name:@"OakDocumentNotificationWillSave" object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(documentDidSave:) name:@"OakDocumentNotificationDidSave" object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDefaultsDidChange:) name:NSUserDefaultsDidChangeNotification object:[NSUserDefaults standardUserDefaults]]; } return self; @@ -548,6 +549,20 @@ static std::string shell_quote (std::vector paths) document->set_folded(layout->folded_as_string()); } +- (void)documentDidSave:(NSNotification*)aNotification +{ + NSWindow* window = [[aNotification userInfo] objectForKey:@"window"]; + if(window != self.window) + return; + + D(DBF_Document, bug("search for ‘did save’ hooks in scope ‘%s’\n", to_s(editor->scope(to_s([self scopeAttributes]))).c_str());); + citerate(item, bundles::query(bundles::kFieldSemanticClass, "callback.document.did-save", editor->scope(to_s([self scopeAttributes])))) + { + D(DBF_Document, bug("%s\n", (*item)->name().c_str());); + [self performBundleItem:*item]; + } +} + - (void)reflectDocumentSize { if(document && layout && [self enclosingScrollView]) diff --git a/Frameworks/document/src/document.cc b/Frameworks/document/src/document.cc index bd7c5e10..bbe2fac8 100644 --- a/Frameworks/document/src/document.cc +++ b/Frameworks/document/src/document.cc @@ -613,13 +613,6 @@ namespace document check_modified(revision(), revision()); mark_pristine(); broadcast(callback_t::did_save); - - D(DBF_Document, bug("search for ‘did save’ hooks in scope ‘%s’\n", to_s(scope()).c_str());); - citerate(item, bundles::query(bundles::kFieldSemanticClass, "callback.document.did-save", scope())) - { - D(DBF_Document, bug("%s\n", (*item)->name().c_str());); - document::run(parse_command(*item), buffer(), ng::ranges_t(), shared_from_this()); - } } if(_is_on_disk)