mirror of
https://github.com/textmate/textmate.git
synced 2026-01-19 19:58:11 -05:00
Handle “did-save” bundle item callback in OakTextView
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.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -524,6 +524,7 @@ static std::string shell_quote (std::vector<std::string> 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<std::string> 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])
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user