mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
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).
57 lines
1.8 KiB
Plaintext
57 lines
1.8 KiB
Plaintext
#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 snippet’s scope selector
|
||
doc->open();
|
||
document::show(doc); // If we call show() with a document that isn’t 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
|