diff --git a/Tools/XcodeCapp/XcodeCapp/XCCCappuccinoProjectController.m b/Tools/XcodeCapp/XcodeCapp/XCCCappuccinoProjectController.m index 28aaff1b1..9d90bbc43 100644 --- a/Tools/XcodeCapp/XcodeCapp/XCCCappuccinoProjectController.m +++ b/Tools/XcodeCapp/XcodeCapp/XCCCappuccinoProjectController.m @@ -43,7 +43,7 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n { XCCCappuccinoProjectController *controller = (__bridge XCCCappuccinoProjectController *)userData; NSArray *paths = (__bridge NSArray *)eventPaths; - + [controller _handleFSEventsWithPaths:paths flags:eventFlags ids:eventIds]; } @@ -64,11 +64,11 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n self.cappuccinoProject = [[XCCCappuccinoProject alloc] initWithPath:aPath]; self.mainXcodeCappController = aController; self->sourceProcessingOperations = [@{} mutableCopy]; - self->operationQueue = [[NSApp delegate] mainOperationQueue]; - + self->operationQueue = [((AppDelegate *)[NSApp delegate]) mainOperationQueue]; + [self _reinitializeProjectController]; } - + return self; } @@ -83,16 +83,16 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n - (void)_reinitializeTaskLauncher { NSArray *binaryPaths = @[]; - + if ([self.cappuccinoProject.binaryPaths count]) binaryPaths = [self.cappuccinoProject.binaryPaths valueForKeyPath:@"name"]; - + self->taskLauncher = [[XCCTaskLauncher alloc] initWithEnvironmentPaths:binaryPaths]; - + if (!self->taskLauncher.isValid) { [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; - + NSRunAlertPanel( self.cappuccinoProject.nickname, @"XcodeCapp was unable to find all necessary executables in your environment:\n\n" @@ -102,7 +102,7 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n nil, nil, [self->taskLauncher.executables componentsJoinedByString:@", "]); - + [self _reinitializeProjectController]; } } @@ -183,7 +183,7 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n BOOL projectExists, projectIsDirectory; projectExists = [fm fileExistsAtPath:self.cappuccinoProject.XcodeProjectPath isDirectory:&projectIsDirectory]; - + BOOL supportExists, supportIsDirectory; supportExists = [fm fileExistsAtPath:self.cappuccinoProject.supportPath isDirectory:&supportIsDirectory]; @@ -197,43 +197,43 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n - (BOOL)_isXcodeSupportCompatible { double appCompatibilityVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:XCCCompatibilityVersionKey] doubleValue]; - + NSNumber *projectCompatibilityVersion = @([self.cappuccinoProject.version intValue]); - + if (projectCompatibilityVersion == nil) { NSLog(@"No compatibility version in project"); return NO; } - + NSLog(@"XcodeCapp/project compatibility version: %0.1f/%0.1f", projectCompatibilityVersion.doubleValue, appCompatibilityVersion); - + return projectCompatibilityVersion.doubleValue >= appCompatibilityVersion; } - (void)_createXcodeProject { [self _removeXcodeProject]; - + NSFileManager *fm = [NSFileManager defaultManager]; - + [fm createDirectoryAtPath:self.cappuccinoProject.XcodeProjectPath withIntermediateDirectories:YES attributes:nil error:nil]; - + NSString *pbxPath = [self.cappuccinoProject.XcodeProjectPath stringByAppendingPathComponent:@"project.pbxproj"]; - + [fm copyItemAtPath:[[NSBundle mainBundle] pathForResource:@"project" ofType:@"pbxproj"] toPath:pbxPath error:nil]; - + NSMutableString *content = [NSMutableString stringWithContentsOfFile:pbxPath encoding:NSUTF8StringEncoding error:nil]; - + [content writeToFile:pbxPath atomically:YES encoding:NSUTF8StringEncoding error:nil]; - + NSLog(@"Xcode support project created at: %@", self.cappuccinoProject.XcodeProjectPath); } - (void)_removeXcodeProject { NSFileManager *fm = [NSFileManager defaultManager]; - + if ([fm fileExistsAtPath:self.cappuccinoProject.XcodeProjectPath]) [fm removeItemAtPath:self.cappuccinoProject.XcodeProjectPath error:nil]; } @@ -241,20 +241,20 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n - (void)_createXcodeSupportDirectory { [self _removeXcodeSupportDirectory]; - + [[NSFileManager defaultManager] createDirectoryAtPath:self.cappuccinoProject.supportPath withIntermediateDirectories:YES attributes:nil error:nil]; - + [self.cappuccinoProject saveSettings]; - + NSLog(@".XcodeSupport directory created at: %@", self.cappuccinoProject.supportPath); } - (void)_removeXcodeSupportDirectory { [XcodeProjectCloser closeXcodeProjectForProject:self.cappuccinoProject.projectPath]; - + NSFileManager *fm = [NSFileManager defaultManager]; - + if ([fm fileExistsAtPath:self.cappuccinoProject.supportPath]) [fm removeItemAtPath:self.cappuccinoProject.supportPath error:nil]; } @@ -272,13 +272,13 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n NSArray *subpaths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.cappuccinoProject.supportPath error:nil]; NSMutableArray *orphanFiles = [@[] mutableCopy]; NSFileManager *fm = [NSFileManager defaultManager]; - + for (NSString *path in subpaths) { if ([XCCCappuccinoProject isHeaderFile:path] && ![path.lastPathComponent isEqualToString:@"xcc_general_include.h"]) { NSString *sourcePath = [self.cappuccinoProject sourcePathForShadowPath:path]; - + if (![fm fileExistsAtPath:sourcePath]) [orphanFiles addObject:sourcePath]; } @@ -291,15 +291,15 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n NSString *shadowBasePath = [self.cappuccinoProject shadowBasePathForProjectSourcePath:sourcePath]; NSString *shadowHeaderPath = [shadowBasePath stringByAppendingPathExtension:@"h"]; NSString *shadowImplementationPath = [shadowBasePath stringByAppendingPathExtension:@"m"]; - + [fm removeItemAtPath:shadowHeaderPath error:nil]; [fm removeItemAtPath:shadowImplementationPath error:nil]; - + [self removeOperationErrorsRelatedToSourcePath:sourcePath errorType:XCCDefaultOperationErrorType]; [pathsToRemove addObject:sourcePath]; } - + [self.mainXcodeCappController.errorsViewController reload]; if (self->pendingPBXOperation) @@ -329,14 +329,14 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n - (void)_updateXcodeSupportFilesWithRenamedDirectories:(NSArray *)directories { NSLog(@"Renamed directories: %@", directories); - + NSFileManager *fm = [NSFileManager defaultManager]; - + for (NSString *directory in directories) { if ([directory isEqualToString:self.cappuccinoProject.projectPath]) continue; - + if ([fm fileExistsAtPath:directory]) { if ([directory hasPrefix:self.cappuccinoProject.projectPath]) @@ -549,7 +549,7 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n { if (![self _doesNotificationBelongToCurrentProject:note]) return; - + [self operationDidEnd:note.object type:note.name userInfo:note.userInfo]; } @@ -560,17 +560,17 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n { if (!operationError.fileName) operationError.fileName = @"/No Filename"; - + [self willChangeValueForKey:@"errors"]; - + if (!self.errors[operationError.fileName]) self.errors[operationError.fileName] = [@[] mutableCopy]; - + [self.errors[operationError.fileName] addObject:operationError]; - + [self didChangeValueForKey:@"errors"]; self.numberOfErrors++; - + [self _notifyUserWithOperationError:operationError]; } @@ -578,14 +578,14 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n { if (!operationError.fileName) operationError.fileName = @"/No Filename"; - + [self willChangeValueForKey:@"errors"]; - + [self.errors[operationError.fileName] removeObject:operationError]; - + if (![self.errors[operationError.fileName] count]) [self.errors removeObjectForKey:operationError.fileName]; - + [self didChangeValueForKey:@"errors"]; self.numberOfErrors--; } @@ -601,11 +601,11 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n - (void)removeOperationErrorsRelatedToSourcePath:(NSString *)aPath errorType:(int)anErrorType { NSMutableArray *errorsToRemove = [@[] mutableCopy]; - + for (XCCOperationError *operationError in self.errors[aPath]) if ([operationError.fileName isEqualToString:aPath] && (operationError.errorType == anErrorType || anErrorType == XCCDefaultOperationErrorType)) [errorsToRemove addObject:operationError]; - + for (XCCOperationError *error in errorsToRemove) [self removeOperationError:error]; } @@ -619,11 +619,11 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n { if (numberOfErrors == _numberOfErrors) return; - + [self willChangeValueForKey:@"numberOfErrors"]; _numberOfErrors = numberOfErrors; [self didChangeValueForKey:@"numberOfErrors"]; - + if (!_numberOfErrors) self.errorsCountString = @""; else @@ -882,9 +882,9 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n NSMutableArray *modifiedPaths = [@[] mutableCopy]; NSMutableArray *renamedDirectories = [@[] mutableCopy]; NSFileManager *fm = [NSFileManager defaultManager]; - + BOOL needUpdate = NO; - + for (size_t i = 0; i < paths.count; ++i) { FSEventStreamEventFlags flags = eventFlags[i]; @@ -896,27 +896,27 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n if (rootChanged || needRescan) { NSLog(@"Watched path changed: %@", path); - + [self _handleProjectPathChange:path]; return; } BOOL isHistoryDoneSentinalEvent = (flags & kFSEventStreamEventFlagHistoryDone) != 0; - + if (isHistoryDoneSentinalEvent) { NSLog(@"History done sentinal event"); continue; } - + BOOL isMountEvent = (flags & kFSEventStreamEventFlagMount) || (flags & kFSEventStreamEventFlagUnmount); - + if (isMountEvent) { NSLog(@"Volume %@: %@", (flags & kFSEventStreamEventFlagMount) ? @"mounted" : @"unmounted", path); continue; } - + BOOL inodeMetaModified = (flags & kFSEventStreamEventFlagItemInodeMetaMod) != 0; BOOL isFile = (flags & kFSEventStreamEventFlagItemIsFile) != 0; @@ -926,21 +926,21 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n BOOL modified = (flags & kFSEventStreamEventFlagItemModified) != 0; BOOL created = (flags & kFSEventStreamEventFlagItemCreated) != 0; BOOL removed = (flags & kFSEventStreamEventFlagItemRemoved) != 0; - + if (isDir) { if (created && [path isEqualToString:self.cappuccinoProject.projectPath.stringByResolvingSymlinksInPath]) return; - + if ((renamed || created || removed) && ![XCCCappuccinoProject shouldIgnoreDirectoryNamed:path.lastPathComponent] && ![XCCCappuccinoProject pathMatchesIgnoredPaths:path cappuccinoProjectIgnoredPathPredicates:self.cappuccinoProject.ignoredPathPredicates]) { NSLog(@"Renamed directory: %@", path); - + [renamedDirectories addObject:path]; } - + continue; } else if ((isFile || isSymlink) && @@ -957,27 +957,27 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n { // If a xib is deleted, delete its cib. There is no need to update when a xib is deleted, // it is inside a folder in Xcode, which updates automatically. - + if (![fm fileExistsAtPath:path]) { NSString *cibPath = [path.stringByDeletingPathExtension stringByAppendingPathExtension:@"cib"]; - + if ([fm fileExistsAtPath:cibPath]) [fm removeItemAtPath:cibPath error:nil]; - + continue; } } - + needUpdate = YES; } else if ((isFile || isSymlink) && (renamed || removed) && !(modified || created) && [XCCCappuccinoProject isCibFile:path]) { NSLog(@"FSEvent accepted: %@ (%@)", path, [XCCFSEventLogUtils dumpFSEventFlags:flags]); - + // If a cib is deleted, mark its xib as needing update so the cib is regenerated NSString *xibPath = [path.stringByDeletingPathExtension stringByAppendingPathExtension:@"xib"]; - + if ([fm fileExistsAtPath:xibPath]) { [modifiedPaths addObject:xibPath]; @@ -993,7 +993,7 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n [self.cappuccinoProject reloadXcodeCappIgnoreFile]; } } - + // If directories were renamed, we take the easy way out and reset the project if (renamedDirectories.count) [self _updateXcodeSupportFilesWithRenamedDirectories:renamedDirectories]; @@ -1015,9 +1015,9 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n { NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; NSString *app, *type; - + BOOL success = [workspace getInfoForFile:filePath application:&app type:&type]; - + return success ? app : nil; } @@ -1032,14 +1032,14 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n { if (!applicationIdentifier) return; - + NSFileManager *fm = [NSFileManager defaultManager]; NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; NSBundle *bundle = [NSBundle bundleWithPath:applicationIdentifier]; NSString *identifier = bundle.bundleIdentifier; NSString *executablePath = nil; XCCLineSpecifier lineSpecifier = kLineSpecifierNone; - + if ([identifier hasPrefix:@"com.sublimetext."]) { lineSpecifier = kLineSpecifierColon; @@ -1086,34 +1086,34 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n { executablePath = [[bundle bundlePath] stringByAppendingPathComponent:@"Contents/Developer/usr/bin/xed"]; } - + if (!executablePath || ![fm isExecutableFileAtPath:executablePath]) { [workspace openFile:path]; return; } - + NSArray *args; - + switch (lineSpecifier) { case kLineSpecifierNone: args = @[path]; break; - + case kLineSpecifierColon: args = @[[NSString stringWithFormat:@"%1$@:%2$ld", path, line]]; break; - + case kLineSpecifierMinusL: args = @[@"-l", [NSString stringWithFormat:@"%ld", line], path]; break; - + case kLineSpecifierPlus: args = @[[NSString stringWithFormat:@"+%ld", line], path]; break; } - + [self->taskLauncher runTaskWithCommand:executablePath arguments:args returnType:kTaskReturnTypeNone]; } @@ -1128,7 +1128,7 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n note.actionButtonTitle = @"Show"; note.otherButtonTitle = @"Close"; note.userInfo = @{@"cappuccinoProjectPath" : self.cappuccinoProject.projectPath, @"sourcePath": anOperationError.fileName}; - + [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:note]; } @@ -1138,7 +1138,7 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n - (void)reinitializeProjectFromSettings { NSLog(@"Saving Cappuccino configuration project %@", self.cappuccinoProject.projectPath); - + [self _cancelAllProjectRelatedOperations]; [self.cappuccinoProject saveSettings]; @@ -1196,26 +1196,26 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n BOOL isOpened = YES; NSFileManager *fm = [NSFileManager defaultManager]; BOOL exists = [fm fileExistsAtPath:self.cappuccinoProject.XcodeProjectPath isDirectory:&isDirectory]; - + if (exists && isDirectory) { NSLog(@"Opening Xcode project at: %@", self.cappuccinoProject.XcodeProjectPath); - + isOpened = [[NSWorkspace sharedWorkspace] openFile:self.cappuccinoProject.XcodeProjectPath]; } - + if (!exists || !isDirectory || !isOpened) { NSString *text; - + if (!isOpened) text = @"The project exists, but failed to open."; else text = [NSString stringWithFormat:@"%@ %@.", self.cappuccinoProject.XcodeProjectPath, !exists ? @"does not exist" : @"is not an Xcode project"]; - + [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; NSInteger response = NSRunAlertPanel(@"The project could not be opened.", @"%@\n\nWould you like to regenerate the project?", @"Yes", @"No", nil, text); - + if (response == NSAlertFirstButtonReturn) [self resetProject:self]; } @@ -1231,7 +1231,7 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n NSFileManager *fm = [NSFileManager defaultManager]; NSArray *contents = [fm contentsOfDirectoryAtPath:self.cappuccinoProject.projectPath error:nil]; NSString *firstObjjFile; - + for (NSString *file in contents) { if ([[file pathExtension] isEqualToString:@"j"]) @@ -1240,15 +1240,15 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n break; } } - + if (!firstObjjFile) return; - + NSString *applicationIdentifier = [self _managingApplicationIdenfierForFilePath:[self.cappuccinoProject.projectPath stringByAppendingPathComponent:firstObjjFile]]; - + if (!applicationIdentifier) return; - + [self launchEditorForPath:self.cappuccinoProject.projectPath line:0 applicationIdentifier:applicationIdentifier]; } @@ -1268,5 +1268,3 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, void *userData, size_t n } @end - -