PageRenderTime 51ms CodeModel.GetById 19ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/externals/google-toolbox-for-mac/XcodePlugin/GTMXcodeMenuItem.m

http://macfuse.googlecode.com/
Objective C | 136 lines | 99 code | 18 blank | 19 comment | 16 complexity | 49ea6da6c63f2d1490f38e7ee6dea1e1 MD5 | raw file
  1//
  2//  GTMXcodeMenuItem.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 "GTMNSEnumerator+Filter.h"
 21#import "PBXAppDelegate.h"
 22#import "PBXProject.h"
 23#import "PBXTarget.h"
 24#import "GTMMethodCheck.h"
 25#import "GTMDefines.h"
 26
 27static NSString *const kGTMSrcRootPath = @"$(SRCROOT)/";
 28
 29@implementation GTMXcodeMenuItem
 30
 31GTM_METHOD_CHECK(NSEnumerator, gtm_filteredEnumeratorByMakingEachObjectPerformSelector:withObject:);
 32GTM_METHOD_CHECK(NSEnumerator, gtm_enumeratorByMakingEachObjectPerformSelector:withObject:);
 33
 34- (NSString*)keyEquivalent {
 35  return @"";
 36}
 37
 38- (NSMenu*)insertionMenu {
 39  NSMenu *rootMenu = [NSApp mainMenu];
 40  NSInteger googleIndex = [rootMenu indexOfItemWithTitle:@"Google Scripts"];
 41  NSMenuItem *googleMenuItem = [rootMenu itemAtIndex:googleIndex];
 42  return [googleMenuItem submenu];
 43}
 44
 45- (SEL)actionSelector {
 46  return @selector(action:);
 47}
 48
 49- (void)action:(id)sender {
 50  NSBeep();
 51}
 52
 53- (int)insertionIndex {
 54  return 0;
 55}
 56
 57- (NSString*)title {
 58  return @"Unnamed";
 59}
 60
 61- (int)depth {
 62  return 1;
 63}
 64
 65- (NSComparisonResult)compareDepth:(id<GTMXcodeMenuItemProtocol>)item {
 66  int itemDepth = [item depth];
 67  int selfDepth = [self depth];
 68  
 69  if (selfDepth > itemDepth) {
 70    return NSOrderedDescending;
 71  } else if (selfDepth == itemDepth) {
 72    int itemInsertionIndex = [item insertionIndex];
 73    int selfInsertionIndex = [self insertionIndex];
 74    if (selfInsertionIndex > itemInsertionIndex) {
 75      return NSOrderedDescending;
 76    } else if (selfInsertionIndex == itemInsertionIndex) {
 77      return NSOrderedSame;
 78    } else {
 79      return NSOrderedAscending;
 80    }
 81  } else {
 82    return NSOrderedAscending;
 83  }
 84}
 85
 86- (NSArray*)selectedPaths {
 87  NSArray *paths = nil;
 88  PBXWindowController *controller = [[NSApp mainWindow] windowController];
 89  if (controller) {
 90    PBXModule *activeModule = [controller activeModule];
 91    if ([activeModule conformsToProtocol:@protocol(XCSelectionSource)]) {
 92      XCProjectBasedSelection *selection 
 93        = (XCProjectBasedSelection *)[activeModule xcSelection];
 94      if ([selection isKindOfClass:[XCProjectBasedSelection class]]) {
 95        NSArray* selectionItems = [selection items];
 96        if (selectionItems) {
 97          NSEnumerator *pathEnum = [selectionItems objectEnumerator];
 98          pathEnum 
 99            = [pathEnum gtm_filteredEnumeratorByMakingEachObjectPerformSelector:@selector(isMemberOfClass:)
100                                                                     withObject:NSClassFromString(@"PBXFileReference")];
101          pathEnum 
102            = [pathEnum gtm_enumeratorByMakingEachObjectPerformSelector:@selector(resolvedAbsolutePath)
103                                                             withObject:nil];
104          paths = [pathEnum allObjects];
105        }
106      }
107    }
108  }
109  return paths;
110}  
111
112- (void)wasInserted:(NSMenuItem*)item {
113}
114
115- (BOOL)allowGDTMenuIcon {
116  return YES;
117}
118
119// Expand |path| based on |target| and |configuration|.
120// If newPath is not absolute, expand kSrcRootPath and prepend it to newPath.
121- (NSString *)pathByExpandingString:(NSString *)path 
122              forBuildConfiguration:(NSString *)configuration
123                           ofTarget:(PBXTarget *)target {
124  NSString *newPath = [target stringByExpandingString:path
125                           forBuildConfigurationNamed:configuration];
126  if (![newPath hasPrefix:@"/"]) {
127    NSString *srcRoot = [target stringByExpandingString:kGTMSrcRootPath
128                             forBuildConfigurationNamed:configuration];
129    if (srcRoot) {
130      newPath = [srcRoot stringByAppendingString:newPath];
131    }
132  }
133  return newPath;
134}
135
136@end