PolycodeAppDelegate.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. - (id) init {
  14. app = NULL;
  15. return [super init];
  16. }
  17. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
  18. // Insert code here to initialize your application
  19. mustShowProjectMenu = NO;
  20. eventHandler = new PolycodeAppEventHandler();
  21. eventHandler->appDelegate = self;
  22. app = new PolycodeIDEApp(polycodeView);
  23. app->addEventListener(eventHandler, PolycodeIDEApp::EVENT_SHOW_MENU);
  24. if(fileToOpen != "") {
  25. app->openProject(fileToOpen);
  26. }
  27. timer = [NSTimer timerWithTimeInterval:(1.0f/90.0f) target:self selector:@selector(animationTimer:) userInfo:nil repeats:YES];
  28. [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
  29. [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode]; // ensure timer fires during resize
  30. }
  31. - (void)animationTimer:(NSTimer *)timer
  32. {
  33. if(!app->Update()) {
  34. [[NSApplication sharedApplication] stop:self];
  35. }
  36. if(mustShowProjectMenu) {
  37. NSPoint menuOrigin = NSMakePoint(polycodeView.mouseX, polycodeView.mouseY);
  38. NSEvent *event = [NSEvent mouseEventWithType:NSLeftMouseDown
  39. location:menuOrigin
  40. modifierFlags:NSLeftMouseDownMask // 0x100
  41. timestamp:nil
  42. windowNumber:[window windowNumber]
  43. context:[window graphicsContext]
  44. eventNumber:0
  45. clickCount:1
  46. pressure:1];
  47. [NSMenu popUpContextMenu:projectMenu withEvent:event forView:polycodeView];
  48. mustShowProjectMenu = NO;
  49. }
  50. }
  51. - (void) showProjectMenu {
  52. mustShowProjectMenu = YES;
  53. }
  54. - (void)applicationWillTerminate:(NSNotification *)aNotification {
  55. NSLog(@"STOPPING\n");
  56. app->saveConfigFile();
  57. app->core->Shutdown();
  58. }
  59. - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
  60. {
  61. return YES;
  62. }
  63. - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
  64. {
  65. // this gets called before applicationDidFinishLaunching if
  66. // user double-clicks the file to open the app
  67. if(app) {
  68. app->openProject([filename cStringUsingEncoding:NSUTF8StringEncoding]);
  69. } else {
  70. fileToOpen = [filename cStringUsingEncoding:NSUTF8StringEncoding];
  71. }
  72. return YES;
  73. }
  74. -(IBAction) refreshProject: (id) sender {
  75. app->refreshProject();
  76. }
  77. -(IBAction) renameFile: (id) sender {
  78. app->renameFile();
  79. }
  80. -(IBAction) removeFile: (id) sender {
  81. app->removeFile();
  82. }
  83. -(IBAction) newGroup: (id) sender {
  84. app->newGroup();
  85. }
  86. -(IBAction) browseExamples: (id) sender {
  87. app->browseExamples();
  88. }
  89. -(IBAction) runProject: (id) sender {
  90. app->runProject();
  91. }
  92. -(IBAction) exportProject: (id) sender {
  93. app->exportProject();
  94. }
  95. -(IBAction) newProject: (id) sender {
  96. app->newProject();
  97. }
  98. -(IBAction) newFile: (id) sender {
  99. app->newFile();
  100. }
  101. -(IBAction) openProject: (id) sender {
  102. app->openProject();
  103. }
  104. -(IBAction) closeProject: (id) sender {
  105. app->closeProject();
  106. }
  107. -(IBAction) saveFile: (id) sender {
  108. app->saveFile();
  109. }
  110. -(IBAction) findText: (id) sender {
  111. app->findText();
  112. }
  113. -(IBAction) openDocs: (id) sender {
  114. app->openDocs();
  115. }
  116. @end