~ubuntu-branches/ubuntu/vivid/projectcenter.app/vivid

« back to all changes in this revision

Viewing changes to Framework/PCProjectManager.m

  • Committer: Bazaar Package Importer
  • Author(s): Gürkan Sengün
  • Date: 2011-02-08 14:48:25 UTC
  • mfrom: (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110208144825-kww817wxl5y9ail8
Tags: 0.6.0-1
* New upstream release.
* Add myself to uploaders.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
   GNUstep ProjectCenter - http://www.gnustep.org/experience/ProjectCenter.html
3
3
 
4
 
   Copyright (C) 2000-2004 Free Software Foundation
 
4
   Copyright (C) 2000-2010 Free Software Foundation
5
5
 
6
6
   Authors: Philippe C.D. Robert
7
7
            Serg Stoyan
 
8
            Riccardo Mottola
8
9
 
9
10
   This file is part of GNUstep.
10
11
 
444
445
      return nil;
445
446
    }
446
447
 
447
 
  NSLog(@"Convert legacy");
 
448
  PCLogInfo(self, @"Converting legacy project");
448
449
 
449
450
  // Gorm project type doesn't exists anymore
450
451
  if ([projectClassName isEqualToString:@"PCGormProj"] ||
517
518
      [fm movePath:_file toPath:_2file handler:nil];
518
519
    }
519
520
 
 
521
  /* remove non meaningful keys */
 
522
  [pDict removeObjectForKey: PCWindows];
 
523
  [pDict removeObjectForKey: PCLastEditing];
 
524
 
520
525
  // GNUmakefiles will be generated in [PCProject initWithProjectDictionary:]
521
526
 
522
527
  // Remove obsolete records from project dictionary and write to PC.project
540
545
  return project;
541
546
}
542
547
 
 
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
544
551
{
 
552
  NSString     *projectPath = nil;
 
553
  NSString     *projectFileType = nil;
545
554
  PCProject    *project = nil;
546
555
  NSDictionary *wap = nil;
547
 
  
548
 
  if ((project = [loadedProjects objectForKey: [aPath stringByDeletingLastPathComponent]]) == nil)
 
556
 
 
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)
 
