mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-26 05:27:03 +00:00
Merge pull request #1969 from Dogild/xCodeCappCreateProject
New: Added menu Create Project... in xCodeCapp
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
|
||||
+ (AppController *)sharedAppController;
|
||||
|
||||
- (IBAction)createProject:(id)sender;
|
||||
- (IBAction)loadProject:(id)aSender;
|
||||
- (IBAction)openHelp:(id)aSender;
|
||||
- (IBAction)openAbout:(id)aSender;
|
||||
|
||||
@@ -150,7 +150,8 @@ AppController *SharedAppControllerInstance = nil;
|
||||
kDefaultMaxRecentProjects: @20,
|
||||
kDefaultLogLevel: [NSNumber numberWithInt:LOG_LEVEL_WARN],
|
||||
kDefaultAutoOpenXcodeProject: @YES,
|
||||
kDefaultShowProcessingNotices: @YES
|
||||
kDefaultShowProcessingNotices: @YES,
|
||||
kDefaultUseSymlinkWhenCreatingProject: @YES
|
||||
};
|
||||
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
@@ -401,6 +402,25 @@ AppController *SharedAppControllerInstance = nil;
|
||||
[self openWindow:self.preferencesWindow];
|
||||
}
|
||||
|
||||
- (IBAction)createProject:(id)sender
|
||||
{
|
||||
NSSavePanel *savePanel = [NSSavePanel savePanel];
|
||||
savePanel.title = @"Create a new Cappuccino Project";
|
||||
savePanel.canCreateDirectories = YES;
|
||||
|
||||
if ([savePanel runModal] != NSFileHandlingPanelOKButton)
|
||||
return;
|
||||
|
||||
NSString *projectPath = [[savePanel.URL path] stringByStandardizingPath];
|
||||
|
||||
NSDictionary *taskResult = [self.xcc createProject:projectPath];
|
||||
|
||||
if ([taskResult[@"status"] intValue])
|
||||
return;
|
||||
|
||||
[self loadProjectAtPath:projectPath reopening:YES];
|
||||
}
|
||||
|
||||
#pragma mark - Delegates
|
||||
|
||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app
|
||||
@@ -439,6 +459,7 @@ AppController *SharedAppControllerInstance = nil;
|
||||
|
||||
#pragma mark - Private Helpers
|
||||
|
||||
|
||||
- (BOOL)loadProjectAtPath:(NSString *)path reopening:(BOOL)reopen
|
||||
{
|
||||
if (!reopen && [self.xcc.projectPath isEqualToString:path])
|
||||
|
||||
@@ -26,5 +26,6 @@ extern NSString * const kDefaultMaxRecentProjects;
|
||||
extern NSString * const kDefaultLogLevel;
|
||||
extern NSString * const kDefaultAutoOpenXcodeProject;
|
||||
extern NSString * const kDefaultShowProcessingNotices;
|
||||
extern NSString * const kDefaultUseSymlinkWhenCreatingProject;
|
||||
|
||||
#endif
|
||||
|
||||
@@ -24,3 +24,4 @@ NSString * const kDefaultMaxRecentProjects = @"maxRecentProjects";
|
||||
NSString * const kDefaultLogLevel = @"logLevel";
|
||||
NSString * const kDefaultAutoOpenXcodeProject = @"autoOpenXcodeProject";
|
||||
NSString * const kDefaultShowProcessingNotices = @"showProcessingNotices";
|
||||
NSString * const kDefaultUseSymlinkWhenCreatingProject = @"useSymlinkWhenCreatingProject";
|
||||
|
||||
@@ -79,6 +79,9 @@ extern NSString * const XCCProjectDidFinishLoadingNotification;
|
||||
// Full path to pbxprojModifier.py
|
||||
@property NSString *pbxModifierScriptPath;
|
||||
|
||||
// Tooltip for the radio button symlink
|
||||
@property NSString *toolTipSymlinkRadioButton;
|
||||
|
||||
// Full paths to the executables we rely on: jsc, objj, nib2cib, python
|
||||
@property NSMutableDictionary *executablePaths;
|
||||
|
||||
@@ -97,6 +100,9 @@ extern NSString * const XCCProjectDidFinishLoadingNotification;
|
||||
// Whether we are currently processing source files
|
||||
@property BOOL isProcessing;
|
||||
|
||||
// Whether $CAPP_BUILD is defined or not
|
||||
@property BOOL isCappBuildDefined;
|
||||
|
||||
// A mapping from full paths to project-relative paths
|
||||
@property NSMutableDictionary *projectPathsForSourcePaths;
|
||||
|
||||
@@ -134,6 +140,8 @@ extern NSString * const XCCProjectDidFinishLoadingNotification;
|
||||
- (void)wantUserNotificationWithInfo:(NSDictionary *)info;
|
||||
- (NSDictionary *)runTaskWithLaunchPath:(NSString *)launchPath arguments:(NSArray *)arguments returnType:(XCCTaskReturnType)returnType;
|
||||
|
||||
- (NSDictionary*)createProject:(NSString*)aPath;
|
||||
|
||||
@end
|
||||
|
||||
@interface XcodeCapp (SnowLeopard)
|
||||
|
||||
@@ -187,6 +187,8 @@ void fsevents_callback(ConstFSEventStreamRef streamRef,
|
||||
self.pbxOperations = [NSMutableDictionary new];
|
||||
self.executablePaths = [NSMutableDictionary new];
|
||||
self.projectPathFileDescriptor = -1;
|
||||
self.isCappBuildDefined = YES;
|
||||
self.toolTipSymlinkRadioButton = @"If this is checked, when a Cappuccino project is created, the frameworks of the new project will be symlinked from the $CAPP_BUILD";
|
||||
|
||||
[self initTaskEnvironment];
|
||||
|
||||
@@ -239,7 +241,29 @@ void fsevents_callback(ConstFSEventStreamRef streamRef,
|
||||
// Make sure we are using jsc as the narwhal engine!
|
||||
self.environment[@"NARWHAL_ENGINE"] = @"jsc";
|
||||
|
||||
self.executables = @[@"python", @"narwhal-jsc", @"objj", @"nib2cib"];
|
||||
self.executables = @[@"python", @"narwhal-jsc", @"objj", @"nib2cib", @"capp"];
|
||||
|
||||
// This is used to get the env var of $CAPP_BUILD
|
||||
NSDictionary *processEnvironment = [[NSProcessInfo processInfo] environment];
|
||||
NSArray *arguments = [NSArray arrayWithObjects:@"-l", @"-c", @"echo $CAPP_BUILD", nil];
|
||||
|
||||
NSDictionary *taskResult = [self runTaskWithLaunchPath:[processEnvironment objectForKey:@"SHELL"]
|
||||
arguments:arguments
|
||||
returnType:kTaskReturnTypeStdOut];
|
||||
|
||||
// Make sure to remove the \n at the end of the response
|
||||
NSString *response = [taskResult[@"response"] stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
|
||||
|
||||
self.environment[@"CAPP_BUILD"] = response;
|
||||
|
||||
// Make sure we have found a CAPP_BUILD
|
||||
if ([response length] == 0 || [taskResult[@"status"] intValue] == -1)
|
||||
{
|
||||
self.toolTipSymlinkRadioButton = @"To use this option you need to have the variable $CAPP_BUILD in your environement (export CAPP_BUILD='path/to/your/cappuccino/build')";
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
[defaults setObject:@NO forKey:kDefaultUseSymlinkWhenCreatingProject];
|
||||
self.isCappBuildDefined = NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)initObservers
|
||||
@@ -574,6 +598,42 @@ void fsevents_callback(ConstFSEventStreamRef streamRef,
|
||||
[self openXcodeProject:self];
|
||||
}
|
||||
|
||||
- (NSDictionary*)createProject:(NSString*)aPath
|
||||
{
|
||||
NSDictionary *taskResult;
|
||||
NSMutableArray *arguments = [NSMutableArray arrayWithObjects:@"gen", aPath ,@"-t", @"NibApplication", nil];
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
|
||||
// This is used when an user wants to replace an existing project
|
||||
NSArray *argumentsRemove = [NSArray arrayWithObjects:@"-rf", aPath, nil];
|
||||
[self runTaskWithLaunchPath:@"/bin/rm" arguments:argumentsRemove returnType:kTaskReturnTypeAny];
|
||||
|
||||
if ([defaults boolForKey:kDefaultUseSymlinkWhenCreatingProject])
|
||||
[arguments addObject:@"-l"];
|
||||
|
||||
taskResult = [self runTaskWithLaunchPath:self.executablePaths[@"capp"]
|
||||
arguments:arguments
|
||||
returnType:kTaskReturnTypeStdOut];
|
||||
|
||||
NSInteger status = [taskResult[@"status"] intValue];
|
||||
NSString *response = taskResult[@"response"];
|
||||
|
||||
if (!status)
|
||||
{
|
||||
DDLogVerbose(@"Created Xcode project: [%ld, %@]", status, status ? response : @"");
|
||||
[self notifyUserWithTitle:@"Project created" message:aPath.lastPathComponent];
|
||||
}
|
||||
else
|
||||
{
|
||||
DDLogVerbose(@"Created Xcode project failed: [%ld, %@]", status, status ? response : @"");
|
||||
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:response forKey:@"message"];
|
||||
[self.errorListController addObject:dictionary];
|
||||
[self showErrors];
|
||||
}
|
||||
|
||||
return taskResult;
|
||||
}
|
||||
|
||||
#pragma mark - Notification handlers
|
||||
|
||||
/*
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user