548
// aPath is path to a project file PC.project or project bundle *.pcproj.
549
// Also it can be project directory where one of the above resides.
543
550
- (PCProject *)openProjectAt:(NSString *)aPath makeActive: (BOOL)flag
552
NSString *projectPath = nil;
553
NSString *projectFileType = nil;
545
554
PCProject *project = nil;
546
555
NSDictionary *wap = nil;
548
if ((project = [loadedProjects objectForKey: [aPath stringByDeletingLastPathComponent]]) == nil)
557
// Check project path for invalid characters
558
if ([aPath rangeOfString: @" "].location != NSNotFound ||
559
[aPath rangeOfString: @"\t"].location != NSNotFound ||
560
[aPath rangeOfString: @"\r"].location != NSNotFound ||
561
[aPath rangeOfString: @"\n"].location != NSNotFound)
565
@"Project path contains whitespaces.\n"
566
@"GNUstep's build environment currently "
567
@"can't handle that reliably.\n"
568
@"Do you want to open a project anyway?\n",
569
@"Open", @"Don't open", nil) != NSAlertDefaultReturn)
575
projectFileType = [[aPath lastPathComponent] pathExtension];
576
if ([projectFileType isEqualToString:@"pcproj"] ||
577
[projectFileType isEqualToString:@"project"])
579
projectPath = [aPath stringByDeletingLastPathComponent];
586
if ((project = [loadedProjects objectForKey:projectPath])== nil)
550
NSMutableDictionary *projectFile = nil;
551
NSString *projectTypeName = nil;
552
NSString *projectClassName = nil;
554
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:aPath
555
isDirectory: &isDir];
588
NSMutableDictionary *projectFile = nil;
589
NSString *projectTypeName = nil;
590
NSString *projectClassName = nil;
595
exists = [[NSFileManager defaultManager] fileExistsAtPath:aPath
561
if ([aPath rangeOfString: @" "].location != NSNotFound ||
562
[aPath rangeOfString: @"\t"].location != NSNotFound ||
563
[aPath rangeOfString: @"\r"].location != NSNotFound ||
564
[aPath rangeOfString: @"\n"].location != NSNotFound)
568
@"Are you sure you want to open a project with whitespace in it's path?\n"
569
@"GNUstep's build environment currently can't handle that reliably.",
570
@"OK", @"Cancel", nil) != NSAlertDefaultReturn)
604
if ([projectFileType isEqualToString:@"pcproj"] == NO)
606
tempList = [fileManager filesWithExtension:@"pcproj"
609
if ([tempList count] > 0)
611
aPath = [tempList objectAtIndex:0];
614
aPath = [aPath stringByAppendingPathComponent:@"PC.project"];
615
projectFile = [NSMutableDictionary dictionaryWithContentsOfFile:aPath];
617
else if ([projectFileType isEqualToString:@"project"])
578
projectFile = [NSMutableDictionary dictionaryWithContentsOfFile: aPath];
619
projectFile = [NSMutableDictionary dictionaryWithContentsOfFile:aPath];
582
projectFile = [NSMutableDictionary dictionaryWithContentsOfFile: [aPath stringByAppendingPathComponent: @"PC.project"]];
622
{ //TODO: Remove support of 0.3.x projects
623
projectFile = [NSMutableDictionary dictionaryWithContentsOfFile:aPath];
624
if (projectFile != nil)
626
// For compatibility with 0.3.x projects
627
project = [self convertLegacyProject:projectFile atPath:aPath];
585
if(projectFile == nil)
631
if (projectFile == nil)
590
// For compatibility with 0.3.x projects
591
project = [self convertLegacyProject: projectFile atPath: aPath];
593
635
{// Project was converted and created PC*Project with alloc&init
594
636
aPath = [[aPath stringByDeletingLastPathComponent]
635
[loadedProjects setObject:project forKey: [project projectPath]];
636
[project setProjectManager:self];
638
// Windows and panels
639
wap = [projectFile objectForKey:PCWindows];
640
if ([[wap allKeys] containsObject:@"ProjectBuild"])
642
[[project projectWindow] showProjectBuild:self];
644
if ([[wap allKeys] containsObject:@"ProjectLaunch"])
646
[[project projectWindow] showProjectLaunch:self];
648
if ([[wap allKeys] containsObject:@"LoadedFiles"])
650
[[project projectWindow] showProjectLoadedFiles:self];
677
[loadedProjects setObject:project forKey:[project projectPath]];
680
[project setProjectManager:self];
682
// Windows and panels
683
wap = [projectFile objectForKey:PCWindows];
684
if ([[wap allKeys] containsObject:@"ProjectBuild"])
686
[[project projectWindow] showProjectBuild:self];
688
if ([[wap allKeys] containsObject:@"ProjectLaunch"])
690
[[project projectWindow] showProjectLaunch:self];
692
if ([[wap allKeys] containsObject:@"LoadedFiles"])
694
[[project projectWindow] showProjectLoadedFiles:self];
655
697
[[project projectWindow] makeKeyAndOrderFront:self];
656
698
[self setActiveProject: project];
663
705
- (void)openProject
665
NSArray *files = nil;
666
NSString *filePath = nil, *temp = nil;
667
NSArray *fileTypes = [NSArray arrayWithObjects:@"pcproj",@"project",nil];
668
NSEnumerator *en = nil;
707
NSArray *fileTypes = nil;
708
NSArray *files = nil;
709
NSString *filePath = nil;
710
NSFileManager *fm = [NSFileManager defaultManager];
712
NSArray *tempList = nil;
714
fileTypes = [NSArray arrayWithObjects:@"pcproj",@"project",nil];
670
715
files = [fileManager filesOfTypes:fileTypes
671
716
operation:PCOpenProjectOperation
676
721
filePath = [files objectAtIndex:0];
677
en = [files objectEnumerator];
678
while((temp = [en nextObject]) != nil)
723
[fm fileExistsAtPath:filePath isDirectory:&isDir];
680
if([[temp pathExtension] isEqual: @"pcproj"])
726
if (![[filePath pathExtension] isEqualToString:@"pcproj"])
728
tempList = [fileManager filesWithExtension:@"pcproj"
731
if ([tempList count] > 0)
733
filePath = [tempList objectAtIndex:0];
736
filePath = [filePath stringByAppendingPathComponent:@"PC.project"];
739
NSLog(@"PCPM: openProject: %@", filePath);
686
741
if (filePath != nil)
688
[self openProjectAt:filePath makeActive: YES];
743
[self openProjectAt:filePath makeActive:YES];
1023
1077
- (BOOL)closeAllProjects
1025
1079
PCProject *project = nil;
1026
NSEnumerator *enumerator = [loadedProjects objectEnumerator];
1080
NSEnumerator *enumerator = [[loadedProjects allValues] objectEnumerator];
1028
1082
// PCLogInfo(self, @"loaded %i projects", [loadedProjects count]);
1030
while ([loadedProjects count] > 0)
1084
while ((project = [enumerator nextObject]) != nil)
1032
project = [enumerator nextObject];
1033
1086
if ([prefController boolForKey:SaveOnQuit])
1035
1088
[project save];