2002-05-29 11:21:25 +00:00
|
|
|
/*
|
|
|
|
Project.m
|
|
|
|
|
|
|
|
Project manager class
|
|
|
|
|
|
|
|
Copyright (C) 2002 Dusk to Dawn Computing, Inc.
|
|
|
|
|
|
|
|
Author: Jeff Teunissen <deek@d2dc.net>
|
|
|
|
Date: 29 May 2002
|
|
|
|
|
|
|
|
This program 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 program 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public
|
|
|
|
License along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
static const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "Config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#import <Foundation/NSFileManager.h>
|
|
|
|
#import <Foundation/NSString.h>
|
2002-07-06 03:00:28 +00:00
|
|
|
#import <Foundation/NSUserDefaults.h>
|
2002-05-29 11:21:25 +00:00
|
|
|
|
2002-07-06 03:00:28 +00:00
|
|
|
#import <AppKit/NSBrowser.h>
|
|
|
|
#import <AppKit/NSBrowserCell.h>
|
2002-05-29 11:21:25 +00:00
|
|
|
#import <AppKit/NSOpenPanel.h>
|
|
|
|
#import <AppKit/NSSavePanel.h>
|
|
|
|
|
|
|
|
#import "Controller.h"
|
|
|
|
#import "Project.h"
|
|
|
|
|
|
|
|
@implementation Project
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
return self = [super init];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2002-07-06 03:00:28 +00:00
|
|
|
[rFiles release];
|
|
|
|
[imgFiles release];
|
|
|
|
[otherFiles release];
|
|
|
|
[suppFiles release];
|
2002-05-29 11:21:25 +00:00
|
|
|
NSLog (@"Project deallocating");
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
2002-07-06 03:00:28 +00:00
|
|
|
int result;
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
|
|
|
imgFiles = [NSMutableArray new];
|
|
|
|
rFiles = [NSMutableArray new];
|
|
|
|
suppFiles = [NSMutableArray new];
|
|
|
|
otherFiles = [NSMutableArray new];
|
2002-05-29 11:21:25 +00:00
|
|
|
|
|
|
|
if (![owner fileMode]) {
|
|
|
|
NSLog (@"Project -awakeFromNib: Uhh, file mode isn't set. WTF?");
|
|
|
|
[self dealloc];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-07-06 03:00:28 +00:00
|
|
|
if ([owner fileName]) {
|
|
|
|
[self openProjectAtPath: [owner fileName]];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-05-29 11:21:25 +00:00
|
|
|
switch ([owner fileMode]) {
|
|
|
|
case COpenMode: { // load project
|
|
|
|
NSArray *fileTypes = [NSArray arrayWithObject: @"forge"];
|
|
|
|
NSOpenPanel *oPanel = [NSOpenPanel openPanel];
|
|
|
|
|
|
|
|
[oPanel setAllowsMultipleSelection: NO];
|
|
|
|
[oPanel setCanChooseFiles: YES];
|
|
|
|
[oPanel setCanChooseDirectories: NO];
|
|
|
|
|
2002-07-06 03:00:28 +00:00
|
|
|
result = [oPanel runModalForDirectory: [defaults objectForKey: @"ProjectPath"]
|
|
|
|
file: nil
|
|
|
|
types: fileTypes];
|
2002-05-29 11:21:25 +00:00
|
|
|
|
|
|
|
if (result == NSOKButton) { // got a path
|
|
|
|
NSArray *pathArray = [oPanel filenames];
|
|
|
|
|
|
|
|
[self openProjectAtPath: [pathArray objectAtIndex: 0]];
|
|
|
|
} else {
|
|
|
|
[self dealloc];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CCreateMode: { // Create new project
|
|
|
|
NSSavePanel *sPanel = [NSSavePanel savePanel];
|
|
|
|
|
|
|
|
[sPanel setPrompt: _(@"Project location")];
|
|
|
|
[sPanel setRequiredFileType: @"forge"];
|
|
|
|
[sPanel setTreatsFilePackagesAsDirectories: NO];
|
|
|
|
|
2002-07-06 03:00:28 +00:00
|
|
|
result = [sPanel runModalForDirectory: [defaults objectForKey: @"ProjectPath"]
|
|
|
|
file: @"ProjectName.forge"];
|
2002-05-29 11:21:25 +00:00
|
|
|
|
|
|
|
if (result == NSOKButton) { // got a path
|
|
|
|
[self createProjectAtPath: [sPanel filename]];
|
|
|
|
} else {
|
|
|
|
[self dealloc];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-07-06 02:22:15 +00:00
|
|
|
default:
|
|
|
|
break;
|
2002-05-29 11:21:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) createProjectAtPath: (NSString *) aPath
|
|
|
|
{
|
|
|
|
NSFileManager *filer = [NSFileManager defaultManager];
|
2002-07-06 03:00:28 +00:00
|
|
|
// create dictionary with dictionaries in it, each containing nothing
|
|
|
|
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
imgFiles, @"Image Files",
|
|
|
|
rFiles, @"Ruamoko Source",
|
|
|
|
suppFiles, @"Supporting Files",
|
|
|
|
otherFiles, @"Unmanaged Files",
|
|
|
|
nil];
|
2002-05-29 11:21:25 +00:00
|
|
|
|
|
|
|
if (!aPath) {
|
|
|
|
NSLog (@"No path given!");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (![filer createDirectoryAtPath: aPath attributes: nil]) {
|
|
|
|
NSLog (@"Could not create directory %@", aPath);
|
|
|
|
}
|
|
|
|
|
2002-07-06 03:00:28 +00:00
|
|
|
// write the dictionary
|
2002-05-29 11:21:25 +00:00
|
|
|
[dict writeToFile: [aPath stringByAppendingPathComponent: @"Forge.project"]
|
|
|
|
atomically: YES];
|
2002-07-06 03:00:28 +00:00
|
|
|
[window makeKeyAndOrderFront: self];
|
2002-05-29 11:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) openProjectAtPath: (NSString *) aPath
|
|
|
|
{
|
2002-07-06 03:00:28 +00:00
|
|
|
NSLog (@"No code to load project %@.", aPath);
|
2002-05-29 11:21:25 +00:00
|
|
|
[self dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) closeProject: (id) sender
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-07-06 03:00:28 +00:00
|
|
|
- (int) browser: (NSBrowser *) sender numberOfRowsInColumn: (int) column
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) browser: (NSBrowser *) sender
|
|
|
|
willDisplayCell: (id) cell
|
|
|
|
atRow: (int) row
|
|
|
|
column: (int) column
|
|
|
|
{
|
|
|
|
[cell setStringValue: @"hi"];
|
|
|
|
[cell setLoaded: YES];
|
|
|
|
[cell setLeaf: YES];
|
|
|
|
}
|
2002-05-29 11:21:25 +00:00
|
|
|
@end
|