562
    {
 
563
      if (NSRunAlertPanel 
 
564
          (@"Open Project",
 
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)
 
570
        {
 
571
          return nil;
 
572
        }
 
573
    }
 
574
 
 
575
  projectFileType = [[aPath lastPathComponent] pathExtension];
 
576
  if ([projectFileType isEqualToString:@"pcproj"] || 
 
577
      [projectFileType isEqualToString:@"project"])
 
578
    {
 
579
      projectPath = [aPath stringByDeletingLastPathComponent];
 
580
    }
 
581
  else
 
582
    {
 
583
      projectPath = aPath;
 
584
    }
 
585
 
 
586
  if ((project = [loadedProjects objectForKey:projectPath])== nil)
549
587
    {  
550
 
      NSMutableDictionary    *projectFile = nil;
551
 
      NSString               *projectTypeName = nil;
552
 
      NSString               *projectClassName = nil;
553
 
      BOOL         isDir = NO;
554
 
      BOOL         exists = [[NSFileManager defaultManager] fileExistsAtPath:aPath 
555
 
                                                            isDirectory: &isDir];
 
588
      NSMutableDictionary *projectFile = nil;
 
589
      NSString            *projectTypeName = nil;
 
590
      NSString            *projectClassName = nil;
 
591
      BOOL                isDir = NO;
 
592
      BOOL                exists = NO;
 
593
      NSArray             *tempList;
 
594
 
 
595
      exists = [[NSFileManager defaultManager] fileExistsAtPath:aPath 
 
596
                                                    isDirectory:&isDir];
556
597
      if (!exists)
557
598
        {
558
599
          return nil;
559
600
        }
560
 
      
561
 
      if ([aPath rangeOfString: @" "].location != NSNotFound ||
562
 
          [aPath rangeOfString: @"\t"].location != NSNotFound ||
563
 
          [aPath rangeOfString: @"\r"].location != NSNotFound ||
564
 
          [aPath rangeOfString: @"\n"].location != NSNotFound)
 
601
 
 
602
      if (isDir)
565
603
        {
566
 
          if (NSRunAlertPanel 
567
 
              (@"Open Project",
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)
571
605
            {
572
 
              return nil;
 
606
              tempList = [fileManager filesWithExtension:@"pcproj"
 
607
                                                  atPath:aPath
 
608
                                             includeDirs:YES];
 
609
              if ([tempList count] > 0)
 
610
                {
 
611
                  aPath = [tempList objectAtIndex:0];
 
612
                }
573
613
            }
 
614
          aPath = [aPath stringByAppendingPathComponent:@"PC.project"];
 
615
          projectFile = [NSMutableDictionary dictionaryWithContentsOfFile:aPath];
574
616
        }
575
 
 
576
 
      if (!isDir)
 
617
      else if ([projectFileType isEqualToString:@"project"])
577
618
        {
578
 
          projectFile = [NSMutableDictionary dictionaryWithContentsOfFile: aPath];        
 
619
          projectFile = [NSMutableDictionary dictionaryWithContentsOfFile:aPath];
579
620
        }
580
621
      else
581
 
        {
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)
 
625
            {
 
626
              // For compatibility with 0.3.x projects
 
627
              project = [self convertLegacyProject:projectFile atPath:aPath];
 
628
            }
583
629
        }
584
 
      
585
 
      if(projectFile == nil)
586
 
        {
 
630
 
 
631
      if (projectFile == nil)
587
632
          return nil;
588
 
        }
589
 
      
590
 
      // For compatibility with 0.3.x projects
591
 
      project = [self convertLegacyProject: projectFile atPath: aPath];
 
633
 
592
634
      if (project)
593
635
        {// Project was converted and created PC*Project with alloc&init
594
636
          aPath = [[aPath stringByDeletingLastPathComponent]
609
651
        }
610
652
      
611
653
      project = [bundleManager objectForClassName:projectClassName
612
 
                               bundleType:@"project"
613
 
                               protocol:@protocol(ProjectType)];
 
654
                                       bundleType:@"project"
 
655
                                         protocol:@protocol(ProjectType)];
614
656
      
615
657
      if (!project || ![project openWithWrapperAt:aPath]) 
616
658
        {
632
674
          return nil;
633
675
        }
634
676
      
635
 
      [loadedProjects setObject:project forKey: [project projectPath]];
636
 
      [project setProjectManager:self];
637
 
      
638
 
      // Windows and panels
639
 
      wap = [projectFile objectForKey:PCWindows];
640
 
      if ([[wap allKeys] containsObject:@"ProjectBuild"])
641
 
        {
642
 
          [[project projectWindow] showProjectBuild:self];
643
 
        }
644
 
      if ([[wap allKeys] containsObject:@"ProjectLaunch"])
645
 
        {
646
 
          [[project projectWindow] showProjectLaunch:self];
647
 
        }
648
 
      if ([[wap allKeys] containsObject:@"LoadedFiles"])
649
 
        {
650
 
          [[project projectWindow] showProjectLoadedFiles:self];
651
 
        }
652
 
      
 
677
      [loadedProjects setObject:project forKey:[project projectPath]];
653
678
      if (flag)
654
679
        {
 
680
          [project setProjectManager:self];
 
681
          
 
682
          // Windows and panels
 
683
          wap = [projectFile objectForKey:PCWindows];
 
684
          if ([[wap allKeys] containsObject:@"ProjectBuild"])
 
685
            {
 
686
              [[project projectWindow] showProjectBuild:self];
 
687
            }
 
688
          if ([[wap allKeys] containsObject:@"ProjectLaunch"])
 
689
            {
 
690
              [[project projectWindow] showProjectLaunch:self];
 
691
            }
 
692
          if ([[wap allKeys] containsObject:@"LoadedFiles"])
 
693
            {
 
694
              [[project projectWindow] showProjectLoadedFiles:self];
 
695
            }
 
696
          
655
697
          [[project projectWindow] makeKeyAndOrderFront:self];
656
698
          [self setActiveProject: project];
657
699
        }
662
704
 
663
705
- (void)openProject
664
706
{
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];
 
711
  BOOL          isDir;
 
712
  NSArray       *tempList = nil;
669
713
 
 
714
  fileTypes = [NSArray arrayWithObjects:@"pcproj",@"project",nil];
670
715
  files = [fileManager filesOfTypes:fileTypes
671
716
                          operation:PCOpenProjectOperation
672
717
                           multiple:NO
674
719
                            accView:nil];
675
720
 
676
721
  filePath = [files objectAtIndex:0];
677
 
  en = [files objectEnumerator];
678
 
  while((temp = [en nextObject]) != nil)
 
722
 
 
723
  [fm fileExistsAtPath:filePath isDirectory:&isDir];
 
724
  if (isDir)
679
725
    {
680
 
      if([[temp pathExtension] isEqual: @"pcproj"])
 
726
      if (![[filePath pathExtension] isEqualToString:@"pcproj"])
681
727
        {
682
 
          filePath = temp;
 
728
          tempList = [fileManager filesWithExtension:@"pcproj" 
 
729
                                              atPath:filePath
 
730
                                         includeDirs:YES];
 
731
          if ([tempList count] > 0)
 
732
            {
 
733
              filePath = [tempList objectAtIndex:0];
 
734
            }
683
735
        }
 
736
      filePath = [filePath stringByAppendingPathComponent:@"PC.project"];
684
737
    }
685
738
 
 
739
  NSLog(@"PCPM: openProject: %@", filePath);
 
740
 
686
741
  if (filePath != nil)
687
742
    {
688
 
      [self openProjectAt:filePath makeActive: YES];
 
743
      [self openProjectAt:filePath makeActive:YES];
689
744
    }
690
745
}
691
746
 
695
750
  NSString               *className = [projectTypes objectForKey:projectType];
696
751
  PCProject<ProjectType> *projectCreator;
697
752
  PCProject              *project = nil;
698
 
 
 
753
 
699
754
  if ((project = [loadedProjects objectForKey: [aPath stringByDeletingLastPathComponent]]) != nil)
700
755
    {
701
756
      [[project projectWindow] makeKeyAndOrderFront:self];
745
800
{
746
801
  NSArray   *files;
747
802
  NSString  *filePath;
748
 
  NSArray   *fileTypes = [NSArray arrayWithObjects:@"project",@"pcproj",nil];
749
803
  NSString  *projectType;
750
804
  PCProject *project;
751
805
 
752
806
  [self createProjectTypeAccessaryView];
753
807
  
754
 
  files = [fileManager filesOfTypes:fileTypes
 
808
  files = [fileManager filesOfTypes:nil
755
809
                          operation:PCSaveFileOperation
756
810
                           multiple:NO
757
811
                              title:@"New Project"
1023
1077
- (BOOL)closeAllProjects
1024
1078
{
1025
1079
  PCProject      *project = nil;
1026
 
  NSEnumerator   *enumerator = [loadedProjects objectEnumerator];
 
1080
  NSEnumerator   *enumerator = [[loadedProjects allValues] objectEnumerator];
1027
1081
 
1028
1082
//  PCLogInfo(self, @"loaded %i projects", [loadedProjects count]);
1029
1083
 
1030
 
  while ([loadedProjects count] > 0)
 
1084
  while ((project = [enumerator nextObject]) != nil)
1031
1085
    {
1032
 
      project = [enumerator nextObject];
1033
1086
      if ([prefController boolForKey:SaveOnQuit])
1034
1087
        {
1035
1088
          [project save];