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