diff options
-rwxr-xr-x | Xcode4Plugin/GTMXcode4Plugin.xcodeproj/project.pbxproj | 312 | ||||
-rw-r--r-- | Xcode4Plugin/GTMXcodeAboutItem.m | 70 | ||||
-rwxr-xr-x | Xcode4Plugin/GTMXcodeCorrectWhitespace.m | 165 | ||||
-rw-r--r-- | Xcode4Plugin/GTMXcodePluginManager.h | 37 | ||||
-rw-r--r-- | Xcode4Plugin/GTMXcodePluginManager.m | 100 | ||||
-rw-r--r-- | Xcode4Plugin/Resources/Credits.rtf | 8 | ||||
-rwxr-xr-x | Xcode4Plugin/Resources/English.lproj/InfoPlist.strings | 2 | ||||
-rw-r--r-- | Xcode4Plugin/Resources/GTM.icns | bin | 0 -> 33864 bytes | |||
-rwxr-xr-x | Xcode4Plugin/Resources/Info.plist | 38 |
9 files changed, 732 insertions, 0 deletions
diff --git a/Xcode4Plugin/GTMXcode4Plugin.xcodeproj/project.pbxproj b/Xcode4Plugin/GTMXcode4Plugin.xcodeproj/project.pbxproj new file mode 100755 index 0000000..0c6eee6 --- /dev/null +++ b/Xcode4Plugin/GTMXcode4Plugin.xcodeproj/project.pbxproj @@ -0,0 +1,312 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 55C015D212B7BC2500354E5C /* GTMXcodeCorrectWhitespace.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C015D112B7BC2500354E5C /* GTMXcodeCorrectWhitespace.m */; }; + 8B515B23146B2D7E00CEB6B7 /* GTMXcodeAboutItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B515B20146B2D7E00CEB6B7 /* GTMXcodeAboutItem.m */; }; + 8B515B24146B2D7E00CEB6B7 /* GTMXcodePluginManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B515B22146B2D7E00CEB6B7 /* GTMXcodePluginManager.m */; }; + 8B515B38146B341C00CEB6B7 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 8B515B36146B341C00CEB6B7 /* Credits.rtf */; }; + 8B515B39146B341C00CEB6B7 /* GTM.icns in Resources */ = {isa = PBXBuildFile; fileRef = 8B515B37146B341C00CEB6B7 /* GTM.icns */; }; + 8D5B49B0048680CD000E48DA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C167DFE841241C02AAC07 /* InfoPlist.strings */; }; + 8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 089C167EFE841241C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; }; + 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; }; + 55C015D112B7BC2500354E5C /* GTMXcodeCorrectWhitespace.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTMXcodeCorrectWhitespace.m; sourceTree = "<group>"; }; + 8B515B20146B2D7E00CEB6B7 /* GTMXcodeAboutItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTMXcodeAboutItem.m; sourceTree = "<group>"; }; + 8B515B21146B2D7E00CEB6B7 /* GTMXcodePluginManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GTMXcodePluginManager.h; sourceTree = "<group>"; }; + 8B515B22146B2D7E00CEB6B7 /* GTMXcodePluginManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GTMXcodePluginManager.m; sourceTree = "<group>"; }; + 8B515B36146B341C00CEB6B7 /* Credits.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = "<group>"; }; + 8B515B37146B341C00CEB6B7 /* GTM.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = GTM.icns; sourceTree = "<group>"; }; + 8BD93711146C305800FDE849 /* DebugSnowLeopardOrLater.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = DebugSnowLeopardOrLater.xcconfig; sourceTree = "<group>"; }; + 8BD93715146C305800FDE849 /* ReleaseSnowLeopardOrLater.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = ReleaseSnowLeopardOrLater.xcconfig; sourceTree = "<group>"; }; + 8BD93776146C337E00FDE849 /* LoadableBundleGCSupported.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = LoadableBundleGCSupported.xcconfig; sourceTree = "<group>"; }; + 8D5B49B6048680CD000E48DA /* GTMXcode4Plugin.xcplugin */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GTMXcode4Plugin.xcplugin; sourceTree = BUILT_PRODUCTS_DIR; }; + 8D5B49B7048680CD000E48DA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 8D5B49B3048680CD000E48DA /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 089C166AFE841209C02AAC07 /* XCFixin_DisableAnimations */ = { + isa = PBXGroup; + children = ( + 8BD9370D146C305800FDE849 /* XcodeConfig */, + 08FB77AFFE84173DC02AAC07 /* Classes */, + 089C167CFE841241C02AAC07 /* Resources */, + 089C1671FE841209C02AAC07 /* Frameworks and Libraries */, + 19C28FB8FE9D52D311CA2CBB /* Products */, + ); + name = XCFixin_DisableAnimations; + sourceTree = "<group>"; + }; + 089C1671FE841209C02AAC07 /* Frameworks and Libraries */ = { + isa = PBXGroup; + children = ( + 1058C7ACFEA557BF11CA2CBB /* Linked Frameworks */, + ); + name = "Frameworks and Libraries"; + sourceTree = "<group>"; + }; + 089C167CFE841241C02AAC07 /* Resources */ = { + isa = PBXGroup; + children = ( + 8B515B36146B341C00CEB6B7 /* Credits.rtf */, + 8B515B37146B341C00CEB6B7 /* GTM.icns */, + 8D5B49B7048680CD000E48DA /* Info.plist */, + 089C167DFE841241C02AAC07 /* InfoPlist.strings */, + ); + path = Resources; + sourceTree = "<group>"; + }; + 08FB77AFFE84173DC02AAC07 /* Classes */ = { + isa = PBXGroup; + children = ( + 8B515B20146B2D7E00CEB6B7 /* GTMXcodeAboutItem.m */, + 8B515B21146B2D7E00CEB6B7 /* GTMXcodePluginManager.h */, + 8B515B22146B2D7E00CEB6B7 /* GTMXcodePluginManager.m */, + 55C015D112B7BC2500354E5C /* GTMXcodeCorrectWhitespace.m */, + ); + name = Classes; + sourceTree = "<group>"; + }; + 1058C7ACFEA557BF11CA2CBB /* Linked Frameworks */ = { + isa = PBXGroup; + children = ( + 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */, + ); + name = "Linked Frameworks"; + sourceTree = "<group>"; + }; + 19C28FB8FE9D52D311CA2CBB /* Products */ = { + isa = PBXGroup; + children = ( + 8D5B49B6048680CD000E48DA /* GTMXcode4Plugin.xcplugin */, + ); + name = Products; + sourceTree = "<group>"; + }; + 8BD9370D146C305800FDE849 /* XcodeConfig */ = { + isa = PBXGroup; + children = ( + 8BD9370E146C305800FDE849 /* Project */, + 8BD93773146C337E00FDE849 /* Target */, + ); + name = XcodeConfig; + path = ../XcodeConfig; + sourceTree = SOURCE_ROOT; + }; + 8BD9370E146C305800FDE849 /* Project */ = { + isa = PBXGroup; + children = ( + 8BD93711146C305800FDE849 /* DebugSnowLeopardOrLater.xcconfig */, + 8BD93715146C305800FDE849 /* ReleaseSnowLeopardOrLater.xcconfig */, + ); + path = Project; + sourceTree = "<group>"; + }; + 8BD93773146C337E00FDE849 /* Target */ = { + isa = PBXGroup; + children = ( + 8BD93776146C337E00FDE849 /* LoadableBundleGCSupported.xcconfig */, + ); + path = Target; + sourceTree = "<group>"; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 8D5B49AC048680CD000E48DA /* GTMXcode4Plugin */ = { + isa = PBXNativeTarget; + buildConfigurationList = 1DEB913A08733D840010E9CD /* Build configuration list for PBXNativeTarget "GTMXcode4Plugin" */; + buildPhases = ( + 8D5B49AF048680CD000E48DA /* Resources */, + 8D5B49B1048680CD000E48DA /* Sources */, + 8D5B49B3048680CD000E48DA /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = GTMXcode4Plugin; + productInstallPath = "$(HOME)/Library/Bundles"; + productName = XCFixin_DisableAnimations; + productReference = 8D5B49B6048680CD000E48DA /* GTMXcode4Plugin.xcplugin */; + productType = "com.apple.product-type.bundle"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 089C1669FE841209C02AAC07 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0420; + }; + buildConfigurationList = 1DEB913E08733D840010E9CD /* Build configuration list for PBXProject "GTMXcode4Plugin" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 1; + knownRegions = ( + English, + Japanese, + French, + German, + ); + mainGroup = 089C166AFE841209C02AAC07 /* XCFixin_DisableAnimations */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 8D5B49AC048680CD000E48DA /* GTMXcode4Plugin */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 8D5B49AF048680CD000E48DA /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 8D5B49B0048680CD000E48DA /* InfoPlist.strings in Resources */, + 8B515B38146B341C00CEB6B7 /* Credits.rtf in Resources */, + 8B515B39146B341C00CEB6B7 /* GTM.icns in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 8D5B49B1048680CD000E48DA /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 55C015D212B7BC2500354E5C /* GTMXcodeCorrectWhitespace.m in Sources */, + 8B515B23146B2D7E00CEB6B7 /* GTMXcodeAboutItem.m in Sources */, + 8B515B24146B2D7E00CEB6B7 /* GTMXcodePluginManager.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 089C167DFE841241C02AAC07 /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + 089C167EFE841241C02AAC07 /* English */, + ); + name = InfoPlist.strings; + sourceTree = "<group>"; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 1DEB913B08733D840010E9CD /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 8BD93776146C337E00FDE849 /* LoadableBundleGCSupported.xcconfig */; + buildSettings = { + DEPLOYMENT_LOCATION = YES; + DEPLOYMENT_POSTPROCESSING = YES; + DSTROOT = "$(HOME)"; + GCC_ENABLE_OBJC_GC = supported; + INFOPLIST_FILE = Resources/Info.plist; + INSTALL_PATH = "/Library/Application Support/Developer/Shared/Xcode/Plug-ins"; + LD_RUNPATH_SEARCH_PATHS = /Developer; + PRODUCT_NAME = GTMXcode4Plugin; + STRIP_INSTALLED_PRODUCT = YES; + WRAPPER_EXTENSION = xcplugin; + }; + name = Debug; + }; + 1DEB913C08733D840010E9CD /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 8BD93776146C337E00FDE849 /* LoadableBundleGCSupported.xcconfig */; + buildSettings = { + DEPLOYMENT_LOCATION = YES; + DEPLOYMENT_POSTPROCESSING = YES; + DSTROOT = "$(HOME)"; + GCC_ENABLE_OBJC_GC = supported; + INFOPLIST_FILE = Resources/Info.plist; + INSTALL_PATH = "/Library/Application Support/Developer/Shared/Xcode/Plug-ins"; + LD_RUNPATH_SEARCH_PATHS = /Developer; + PRODUCT_NAME = GTMXcode4Plugin; + STRIP_INSTALLED_PRODUCT = YES; + WRAPPER_EXTENSION = xcplugin; + }; + name = Release; + }; + 1DEB913F08733D840010E9CD /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 8BD93711146C305800FDE849 /* DebugSnowLeopardOrLater.xcconfig */; + buildSettings = { + GTM_PRODUCT_NAME = "$(PROJECT_NAME)"; + GTM_VERSIONINFO_ABOUT = "© $(GTM_VERSION_COPYRIGHT) Google Inc."; + GTM_VERSIONINFO_FINDER = "$(GTM_PRODUCT_NAME) $(GTM_VERSIONINFO_LONG)$(GTM_VERSION_EXTRAINFO)$(GTM_VERSION_DEBUG_FLAG), © $(GTM_VERSION_COPYRIGHT) Google Inc."; + GTM_VERSIONINFO_HUMAN = "$(GTM_VERSIONINFO_SHORT)$(GTM_VERSION_EXTRAINFO)"; + GTM_VERSIONINFO_LONG = "$(GTM_VERSIONINFO_SHORT).$(GTM_VERSION_BUILDNUMBER)"; + GTM_VERSIONINFO_SHORT = "$(GTM_VERSION_MAJOR).$(GTM_VERSION_MINOR).$(GTM_VERSION_FIXLEVEL)"; + GTM_VERSION_BUILDNUMBER = 0; + GTM_VERSION_COPYRIGHT = 2011; + GTM_VERSION_FIXLEVEL = 0; + GTM_VERSION_MAJOR = 4; + GTM_VERSION_MINOR = 2; + }; + name = Debug; + }; + 1DEB914008733D840010E9CD /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 8BD93715146C305800FDE849 /* ReleaseSnowLeopardOrLater.xcconfig */; + buildSettings = { + GTM_PRODUCT_NAME = "$(PROJECT_NAME)"; + GTM_VERSIONINFO_ABOUT = "© $(GTM_VERSION_COPYRIGHT) Google Inc."; + GTM_VERSIONINFO_FINDER = "$(GTM_PRODUCT_NAME) $(GTM_VERSIONINFO_LONG)$(GTM_VERSION_EXTRAINFO)$(GTM_VERSION_DEBUG_FLAG), © $(GTM_VERSION_COPYRIGHT) Google Inc."; + GTM_VERSIONINFO_HUMAN = "$(GTM_VERSIONINFO_SHORT)$(GTM_VERSION_EXTRAINFO)"; + GTM_VERSIONINFO_LONG = "$(GTM_VERSIONINFO_SHORT).$(GTM_VERSION_BUILDNUMBER)"; + GTM_VERSIONINFO_SHORT = "$(GTM_VERSION_MAJOR).$(GTM_VERSION_MINOR).$(GTM_VERSION_FIXLEVEL)"; + GTM_VERSION_BUILDNUMBER = 0; + GTM_VERSION_COPYRIGHT = 2011; + GTM_VERSION_FIXLEVEL = 0; + GTM_VERSION_MAJOR = 4; + GTM_VERSION_MINOR = 2; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 1DEB913A08733D840010E9CD /* Build configuration list for PBXNativeTarget "GTMXcode4Plugin" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1DEB913B08733D840010E9CD /* Debug */, + 1DEB913C08733D840010E9CD /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 1DEB913E08733D840010E9CD /* Build configuration list for PBXProject "GTMXcode4Plugin" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 1DEB913F08733D840010E9CD /* Debug */, + 1DEB914008733D840010E9CD /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 089C1669FE841209C02AAC07 /* Project object */; +} diff --git a/Xcode4Plugin/GTMXcodeAboutItem.m b/Xcode4Plugin/GTMXcodeAboutItem.m new file mode 100644 index 0000000..3165582 --- /dev/null +++ b/Xcode4Plugin/GTMXcodeAboutItem.m @@ -0,0 +1,70 @@ +// +// GTMXcodeAboutItem.m +// +// Copyright 2007-2011 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy +// of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. +// + +#import "GTMXcodePluginManager.h" +#import <Cocoa/Cocoa.h> + +// Handles the about GTM Xcode Plugin menu item in the Application menu. +@interface GTMXcodeAboutItem : GTMXcodePlugin +- (void)performAbout:(id)sender; +@end + +@implementation GTMXcodeAboutItem ++ (void)load { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + [GTMXcodePluginManager registerPluginClass:self]; + [pool release]; +} + +- (void)applicationDidFinishLaunching:(NSNotification *)notification { + NSMenu *rootMenu = [NSApp mainMenu]; + NSMenuItem *appleMenuItem = [rootMenu itemAtIndex:0]; + NSMenu *menu = [appleMenuItem submenu]; + NSMenuItem *aboutItem + = [[NSMenuItem alloc] initWithTitle:@"About GTM Xcode Plugin" + action:@selector(performAbout:) + keyEquivalent:@""]; + [aboutItem setTarget:self]; + [menu insertItem:aboutItem atIndex:1]; +} + +- (void)performAbout:(id)sender { + NSBundle *mainBundle = [self bundle]; + NSString *creditsPath = [mainBundle pathForResource:@"Credits" ofType:@"rtf"]; + NSAttributedString *credits + = [[[NSAttributedString alloc] initWithPath:creditsPath + documentAttributes:nil] autorelease]; + + NSString *path = [mainBundle pathForResource:@"GTM" + ofType:@"icns"]; + NSImage *icon = [[[NSImage alloc] initWithContentsOfFile:path] autorelease]; + NSDictionary *optionsDict = [NSDictionary dictionaryWithObjectsAndKeys: + credits, @"Credits", + [mainBundle objectForInfoDictionaryKey:@"CFBundleName"], + @"ApplicationName", + [mainBundle objectForInfoDictionaryKey:@"NSHumanReadableCopyright"], + @"Copyright", + [mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"], + @"ApplicationVersion", + @"", @"Version", + icon, @"ApplicationIcon", + nil]; + [NSApp orderFrontStandardAboutPanelWithOptions:optionsDict]; +} + +@end diff --git a/Xcode4Plugin/GTMXcodeCorrectWhitespace.m b/Xcode4Plugin/GTMXcodeCorrectWhitespace.m new file mode 100755 index 0000000..b3d4b47 --- /dev/null +++ b/Xcode4Plugin/GTMXcodeCorrectWhitespace.m @@ -0,0 +1,165 @@ +// +// GTMXcodeCorrectWhitespace.m +// +// Copyright 2007-2011 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy +// of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. +// + +#import "GTMXcodePluginManager.h" +#import <Cocoa/Cocoa.h> + +@interface GTMXcodeCorrectWhitespace : GTMXcodePlugin +- (void)cleanUpWhitespace:(id)sender; +@end + +@implementation GTMXcodeCorrectWhitespace + +// Perform a "subtraction of ranges". A - B. Not transitive. +static NSRange SubtractRange(NSRange a, NSRange b) { + NSRange newRange; + NSUInteger maxRangeA = NSMaxRange(a); + NSUInteger maxRangeB = NSMaxRange(b); + if (b.location == NSNotFound) { + // B is bogus + newRange = a; + } else if (maxRangeB <= a.location) { + // B is completely before A + newRange = NSMakeRange(a.location - b.length, a.length); + } else if (maxRangeA <= b.location) { + // B is completely after A + newRange = a; + } else if (b.location <= a.location && maxRangeB >= maxRangeA) { + // B subsumes A + newRange = NSMakeRange(b.location, 0); + } else if (a.location <= b.location && maxRangeA >= maxRangeB) { + // A subsumes B + newRange = NSMakeRange(a.location, a.length - b.length); + } else if (b.location <= a.location && maxRangeB <= maxRangeA) { + // B overlaps front edge of A + NSUInteger diff = maxRangeB - a.location; + newRange = NSMakeRange(a.location + diff, a.length - diff); + } else if (b.location <= maxRangeA && maxRangeB >= maxRangeA) { + // B overlaps back edge of A + NSUInteger diff = maxRangeA - b.location; + newRange = NSMakeRange(a.location, a.length - diff); + } + return newRange; +} + ++ (void)load { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + [GTMXcodePluginManager registerPluginClass:self]; + [pool release]; +} + +- (void)applicationDidFinishLaunching:(NSNotification *)notification { + NSMenu *menu = [NSApp mainMenu]; + NSArray *items = [menu itemArray]; + for (NSMenuItem *item in items) { + // Added to Edit instead of Editor menu because the Editor menu is + // very dynamic in Xcode4. + if ([[item title] isEqualToString:@"Edit"]) { + NSMenu *editMenu = [item submenu]; + [editMenu addItem:[NSMenuItem separatorItem]]; + NSMenuItem *whiteSpaceItem + = [[NSMenuItem alloc] initWithTitle:@"Clean Up Whitespace" + action:@selector(cleanUpWhitespace:) + keyEquivalent:@""]; + [whiteSpaceItem setKeyEquivalent:@"s"]; + [whiteSpaceItem setKeyEquivalentModifierMask:(NSCommandKeyMask | + NSControlKeyMask | + NSAlternateKeyMask)]; + [editMenu addItem:whiteSpaceItem]; + [whiteSpaceItem setTarget:self]; + } + } +} + +- (void)cleanUpWhitespace:(id)sender { + NSWindow *nsKeyWindow = [[NSApplication sharedApplication] keyWindow]; + NSResponder *responder = [nsKeyWindow firstResponder]; + if ([responder conformsToProtocol:@protocol(NSTextInputClient)]) { + id client = responder; + NSRange selectedRange = [client selectedRange]; + NSMutableAttributedString *src + = [[[client attributedString] mutableCopy] autorelease]; + NSMutableString *text = [NSMutableString stringWithString:[src string]]; + + // Figure out the newlines in our file. + NSString *newlineString = @"\n"; + if ([text rangeOfString:@"\r\n"].length > 0) { + newlineString = @"\r\n"; + } else if ([text rangeOfString:@"\r"].length > 0) { + newlineString = @"\r"; + } + NSUInteger newlineStringLength = [newlineString length]; + NSCharacterSet *whiteSpace + = [NSCharacterSet characterSetWithCharactersInString:@" \t"]; + NSMutableCharacterSet *nonWhiteSpace + = [[whiteSpace mutableCopy] autorelease]; + [nonWhiteSpace invert]; + + NSRange oldRange = NSMakeRange(0, [text length]); + NSRange textRange = oldRange; + textRange.length -= 1; + while (textRange.length > 0) { + NSRange lineRange = [text rangeOfString:newlineString + options:NSBackwardsSearch + range:textRange]; + if (lineRange.location == NSNotFound) { + lineRange.location = 0; + } else { + lineRange.location += newlineStringLength; + } + lineRange.length = textRange.length - lineRange.location; + textRange.length = lineRange.location; + if (textRange.length != 0) { + textRange.length -= newlineStringLength; + } + + NSRange whiteRange = [text rangeOfCharacterFromSet:whiteSpace + options:NSBackwardsSearch + range:lineRange]; + if (NSMaxRange(whiteRange) == NSMaxRange(lineRange)) { + NSRange nonWhiteRange = [text rangeOfCharacterFromSet:nonWhiteSpace + options:NSBackwardsSearch + range:lineRange]; + NSRange deleteRange; + if (nonWhiteRange.location == NSNotFound) { + deleteRange.location = lineRange.location; + } else { + deleteRange.location = NSMaxRange(nonWhiteRange); + } + deleteRange.length = NSMaxRange(whiteRange) - deleteRange.location; + [text deleteCharactersInRange:deleteRange]; + selectedRange = SubtractRange(selectedRange, deleteRange); + } + } + + // If the file is missing a newline at the end, add it now. + if (![text hasSuffix:newlineString]) { + [text appendString:newlineString]; + } + + [client insertText:text replacementRange:oldRange]; + if ([client respondsToSelector:@selector(setSelectedRange:)]) { + if (NSMaxRange(selectedRange) < [text length]) { + [client setSelectedRange:selectedRange]; + [client scrollRangeToVisible:selectedRange]; + } + } + } +} + +@end diff --git a/Xcode4Plugin/GTMXcodePluginManager.h b/Xcode4Plugin/GTMXcodePluginManager.h new file mode 100644 index 0000000..a2d12b3 --- /dev/null +++ b/Xcode4Plugin/GTMXcodePluginManager.h @@ -0,0 +1,37 @@ +// +// GTMXcodePlugin.h +// +// Copyright 2007-2011 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy +// of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. +// + +// Principal class for GTMXcodePlugin. +// Handles settings everything up +#import <Foundation/Foundation.h> + +@interface GTMXcodePluginManager : NSObject ++ (void)registerPluginClass:(Class)cls; ++ (float)xCodeVersion; +@end + +@interface GTMXcodePlugin : NSObject { + @private + NSBundle *bundle_; +} + +@property (readonly, retain) NSBundle *bundle; + +- (id)initWithBundle:(NSBundle *)bundle; +- (void)applicationDidFinishLaunching:(NSNotification *)notification; +@end diff --git a/Xcode4Plugin/GTMXcodePluginManager.m b/Xcode4Plugin/GTMXcodePluginManager.m new file mode 100644 index 0000000..3ca3851 --- /dev/null +++ b/Xcode4Plugin/GTMXcodePluginManager.m @@ -0,0 +1,100 @@ +// +// GTMXcodePluginManager.m +// +// Copyright 2007-2011 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy +// of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. +// + +#import "GTMXcodePluginManager.h" + +#import <Cocoa/Cocoa.h> + +static NSMutableArray *gRegisteredClasses = nil; +static NSMutableArray *gPlugins = nil; + +@implementation GTMXcodePluginManager ++ (void)registerPluginClass:(Class)cls { + @synchronized([self class]) { + if (!gRegisteredClasses) { + gRegisteredClasses = [[NSMutableArray alloc] init]; + } + if (cls) { + [gRegisteredClasses addObject:cls]; + } + } +} + ++ (void)pluginDidLoad:(NSBundle *)bundle { + gPlugins + = [[NSMutableArray alloc] initWithCapacity:[gRegisteredClasses count]]; + for (Class cls in gRegisteredClasses) { + GTMXcodePlugin *plugin = [[cls alloc] initWithBundle:bundle]; + if (plugin) { + [gPlugins addObject:plugin]; + } + } + + [gRegisteredClasses release]; + gRegisteredClasses = nil; + + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + [nc addObserver:self + selector:@selector(applicationDidFinishLaunching:) + name:NSApplicationDidFinishLaunchingNotification + object:NSApp]; +} + ++ (void)applicationDidFinishLaunching:(NSNotification *)notification { + NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; + [nc removeObserver:self + name:NSApplicationDidFinishLaunchingNotification + object:NSApp]; + for (GTMXcodePlugin *plugin in gPlugins) { + [plugin applicationDidFinishLaunching:notification]; + } +} + ++ (float)xCodeVersion { + NSBundle *bundle = [NSBundle mainBundle]; + id object = [bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; + float value = [object floatValue]; + if (!(value > 0.0)) { + NSLog(@"Unable to get Xcode Version"); + } + return value; +} + +@end + +@implementation GTMXcodePlugin + +@synthesize bundle = bundle_; + +- (id)initWithBundle:(NSBundle *)bundle { + if ((self = [super init])) { + bundle_ = [bundle retain]; + } + return self; +} + +- (void)dealloc { + [bundle_ release]; + [super dealloc]; +} + +- (void)applicationDidFinishLaunching:(NSNotification *)notification { +} + +@end + diff --git a/Xcode4Plugin/Resources/Credits.rtf b/Xcode4Plugin/Resources/Credits.rtf new file mode 100644 index 0000000..120dc13 --- /dev/null +++ b/Xcode4Plugin/Resources/Credits.rtf @@ -0,0 +1,8 @@ +{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf540 +{\fonttbl\f0\fswiss\fcharset0 Helvetica;} +{\colortbl;\red255\green255\blue255;} +\vieww9000\viewh8400\viewkind0 +\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\qc\pardirnatural + +\f0\fs24 \cf0 Part of {\field{\*\fldinst{HYPERLINK "http://code.google.com/p/google-toolbox-for-mac/"}}{\fldrslt Google Toolbox For Mac}}\ +}
\ No newline at end of file diff --git a/Xcode4Plugin/Resources/English.lproj/InfoPlist.strings b/Xcode4Plugin/Resources/English.lproj/InfoPlist.strings new file mode 100755 index 0000000..88f65cf --- /dev/null +++ b/Xcode4Plugin/Resources/English.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/Xcode4Plugin/Resources/GTM.icns b/Xcode4Plugin/Resources/GTM.icns Binary files differnew file mode 100644 index 0000000..89cad67 --- /dev/null +++ b/Xcode4Plugin/Resources/GTM.icns diff --git a/Xcode4Plugin/Resources/Info.plist b/Xcode4Plugin/Resources/Info.plist new file mode 100755 index 0000000..d5769f8 --- /dev/null +++ b/Xcode4Plugin/Resources/Info.plist @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleDevelopmentRegion</key> + <string>English</string> + <key>CFBundleExecutable</key> + <string>${EXECUTABLE_NAME}</string> + <key>CFBundleIconFile</key> + <string></string> + <key>CFBundleIdentifier</key> + <string>com.google.GTM.${PRODUCT_NAME:rfc1034Identifier}</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleName</key> + <string>${PRODUCT_NAME}</string> + <key>CFBundlePackageType</key> + <string>BNDL</string> + <key>CFBundleShortVersionString</key> + <string>${GTM_VERSIONINFO_SHORT}</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleVersion</key> + <string>${GTM_VERSIONINFO_LONG}</string> + <key>NSPrincipalClass</key> + <string>GTMXcodePluginManager</string> + <key>XC4Compatible</key> + <true/> + <key>XCGCReady</key> + <true/> + <key>XCPluginHasUI</key> + <false/> + <key>CFBundleGetInfoString</key> + <string>${GTM_VERSIONINFO_FINDER}</string> + <key>NSHumanReadableCopyright</key> + <string>${GTM_VERSIONINFO_ABOUT}</string> +</dict> +</plist> |