Files
textmate/Applications/TextMate/src/AppController Commands.mm
Allan Odgaard d4f664d4c8 Use factory method for DocumentController objects
We regularly iterate through all open windows and test if these are document controller windows. It will be easier to let the document controller class (or application delegate) manage a list of open document windows, as we anyway need some sort of owner with ARC (currently the instances own themselves and give up ownership in windowWillClose: which cause them to be released).
2013-01-08 22:48:07 +01:00

57 lines
1.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#import "AppController.h"
#import <DocumentWindow/DocumentController.h>
#import <bundles/bundles.h>
#import <command/parser.h>
#import <command/runner.h>
#import <document/collection.h>
#import <editor/editor.h>
#import <ns/ns.h>
#import <settings/settings.h>
#import <OakAppKit/NSAlert Additions.h>
#import <OakAppKit/OakToolTip.h>
#import <OakFoundation/NSString Additions.h>
#import <OakSystem/application.h>
#import <plist/uuid.h>
#import <HTMLOutputWindow/HTMLOutputWindow.h>
OAK_DEBUG_VAR(AppController_Commands);
@implementation AppController (Commands)
- (void)performBundleItemWithUUIDString:(NSString*)uuidString
{
if(bundles::item_ptr item = bundles::lookup(to_s(uuidString)))
{
DocumentController* delegate = (DocumentController*)[[NSApp mainWindow] delegate];
if([delegate respondsToSelector:@selector(performBundleItem:)])
return [delegate performBundleItem:item];
switch(item->kind())
{
case bundles::kItemTypeSnippet:
{
document::document_ptr doc = document::create();
// TODO set language according to snippets scope selector
doc->open();
document::show(doc); // If we call show() with a document that isnt open then it will be loaded in the background, and show() will return before this has completed, meaning the next line may not target our new document.
[[DocumentController controllerForDocument:doc] performBundleItem:item];
doc->close();
// TODO mark document as “not modified”
}
break;
case bundles::kItemTypeCommand:
{
document::run(parse_command(item), ng::buffer_t(), ng::ranges_t(), document::document_ptr());
}
break;
case bundles::kItemTypeGrammar:
{
document::show(document::from_content("", item->value_for_field(bundles::kFieldGrammarScope)));
}
break;
}
}
}
@end