PolycodeAppDelegate.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // PolycodeAppDelegate.m
  3. // Polycode
  4. //
  5. // Created by Ivan Safrin on 11/28/10.
  6. // Copyright 2010 Local Projects. All rights reserved.
  7. //PolycodeIDEApp
  8. #import "PolycodeAppDelegate.h"
  9. @implementation PolycodeAppDelegate
  10. @synthesize window;
  11. @synthesize substanceView;
  12. @synthesize projectMenu;
  13. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
  14. // Insert code here to initialize your application
  15. mustShowProjectMenu = NO;
  16. eventHandler = new PolycodeAppEventHandler();
  17. eventHandler->appDelegate = self;
  18. app = new PolycodeIDEApp(substanceView);
  19. app->addEventListener(eventHandler, PolycodeIDEApp::EVENT_SHOW_MENU);
  20. timer = [NSTimer timerWithTimeInterval:(1.0f/90.0f) target:self selector:@selector(animationTimer:) userInfo:nil repeats:YES];
  21. [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
  22. [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode]; // ensure timer fires during resize
  23. }
  24. - (void)animationTimer:(NSTimer *)timer
  25. {
  26. if(!app->Update()) {
  27. [[NSApplication sharedApplication] stop:self];
  28. }
  29. if(mustShowProjectMenu) {
  30. NSPoint menuOrigin = NSMakePoint(substanceView.mouseX, substanceView.mouseY);
  31. NSEvent *event = [NSEvent mouseEventWithType:NSLeftMouseDown
  32. location:menuOrigin
  33. modifierFlags:NSLeftMouseDownMask // 0x100
  34. timestamp:nil
  35. windowNumber:[window windowNumber]
  36. context:[window graphicsContext]
  37. eventNumber:0
  38. clickCount:1
  39. pressure:1];
  40. [NSMenu popUpContextMenu:projectMenu withEvent:event forView:substanceView];
  41. mustShowProjectMenu = NO;
  42. }
  43. }
  44. - (void) showProjectMenu {
  45. mustShowProjectMenu = YES;
  46. }
  47. - (void)applicationWillTerminate:(NSNotification *)aNotification {
  48. delete app;
  49. }
  50. -(void) newProject: (id) sender {
  51. app->newProject();
  52. }
  53. -(void) newFile: (id) sender {
  54. app->newFile();
  55. }
  56. -(void) openProject: (id) sender {
  57. app->openProject();
  58. }
  59. -(void) closeProject: (id) sender {
  60. app->closeProject();
  61. }
  62. -(void) saveFile: (id) sender {
  63. app->saveFile();
  64. }
  65. @end