diff --git a/Framework/PCProjectBrowser.m b/Framework/PCProjectBrowser.m index f292b1c..aa9f7ca 100644 --- a/Framework/PCProjectBrowser.m +++ b/Framework/PCProjectBrowser.m @@ -150,9 +150,15 @@ NSString *PCBrowserDidSetPathNotification = @"PCBrowserDidSetPathNotification"; NSString *name = nil; int i; + // Name of subproject selected: change path to be ended with 'Subprojects' + // category of superproject. + // But: path '/Subproject/Foo' and '/Subprojects/Foo/Subprojects' will + // return the same category 'Subprojects' and active project will be 'Foo' + // in both cases if ([lastPathElement isEqualToString:[activeProject projectName]]) { - return [activeProject projectName]; + activeProject = [activeProject superProject]; + rootCategories = [activeProject rootCategories]; } if (([rootCategories containsObject:lastPathElement] @@ -374,12 +380,12 @@ NSString *PCBrowserDidSetPathNotification = @"PCBrowserDidSetPathNotification"; browserPath = [self path]; filePath = [self pathToSelectedFile]; -// NSLog(@"browserPath: %@ forProject: %@", -// browserPath, [activeProject projectName]); + NSLog(@"category: %@ forProject: %@", + category, [activeProject projectName]); -// if ([[self selectedFiles] count] == 1 if (filePath && [filePath isEqualToString:browserPath] && + ![category isEqualToString:[activeProject projectName]] && ![[ud objectForKey:SeparateEditor] isEqualToString:@"YES"]) { // NSLog(@"[click] category: %@ filePath: %@", category, filePath); diff --git a/Framework/PCProjectManager.m b/Framework/PCProjectManager.m index 71239c7..b1e6f01 100644 --- a/Framework/PCProjectManager.m +++ b/Framework/PCProjectManager.m @@ -568,9 +568,10 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; projectClassName = [projectTypes objectForKey:projectTypeName]; if (projectClassName == nil) { - NSRunAlertPanel(@"Load Project", - @"Project type '%@' is not supported!", - @"OK",nil,nil,projectTypeName); + NSRunAlertPanel(@"Open Project", + @"Project type '%@' is not supported!\n" + "Report the bug, please!", + @"OK", nil, nil, projectTypeName); return nil; } project = [bundleManager objectForClassName:projectClassName @@ -578,10 +579,10 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; protocol:@protocol(ProjectType)]; } - if (![project openWithDictionaryAt:aPath]) + if (!project || ![project openWithDictionaryAt:aPath]) { - NSRunAlertPanel(@"Load Project", - @"Could not load project '%@'!", + NSRunAlertPanel(@"Open Project", + @"Unable to open project '%@'.\nReport bug, please!", @"OK",nil,nil,aPath); return nil; } @@ -646,6 +647,31 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; return NO; } +- (void)openProject +{ + NSArray *files = nil; + NSString *filePath = nil; + NSArray *fileTypes = [NSArray arrayWithObjects:@"project",@"pcproj",nil]; + + files = [fileManager filesOfTypes:fileTypes + operation:PCOpenProjectOperation + multiple:NO + title:@"Open Project" + accView:nil]; + filePath = [files objectAtIndex:0]; + + if (filePath != nil) + { + if (![self openProjectAt:filePath]); + { + // No need to open alert panel. + // Panel was opened in openProjectAt:->loadProjectAt: method. + return; + } + [[activeProject projectWindow] makeKeyAndOrderFront:self]; + } +} + - (PCProject *)createProjectOfType:(NSString *)projectType path:(NSString *)aPath { @@ -666,18 +692,30 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; // NSLog(@"%@ CLASS: %@", className, projectCreator); if (!projectCreator) { + NSRunAlertPanel(@"New Project", + @"Could not create project directory %@.\n" + "No project creator. Report the bug, please!", + @"OK", nil, nil, aPath); return nil; } // Create project directory if (![[PCFileManager defaultManager] createDirectoriesIfNeededAtPath:aPath]) { + NSRunAlertPanel(@"New Project", + @"Could not create project directory %@.\n" + "Check permissions of the directory where you" + " want to create a project", + @"OK", nil, nil, aPath); return nil; } // Create project if (!(project = [projectCreator createProjectAt:aPath])) { + NSRunAlertPanel(@"New Project", + @"Project %@ could not be created.\nReport bug, please!", + @"OK",nil,nil,[project projectName]); return nil; } @@ -687,31 +725,6 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; return project; } -- (void)openProject -{ - NSArray *files = nil; - NSString *filePath = nil; - NSArray *fileTypes = [NSArray arrayWithObjects:@"project",@"pcproj",nil]; - - files = [fileManager filesOfTypes:fileTypes - operation:PCOpenProjectOperation - multiple:NO - title:@"Open Project" - accView:nil]; - filePath = [files objectAtIndex:0]; - - if (filePath != nil) - { - [self openProjectAt:filePath]; - [[activeProject projectWindow] makeKeyAndOrderFront:self]; - -/* NSRunAlertPanel(@"Attention!", - @"Couldn't open project %@!", - @"OK",nil,nil, - [filePath stringByDeletingLastPathComponent]);*/ - } -} - - (void)newProject { NSArray *files; @@ -734,9 +747,9 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; if (!(project = [self createProjectOfType:projectType path:filePath])) { - NSRunAlertPanel(@"New Project", - @"Failed to create %@!", - @"OK",nil,nil,filePath); + // No need to open alert panel. Alert panel was already opened + // in createProjectOfType:path: method. + return; } [loadedProjects setObject:project forKey:[project projectName]]; @@ -761,7 +774,7 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; { NSRunAlertPanel(@"Save Project", @"Couldn't save project %@!", - @"OK",nil,nil,[activeProject projectName]); + @"OK", nil, nil, [activeProject projectName]); return NO; } @@ -830,6 +843,9 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; NSMutableArray *subprojs = [NSMutableArray array]; unsigned i; + NSLog(@"Root active project '%@' category '%@'", + [project projectName], category); + // Determining target project if ([categoryKey isEqualToString:PCSubprojects]) { @@ -908,7 +924,7 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; else if (flag) { // Save project because we've removed file(s) from disk - // TODO: Should be fixed later (add pending removal of files?) + // TODO: Maybe fix it later? (add pending removal of files) [activeProject save]; } } @@ -1028,7 +1044,10 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; title:@"Open File" accView:nil]; filePath = [files objectAtIndex:0]; - [self openFileAtPath:filePath]; + if (filePath) + { + [self openFileAtPath:filePath]; + } } - (void)newFile @@ -1049,13 +1068,14 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; files = [fileManager filesOfTypes:nil operation:PCSaveFileOperation multiple:NO - title:@"Save As..." + title:@"Save File As..." accView:nil]; filePath = [files objectAtIndex:0]; if (filePath != nil && ![[activeProject projectEditor] saveFileAs:filePath]) { - NSRunAlertPanel(@"Alert", @"Couldn't save file to\n%@!", + NSRunAlertPanel(@"Save File As", + @"Unable to save file as\n%@!", @"OK", nil, nil, filePath); return NO; } @@ -1091,13 +1111,14 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; files = [fileManager filesOfTypes:nil operation:PCSaveFileOperation multiple:NO - title:@"Save To..." + title:@"Save File To..." accView:nil]; filePath = [files objectAtIndex:0]; if (filePath != nil && ![[activeProject projectEditor] saveFileTo:filePath]) { - NSRunAlertPanel(@"Alert", @"Couldn't save file to\n%@!", + NSRunAlertPanel(@"Save File To", + @"Unable to save file to\n%@!", @"OK", nil, nil, filePath); return NO; } @@ -1128,7 +1149,7 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; @implementation PCProjectManager (Subprojects) -- (BOOL)newSubproject +- (BOOL)openNewSubprojectPanel { // PCLogInfo(self, @"newSubproject"); @@ -1136,7 +1157,10 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; { if ([NSBundle loadNibNamed:@"NewSubproject" owner:self] == NO) { - PCLogError(self, @"error loading NewSubproject NIB!"); + NSRunAlertPanel(@"New Subproject", + @"Internal error!" + " Install ProjectCenter again, please.", + @"OK", nil, nil); return NO; } @@ -1173,20 +1197,24 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; [NSApp stopModal]; } -- (BOOL)createSubproject:(id)sender -{ - [self closeNewSubprojectPanel:self]; - - return [self createSubproject]; -} - -- (BOOL)createSubproject +- (void)createSubproject:(id)sender { PCProject *subproject = nil; NSString *spName = [nsNameField stringValue]; NSString *spPath = nil; NSString *spType = [nsTypePB titleOfSelectedItem]; + // Check if subproject with entered name already exists. + if (![activeProject doesAcceptFile:spName forKey:PCSubprojects]) + { + NSRunAlertPanel(@"New Subproject", + @"Subproject with name %@ already exists in project %@", + @"OK", nil, nil, spName, [activeProject projectName]); + return; + } + + [self closeNewSubprojectPanel:self]; + if (![[spName pathExtension] isEqualToString:@"subproj"]) { spName = [[nsNameField stringValue] @@ -1201,7 +1229,7 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; // Create subproject subproject = [self createSubprojectOfType:spType path:spPath]; - return YES; + return; } - (PCProject *)createSubprojectOfType:(NSString *)projectType @@ -1210,19 +1238,16 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; NSString *className = [projectTypes objectForKey:projectType]; PCProject *projectCreator; PCProject *subproject = nil; -/* NSString *subprojectName = [aPath lastPathComponent]; - - if ((project = [activeProject objectForKey:projectName]) != nil) - { - [[project projectWindow] makeKeyAndOrderFront:self]; - return project; - }*/ projectCreator = [bundleManager objectForClassName:className bundleType:@"project" protocol:@protocol(ProjectType)]; if (!(subproject = [projectCreator createProjectAt:aPath])) { + NSRunAlertPanel(@"New Subproject", + @"Internal error!" + " Install ProjectCenter again, please.", + @"OK", nil, nil); return nil; } [subproject setIsSubproject:YES]; @@ -1237,13 +1262,18 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; - (void)controlTextDidChange:(NSNotification *)aNotif { + NSString *tfString = nil; + NSArray *subprojectList = nil; + if ([aNotif object] != nsNameField) { return; } - // TODO: Add check for valid subproject named - if ([[nsNameField stringValue] length] > 0) + // Check for valid subproject names + tfString = [nsNameField stringValue]; + subprojectList = [[activeProject projectDict] objectForKey:PCSubprojects]; + if (![subprojectList containsObject:tfString]) { [nsCreateButton setEnabled:YES]; } diff --git a/Headers/ProjectCenter/PCProjectManager.h b/Headers/ProjectCenter/PCProjectManager.h index d390280..2b88cc9 100644 --- a/Headers/ProjectCenter/PCProjectManager.h +++ b/Headers/ProjectCenter/PCProjectManager.h @@ -139,17 +139,13 @@ extern NSString *PCActiveProjectDidChangeNotification; - (PCProject *)convertLegacyProject:(NSMutableDictionary *)pDict atPath:(NSString *)aPath; - // Returns the loaded project if the builder class is known, nil else. - (PCProject *)loadProjectAt:(NSString *)aPath; - // Invokes loadProjectAt to load the project properly. - (BOOL)openProjectAt:(NSString *)aPath; - +- (void)openProject; - (PCProject *)createProjectOfType:(NSString *)projectType path:(NSString *)aPath; - -- (void)openProject; - (void)newProject; - (BOOL)saveProject; @@ -205,13 +201,13 @@ extern NSString *PCActiveProjectDidChangeNotification; @interface PCProjectManager (Subprojects) -- (BOOL)newSubproject; -- (BOOL)addSubproject; +- (BOOL)openNewSubprojectPanel; - (void)closeNewSubprojectPanel:(id)sender; -- (BOOL)createSubproject:(id)sender; + +- (void)createSubproject:(id)sender; - (PCProject *)createSubprojectOfType:(NSString *)projectType path:(NSString *)aPath; -- (BOOL)createSubproject; +- (BOOL)addSubproject; @end #endif diff --git a/PCMenuController.m b/PCMenuController.m index 40b88ac..1834742 100644 --- a/PCMenuController.m +++ b/PCMenuController.m @@ -139,7 +139,7 @@ // Subproject - (void)subprojectNew:(id)sender { - [projectManager newSubproject]; + [projectManager openNewSubprojectPanel]; } - (void)subprojectAdd:(id)sender