PageRenderTime 43ms CodeModel.GetById 14ms app.highlight 25ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 19#import "GTMXcodeMenuItem.h"
 20#import "GTMXcodePlugin.h"
 21#import "PBXAppDelegate.h"
 22#import "GTMDefines.h"
 23
 24// Handles all the quick link menu items in the help menu.
 25// Creates a separator and two menu items with submenu items
 26// linking to useful URLS.
 27
 28NSString* kGoogleStyleGuideMenuItem = @"Google Style Guides";
 29NSString* kGoogleOtherSitesMenuItem = @"Other Useful Sites";
 30
 31@interface GTMXcodeStyleGuideSeparatorItem : GTMXcodeMenuItem
 32@end
 33
 34@implementation GTMXcodeStyleGuideSeparatorItem
 35+ (void)load {
 36  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 37  [GTMXcodePlugin registerMenuItem:[[[self alloc] init] autorelease]];
 38  [pool release];
 39}
 40
 41- (NSString*)title {
 42  return @"-";
 43}
 44
 45- (NSMenu*)insertionMenu {
 46  return [[NSApp delegate] helpMenu];
 47}
 48
 49- (int)insertionIndex {
 50  return 14;
 51}
 52@end
 53
 54@interface GTMXcodeStyleGuidesItem : GTMXcodeMenuItem
 55@end
 56
 57@implementation GTMXcodeStyleGuidesItem
 58+ (void)load {
 59  [GTMXcodePlugin registerMenuItem:[[[self alloc] init] autorelease]];
 60}
 61
 62- (NSString*)title {
 63  return kGoogleStyleGuideMenuItem;
 64}
 65
 66- (NSMenu*)insertionMenu {
 67  return [[NSApp delegate] helpMenu];
 68}
 69
 70- (int)insertionIndex {
 71  return 15;
 72}
 73
 74- (void)wasInserted:(NSMenuItem*)item {
 75  NSMenu *menu = [[[NSMenu alloc] initWithTitle:kGoogleStyleGuideMenuItem] autorelease];
 76  [item setSubmenu:menu];
 77}
 78@end
 79
 80@interface GTMXcodeOtherUsefulSitesItem : GTMXcodeMenuItem
 81@end
 82
 83@implementation GTMXcodeOtherUsefulSitesItem
 84+ (void)load {
 85  [GTMXcodePlugin registerMenuItem:[[[self alloc] init] autorelease]];
 86}
 87
 88- (NSString*)title {
 89  return kGoogleOtherSitesMenuItem;
 90}
 91
 92- (NSMenu*)insertionMenu {
 93  return [[NSApp delegate] helpMenu];
 94}
 95
 96- (int)insertionIndex {
 97  return 16;
 98}
 99
100- (void)wasInserted:(NSMenuItem*)item {
101  NSMenu *menu = [[[NSMenu alloc] initWithTitle:kGoogleOtherSitesMenuItem] autorelease];
102  [item setSubmenu:menu];
103}
104@end
105
106@interface GTMXcodeOpenUrlItem : GTMXcodeMenuItem {
107  NSString *title_;
108  NSString *parent_;
109  NSString *url_;
110  int index_;
111}
112- (id)initWithTitle:(NSString*)title parent:(NSString*)parent url:(NSString*)url index:(int)index;
113@end
114
115@implementation GTMXcodeOpenUrlItem
116+ (void)load {
117  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
118  struct OpenUrlItemDesc {
119    NSString *title;
120    NSString *parent;
121    NSString *url;
122    int index;
123  };
124
125  struct OpenUrlItemDesc items [] = {
126    {
127      @"Objective-C Style Guide",
128      kGoogleStyleGuideMenuItem,
129      @"http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml",
130      0
131    },
132    {
133      @"C++ Style Guide",
134      kGoogleStyleGuideMenuItem,
135      @"http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml",
136      1
137    },
138    {
139      @"Radar",
140      kGoogleOtherSitesMenuItem,
141      @"https://bugreport.apple.com/cgi-bin/WebObjects/RadarWeb.woa",
142      0
143    },
144    {
145      @"TN2124 Mac OS X Debugging Magic",
146      kGoogleOtherSitesMenuItem,
147      @"http://developer.apple.com/mac/library/technotes/tn2004/tn2124.html",
148      1
149    },
150  };
151
152  for(size_t i = 0; i < sizeof(items) / sizeof(struct OpenUrlItemDesc); ++i) {
153    GTMXcodeOpenUrlItem *item = [[[self alloc] initWithTitle:items[i].title
154                                                     parent:items[i].parent
155                                                        url:items[i].url
156                                                      index:items[i].index]
157                                autorelease];
158    [GTMXcodePlugin registerMenuItem:item];
159  }
160  [pool release];
161}
162
163- (id)initWithTitle:(NSString*)title
164             parent:(NSString*)parent
165                url:(NSString*)url
166              index:(int)idx {
167  if ((self = [super init])) {
168    title_ = title;
169    parent_ = parent;
170    url_ = url;
171    index_ = idx;
172  }
173  return self;
174}
175
176- (NSString*)title {
177  return title_;
178}
179
180- (NSString*)urlToOpen {
181  return url_;
182}
183
184- (NSString*)parentMenuName {
185  return parent_;
186}
187
188- (void)action:(id)sender {
189  NSURL *url = [NSURL URLWithString:[self urlToOpen]];
190  [[NSWorkspace sharedWorkspace] openURL:url];
191}
192
193- (NSMenu*)insertionMenu {
194  NSMenu *menu = [[NSApp delegate] helpMenu];
195  NSInteger menuIndex = [menu indexOfItemWithTitle:[self parentMenuName]];
196  NSMenuItem *menuItem = [menu itemAtIndex:menuIndex];
197  return [menuItem submenu];
198}
199
200- (int)depth {
201  return 2;
202}
203
204- (int)insertionIndex {
205  return index_;
206}
207
208- (BOOL)allowGDTMenuIcon {
209  return NO;
210}
211@end
212
213
214
215