PolycodeAppDelegate.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 polycodeView;
  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(polycodeView);
  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(polycodeView.mouseX, polycodeView.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:polycodeView];
  41. mustShowProjectMenu = NO;
  42. }
  43. }
  44. - (void) showProjectMenu {
  45. mustShowProjectMenu = YES;
  46. }
  47. - (void)applicationWillTerminate:(NSNotification *)aNotification {
  48. NSLog(@"STOPPING\n");
  49. app->saveConfigFile();
  50. app->core->Shutdown();
  51. }
  52. - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
  53. {
  54. return YES;
  55. }
  56. -(IBAction) refreshProject: (id) sender {
  57. app->refreshProject();
  58. }
  59. -(IBAction) renameFile: (id) sender {
  60. app->renameFile();
  61. }
  62. -(IBAction) removeFile: (id) sender {
  63. app->removeFile();
  64. }
  65. -(IBAction) newGroup: (id) sender {
  66. app->newGroup();
  67. }
  68. -(IBAction) browseExamples: (id) sender {
  69. app->browseExamples();
  70. }
  71. -(IBAction) runProject: (id) sender {
  72. app->runProject();
  73. }
  74. -(IBAction) newProject: (id) sender {
  75. app->newProject();
  76. }
  77. -(IBAction) newFile: (id) sender {
  78. app->newFile();
  79. }
  80. -(IBAction) openProject: (id) sender {
  81. app->openProject();
  82. }
  83. -(IBAction) closeProject: (id) sender {
  84. app->closeProject();
  85. }
  86. -(IBAction) saveFile: (id) sender {
  87. app->saveFile();
  88. }
  89. @end