| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- //
- // PolycodeAppDelegate.m
- // Polycode
- //
- // Created by Ivan Safrin on 11/28/10.
- // Copyright 2010 Local Projects. All rights reserved.
- //PolycodeIDEApp
- #import "PolycodeAppDelegate.h"
- @implementation PolycodeAppDelegate
- @synthesize window;
- @synthesize polycodeView;
- @synthesize projectMenu;
- - (id) init {
- app = NULL;
- return [super init];
- }
- - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
- // Insert code here to initialize your application
-
- mustShowProjectMenu = NO;
-
- eventHandler = new PolycodeAppEventHandler();
- eventHandler->appDelegate = self;
-
- app = new PolycodeIDEApp(polycodeView);
- app->addEventListener(eventHandler, PolycodeIDEApp::EVENT_SHOW_MENU);
-
- if(fileToOpen != "") {
- app->openProject(fileToOpen);
- }
-
- timer = [NSTimer timerWithTimeInterval:(1.0f/90.0f) target:self selector:@selector(animationTimer:) userInfo:nil repeats:YES];
- [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
- [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode]; // ensure timer fires during resize
- }
- - (void)animationTimer:(NSTimer *)timer
- {
- if(!app->Update()) {
- [[NSApplication sharedApplication] stop:self];
- }
-
- if(mustShowProjectMenu) {
- NSPoint menuOrigin = NSMakePoint(polycodeView.mouseX, polycodeView.mouseY);
-
- NSEvent *event = [NSEvent mouseEventWithType:NSLeftMouseDown
- location:menuOrigin
- modifierFlags:NSLeftMouseDownMask // 0x100
- timestamp:nil
- windowNumber:[window windowNumber]
- context:[window graphicsContext]
- eventNumber:0
- clickCount:1
- pressure:1];
-
- [NSMenu popUpContextMenu:projectMenu withEvent:event forView:polycodeView];
-
- mustShowProjectMenu = NO;
- }
- }
- - (void) showProjectMenu {
-
- mustShowProjectMenu = YES;
- }
- - (void)applicationWillTerminate:(NSNotification *)aNotification {
- NSLog(@"STOPPING\n");
- app->saveConfigFile();
- app->core->Shutdown();
- }
- - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
- {
- return YES;
- }
- - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
- {
- // this gets called before applicationDidFinishLaunching if
- // user double-clicks the file to open the app
-
- if(app) {
- app->openProject([filename cStringUsingEncoding:NSUTF8StringEncoding]);
- } else {
- fileToOpen = [filename cStringUsingEncoding:NSUTF8StringEncoding];
- }
- return YES;
- }
- -(IBAction) refreshProject: (id) sender {
- app->refreshProject();
- }
- -(IBAction) renameFile: (id) sender {
- app->renameFile();
- }
- -(IBAction) removeFile: (id) sender {
- app->removeFile();
- }
- -(IBAction) newGroup: (id) sender {
- app->newGroup();
- }
- -(IBAction) browseExamples: (id) sender {
- app->browseExamples();
- }
- -(IBAction) runProject: (id) sender {
- app->runProject();
- }
- -(IBAction) exportProject: (id) sender {
- app->exportProject();
- }
- -(IBAction) newProject: (id) sender {
- app->newProject();
- }
- -(IBAction) newFile: (id) sender {
- app->newFile();
- }
- -(IBAction) openProject: (id) sender {
- app->openProject();
- }
- -(IBAction) closeProject: (id) sender {
- app->closeProject();
- }
- -(IBAction) saveFile: (id) sender {
- app->saveFile();
- }
- -(IBAction) findText: (id) sender {
- app->findText();
- }
- -(IBAction) openDocs: (id) sender {
- app->openDocs();
- }
- @end
|