/core/externals/google-toolbox-for-mac/XcodePlugin/GTMXcodeQuickLinks.m

http://macfuse.googlecode.com/ · Objective C · 215 lines · 158 code · 37 blank · 20 comment · 2 complexity · dc5db7af98639d87ea6745b9d5256862 MD5 · raw file

  1. //
  2. // GTMXcodeQuickLinksItem.m
  3. //
  4. // Copyright 2007-2009 Google Inc.
  5. //
  6. // Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7. // use this file except in compliance with the License. You may obtain a copy
  8. // of the License at
  9. //
  10. // http://www.apache.org/licenses/LICENSE-2.0
  11. //
  12. // Unless required by applicable law or agreed to in writing, software
  13. // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15. // License for the specific language governing permissions and limitations under
  16. // the License.
  17. //
  18. #import "GTMXcodeMenuItem.h"
  19. #import "GTMXcodePlugin.h"
  20. #import "PBXAppDelegate.h"
  21. #import "GTMDefines.h"
  22. // Handles all the quick link menu items in the help menu.
  23. // Creates a separator and two menu items with submenu items
  24. // linking to useful URLS.
  25. NSString* kGoogleStyleGuideMenuItem = @"Google Style Guides";
  26. NSString* kGoogleOtherSitesMenuItem = @"Other Useful Sites";
  27. @interface GTMXcodeStyleGuideSeparatorItem : GTMXcodeMenuItem
  28. @end
  29. @implementation GTMXcodeStyleGuideSeparatorItem
  30. + (void)load {
  31. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  32. [GTMXcodePlugin registerMenuItem:[[[self alloc] init] autorelease]];
  33. [pool release];
  34. }
  35. - (NSString*)title {
  36. return @"-";
  37. }
  38. - (NSMenu*)insertionMenu {
  39. return [[NSApp delegate] helpMenu];
  40. }
  41. - (int)insertionIndex {
  42. return 14;
  43. }
  44. @end
  45. @interface GTMXcodeStyleGuidesItem : GTMXcodeMenuItem
  46. @end
  47. @implementation GTMXcodeStyleGuidesItem
  48. + (void)load {
  49. [GTMXcodePlugin registerMenuItem:[[[self alloc] init] autorelease]];
  50. }
  51. - (NSString*)title {
  52. return kGoogleStyleGuideMenuItem;
  53. }
  54. - (NSMenu*)insertionMenu {
  55. return [[NSApp delegate] helpMenu];
  56. }
  57. - (int)insertionIndex {
  58. return 15;
  59. }
  60. - (void)wasInserted:(NSMenuItem*)item {
  61. NSMenu *menu = [[[NSMenu alloc] initWithTitle:kGoogleStyleGuideMenuItem] autorelease];
  62. [item setSubmenu:menu];
  63. }
  64. @end
  65. @interface GTMXcodeOtherUsefulSitesItem : GTMXcodeMenuItem
  66. @end
  67. @implementation GTMXcodeOtherUsefulSitesItem
  68. + (void)load {
  69. [GTMXcodePlugin registerMenuItem:[[[self alloc] init] autorelease]];
  70. }
  71. - (NSString*)title {
  72. return kGoogleOtherSitesMenuItem;
  73. }
  74. - (NSMenu*)insertionMenu {
  75. return [[NSApp delegate] helpMenu];
  76. }
  77. - (int)insertionIndex {
  78. return 16;
  79. }
  80. - (void)wasInserted:(NSMenuItem*)item {
  81. NSMenu *menu = [[[NSMenu alloc] initWithTitle:kGoogleOtherSitesMenuItem] autorelease];
  82. [item setSubmenu:menu];
  83. }
  84. @end
  85. @interface GTMXcodeOpenUrlItem : GTMXcodeMenuItem {
  86. NSString *title_;
  87. NSString *parent_;
  88. NSString *url_;
  89. int index_;
  90. }
  91. - (id)initWithTitle:(NSString*)title parent:(NSString*)parent url:(NSString*)url index:(int)index;
  92. @end
  93. @implementation GTMXcodeOpenUrlItem
  94. + (void)load {
  95. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  96. struct OpenUrlItemDesc {
  97. NSString *title;
  98. NSString *parent;
  99. NSString *url;
  100. int index;
  101. };
  102. struct OpenUrlItemDesc items [] = {
  103. {
  104. @"Objective-C Style Guide",
  105. kGoogleStyleGuideMenuItem,
  106. @"http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml",
  107. 0
  108. },
  109. {
  110. @"C++ Style Guide",
  111. kGoogleStyleGuideMenuItem,
  112. @"http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml",
  113. 1
  114. },
  115. {
  116. @"Radar",
  117. kGoogleOtherSitesMenuItem,
  118. @"https://bugreport.apple.com/cgi-bin/WebObjects/RadarWeb.woa",
  119. 0
  120. },
  121. {
  122. @"TN2124 Mac OS X Debugging Magic",
  123. kGoogleOtherSitesMenuItem,
  124. @"http://developer.apple.com/mac/library/technotes/tn2004/tn2124.html",
  125. 1
  126. },
  127. };
  128. for(size_t i = 0; i < sizeof(items) / sizeof(struct OpenUrlItemDesc); ++i) {
  129. GTMXcodeOpenUrlItem *item = [[[self alloc] initWithTitle:items[i].title
  130. parent:items[i].parent
  131. url:items[i].url
  132. index:items[i].index]
  133. autorelease];
  134. [GTMXcodePlugin registerMenuItem:item];
  135. }
  136. [pool release];
  137. }
  138. - (id)initWithTitle:(NSString*)title
  139. parent:(NSString*)parent
  140. url:(NSString*)url
  141. index:(int)idx {
  142. if ((self = [super init])) {
  143. title_ = title;
  144. parent_ = parent;
  145. url_ = url;
  146. index_ = idx;
  147. }
  148. return self;
  149. }
  150. - (NSString*)title {
  151. return title_;
  152. }
  153. - (NSString*)urlToOpen {
  154. return url_;
  155. }
  156. - (NSString*)parentMenuName {
  157. return parent_;
  158. }
  159. - (void)action:(id)sender {
  160. NSURL *url = [NSURL URLWithString:[self urlToOpen]];
  161. [[NSWorkspace sharedWorkspace] openURL:url];
  162. }
  163. - (NSMenu*)insertionMenu {
  164. NSMenu *menu = [[NSApp delegate] helpMenu];
  165. NSInteger menuIndex = [menu indexOfItemWithTitle:[self parentMenuName]];
  166. NSMenuItem *menuItem = [menu itemAtIndex:menuIndex];
  167. return [menuItem submenu];
  168. }
  169. - (int)depth {
  170. return 2;
  171. }
  172. - (int)insertionIndex {
  173. return index_;
  174. }
  175. - (BOOL)allowGDTMenuIcon {
  176. return NO;
  177. }
  178. @end