PolycodeAppDelegate.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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] terminate: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. }
  56. - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)theApplication
  57. {
  58. bool retVal = app->quitApp();
  59. if(retVal) {
  60. app->saveConfigFile();
  61. app->core->Shutdown();
  62. printf("STOPPING\n");
  63. }
  64. return retVal;
  65. }
  66. - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
  67. {
  68. return YES;
  69. }
  70. - (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
  71. {
  72. // this gets called before applicationDidFinishLaunching if
  73. // user double-clicks the file to open the app
  74. if(app) {
  75. app->openProject([filename cStringUsingEncoding:NSUTF8StringEncoding]);
  76. } else {
  77. fileToOpen = [filename cStringUsingEncoding:NSUTF8StringEncoding];
  78. }
  79. return YES;
  80. }
  81. -(IBAction) refreshProject: (id) sender {
  82. app->refreshProject();
  83. }
  84. -(IBAction) renameFile: (id) sender {
  85. app->renameFile();
  86. }
  87. -(IBAction) removeFile: (id) sender {
  88. app->removeFile();
  89. }
  90. -(IBAction) newGroup: (id) sender {
  91. app->newGroup();
  92. }
  93. -(IBAction) browseExamples: (id) sender {
  94. app->browseExamples();
  95. }
  96. -(IBAction) runProject: (id) sender {
  97. app->runProject();
  98. }
  99. -(IBAction) exportProject: (id) sender {
  100. app->exportProject();
  101. }
  102. -(IBAction) newProject: (id) sender {
  103. app->newProject();
  104. }
  105. -(IBAction) newFile: (id) sender {
  106. app->newFile();
  107. }
  108. -(IBAction) openProject: (id) sender {
  109. app->openProject();
  110. }
  111. -(IBAction) closeProject: (id) sender {
  112. app->closeProject();
  113. }
  114. -(IBAction) closeFile: (id) sender {
  115. app->closeFile();
  116. }
  117. -(IBAction) saveFile: (id) sender {
  118. app->saveFile();
  119. }
  120. -(IBAction) findText: (id) sender {
  121. app->findText();
  122. }
  123. -(IBAction) openDocs: (id) sender {
  124. app->openDocs();
  125. }
  126. -(IBAction) showAbout: (id) sender {
  127. app->showAbout();
  128. }
  129. -(IBAction) toggleConsole: (id) sender {
  130. app->toggleConsole();
  131. }
  132. -(IBAction) showSettings: (id) sender {
  133. app->showSettings();
  134. }
  135. @end