2006-12-26 10:58:39 +00:00
|
|
|
/*
|
|
|
|
GNUstep ProjectCenter - http://www.gnustep.org/experience/ProjectCenter.html
|
|
|
|
|
2021-02-04 16:57:40 +00:00
|
|
|
Copyright (C) 2000-2021 Free Software Foundation
|
2006-12-26 10:58:39 +00:00
|
|
|
|
|
|
|
Authors: Philippe C.D. Robert
|
|
|
|
Serg Stoyan
|
2010-12-01 15:26:12 +00:00
|
|
|
Riccardo Mottola
|
2006-12-26 10:58:39 +00:00
|
|
|
|
|
|
|
This file is part of GNUstep.
|
|
|
|
|
|
|
|
This application is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This application is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public
|
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
|
|
|
*/
|
|
|
|
|
2008-12-30 13:47:27 +00:00
|
|
|
#import <ProjectCenter/PCDefines.h>
|
|
|
|
#import <ProjectCenter/PCLogController.h>
|
|
|
|
|
|
|
|
#import <ProjectCenter/PCBundleManager.h>
|
|
|
|
#import <ProjectCenter/PCFileManager.h>
|
|
|
|
#import <ProjectCenter/PCFileCreator.h>
|
|
|
|
#import <ProjectCenter/PCEditorManager.h>
|
|
|
|
#import <ProjectCenter/PCProjectManager.h>
|
|
|
|
|
|
|
|
#import <ProjectCenter/PCProject.h>
|
|
|
|
#import <ProjectCenter/PCProjectWindow.h>
|
|
|
|
#import <ProjectCenter/PCProjectBrowser.h>
|
|
|
|
#import <ProjectCenter/PCProjectInspector.h>
|
|
|
|
#import <ProjectCenter/PCProjectEditor.h>
|
|
|
|
#import <ProjectCenter/PCProjectBuilderPanel.h>
|
|
|
|
#import <ProjectCenter/PCProjectLauncherPanel.h>
|
|
|
|
#import <ProjectCenter/PCProjectLoadedFilesPanel.h>
|
|
|
|
|
|
|
|
#import "Protocols/ProjectType.h"
|
|
|
|
#import "Protocols/CodeEditor.h"
|
2006-12-26 10:58:39 +00:00
|
|
|
|
2009-02-27 00:46:25 +00:00
|
|
|
#import "Modules/Preferences/Saving/PCSavingPrefs.h"
|
2009-03-09 20:15:10 +00:00
|
|
|
#import "Modules/Preferences/Misc/PCMiscPrefs.h"
|
2009-02-27 00:46:25 +00:00
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange";
|
|
|
|
|
|
|
|
@implementation PCProjectManager
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// ==== Intialization & deallocation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
buildPanel = nil;
|
|
|
|
launchPanel = nil;
|
|
|
|
loadedFilesPanel = nil;
|
|
|
|
findPanel = nil;
|
|
|
|
|
|
|
|
// Prepare bundles
|
|
|
|
bundleManager = [[PCBundleManager alloc] init];
|
|
|
|
projectTypes = [self loadProjectTypesInfo];
|
|
|
|
|
|
|
|
loadedProjects = [[NSMutableDictionary alloc] init];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver:self
|
|
|
|
selector:@selector(resetSaveTimer:)
|
|
|
|
name:PCSavePeriodDidChangeNotification
|
|
|
|
object:nil];
|
|
|
|
|
|
|
|
fileManager = [[PCFileManager alloc] initWithProjectManager:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2009-02-16 00:10:59 +00:00
|
|
|
- (BOOL)close
|
|
|
|
{
|
|
|
|
if ([self closeAllProjects] == NO)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((editorManager != nil) && ([editorManager closeAllEditors] == NO))
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
2009-03-04 22:05:51 +00:00
|
|
|
#ifdef DEBUG
|
2006-12-26 10:58:39 +00:00
|
|
|
NSLog (@"PCProjectManager: dealloc");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
|
|
|
|
if ([saveTimer isValid])
|
|
|
|
{
|
|
|
|
[saveTimer invalidate];
|
|
|
|
}
|
|
|
|
|
|
|
|
RELEASE(loadedProjects);
|
|
|
|
RELEASE(fileManager);
|
|
|
|
|
|
|
|
RELEASE(bundleManager);
|
|
|
|
RELEASE(projectTypes);
|
|
|
|
RELEASE(projectTypeAccessaryView);
|
|
|
|
RELEASE(fileTypeAccessaryView);
|
|
|
|
|
2009-03-19 00:13:25 +00:00
|
|
|
TEST_RELEASE(editorManager);
|
2008-01-21 22:26:36 +00:00
|
|
|
|
2009-03-19 00:13:25 +00:00
|
|
|
TEST_RELEASE(projectInspector);
|
|
|
|
TEST_RELEASE(loadedFilesPanel);
|
|
|
|
TEST_RELEASE(buildPanel);
|
|
|
|
TEST_RELEASE(launchPanel);
|
2006-12-26 10:58:39 +00:00
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDelegate:(id)aDelegate
|
|
|
|
{
|
|
|
|
delegate = aDelegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)delegate
|
|
|
|
{
|
|
|
|
return delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setPrefController:(id)aController
|
|
|
|
{
|
|
|
|
prefController = aController;
|
|
|
|
}
|
|
|
|
|
2009-01-26 22:56:03 +00:00
|
|
|
- (id <PCPreferences>)prefController
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
|
|
|
return prefController;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)createProjectTypeAccessaryView
|
|
|
|
{
|
|
|
|
NSRect fr = NSMakeRect(20,30,160,20);
|
|
|
|
|
|
|
|
if (projectTypeAccessaryView != nil)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For "Open Project" and "New Project" panels
|
|
|
|
projectTypePopup = [[NSPopUpButton alloc] initWithFrame:fr pullsDown:NO];
|
|
|
|
[projectTypePopup setRefusesFirstResponder:YES];
|
|
|
|
[projectTypePopup setAutoenablesItems:NO];
|
|
|
|
[projectTypePopup addItemsWithTitles:
|
|
|
|
[[projectTypes allKeys]
|
|
|
|
sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]];
|
|
|
|
[projectTypePopup sizeToFit];
|
|
|
|
[projectTypeAccessaryView sizeToFit];
|
|
|
|
[projectTypePopup selectItemAtIndex:0];
|
|
|
|
|
|
|
|
projectTypeAccessaryView = [[NSBox alloc] init];
|
|
|
|
[projectTypeAccessaryView setTitle:@"Project Types"];
|
|
|
|
[projectTypeAccessaryView setTitlePosition:NSAtTop];
|
|
|
|
[projectTypeAccessaryView setBorderType:NSGrooveBorder];
|
|
|
|
[projectTypeAccessaryView addSubview:projectTypePopup];
|
|
|
|
[projectTypeAccessaryView sizeToFit];
|
|
|
|
[projectTypeAccessaryView setAutoresizingMask:NSViewMinXMargin
|
|
|
|
| NSViewMaxXMargin];
|
|
|
|
RELEASE(projectTypePopup);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSMutableDictionary *)loadProjectTypesInfo
|
|
|
|
{
|
|
|
|
NSDictionary *bundlesInfo;
|
|
|
|
NSEnumerator *enumerator;
|
|
|
|
NSArray *bundlePaths;
|
|
|
|
NSString *key;
|
|
|
|
NSDictionary *infoTable;
|
|
|
|
|
|
|
|
if (projectTypes == nil)
|
|
|
|
{
|
|
|
|
projectTypes = [[NSMutableDictionary alloc] init];
|
2007-09-27 00:03:51 +00:00
|
|
|
bundlesInfo = [bundleManager infoForBundlesType:@"project"];
|
2006-12-26 10:58:39 +00:00
|
|
|
|
|
|
|
bundlePaths = [bundlesInfo allKeys];
|
|
|
|
enumerator = [bundlePaths objectEnumerator];
|
|
|
|
|
|
|
|
while ((key = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
infoTable = [bundlesInfo objectForKey:key];
|
|
|
|
[projectTypes setObject:[infoTable objectForKey:@"PrincipalClassName"]
|
|
|
|
forKey:[infoTable objectForKey:@"Name"]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return projectTypes;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// ==== Timer handling
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
- (BOOL)startSaveTimer
|
|
|
|
{
|
|
|
|
NSTimeInterval interval;
|
|
|
|
|
* Headers/Protocols/Preferences.h: Add new methods.
* PCPrefController.m: Implemented set/get of preferences value dependent. All
values are stored in preferences as NSString values and converted upon
request to specified type.
* Modules/Preferences/EditorFSC/PCEditorFSCPrefs.m: Use new methods of
PCPrefController. Implemented setting of editor fonts.
(setDefaults): Removed.
* Modules/Preferences/Build/PCBuildPrefs.m,
* Modules/Preferences/Misc/PCMiscPrefs.m,
* Modules/Preferences/Saving/PCSavingPrefs.m: Use new methods of PCPrefController.
(setDefaults): Removed.
* Framework/PCProjectLoadedFiles.m,
* Framework/PCMakefileFactory.m,
* Framework/PCProject.m,
* Framework/PCProjectLauncherPanel.m,
* Framework/PCFileManager.m,
* Framework/PCProjectBrowser.m,
* Framework/PCProjectBuilder.m,
* Framework/PCEditorManager.m,
* Framework/PCProjectLoadedFilesPanel.m,
* Framework/PCProjectLauncher.m,
* Framework/PCProjectBuilderPanel.m,
* Framework/PCProjectWindow.m,
* PCAppController.m,
* Framework/PCProjectManager.m: Use new methods of PCPrefController.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@28074 72102866-910b-0410-8b05-ffd578937521
2009-03-15 00:12:00 +00:00
|
|
|
interval = [[prefController stringForKey:AutoSavePeriod] intValue];
|
2006-12-26 10:58:39 +00:00
|
|
|
|
|
|
|
if (interval > 0 && saveTimer == nil)
|
|
|
|
{
|
|
|
|
saveTimer = [NSTimer
|
|
|
|
scheduledTimerWithTimeInterval:interval
|
|
|
|
target:self
|
|
|
|
selector:@selector(saveAllProjects)
|
|
|
|
userInfo:nil
|
|
|
|
repeats:YES];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)resetSaveTimer:(NSNotification *)notif
|
|
|
|
{
|
|
|
|
[self stopSaveTimer];
|
|
|
|
|
|
|
|
return [self startSaveTimer];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)stopSaveTimer
|
|
|
|
{
|
|
|
|
if (saveTimer && [saveTimer isValid])
|
|
|
|
{
|
|
|
|
[saveTimer invalidate];
|
|
|
|
saveTimer = nil;
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// ==== Accessory methods
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
- (PCBundleManager *)bundleManager
|
|
|
|
{
|
|
|
|
return bundleManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (PCFileManager *)fileManager
|
|
|
|
{
|
|
|
|
return fileManager;
|
|
|
|
}
|
|
|
|
|
2008-02-04 23:51:28 +00:00
|
|
|
- (PCEditorManager *)editorManager
|
|
|
|
{
|
|
|
|
if (!editorManager)
|
|
|
|
{
|
|
|
|
// For non project editors
|
|
|
|
editorManager = [[PCEditorManager alloc] init];
|
|
|
|
[editorManager setProjectManager:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
return editorManager;
|
|
|
|
}
|
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
- (PCProjectInspector *)projectInspector
|
|
|
|
{
|
|
|
|
if (!projectInspector)
|
|
|
|
{
|
|
|
|
projectInspector =
|
|
|
|
[[PCProjectInspector alloc] initWithProjectManager:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
return projectInspector;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPanel *)inspectorPanel
|
|
|
|
{
|
|
|
|
return [[self projectInspector] panel];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showProjectInspector:(id)sender
|
|
|
|
{
|
|
|
|
[[[self projectInspector] panel] makeKeyAndOrderFront:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPanel *)loadedFilesPanel
|
|
|
|
{
|
* Headers/Protocols/Preferences.h: Add new methods.
* PCPrefController.m: Implemented set/get of preferences value dependent. All
values are stored in preferences as NSString values and converted upon
request to specified type.
* Modules/Preferences/EditorFSC/PCEditorFSCPrefs.m: Use new methods of
PCPrefController. Implemented setting of editor fonts.
(setDefaults): Removed.
* Modules/Preferences/Build/PCBuildPrefs.m,
* Modules/Preferences/Misc/PCMiscPrefs.m,
* Modules/Preferences/Saving/PCSavingPrefs.m: Use new methods of PCPrefController.
(setDefaults): Removed.
* Framework/PCProjectLoadedFiles.m,
* Framework/PCMakefileFactory.m,
* Framework/PCProject.m,
* Framework/PCProjectLauncherPanel.m,
* Framework/PCFileManager.m,
* Framework/PCProjectBrowser.m,
* Framework/PCProjectBuilder.m,
* Framework/PCEditorManager.m,
* Framework/PCProjectLoadedFilesPanel.m,
* Framework/PCProjectLauncher.m,
* Framework/PCProjectBuilderPanel.m,
* Framework/PCProjectWindow.m,
* PCAppController.m,
* Framework/PCProjectManager.m: Use new methods of PCPrefController.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@28074 72102866-910b-0410-8b05-ffd578937521
2009-03-15 00:12:00 +00:00
|
|
|
if (!loadedFilesPanel && [prefController boolForKey:UseTearOffWindows])
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
|
|
|
loadedFilesPanel =
|
|
|
|
[[PCProjectLoadedFilesPanel alloc] initWithProjectManager:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
return loadedFilesPanel;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showProjectLoadedFiles:(id)sender
|
|
|
|
{
|
* Headers/Protocols/Preferences.h: Add new methods.
* PCPrefController.m: Implemented set/get of preferences value dependent. All
values are stored in preferences as NSString values and converted upon
request to specified type.
* Modules/Preferences/EditorFSC/PCEditorFSCPrefs.m: Use new methods of
PCPrefController. Implemented setting of editor fonts.
(setDefaults): Removed.
* Modules/Preferences/Build/PCBuildPrefs.m,
* Modules/Preferences/Misc/PCMiscPrefs.m,
* Modules/Preferences/Saving/PCSavingPrefs.m: Use new methods of PCPrefController.
(setDefaults): Removed.
* Framework/PCProjectLoadedFiles.m,
* Framework/PCMakefileFactory.m,
* Framework/PCProject.m,
* Framework/PCProjectLauncherPanel.m,
* Framework/PCFileManager.m,
* Framework/PCProjectBrowser.m,
* Framework/PCProjectBuilder.m,
* Framework/PCEditorManager.m,
* Framework/PCProjectLoadedFilesPanel.m,
* Framework/PCProjectLauncher.m,
* Framework/PCProjectBuilderPanel.m,
* Framework/PCProjectWindow.m,
* PCAppController.m,
* Framework/PCProjectManager.m: Use new methods of PCPrefController.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@28074 72102866-910b-0410-8b05-ffd578937521
2009-03-15 00:12:00 +00:00
|
|
|
if ([prefController boolForKey:UseTearOffWindows])
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
2009-02-28 22:10:30 +00:00
|
|
|
[[self loadedFilesPanel] orderFront:nil];
|
2006-12-26 10:58:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPanel *)buildPanel
|
|
|
|
{
|
* Headers/Protocols/Preferences.h: Add new methods.
* PCPrefController.m: Implemented set/get of preferences value dependent. All
values are stored in preferences as NSString values and converted upon
request to specified type.
* Modules/Preferences/EditorFSC/PCEditorFSCPrefs.m: Use new methods of
PCPrefController. Implemented setting of editor fonts.
(setDefaults): Removed.
* Modules/Preferences/Build/PCBuildPrefs.m,
* Modules/Preferences/Misc/PCMiscPrefs.m,
* Modules/Preferences/Saving/PCSavingPrefs.m: Use new methods of PCPrefController.
(setDefaults): Removed.
* Framework/PCProjectLoadedFiles.m,
* Framework/PCMakefileFactory.m,
* Framework/PCProject.m,
* Framework/PCProjectLauncherPanel.m,
* Framework/PCFileManager.m,
* Framework/PCProjectBrowser.m,
* Framework/PCProjectBuilder.m,
* Framework/PCEditorManager.m,
* Framework/PCProjectLoadedFilesPanel.m,
* Framework/PCProjectLauncher.m,
* Framework/PCProjectBuilderPanel.m,
* Framework/PCProjectWindow.m,
* PCAppController.m,
* Framework/PCProjectManager.m: Use new methods of PCPrefController.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@28074 72102866-910b-0410-8b05-ffd578937521
2009-03-15 00:12:00 +00:00
|
|
|
if (!buildPanel && [prefController boolForKey:UseTearOffWindows])
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
|
|
|
buildPanel = [[PCProjectBuilderPanel alloc] initWithProjectManager:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
return buildPanel;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPanel *)launchPanel
|
|
|
|
{
|
* Headers/Protocols/Preferences.h: Add new methods.
* PCPrefController.m: Implemented set/get of preferences value dependent. All
values are stored in preferences as NSString values and converted upon
request to specified type.
* Modules/Preferences/EditorFSC/PCEditorFSCPrefs.m: Use new methods of
PCPrefController. Implemented setting of editor fonts.
(setDefaults): Removed.
* Modules/Preferences/Build/PCBuildPrefs.m,
* Modules/Preferences/Misc/PCMiscPrefs.m,
* Modules/Preferences/Saving/PCSavingPrefs.m: Use new methods of PCPrefController.
(setDefaults): Removed.
* Framework/PCProjectLoadedFiles.m,
* Framework/PCMakefileFactory.m,
* Framework/PCProject.m,
* Framework/PCProjectLauncherPanel.m,
* Framework/PCFileManager.m,
* Framework/PCProjectBrowser.m,
* Framework/PCProjectBuilder.m,
* Framework/PCEditorManager.m,
* Framework/PCProjectLoadedFilesPanel.m,
* Framework/PCProjectLauncher.m,
* Framework/PCProjectBuilderPanel.m,
* Framework/PCProjectWindow.m,
* PCAppController.m,
* Framework/PCProjectManager.m: Use new methods of PCPrefController.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@28074 72102866-910b-0410-8b05-ffd578937521
2009-03-15 00:12:00 +00:00
|
|
|
if (!launchPanel && [prefController boolForKey:UseTearOffWindows])
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
|
|
|
launchPanel = [[PCProjectLauncherPanel alloc] initWithProjectManager:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
return launchPanel;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPanel *)projectFinderPanel
|
|
|
|
{
|
|
|
|
return findPanel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// ==== Project management
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
- (NSMutableDictionary *)loadedProjects
|
|
|
|
{
|
|
|
|
return loadedProjects;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (PCProject *)activeProject
|
|
|
|
{
|
|
|
|
return activeProject;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (PCProject *)rootActiveProject
|
|
|
|
{
|
|
|
|
PCProject *rootProject = nil;
|
|
|
|
|
|
|
|
if (!activeProject)
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
rootProject = activeProject;
|
|
|
|
while ([rootProject isSubproject] == YES)
|
|
|
|
{
|
|
|
|
rootProject = [rootProject superProject];
|
|
|
|
}
|
|
|
|
|
|
|
|
return rootProject;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setActiveProject:(PCProject *)aProject
|
|
|
|
{
|
|
|
|
if (aProject != activeProject)
|
|
|
|
{
|
|
|
|
activeProject = aProject;
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
postNotificationName:PCActiveProjectDidChangeNotification
|
2021-02-06 18:55:14 +00:00
|
|
|
object:activeProject];
|
2006-12-26 10:58:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)saveAllProjectsIfNeeded
|
|
|
|
{
|
|
|
|
// PCLogInfo(self, @"saveAllProjectsIfNeeded");
|
|
|
|
|
|
|
|
// If this method was called not by NSTimer, check if we should save projects
|
* Headers/Protocols/Preferences.h: Add new methods.
* PCPrefController.m: Implemented set/get of preferences value dependent. All
values are stored in preferences as NSString values and converted upon
request to specified type.
* Modules/Preferences/EditorFSC/PCEditorFSCPrefs.m: Use new methods of
PCPrefController. Implemented setting of editor fonts.
(setDefaults): Removed.
* Modules/Preferences/Build/PCBuildPrefs.m,
* Modules/Preferences/Misc/PCMiscPrefs.m,
* Modules/Preferences/Saving/PCSavingPrefs.m: Use new methods of PCPrefController.
(setDefaults): Removed.
* Framework/PCProjectLoadedFiles.m,
* Framework/PCMakefileFactory.m,
* Framework/PCProject.m,
* Framework/PCProjectLauncherPanel.m,
* Framework/PCFileManager.m,
* Framework/PCProjectBrowser.m,
* Framework/PCProjectBuilder.m,
* Framework/PCEditorManager.m,
* Framework/PCProjectLoadedFilesPanel.m,
* Framework/PCProjectLauncher.m,
* Framework/PCProjectBuilderPanel.m,
* Framework/PCProjectWindow.m,
* PCAppController.m,
* Framework/PCProjectManager.m: Use new methods of PCPrefController.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@28074 72102866-910b-0410-8b05-ffd578937521
2009-03-15 00:12:00 +00:00
|
|
|
if ([prefController boolForKey:SaveOnQuit])
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
|
|
|
[self saveAllProjects];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)saveAllProjects
|
|
|
|
{
|
|
|
|
NSEnumerator *enumerator = [loadedProjects keyEnumerator];
|
|
|
|
NSString *key;
|
|
|
|
PCProject *project;
|
|
|
|
|
|
|
|
while ((key = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
project = [loadedProjects objectForKey:key];
|
|
|
|
|
|
|
|
if ([project save] == NO)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// ==== Project actions
|
|
|
|
// ============================================================================
|
|
|
|
|
2009-06-23 22:21:10 +00:00
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
- (PCProject *)convertLegacyProject:(NSMutableDictionary *)pDict
|
|
|
|
atPath:(NSString *)aPath
|
|
|
|
{
|
|
|
|
NSString *pPath = nil;
|
|
|
|
NSString *projectClassName = nil;
|
|
|
|
NSString *projectTypeName = nil;
|
|
|
|
NSString *_projectPath = nil;
|
|
|
|
NSFileManager *fm = [NSFileManager defaultManager];
|
|
|
|
NSString *_resPath = nil;
|
|
|
|
NSArray *_fromDirArray = nil;
|
|
|
|
NSString *_fromDirPath = nil;
|
|
|
|
NSString *_file = nil;
|
|
|
|
NSString *_2file = nil;
|
|
|
|
NSString *_resFile = nil;
|
|
|
|
unsigned i = 0;
|
2009-06-23 22:21:10 +00:00
|
|
|
PCProject *project = nil;
|
2006-12-26 10:58:39 +00:00
|
|
|
NSMutableArray *otherResArray = nil;
|
|
|
|
NSString *plistFile = nil;
|
|
|
|
|
|
|
|
projectClassName = [pDict objectForKey:PCProjectBuilderClass];
|
|
|
|
if (projectClassName == nil)
|
|
|
|
{
|
|
|
|
// Project created by 0.4 release or later
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2010-07-13 09:31:38 +00:00
|
|
|
PCLogInfo(self, @"Converting legacy project");
|
2006-12-26 10:58:39 +00:00
|
|
|
|
|
|
|
// Gorm project type doesn't exists anymore
|
2009-03-04 23:00:19 +00:00
|
|
|
if ([projectClassName isEqualToString:@"PCGormProj"] ||
|
|
|
|
[projectClassName isEqualToString:@"PCAppProj"])
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
2013-02-09 14:29:44 +00:00
|
|
|
projectTypeName = @"Application";
|
2006-12-26 10:58:39 +00:00
|
|
|
projectClassName = [projectTypes objectForKey:projectTypeName];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handling directory layout
|
|
|
|
_projectPath = [aPath stringByDeletingLastPathComponent];
|
|
|
|
_resPath = [_projectPath stringByAppendingPathComponent:@"Resources"];
|
|
|
|
[fm createDirectoryAtPath:_resPath attributes:nil];
|
|
|
|
|
|
|
|
// Documents
|
|
|
|
_fromDirPath = [_projectPath stringByAppendingPathComponent:@"Documentation"];
|
|
|
|
_fromDirArray = [pDict objectForKey:PCDocuFiles];
|
|
|
|
for (i = 0; i < [_fromDirArray count]; i++)
|
|
|
|
{
|
|
|
|
_resFile = [_fromDirArray objectAtIndex:i];
|
|
|
|
_file = [_fromDirPath stringByAppendingPathComponent:_resFile];
|
|
|
|
_2file = [_resPath stringByAppendingPathComponent:_resFile];
|
|
|
|
[fm movePath:_file toPath:_2file handler:nil];
|
|
|
|
}
|
|
|
|
[fm removeFileAtPath:_fromDirPath handler:nil];
|
|
|
|
|
|
|
|
// Images
|
|
|
|
_fromDirPath = [_projectPath stringByAppendingPathComponent:@"Images"];
|
|
|
|
_fromDirArray = [pDict objectForKey:PCImages];
|
|
|
|
for (i = 0; i < [_fromDirArray count]; i++)
|
|
|
|
{
|
|
|
|
_resFile = [_fromDirArray objectAtIndex:i];
|
|
|
|
_file = [_fromDirPath stringByAppendingPathComponent:_resFile];
|
|
|
|
_2file = [_resPath stringByAppendingPathComponent:_resFile];
|
|
|
|
[fm movePath:_file toPath:_2file handler:nil];
|
|
|
|
}
|
|
|
|
[fm removeFileAtPath:_fromDirPath handler:nil];
|
|
|
|
|
|
|
|
// Interfaces
|
|
|
|
_fromDirArray = [pDict objectForKey:PCInterfaces];
|
|
|
|
for (i = 0; i < [_fromDirArray count]; i++)
|
|
|
|
{
|
|
|
|
_resFile = [_fromDirArray objectAtIndex:i];
|
|
|
|
_file = [_projectPath stringByAppendingPathComponent:_resFile];
|
|
|
|
_2file = [_resPath stringByAppendingPathComponent:_resFile];
|
|
|
|
[fm movePath:_file toPath:_2file handler:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Other resources
|
|
|
|
otherResArray = [NSMutableArray
|
|
|
|
arrayWithArray:[pDict objectForKey:PCOtherResources]];
|
|
|
|
plistFile = [NSString stringWithFormat:@"%@Info.plist",
|
|
|
|
[pDict objectForKey:PCProjectName]];
|
|
|
|
for (i = 0; i < [otherResArray count]; i++)
|
|
|
|
{
|
|
|
|
_resFile = [otherResArray objectAtIndex:i];
|
|
|
|
_file = [_projectPath stringByAppendingPathComponent:_resFile];
|
|
|
|
if ([_resFile isEqualToString:plistFile])
|
|
|
|
{
|
|
|
|
_2file =
|
|
|
|
[_resPath stringByAppendingPathComponent:@"Info-gnustep.plist"];
|
|
|
|
[otherResArray replaceObjectAtIndex:i
|
|
|
|
withObject:@"Info-gnustep.plist"];
|
|
|
|
[pDict setObject:otherResArray forKey:PCOtherResources];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_2file = [_resPath stringByAppendingPathComponent:_resFile];
|
|
|
|
}
|
|
|
|
[fm movePath:_file toPath:_2file handler:nil];
|
|
|
|
}
|
|
|
|
|
2010-07-13 09:31:38 +00:00
|
|
|
/* remove non meaningful keys */
|
|
|
|
[pDict removeObjectForKey: PCWindows];
|
|
|
|
[pDict removeObjectForKey: PCLastEditing];
|
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
// GNUmakefiles will be generated in [PCProject initWithProjectDictionary:]
|
|
|
|
|
|
|
|
// Remove obsolete records from project dictionary and write to PC.project
|
|
|
|
pPath = [[aPath stringByDeletingLastPathComponent]
|
|
|
|
stringByAppendingPathComponent:@"PC.project"];
|
|
|
|
|
|
|
|
project = [bundleManager objectForClassName:projectClassName
|
2007-09-27 00:03:51 +00:00
|
|
|
bundleType:@"project"
|
|
|
|
protocol:@protocol(ProjectType)];
|
2006-12-26 10:58:39 +00:00
|
|
|
|
|
|
|
projectTypeName = [project projectTypeName];
|
|
|
|
[pDict setObject:projectTypeName forKey:PCProjectType];
|
|
|
|
[pDict removeObjectForKey:PCProjectBuilderClass];
|
|
|
|
[pDict removeObjectForKey:PCPrincipalClass];
|
|
|
|
|
|
|
|
if ([pDict writeToFile:pPath atomically:YES] == YES)
|
|
|
|
{
|
|
|
|
// [[NSFileManager defaultManager] removeFileAtPath:aPath handler:nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
return project;
|
|
|
|
}
|
|
|
|
|
2010-08-07 21:56:04 +00:00
|
|
|
// aPath is path to a project file PC.project or project bundle *.pcproj.
|
|
|
|
// Also it can be project directory where one of the above resides.
|
2009-06-23 22:21:10 +00:00
|
|
|
- (PCProject *)openProjectAt:(NSString *)aPath makeActive: (BOOL)flag
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
2010-08-07 21:56:04 +00:00
|
|
|
NSString *projectPath = nil;
|
|
|
|
NSString *projectFileType = nil;
|
2009-06-23 22:21:10 +00:00
|
|
|
PCProject *project = nil;
|
2012-08-09 16:23:39 +00:00
|
|
|
NSString *projectPathToSave;
|
2010-08-07 21:56:04 +00:00
|
|
|
|
|
|
|
// Check project path for invalid characters
|
|
|
|
if ([aPath rangeOfString: @" "].location != NSNotFound ||
|
|
|
|
[aPath rangeOfString: @"\t"].location != NSNotFound ||
|
|
|
|
[aPath rangeOfString: @"\r"].location != NSNotFound ||
|
|
|
|
[aPath rangeOfString: @"\n"].location != NSNotFound)
|
|
|
|
{
|
|
|
|
if (NSRunAlertPanel
|
|
|
|
(@"Open Project",
|
|
|
|
@"Project path contains whitespaces.\n"
|
|
|
|
@"GNUstep's build environment currently "
|
|
|
|
@"can't handle that reliably.\n"
|
|
|
|
@"Do you want to open a project anyway?\n",
|
|
|
|
@"Open", @"Don't open", nil) != NSAlertDefaultReturn)
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
projectFileType = [[aPath lastPathComponent] pathExtension];
|
|
|
|
if ([projectFileType isEqualToString:@"pcproj"] ||
|
|
|
|
[projectFileType isEqualToString:@"project"])
|
|
|
|
{
|
|
|
|
projectPath = [aPath stringByDeletingLastPathComponent];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
projectPath = aPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((project = [loadedProjects objectForKey:projectPath])== nil)
|
2009-06-23 22:21:10 +00:00
|
|
|
{
|
2010-08-07 21:56:04 +00:00
|
|
|
NSMutableDictionary *projectFile = nil;
|
|
|
|
NSString *projectTypeName = nil;
|
|
|
|
NSString *projectClassName = nil;
|
|
|
|
BOOL isDir = NO;
|
|
|
|
BOOL exists = NO;
|
|
|
|
NSArray *tempList;
|
2012-08-09 16:23:39 +00:00
|
|
|
|
2010-08-07 21:56:04 +00:00
|
|
|
exists = [[NSFileManager defaultManager] fileExistsAtPath:aPath
|
|
|
|
isDirectory:&isDir];
|
2009-06-23 22:21:10 +00:00
|
|
|
if (!exists)
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
2010-08-07 21:56:04 +00:00
|
|
|
|
2012-08-09 16:23:39 +00:00
|
|
|
projectPathToSave = projectPath;
|
2010-08-07 21:56:04 +00:00
|
|
|
if (isDir)
|
2009-09-17 09:05:45 +00:00
|
|
|
{
|
2010-08-07 21:56:04 +00:00
|
|
|
if ([projectFileType isEqualToString:@"pcproj"] == NO)
|
2009-09-17 09:05:45 +00:00
|
|
|
{
|
2010-08-07 21:56:04 +00:00
|
|
|
tempList = [fileManager filesWithExtension:@"pcproj"
|
|
|
|
atPath:aPath
|
|
|
|
includeDirs:YES];
|
|
|
|
if ([tempList count] > 0)
|
|
|
|
{
|
|
|
|
aPath = [tempList objectAtIndex:0];
|
|
|
|
}
|
2009-09-17 09:05:45 +00:00
|
|
|
}
|
2012-08-09 16:23:39 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
projectPathToSave = aPath;
|
|
|
|
}
|
2010-08-07 21:56:04 +00:00
|
|
|
aPath = [aPath stringByAppendingPathComponent:@"PC.project"];
|
|
|
|
projectFile = [NSMutableDictionary dictionaryWithContentsOfFile:aPath];
|
2009-09-17 09:05:45 +00:00
|
|
|
}
|
2010-08-07 21:56:04 +00:00
|
|
|
else if ([projectFileType isEqualToString:@"project"])
|
2009-06-23 22:21:10 +00:00
|
|
|
{
|
2010-08-07 21:56:04 +00:00
|
|
|
projectFile = [NSMutableDictionary dictionaryWithContentsOfFile:aPath];
|
2009-06-23 22:21:10 +00:00
|
|
|
}
|
|
|
|
else
|
2010-08-07 21:56:04 +00:00
|
|
|
{ //TODO: Remove support of 0.3.x projects
|
|
|
|
projectFile = [NSMutableDictionary dictionaryWithContentsOfFile:aPath];
|
|
|
|
if (projectFile != nil)
|
|
|
|
{
|
|
|
|
// For compatibility with 0.3.x projects
|
|
|
|
project = [self convertLegacyProject:projectFile atPath:aPath];
|
|
|
|
}
|
2009-06-23 22:21:10 +00:00
|
|
|
}
|
2010-08-07 21:56:04 +00:00
|
|
|
|
|
|
|
if (projectFile == nil)
|
2009-06-23 22:21:10 +00:00
|
|
|
return nil;
|
2010-07-08 22:45:40 +00:00
|
|
|
|
2009-06-23 22:21:10 +00:00
|
|
|
if (project)
|
|
|
|
{// Project was converted and created PC*Project with alloc&init
|
|
|
|
aPath = [[aPath stringByDeletingLastPathComponent]
|
|
|
|
stringByAppendingPathComponent:@"PC.project"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{// No conversion were taken
|
|
|
|
projectTypeName = [projectFile objectForKey:PCProjectType];
|
|
|
|
projectClassName = [projectTypes objectForKey:projectTypeName];
|
|
|
|
if (projectClassName == nil)
|
|
|
|
{
|
|
|
|
NSRunAlertPanel(@"Open Project",
|
|
|
|
@"Project type '%@' is not supported!\n"
|
|
|
|
@"Report the bug, please!",
|
|
|
|
@"OK", nil, nil, projectTypeName);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
project = [bundleManager objectForClassName:projectClassName
|
2010-08-07 21:56:04 +00:00
|
|
|
bundleType:@"project"
|
|
|
|
protocol:@protocol(ProjectType)];
|
2009-06-23 22:21:10 +00:00
|
|
|
|
|
|
|
if (!project || ![project openWithWrapperAt:aPath])
|
|
|
|
{
|
|
|
|
NSRunAlertPanel(@"Open Project",
|
|
|
|
@"Unable to open project '%@'.\nReport bug, please!",
|
|
|
|
@"OK",nil,nil,aPath);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
PCLogStatus(self, @"Project %@ loaded as %@",
|
|
|
|
[project projectName], [project projectTypeName]);
|
|
|
|
|
|
|
|
// Started only if there's not save timer yet
|
|
|
|
[self startSaveTimer];
|
|
|
|
[project validateProjectDict];
|
|
|
|
|
2010-08-07 21:56:04 +00:00
|
|
|
[loadedProjects setObject:project forKey:[project projectPath]];
|
2021-02-04 16:57:40 +00:00
|
|
|
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: [NSURL fileURLWithPath:projectPathToSave]];
|
|
|
|
PCLogStatus(self, @"Saved opened Document as %@", projectPathToSave);
|
|
|
|
|
2009-06-23 22:21:10 +00:00
|
|
|
if (flag)
|
|
|
|
{
|
2021-02-04 16:57:40 +00:00
|
|
|
NSDictionary *wap = nil;
|
2010-06-15 03:43:32 +00:00
|
|
|
[project setProjectManager:self];
|
|
|
|
|
|
|
|
// Windows and panels
|
|
|
|
wap = [projectFile objectForKey:PCWindows];
|
|
|
|
if ([[wap allKeys] containsObject:@"ProjectBuild"])
|
|
|
|
{
|
|
|
|
[[project projectWindow] showProjectBuild:self];
|
|
|
|
}
|
|
|
|
if ([[wap allKeys] containsObject:@"ProjectLaunch"])
|
|
|
|
{
|
|
|
|
[[project projectWindow] showProjectLaunch:self];
|
|
|
|
}
|
|
|
|
if ([[wap allKeys] containsObject:@"LoadedFiles"])
|
|
|
|
{
|
|
|
|
[[project projectWindow] showProjectLoadedFiles:self];
|
|
|
|
}
|
2009-06-23 22:21:10 +00:00
|
|
|
}
|
2021-02-04 16:57:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PCLogStatus(self, @"Project %@ already Open", [project projectName]);
|
2006-12-26 10:58:39 +00:00
|
|
|
}
|
2012-08-09 16:23:39 +00:00
|
|
|
|
2021-02-04 16:57:40 +00:00
|
|
|
if (flag)
|
|
|
|
{
|
|
|
|
[self setActiveProject: project];
|
2021-02-06 18:55:14 +00:00
|
|
|
[[project projectWindow] makeKeyAndOrderFront:self];
|
2021-02-04 16:57:40 +00:00
|
|
|
}
|
2009-06-23 22:21:10 +00:00
|
|
|
|
|
|
|
return project;
|
2006-12-26 10:58:39 +00:00
|
|
|
}
|
|
|
|
|
2009-02-11 00:21:23 +00:00
|
|
|
- (void)openProject
|
|
|
|
{
|
2010-08-07 21:56:04 +00:00
|
|
|
NSArray *fileTypes = nil;
|
|
|
|
NSArray *files = nil;
|
|
|
|
NSString *filePath = nil;
|
|
|
|
NSFileManager *fm = [NSFileManager defaultManager];
|
|
|
|
BOOL isDir;
|
|
|
|
NSArray *tempList = nil;
|
2009-02-11 00:21:23 +00:00
|
|
|
|
2010-08-07 21:56:04 +00:00
|
|
|
fileTypes = [NSArray arrayWithObjects:@"pcproj",@"project",nil];
|
2009-02-11 00:21:23 +00:00
|
|
|
files = [fileManager filesOfTypes:fileTypes
|
|
|
|
operation:PCOpenProjectOperation
|
|
|
|
multiple:NO
|
|
|
|
title:@"Open Project"
|
|
|
|
accView:nil];
|
2009-06-23 22:21:10 +00:00
|
|
|
|
2009-02-11 00:21:23 +00:00
|
|
|
filePath = [files objectAtIndex:0];
|
2010-08-07 21:56:04 +00:00
|
|
|
|
|
|
|
[fm fileExistsAtPath:filePath isDirectory:&isDir];
|
|
|
|
if (isDir)
|
2009-06-23 22:21:10 +00:00
|
|
|
{
|
2010-08-07 21:56:04 +00:00
|
|
|
if (![[filePath pathExtension] isEqualToString:@"pcproj"])
|
2009-06-23 22:21:10 +00:00
|
|
|
{
|
2010-08-07 21:56:04 +00:00
|
|
|
tempList = [fileManager filesWithExtension:@"pcproj"
|
|
|
|
atPath:filePath
|
|
|
|
includeDirs:YES];
|
|
|
|
if ([tempList count] > 0)
|
|
|
|
{
|
|
|
|
filePath = [tempList objectAtIndex:0];
|
|
|
|
}
|
2009-06-23 22:21:10 +00:00
|
|
|
}
|
2010-08-07 21:56:04 +00:00
|
|
|
filePath = [filePath stringByAppendingPathComponent:@"PC.project"];
|
2009-06-23 22:21:10 +00:00
|
|
|
}
|
2009-02-11 00:21:23 +00:00
|
|
|
|
2010-08-07 21:56:04 +00:00
|
|
|
NSLog(@"PCPM: openProject: %@", filePath);
|
|
|
|
|
2009-02-11 00:21:23 +00:00
|
|
|
if (filePath != nil)
|
|
|
|
{
|
2010-08-07 21:56:04 +00:00
|
|
|
[self openProjectAt:filePath makeActive:YES];
|
2009-02-11 00:21:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
- (PCProject *)createProjectOfType:(NSString *)projectType
|
|
|
|
path:(NSString *)aPath
|
|
|
|
{
|
|
|
|
NSString *className = [projectTypes objectForKey:projectType];
|
|
|
|
PCProject<ProjectType> *projectCreator;
|
|
|
|
PCProject *project = nil;
|
2017-01-13 01:33:37 +00:00
|
|
|
NSString *subType = nil;
|
2010-12-01 15:26:12 +00:00
|
|
|
|
2009-06-23 22:21:10 +00:00
|
|
|
if ((project = [loadedProjects objectForKey: [aPath stringByDeletingLastPathComponent]]) != nil)
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
|
|
|
[[project projectWindow] makeKeyAndOrderFront:self];
|
|
|
|
return project;
|
|
|
|
}
|
|
|
|
|
2017-01-13 01:33:37 +00:00
|
|
|
if ([projectType isEqualToString:@"Application"])
|
|
|
|
subType = PCProjectInterfaceGorm;
|
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
projectCreator = [bundleManager objectForClassName:className
|
2007-09-27 00:03:51 +00:00
|
|
|
bundleType:@"project"
|
|
|
|
protocol:@protocol(ProjectType)];
|
2006-12-26 10:58:39 +00:00
|
|
|
// NSLog(@"%@ CLASS: %@", className, projectCreator);
|
|
|
|
if (!projectCreator)
|
|
|
|
{
|
2009-02-11 00:21:23 +00:00
|
|
|
NSRunAlertPanel(@"New Project",
|
|
|
|
@"Could not create project directory %@.\n"
|
2009-03-02 01:01:44 +00:00
|
|
|
@"No project creator. Report the bug, please!",
|
2009-02-11 00:21:23 +00:00
|
|
|
@"OK", nil, nil, aPath);
|
2006-12-26 10:58:39 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create project directory
|
|
|
|
if (![[PCFileManager defaultManager] createDirectoriesIfNeededAtPath:aPath])
|
|
|
|
{
|
2009-02-11 00:21:23 +00:00
|
|
|
NSRunAlertPanel(@"New Project",
|
|
|
|
@"Could not create project directory %@.\n"
|
2009-03-02 01:01:44 +00:00
|
|
|
@"Check permissions of the directory where you"
|
|
|
|
@" want to create a project",
|
2009-02-11 00:21:23 +00:00
|
|
|
@"OK", nil, nil, aPath);
|
2006-12-26 10:58:39 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create project
|
2017-01-13 01:33:37 +00:00
|
|
|
if (!(project = [projectCreator createProjectAt:aPath withOption:subType]))
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
2009-02-11 00:21:23 +00:00
|
|
|
NSRunAlertPanel(@"New Project",
|
|
|
|
@"Project %@ could not be created.\nReport bug, please!",
|
|
|
|
@"OK",nil,nil,[project projectName]);
|
2006-12-26 10:58:39 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
[project setProjectManager:self];
|
|
|
|
[self startSaveTimer];
|
|
|
|
|
|
|
|
return project;
|
|
|
|
}
|
|
|
|
|
2014-03-03 04:24:05 +00:00
|
|
|
- (void)newProject: (id)sender
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
2014-03-03 04:24:05 +00:00
|
|
|
NSArray *files, *types = nil;
|
2007-08-29 20:39:25 +00:00
|
|
|
NSString *filePath;
|
|
|
|
NSString *projectType;
|
|
|
|
PCProject *project;
|
2021-02-08 14:44:33 +00:00
|
|
|
NSString *projectPath;
|
2014-03-03 04:24:05 +00:00
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
[self createProjectTypeAccessaryView];
|
|
|
|
|
2014-03-03 04:24:05 +00:00
|
|
|
files = [fileManager filesOfTypes:types
|
2007-08-29 20:39:25 +00:00
|
|
|
operation:PCSaveFileOperation
|
|
|
|
multiple:NO
|
|
|
|
title:@"New Project"
|
|
|
|
accView:projectTypeAccessaryView];
|
2010-12-04 08:08:50 +00:00
|
|
|
filePath = [files objectAtIndex:0];
|
2014-03-08 00:31:35 +00:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
filePath = [filePath stringByDeletingPathExtension];
|
|
|
|
#endif
|
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
if (filePath != nil)
|
|
|
|
{
|
2009-09-17 09:08:02 +00:00
|
|
|
if ([filePath rangeOfString: @" "].location != NSNotFound ||
|
|
|
|
[filePath rangeOfString: @"\t"].location != NSNotFound ||
|
|
|
|
[filePath rangeOfString: @"\r"].location != NSNotFound ||
|
|
|
|
[filePath rangeOfString: @"\n"].location != NSNotFound)
|
2009-09-17 09:05:45 +00:00
|
|
|
{
|
|
|
|
if (NSRunAlertPanel
|
|
|
|
(@"New Project",
|
|
|
|
@"Are you sure you want to create a project with whitespace in it's path?\n"
|
|
|
|
@"GNUstep's build environment currently can't handle that reliably.",
|
|
|
|
@"OK", @"Cancel", nil) != NSAlertDefaultReturn)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
projectType = [projectTypePopup titleOfSelectedItem];
|
|
|
|
|
|
|
|
if (!(project = [self createProjectOfType:projectType path:filePath]))
|
|
|
|
{
|
2009-02-11 00:21:23 +00:00
|
|
|
// No need to open alert panel. Alert panel was already opened
|
|
|
|
// in createProjectOfType:path: method.
|
|
|
|
return;
|
2006-12-26 10:58:39 +00:00
|
|
|
}
|
|
|
|
|
2021-02-08 14:44:33 +00:00
|
|
|
projectPath = [project projectPath];
|
|
|
|
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL fileURLWithPath:projectPath]];
|
|
|
|
[loadedProjects setObject:project forKey:projectPath];
|
2006-12-26 10:58:39 +00:00
|
|
|
[self setActiveProject:project];
|
|
|
|
[[project projectWindow] orderFront:self];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)saveProject
|
|
|
|
{
|
|
|
|
PCProject *rootProject = [self rootActiveProject];
|
|
|
|
|
|
|
|
if (!rootProject)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
// PCLogInfo(self, @"save root project: %@", [rootProject projectName]);
|
|
|
|
|
|
|
|
// Save PC.project and the makefiles!
|
|
|
|
if ([rootProject save] == NO)
|
|
|
|
{
|
2009-02-10 00:31:55 +00:00
|
|
|
NSRunAlertPanel(@"Save Project",
|
2006-12-26 10:58:39 +00:00
|
|
|
@"Couldn't save project %@!",
|
2009-02-15 00:24:12 +00:00
|
|
|
@"OK", nil, nil, [rootProject projectName]);
|
2006-12-26 10:58:39 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)addProjectFiles
|
|
|
|
{
|
|
|
|
PCProject *project = [self rootActiveProject];
|
|
|
|
NSString *category = [[project projectBrowser] nameOfSelectedCategory];
|
|
|
|
NSString *categoryKey = [activeProject keyForCategory:category];
|
|
|
|
NSMutableArray *files = nil;
|
|
|
|
NSString *file = nil;
|
|
|
|
NSString *projectFile = nil;
|
|
|
|
NSArray *fileTypes = [project fileTypesForCategoryKey:categoryKey];
|
|
|
|
|
2007-08-29 20:39:25 +00:00
|
|
|
files = [fileManager filesOfTypes:fileTypes
|
|
|
|
operation:PCAddFileOperation
|
|
|
|
multiple:NO
|
|
|
|
title:nil
|
|
|
|
accView:nil];
|
2006-12-26 10:58:39 +00:00
|
|
|
|
|
|
|
/* PCLogInfo(self, @"[addProjectFiles] %@ to category: %@ of project %@",
|
|
|
|
files, categoryKey, [activeProject projectName]);*/
|
|
|
|
|
|
|
|
// Category may be changed
|
|
|
|
category = [[project projectBrowser] nameOfSelectedCategory];
|
|
|
|
categoryKey = [activeProject keyForCategory:category];
|
|
|
|
|
|
|
|
// No files was selected
|
|
|
|
if (!files)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
file = [[files objectAtIndex:0] lastPathComponent];
|
|
|
|
projectFile = [activeProject projectFileFromFile:[files objectAtIndex:0]
|
|
|
|
forKey:categoryKey];
|
|
|
|
|
|
|
|
if (![projectFile isEqualToString:file])
|
|
|
|
{
|
|
|
|
[activeProject addFiles:files forKey:categoryKey notify:YES];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Copy and add files
|
|
|
|
[activeProject addAndCopyFiles:files forKey:categoryKey];
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)saveProjectFiles
|
|
|
|
{
|
|
|
|
return [[activeProject projectEditor] saveAllFiles];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)removeProjectFiles
|
|
|
|
{
|
|
|
|
PCProject *project = [self rootActiveProject];
|
|
|
|
NSArray *files = [[project projectBrowser] selectedFiles];
|
|
|
|
NSString *category = [[project projectBrowser] nameOfSelectedCategory];
|
|
|
|
NSString *categoryKey = [project keyForCategory:category];
|
|
|
|
NSString *directory = [activeProject dirForCategoryKey:categoryKey];
|
|
|
|
NSString *removeString = nil;
|
|
|
|
NSMutableArray *subprojs = [NSMutableArray array];
|
|
|
|
unsigned i;
|
|
|
|
|
2009-02-11 00:21:23 +00:00
|
|
|
NSLog(@"Root active project '%@' category '%@'",
|
|
|
|
[project projectName], category);
|
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
// Determining target project
|
|
|
|
if ([categoryKey isEqualToString:PCSubprojects])
|
|
|
|
{
|
|
|
|
if ([activeProject isSubproject])
|
|
|
|
{
|
|
|
|
project = [activeProject superProject];
|
|
|
|
[self setActiveProject:project];
|
|
|
|
}
|
2013-02-09 14:29:44 +00:00
|
|
|
removeString = @"Remove subprojects...";
|
2006-12-26 10:58:39 +00:00
|
|
|
directory = [project dirForCategoryKey:categoryKey];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-09 14:29:44 +00:00
|
|
|
removeString = @"Remove files...";
|
2006-12-26 10:58:39 +00:00
|
|
|
project = activeProject;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PCLogInfo(self, @"%@: %@ from %@", removeString, files, directory);
|
|
|
|
PCLogInfo(self, @"[removeProjectFiles]:%@ KEY:%@",
|
|
|
|
[activeProject projectName], categoryKey);*/
|
|
|
|
|
|
|
|
if (files)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if ([categoryKey isEqualToString:PCLibraries])
|
|
|
|
{
|
2009-02-10 00:31:55 +00:00
|
|
|
ret = NSRunAlertPanel(@"Remove File",
|
2006-12-26 10:58:39 +00:00
|
|
|
@"Remove libraries from Project?",
|
|
|
|
@"Remove",
|
|
|
|
@"Cancel",
|
|
|
|
nil);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-02-10 00:31:55 +00:00
|
|
|
ret = NSRunAlertPanel(@"Remove File",
|
2006-12-26 10:58:39 +00:00
|
|
|
removeString,
|
|
|
|
@"...from Project and Disk",
|
|
|
|
@"...from Project only",
|
|
|
|
@"Cancel");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == NSAlertDefaultReturn || ret == NSAlertAlternateReturn)
|
|
|
|
{
|
|
|
|
BOOL flag = (ret == NSAlertDefaultReturn) ? YES : NO;
|
|
|
|
|
|
|
|
// Remove from projectDict
|
|
|
|
// If files localizable make them not localizable
|
|
|
|
ret = [project removeFiles:files forKey:categoryKey notify:YES];
|
|
|
|
|
|
|
|
// Remove files from disk
|
|
|
|
if (flag && ret && ![categoryKey isEqualToString:PCLibraries])
|
|
|
|
{
|
|
|
|
if ([categoryKey isEqualToString:PCSubprojects])
|
|
|
|
{
|
|
|
|
for (i = 0; i < [files count]; i++)
|
|
|
|
{
|
|
|
|
[subprojs addObject:
|
|
|
|
[[files objectAtIndex:i]
|
|
|
|
stringByAppendingPathExtension:@"subproj"]];
|
|
|
|
}
|
|
|
|
files = subprojs;
|
|
|
|
}
|
|
|
|
ret = [fileManager removeFiles:files
|
2007-01-16 16:27:33 +00:00
|
|
|
fromDirectory:directory
|
|
|
|
removeDirsIfEmpty:YES];
|
2006-12-26 10:58:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
{
|
2009-02-10 00:31:55 +00:00
|
|
|
NSRunAlertPanel(@"Remove File",
|
2006-12-26 10:58:39 +00:00
|
|
|
@"Error removing files from project %@!",
|
|
|
|
@"OK", nil, nil, [activeProject projectName]);
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
else if (flag)
|
|
|
|
{
|
|
|
|
// Save project because we've removed file(s) from disk
|
2009-02-11 00:21:23 +00:00
|
|
|
// TODO: Maybe fix it later? (add pending removal of files)
|
2006-12-26 10:58:39 +00:00
|
|
|
[activeProject save];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
} // files
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)closeProject:(PCProject *)aProject
|
|
|
|
{
|
|
|
|
PCProject *currentProject = nil;
|
|
|
|
|
2009-06-23 22:21:10 +00:00
|
|
|
currentProject = [loadedProjects objectForKey: [aProject projectPath]];
|
2006-12-26 10:58:39 +00:00
|
|
|
if (!currentProject)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove it from the loaded projects!
|
2009-06-23 22:21:10 +00:00
|
|
|
[loadedProjects removeObjectForKey: [aProject projectPath]];
|
2006-12-26 10:58:39 +00:00
|
|
|
|
|
|
|
if ([loadedProjects count] == 0)
|
|
|
|
{
|
|
|
|
if (projectInspector)
|
|
|
|
{
|
|
|
|
[projectInspector close];
|
|
|
|
}
|
|
|
|
if (loadedFilesPanel && [loadedFilesPanel isVisible])
|
|
|
|
{
|
|
|
|
[loadedFilesPanel close];
|
|
|
|
}
|
|
|
|
if (buildPanel && [buildPanel isVisible])
|
|
|
|
{
|
|
|
|
[buildPanel close];
|
|
|
|
}
|
|
|
|
if (launchPanel && [launchPanel isVisible])
|
|
|
|
{
|
|
|
|
[launchPanel close];
|
|
|
|
}
|
2007-01-15 18:40:58 +00:00
|
|
|
[self setActiveProject:nil];
|
2006-12-26 10:58:39 +00:00
|
|
|
[self stopSaveTimer];
|
|
|
|
}
|
|
|
|
else if (currentProject == [self activeProject])
|
|
|
|
{
|
|
|
|
[self setActiveProject:[[loadedProjects allValues] lastObject]];
|
|
|
|
}
|
|
|
|
|
|
|
|
RELEASE(currentProject);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)closeProject
|
|
|
|
{
|
* Headers/Protocols/Preferences.h: Add new methods.
* PCPrefController.m: Implemented set/get of preferences value dependent. All
values are stored in preferences as NSString values and converted upon
request to specified type.
* Modules/Preferences/EditorFSC/PCEditorFSCPrefs.m: Use new methods of
PCPrefController. Implemented setting of editor fonts.
(setDefaults): Removed.
* Modules/Preferences/Build/PCBuildPrefs.m,
* Modules/Preferences/Misc/PCMiscPrefs.m,
* Modules/Preferences/Saving/PCSavingPrefs.m: Use new methods of PCPrefController.
(setDefaults): Removed.
* Framework/PCProjectLoadedFiles.m,
* Framework/PCMakefileFactory.m,
* Framework/PCProject.m,
* Framework/PCProjectLauncherPanel.m,
* Framework/PCFileManager.m,
* Framework/PCProjectBrowser.m,
* Framework/PCProjectBuilder.m,
* Framework/PCEditorManager.m,
* Framework/PCProjectLoadedFilesPanel.m,
* Framework/PCProjectLauncher.m,
* Framework/PCProjectBuilderPanel.m,
* Framework/PCProjectWindow.m,
* PCAppController.m,
* Framework/PCProjectManager.m: Use new methods of PCPrefController.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@28074 72102866-910b-0410-8b05-ffd578937521
2009-03-15 00:12:00 +00:00
|
|
|
if ([prefController boolForKey:SaveOnQuit])
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
|
|
|
[activeProject save];
|
|
|
|
}
|
|
|
|
|
|
|
|
[activeProject close:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)closeAllProjects
|
|
|
|
{
|
|
|
|
PCProject *project = nil;
|
2010-06-15 03:43:32 +00:00
|
|
|
NSEnumerator *enumerator = [[loadedProjects allValues] objectEnumerator];
|
2006-12-26 10:58:39 +00:00
|
|
|
|
|
|
|
// PCLogInfo(self, @"loaded %i projects", [loadedProjects count]);
|
|
|
|
|
2010-06-15 03:43:32 +00:00
|
|
|
while ((project = [enumerator nextObject]) != nil)
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
* Headers/Protocols/Preferences.h: Add new methods.
* PCPrefController.m: Implemented set/get of preferences value dependent. All
values are stored in preferences as NSString values and converted upon
request to specified type.
* Modules/Preferences/EditorFSC/PCEditorFSCPrefs.m: Use new methods of
PCPrefController. Implemented setting of editor fonts.
(setDefaults): Removed.
* Modules/Preferences/Build/PCBuildPrefs.m,
* Modules/Preferences/Misc/PCMiscPrefs.m,
* Modules/Preferences/Saving/PCSavingPrefs.m: Use new methods of PCPrefController.
(setDefaults): Removed.
* Framework/PCProjectLoadedFiles.m,
* Framework/PCMakefileFactory.m,
* Framework/PCProject.m,
* Framework/PCProjectLauncherPanel.m,
* Framework/PCFileManager.m,
* Framework/PCProjectBrowser.m,
* Framework/PCProjectBuilder.m,
* Framework/PCEditorManager.m,
* Framework/PCProjectLoadedFilesPanel.m,
* Framework/PCProjectLauncher.m,
* Framework/PCProjectBuilderPanel.m,
* Framework/PCProjectWindow.m,
* PCAppController.m,
* Framework/PCProjectManager.m: Use new methods of PCPrefController.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@28074 72102866-910b-0410-8b05-ffd578937521
2009-03-15 00:12:00 +00:00
|
|
|
if ([prefController boolForKey:SaveOnQuit])
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
|
|
|
[project save];
|
|
|
|
}
|
|
|
|
if ([project close:self] == NO)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// ==== File actions
|
|
|
|
// ============================================================================
|
|
|
|
|
2008-02-04 23:51:28 +00:00
|
|
|
- (void)openFileAtPath:(NSString *)filePath
|
2021-08-01 21:01:58 +00:00
|
|
|
windowed:(BOOL)windowed
|
2008-02-04 23:51:28 +00:00
|
|
|
{
|
2009-03-19 00:13:25 +00:00
|
|
|
editorManager = [self editorManager];
|
2009-02-08 00:38:13 +00:00
|
|
|
|
2008-02-04 23:51:28 +00:00
|
|
|
if (filePath != nil)
|
|
|
|
{
|
2009-03-19 00:13:25 +00:00
|
|
|
[editorManager openEditorForFile:filePath
|
|
|
|
editable:YES
|
2021-08-01 21:01:58 +00:00
|
|
|
windowed:windowed];
|
2009-03-19 00:13:25 +00:00
|
|
|
[editorManager orderFrontEditorForFile:filePath];
|
2008-02-04 23:51:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-01 21:01:58 +00:00
|
|
|
- (void)openFileAtPath:(NSString *)filePath
|
|
|
|
{
|
|
|
|
[self openFileAtPath: filePath windowed: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
- (void)openFile
|
|
|
|
{
|
|
|
|
NSArray *files = nil;
|
|
|
|
NSString *filePath = nil;
|
|
|
|
|
2007-08-29 20:39:25 +00:00
|
|
|
files = [fileManager filesOfTypes:nil
|
|
|
|
operation:PCOpenFileOperation
|
|
|
|
multiple:NO
|
|
|
|
title:@"Open File"
|
|
|
|
accView:nil];
|
2006-12-26 10:58:39 +00:00
|
|
|
filePath = [files objectAtIndex:0];
|
2009-02-11 00:21:23 +00:00
|
|
|
if (filePath)
|
|
|
|
{
|
|
|
|
[self openFileAtPath:filePath];
|
|
|
|
}
|
2006-12-26 10:58:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)newFile
|
|
|
|
{
|
2008-02-04 23:51:28 +00:00
|
|
|
[[PCFileCreator sharedCreator] newFileInProject:activeProject];
|
2006-12-26 10:58:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)saveFile
|
|
|
|
{
|
2009-04-27 21:09:30 +00:00
|
|
|
if (activeProject)
|
2009-03-19 00:13:25 +00:00
|
|
|
{
|
|
|
|
return [[[activeProject projectEditor] activeEditor] saveFile];
|
|
|
|
}
|
|
|
|
else if (editorManager)
|
|
|
|
{
|
|
|
|
return [[editorManager activeEditor] saveFile];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
2006-12-26 10:58:39 +00:00
|
|
|
}
|
|
|
|
|
2008-01-21 22:26:36 +00:00
|
|
|
- (BOOL)saveFileAs
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
2008-01-21 22:26:36 +00:00
|
|
|
NSArray *files = nil;
|
|
|
|
NSString *filePath = nil;
|
|
|
|
|
|
|
|
files = [fileManager filesOfTypes:nil
|
|
|
|
operation:PCSaveFileOperation
|
|
|
|
multiple:NO
|
2009-02-11 00:21:23 +00:00
|
|
|
title:@"Save File As..."
|
2008-01-21 22:26:36 +00:00
|
|
|
accView:nil];
|
|
|
|
filePath = [files objectAtIndex:0];
|
|
|
|
|
|
|
|
if (filePath != nil && ![[activeProject projectEditor] saveFileAs:filePath])
|
|
|
|
{
|
2009-02-11 00:21:23 +00:00
|
|
|
NSRunAlertPanel(@"Save File As",
|
|
|
|
@"Unable to save file as\n%@!",
|
2008-01-21 22:26:36 +00:00
|
|
|
@"OK", nil, nil, filePath);
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// TODO: implement 'Save File As' functionality wrt project and
|
|
|
|
// non-project files
|
|
|
|
/* PCProject *project = [projectManager activeProject];
|
|
|
|
NSString *categoryPath = nil;
|
|
|
|
|
|
|
|
categoryPath = [NSString stringWithString:@"/"];
|
|
|
|
categoryPath = [categoryPath stringByAppendingPathComponent:
|
|
|
|
[[project rootEntries] objectForKey:PCNonProject]];
|
|
|
|
|
|
|
|
[projectManager closeFile];
|
|
|
|
[project addFiles:[NSArray arrayWithObject:newFilePath]
|
|
|
|
forKey:PCNonProject
|
|
|
|
notify:YES];
|
|
|
|
[[activeProject projectEditor] openEditorForFile:newFilePath
|
|
|
|
categoryPath:categoryPath
|
|
|
|
editable:YES
|
|
|
|
windowed:NO];*/
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
2006-12-26 10:58:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)saveFileTo
|
|
|
|
{
|
2007-08-29 20:39:25 +00:00
|
|
|
NSArray *files = nil;
|
2006-12-26 10:58:39 +00:00
|
|
|
NSString *filePath = nil;
|
|
|
|
|
2007-08-29 20:39:25 +00:00
|
|
|
files = [fileManager filesOfTypes:nil
|
|
|
|
operation:PCSaveFileOperation
|
|
|
|
multiple:NO
|
2009-02-11 00:21:23 +00:00
|
|
|
title:@"Save File To..."
|
2007-08-29 20:39:25 +00:00
|
|
|
accView:nil];
|
|
|
|
filePath = [files objectAtIndex:0];
|
2006-12-26 10:58:39 +00:00
|
|
|
|
|
|
|
if (filePath != nil && ![[activeProject projectEditor] saveFileTo:filePath])
|
|
|
|
{
|
2009-02-11 00:21:23 +00:00
|
|
|
NSRunAlertPanel(@"Save File To",
|
|
|
|
@"Unable to save file to\n%@!",
|
2006-12-26 10:58:39 +00:00
|
|
|
@"OK", nil, nil, filePath);
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)revertFileToSaved
|
|
|
|
{
|
|
|
|
return [[activeProject projectEditor] revertFileToSaved];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)renameFile
|
|
|
|
{
|
|
|
|
[self showProjectInspector:self];
|
|
|
|
[projectInspector selectSectionWithTitle:@"File Attributes"];
|
|
|
|
[projectInspector beginFileRename];
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)closeFile
|
|
|
|
{
|
|
|
|
return [[activeProject projectEditor] closeActiveEditor:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation PCProjectManager (Subprojects)
|
|
|
|
|
2009-02-11 00:21:23 +00:00
|
|
|
- (BOOL)openNewSubprojectPanel
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
|
|
|
// PCLogInfo(self, @"newSubproject");
|
|
|
|
|
|
|
|
if (!nsPanel)
|
|
|
|
{
|
|
|
|
if ([NSBundle loadNibNamed:@"NewSubproject" owner:self] == NO)
|
|
|
|
{
|
2009-02-11 00:21:23 +00:00
|
|
|
NSRunAlertPanel(@"New Subproject",
|
|
|
|
@"Internal error!"
|
2009-03-02 01:01:44 +00:00
|
|
|
@" Install ProjectCenter again, please.",
|
2009-02-11 00:21:23 +00:00
|
|
|
@"OK", nil, nil);
|
2006-12-26 10:58:39 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
[nsPanel setFrameAutosaveName:@"NewSubproject"];
|
|
|
|
if (![nsPanel setFrameUsingName: @"NewSubproject"])
|
|
|
|
{
|
|
|
|
[nsPanel center];
|
|
|
|
}
|
|
|
|
|
|
|
|
[nsImage setImage:[NSApp applicationIconImage]];
|
|
|
|
[nsTypePB removeAllItems];
|
|
|
|
[nsTypePB addItemsWithTitles:
|
|
|
|
[[activeProject allowableSubprojectTypes]
|
|
|
|
sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]];
|
|
|
|
[nsTypePB setRefusesFirstResponder:YES];
|
|
|
|
[nsTypePB selectItemAtIndex:0];
|
|
|
|
[nsCancelButton setRefusesFirstResponder:YES];
|
|
|
|
[nsCreateButton setRefusesFirstResponder:YES];
|
|
|
|
}
|
|
|
|
[projectNameField setStringValue:[activeProject projectName]];
|
|
|
|
[nsPanel makeKeyAndOrderFront:nil];
|
|
|
|
[nsNameField setStringValue:@""];
|
|
|
|
[nsPanel makeFirstResponder:nsNameField];
|
|
|
|
|
2009-02-10 00:31:55 +00:00
|
|
|
[nsPanel setLevel:NSModalPanelWindowLevel];
|
|
|
|
[NSApp runModalForWindow:nsPanel];
|
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)closeNewSubprojectPanel:(id)sender
|
|
|
|
{
|
|
|
|
[nsPanel orderOut:self];
|
2009-02-10 00:31:55 +00:00
|
|
|
[NSApp stopModal];
|
2006-12-26 10:58:39 +00:00
|
|
|
}
|
|
|
|
|
2009-02-11 00:21:23 +00:00
|
|
|
- (void)createSubproject:(id)sender
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
|
|
|
PCProject *subproject = nil;
|
|
|
|
NSString *spName = [nsNameField stringValue];
|
|
|
|
NSString *spPath = nil;
|
|
|
|
NSString *spType = [nsTypePB titleOfSelectedItem];
|
|
|
|
|
2009-02-11 00:21:23 +00:00
|
|
|
// 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];
|
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
if (![[spName pathExtension] isEqualToString:@"subproj"])
|
|
|
|
{
|
|
|
|
spName = [[nsNameField stringValue]
|
|
|
|
stringByAppendingPathExtension:@"subproj"];
|
|
|
|
}
|
|
|
|
|
|
|
|
spPath = [[activeProject projectPath] stringByAppendingPathComponent:spName];
|
|
|
|
|
|
|
|
PCLogStatus(self, @"creating subproject with type %@ at path %@",
|
|
|
|
spType, spPath);
|
|
|
|
|
|
|
|
// Create subproject
|
|
|
|
subproject = [self createSubprojectOfType:spType path:spPath];
|
|
|
|
|
2019-12-29 12:37:39 +00:00
|
|
|
// PCLogInfo(self, @"{createSubproject} add to %@", [activeProject projectName]);
|
|
|
|
[activeProject addSubproject:subproject];
|
|
|
|
|
2009-02-11 00:21:23 +00:00
|
|
|
return;
|
2006-12-26 10:58:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (PCProject *)createSubprojectOfType:(NSString *)projectType
|
|
|
|
path:(NSString *)aPath
|
|
|
|
{
|
|
|
|
NSString *className = [projectTypes objectForKey:projectType];
|
|
|
|
PCProject<ProjectType> *projectCreator;
|
|
|
|
PCProject *subproject = nil;
|
2017-01-17 14:42:37 +00:00
|
|
|
NSString *subType = nil;
|
|
|
|
|
|
|
|
if ([projectType isEqualToString:@"Application"])
|
|
|
|
subType = PCProjectInterfaceGorm;
|
2006-12-26 10:58:39 +00:00
|
|
|
|
|
|
|
projectCreator = [bundleManager objectForClassName:className
|
2007-09-27 00:03:51 +00:00
|
|
|
bundleType:@"project"
|
|
|
|
protocol:@protocol(ProjectType)];
|
2017-01-17 14:42:37 +00:00
|
|
|
if (!(subproject = [projectCreator createProjectAt:aPath withOption:subType]))
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
2009-02-11 00:21:23 +00:00
|
|
|
NSRunAlertPanel(@"New Subproject",
|
|
|
|
@"Internal error!"
|
2009-03-02 01:01:44 +00:00
|
|
|
@" Install ProjectCenter again, please.",
|
2009-02-11 00:21:23 +00:00
|
|
|
@"OK", nil, nil);
|
2006-12-26 10:58:39 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
[subproject setIsSubproject:YES];
|
|
|
|
[subproject setSuperProject:activeProject];
|
|
|
|
[subproject setProjectManager:self];
|
|
|
|
|
|
|
|
return subproject;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)controlTextDidChange:(NSNotification *)aNotif
|
|
|
|
{
|
2009-02-11 00:21:23 +00:00
|
|
|
NSString *tfString = nil;
|
|
|
|
NSArray *subprojectList = nil;
|
|
|
|
|
2006-12-26 10:58:39 +00:00
|
|
|
if ([aNotif object] != nsNameField)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-11 00:21:23 +00:00
|
|
|
// Check for valid subproject names
|
|
|
|
tfString = [nsNameField stringValue];
|
|
|
|
subprojectList = [[activeProject projectDict] objectForKey:PCSubprojects];
|
|
|
|
if (![subprojectList containsObject:tfString])
|
2006-12-26 10:58:39 +00:00
|
|
|
{
|
|
|
|
[nsCreateButton setEnabled:YES];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[nsCreateButton setEnabled:NO];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)addSubproject
|
|
|
|
{
|
|
|
|
NSFileManager *fm = [NSFileManager defaultManager];
|
|
|
|
NSMutableArray *files = nil;
|
|
|
|
NSString *pcProject = nil;
|
|
|
|
NSString *spDir = nil;
|
|
|
|
NSDictionary *spDict = nil;
|
|
|
|
NSString *spName = nil;
|
|
|
|
unsigned i;
|
|
|
|
|
2007-08-29 20:39:25 +00:00
|
|
|
files = [fileManager filesOfTypes:[NSArray arrayWithObjects:@"subproj",nil]
|
|
|
|
operation:PCAddFileOperation
|
|
|
|
multiple:NO
|
|
|
|
title:@"Add Subproject"
|
|
|
|
accView:nil];
|
2006-12-26 10:58:39 +00:00
|
|
|
|
|
|
|
// Validate if it real projects
|
|
|
|
for (i = 0; i < [files count]; i++)
|
|
|
|
{
|
|
|
|
spDir = [files objectAtIndex:i];
|
|
|
|
pcProject = [spDir stringByAppendingPathComponent:@"PC.project"];
|
|
|
|
if (![[spDir pathExtension] isEqualToString:@"subproj"]
|
|
|
|
|| ![fm fileExistsAtPath:pcProject])
|
|
|
|
{
|
|
|
|
[files removeObjectAtIndex:i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// PCLogInfo(self, @"{addSubproject} %@", files);
|
|
|
|
|
|
|
|
if (![fileManager copyFiles:files
|
|
|
|
intoDirectory:[activeProject projectPath]])
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < [files count]; i++)
|
|
|
|
{
|
|
|
|
spDir = [files objectAtIndex:i];
|
|
|
|
pcProject = [spDir stringByAppendingPathComponent:@"PC.project"];
|
|
|
|
spDict = [NSDictionary dictionaryWithContentsOfFile:pcProject];
|
|
|
|
spName = [spDict objectForKey:PCProjectName];
|
|
|
|
|
|
|
|
// PCLogInfo(self, @"{addSubproject} dir: %@ file: %@", spDir, pcProject);
|
|
|
|
|
|
|
|
[activeProject addSubprojectWithName:spName];
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|