Implemented a first 'editor', UI enhancements and other nice things

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/projectcenter/trunk@7530 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Robert Slover 2000-09-17 12:13:10 +00:00
parent 8f5233a551
commit a1cfff2685
14 changed files with 592 additions and 303 deletions

View file

@ -56,3 +56,6 @@
- (BOOL)browser:(NSBrowser *)sender selectCellWithString:(NSString *)title inColumn:(int)column;
@end
extern NSString *FileShouldOpenNotification;

View file

@ -26,14 +26,17 @@
#import "PCBrowserController.h"
#import "PCProject.h"
#import "PCFileManager.h"
NSString *FileShouldOpenNotification = @"FileShouldOpenNotification";
@implementation PCBrowserController
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
[super dealloc];
}
- (void)click:(id)sender
@ -72,31 +75,23 @@
- (void)doubleClick:(id)sender
{
#warning No subproject support here yet!
/*
if ([sender selectedColumn] == 0) {
// Ask the project about the valid file types
//NSArray *types = [project typesForKeyPath:[sender pathToColumn:0]];
NSOpenPanel *openPanel;
int retval;
NSArray *types;
if ([sender selectedColumn] != 0) {
NSString *category = [[[browser path] componentsSeparatedByString:@"/"] objectAtIndex:1];
NSString *k = [[project rootCategories] objectForKey:category];
openPanel = [NSOpenPanel openPanel];
[openPanel setAllowsMultipleSelection:NO];
[openPanel setCanChooseDirectories:NO];
[openPanel setCanChooseFiles:YES];
if ((retval = [openPanel runModalForDirectory:[[NSUserDefaults standardUserDefaults] objectForKey:@"LastOpenDirectory"] file:nil types:types])) {
NSString *key = [project projectKeyForKeyPath:[sender path]];
[project addFile:[[openPanel filenames] objectAtIndex:0] forKey:key];
[[NSUserDefaults standardUserDefaults] setObject:[openPanel directory] forKey:@"LastOpenDirectory"];
}
if ([k isEqualToString:PCClasses] || [k isEqualToString:PCHeaders] || [k isEqualToString:PCOtherSources]) {
NSString *projectPath = [project projectPath];
NSString *fn = [self nameOfSelectedFile];
NSString *file = [projectPath stringByAppendingPathComponent:fn];
NSDictionary *ui =[NSDictionary dictionaryWithObjectsAndKeys:
file,@"FilePathKey",nil];
[[NSNotificationCenter defaultCenter] postNotificationName:FileShouldOpenNotification object:self userInfo:ui];
}
else {
}
*/
}
else {
[[PCFileManager fileManager] showAddFileWindow];
}
}
- (void)projectDictDidChange:(NSNotification *)aNotif
@ -118,14 +113,7 @@
- (NSString *)pathOfSelectedFile
{
NSString *path = nil;
// Doesn't work with subprojects!
if ([browser selectedColumn] != 0) {
path = [browser path];
}
return path;
return [browser path];
}
- (void)setBrowser:(NSBrowser *)aBrowser

View file

@ -32,16 +32,17 @@
id fileTypePopup;
id newFileName;
id delegate;
id fileTypeAccessaryView;
id addFileTypePopup;
id delegate; // PCProjectManager
NSMutableDictionary *creators;
BOOL _needsAdditionalReleasing;
}
//===========================================================================================
// ==== Class methods
//===========================================================================================
+ (PCFileManager *)fileManager;
//===========================================================================================
// ==== Init and free
//===========================================================================================
@ -62,7 +63,6 @@
// ==== File stuff
// ===========================================================================
- (void)fileTypePopupChanged:(id)sender;
- (void)showAddFileWindow;
- (void)showNewFileWindow;

View file

@ -135,33 +135,26 @@
[newFileName setStringValue:@""];
[newFileName setAutoresizingMask: (NSViewWidthSizable | NSViewMinYMargin)];
[_c_view addSubview:[newFileName autorelease]];
/*
* the accessory view needed for adding files
*
*/
fileTypeAccessaryView = [[NSBox alloc] init];
addFileTypePopup = [[[NSPopUpButton alloc] initWithFrame:NSMakeRect(20,30,160,20) pullsDown:NO] autorelease];
[addFileTypePopup addItemWithTitle:@"No type available!"];
[fileTypeAccessaryView setTitle:@"Add to category"];
[fileTypeAccessaryView setTitlePosition:NSAtTop];
[fileTypeAccessaryView setBorderType:NSGrooveBorder];
[fileTypeAccessaryView addSubview:addFileTypePopup];
[fileTypeAccessaryView sizeToFit];
[fileTypeAccessaryView setAutoresizingMask: NSViewWidthSizable];
[fileTypePopup setTarget:self];
[fileTypePopup setAction:@selector(fileTypePopupChanged:)];
_needsAdditionalReleasing = YES;
}
@end
@implementation PCFileManager
//===========================================================================================
// ==== Class methods
//===========================================================================================
static PCFileManager *_mgr = nil;
+ (PCFileManager *)fileManager
{
if (!_mgr) {
_mgr = [[PCFileManager alloc] init];
}
return _mgr;
}
//===========================================================================================
// ==== Init and free
//===========================================================================================
@ -170,15 +163,7 @@
{
if ((self = [super init])) {
creators = [[NSMutableDictionary alloc] init];
#if defined(GNUSTEP)
[self _initUI];
#else
if(![NSBundle loadNibNamed:@"FileCreation.nib" owner:self]) {
[[NSException exceptionWithName:NIB_NOT_FOUND_EXCEPTION reason:@"Could not load FileCreation.gmodel" userInfo:nil] raise];
return nil;
}
#endif
}
return self;
}
@ -186,18 +171,14 @@
- (void)dealloc
{
[creators release];
if (_needsAdditionalReleasing) {
[fileTypeAccessaryView release];
[newFileWindow release];
}
[newFileWindow release];
[super dealloc];
}
- (void)awakeFromNib
{
[fileTypePopup removeAllItems];
[fileTypePopup removeAllItems];
}
// ===========================================================================
@ -206,56 +187,53 @@
- (id)delegate
{
return delegate;
return delegate;
}
- (void)setDelegate:(id)aDelegate
{
delegate = aDelegate;
delegate = aDelegate;
}
// ===========================================================================
// ==== File stuff
// ===========================================================================
- (void)fileTypePopupChanged:(id)sender
{
}
- (void)showAddFileWindow
{
NSOpenPanel *openPanel;
int retval;
NSOpenPanel *openPanel;
int retval;
NSMutableArray *validTypes = nil;
NSDictionary *categories = nil;
PCProject *project = nil;
NSString *key = nil;
NSString *title = nil;
NSArray *types = nil;
if (delegate && [delegate respondsToSelector:@selector(fileManagerWillAddFiles:)]) {
if (!(project = [delegate fileManagerWillAddFiles:self])) {
NSLog(@"No project to add files available...");
return;
}
}
// Ask the active project for the valid file types first!
categories = [project rootCategories];
validTypes = [NSMutableArray arrayWithArray:[categories allKeys]];
[validTypes removeObject:@"Subprojects"];
[addFileTypePopup removeAllItems];
[addFileTypePopup addItemsWithTitles:validTypes];
key = [project selectedRootCategory];
title = [[[project rootCategories] allKeysForObject:key] objectAtIndex:0];
title = [NSString stringWithFormat:@"Add to %@...",title];
types = [project fileExtensionsForCategory:key];
openPanel = [NSOpenPanel openPanel];
[openPanel setAllowsMultipleSelection:YES];
[openPanel setCanChooseDirectories:NO];
[openPanel setCanChooseFiles:YES];
[openPanel setTitle:@"Add File(s)..."];
[openPanel setAccessoryView:fileTypeAccessaryView];
retval = [openPanel runModalForDirectory:[[NSUserDefaults standardUserDefaults] objectForKey:@"LastOpenDirectory"] file:nil types:nil];
[openPanel setTitle:title];
retval = [openPanel runModalForDirectory:[[NSUserDefaults standardUserDefaults] objectForKey:@"LastOpenDirectory"] file:nil types:types];
if (retval == NSOKButton) {
NSString *key = [categories objectForKey:[addFileTypePopup titleOfSelectedItem]];
NSEnumerator *enumerator;
NSString *file;
@ -263,17 +241,57 @@
enumerator = [[openPanel filenames] objectEnumerator];
while (file = [enumerator nextObject]) {
NSString *otherKey;
NSString *ext;
BOOL ret = NO;
NSString *fn;
NSString *fileName;
NSString *pth;
if ([delegate fileManager:self shouldAddFile:file forKey:key]) {
NSString *fileName = [file lastPathComponent];
NSString *pth = [[project projectPath] stringByAppendingPathComponent:fileName];
fileName = [file lastPathComponent];
pth = [[project projectPath] stringByAppendingPathComponent:fileName];
if (![key isEqualToString:PCLibraries]) {
if ([[NSFileManager defaultManager] copyPath:file toPath:pth handler:nil]) {
[delegate fileManager:self didAddFile:pth forKey:key];
if (![[NSFileManager defaultManager] fileExistsAtPath:pth]) {
[[NSFileManager defaultManager] copyPath:file toPath:pth handler:nil];
}
}
else {
[delegate fileManager:self didAddFile:pth forKey:key];
[project addFile:pth forKey:key];
}
if ([key isEqualToString:PCClasses]) {
otherKey = PCHeaders;
ext = [NSString stringWithString:@"h"];
fn = [file stringByDeletingPathExtension];
fn = [fn stringByAppendingPathExtension:ext];
if ([[NSFileManager defaultManager] fileExistsAtPath:fn]) {
ret = NSRunAlertPanel(@"Adding Header?",@"Should %@ be added to project %@ as well?",@"Yes",@"No",nil,fn,[project projectName]);
}
}
else if ([key isEqualToString:PCHeaders]) {
otherKey = PCClasses;
ext = [NSString stringWithString:@"m"];
fn = [file stringByDeletingPathExtension];
fn = [fn stringByAppendingPathExtension:ext];
if ([[NSFileManager defaultManager] fileExistsAtPath:fn]) {
ret = NSRunAlertPanel(@"Adding Class?",@"Should %@ be added to project %@ as well?",@"Yes",@"No",nil,fn,[project projectName]);
}
}
if (ret) {
if ([delegate fileManager:self shouldAddFile:fn forKey:otherKey]) {
NSString *pp = [project projectPath];
fileName = [fn lastPathComponent];
pth = [pp stringByAppendingPathComponent:fileName];
[[NSFileManager defaultManager] copyPath:fn toPath:pth handler:nil];
[project addFile:pth forKey:otherKey];
}
}
}
@ -367,3 +385,6 @@
}
@end

View file

@ -28,6 +28,20 @@
#import "ProjectBuilder.h"
#ifndef IMAGE
#define IMAGE(X) [[[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForImageResource:(X)]] autorelease]
#endif
#define BUILD_KEY @"BuildKey"
#define BUILD_ARGS_KEY @"BuildArgsKey"
#define BUILD_HOST_KEY @"BuildHostKey"
#define TARGET_MAKE @"Make"
#define TARGET_MAKE_DEBUG @"MakeDebug"
#define TARGET_MAKE_PROFILE @"MakeProfile"
#define TARGET_MAKE_INSTALL @"MakeInstall"
#define TARGET_MAKE_CLEAN @"MakeClean"
#define TOUCHED_NOTHING (0)
#define TOUCHED_EVERYTHING (1 << 0)
#define TOUCHED_PROJECT_NAME (1 << 1)
@ -82,7 +96,7 @@ static NSString * const PCLibraryVar = @"LIBRARY_VAR";
{
id projectWindow;
id delegate;
id projectBuilder;
id projectManager;
id browserController;
id textView;
@ -92,6 +106,8 @@ static NSString * const PCLibraryVar = @"LIBRARY_VAR";
id projectFileInspectorView;
id buildTargetPanel;
id buildTargetHostField;
id buildTargetArgsField;
id buildTargetPopup;
id buildStatusField;
@ -102,10 +118,11 @@ static NSString * const PCLibraryVar = @"LIBRARY_VAR";
NSMutableDictionary *projectDict;
NSDictionary *rootCategories; // Needs to be initialised by subclasses!
NSMutableDictionary *buildOptions;
@private
BOOL _needsReleasing;
btarget _buildTarget;
btarget _target;
}
//===========================================================================================
@ -122,6 +139,9 @@ static NSString * const PCLibraryVar = @"LIBRARY_VAR";
//===========================================================================================
- (id)browserController;
- (NSString *)selectedRootCategory;
- (NSArray *)fileExtensionsForCategory:(NSString *)key;
- (void)setProjectName:(NSString *)aName;
- (NSString *)projectName;
@ -209,7 +229,8 @@ static NSString * const PCLibraryVar = @"LIBRARY_VAR";
- (void)setArguments:(id)sender;
- (void)build:(id)sender;
- (void)clean:(id)sender;
- (NSDictionary *)buildOptions;
@end
@ -228,3 +249,9 @@ static NSString * const PCLibraryVar = @"LIBRARY_VAR";
- (void)windowWillClose:(NSNotification *)aNotification;
@end
@interface PCProject (TextDelegate)
- (void)textDidEndEditing:(NSNotification *)aNotification;
@end

View file

@ -79,6 +79,7 @@
textView = [[NSTextView alloc] initWithFrame:NSMakeRect(0,0,472,88)];
[textView setMaxSize:NSMakeSize(1e7, 1e7)];
[textView setRichText:NO];
[textView setVerticallyResizable:YES];
[textView setHorizontallyResizable:YES];
[textView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
@ -110,27 +111,28 @@
prototype: buttonCell
numberOfRows: 1
numberOfColumns: 3] autorelease];
[matrix setIntercellSpacing:NSMakeSize(1,1)];
[matrix setSelectionByRect:YES];
[matrix setAutoresizingMask: (NSViewMaxXMargin | NSViewMinYMargin)];
[_c_view addSubview:matrix];
button = [matrix cellAtRow:0 column:0];
[button setImagePosition:NSImageOnly];
[button setImage:[[[NSImage alloc] initWithContentsOfFile:@"ProjectCentre_build.tiff"] autorelease]];
[button setImage:IMAGE(@"ProjectCentre_build")];
[button setButtonType:NSMomentaryPushButton];
[button setTarget:self];
[button setAction:@selector(build:)];
button = [matrix cellAtRow:0 column:1];
[button setImagePosition:NSImageOnly];
[button setImage:[[[NSImage alloc] initWithContentsOfFile:@"ProjectCentre_clean.tiff"] autorelease]];
[button setImage:IMAGE(@"ProjectCentre_settings.tiff")];
[button setButtonType:NSMomentaryPushButton];
[button setTarget:self];
[button setAction:@selector(clean:)];
[button setAction:@selector(showInspector:)];
button = [matrix cellAtRow:0 column:2];
[button setImagePosition:NSImageOnly];
[button setImage:[[[NSImage alloc] initWithContentsOfFile:@"ProjectCentre_prefs.tiff"] autorelease]];
[button setImage:IMAGE(@"ProjectCentre_prefs.tiff")];
[button setTarget:self];
[button setAction:@selector(showBuildTarget:)];
[button setButtonType:NSMomentaryPushButton];
@ -144,28 +146,29 @@
prototype: buttonCell
numberOfRows: 1
numberOfColumns: 4] autorelease];
[matrix setIntercellSpacing:NSMakeSize(1,1)];
[matrix setSelectionByRect:YES];
[matrix setAutoresizingMask: (NSViewMinXMargin | NSViewMinYMargin)];
[_c_view addSubview:matrix];
button = [matrix cellAtRow:0 column:0];
[button setImagePosition:NSImageOnly];
[button setImage:[[[NSImage alloc] initWithContentsOfFile:@"ProjectCentre_run.tiff"] autorelease]];
[button setImage:IMAGE(@"ProjectCentre_run.tiff")];
[button setButtonType:NSMomentaryPushButton];
button = [matrix cellAtRow:0 column:1];
[button setImagePosition:NSImageOnly];
[button setImage:[[[NSImage alloc] initWithContentsOfFile:@"ProjectCentre_uml.tiff"] autorelease]];
[button setImage:IMAGE(@"ProjectCentre_uml.tiff")];
[button setButtonType:NSMomentaryPushButton];
button = [matrix cellAtRow:0 column:2];
[button setImagePosition:NSImageOnly];
[button setImage:[[[NSImage alloc] initWithContentsOfFile:@"ProjectCentre_documentation.tiff"] autorelease]];
[button setImage:IMAGE(@"ProjectCentre_documentation.tiff")];
[button setButtonType:NSMomentaryPushButton];
button = [matrix cellAtRow:0 column:3];
[button setImagePosition:NSImageOnly];
[button setImage:[[[NSImage alloc] initWithContentsOfFile:@"ProjectCentre_find.tiff"] autorelease]];
[button setImage:IMAGE(@"ProjectCentre_find.tiff")];
[button setButtonType:NSMomentaryPushButton];
// Status
@ -225,7 +228,7 @@
_w_frame = NSMakeRect(100,100,272,104);
buildTargetPanel = [[NSWindow alloc] initWithContentRect:_w_frame styleMask:style backing:NSBackingStoreBuffered defer:NO];
[buildTargetPanel setDelegate:self];
[buildTargetPanel setReleasedWhenClosed:NO];
[buildTargetPanel setTitle:@"Build Options"];
_c_view = [buildTargetPanel contentView];
@ -236,7 +239,6 @@
[buildTargetPopup addItemWithTitle:@"Profile"];
[buildTargetPopup addItemWithTitle:@"Install"];
[buildTargetPopup autorelease];
[buildTargetPopup setTarget:self];
[buildTargetPopup setAction:@selector(setTarget:)];
[_c_view addSubview:buildTargetPopup];
@ -262,14 +264,17 @@
[_c_view addSubview:[textField autorelease]];
// Host message
textField = [[NSTextField alloc] initWithFrame:NSMakeRect(72,48,184,21)];
[textField setAlignment: NSLeftTextAlignment];
[textField setBordered: NO];
[textField setEditable: YES];
[textField setBezeled: YES];
[textField setDrawsBackground: YES];
[textField setStringValue:@"localhost"];
[_c_view addSubview:[textField autorelease]];
buildTargetHostField = [[NSTextField alloc] initWithFrame:NSMakeRect(72,48,184,21)];
[buildTargetHostField setAlignment: NSLeftTextAlignment];
[buildTargetHostField setBordered: NO];
[buildTargetHostField setEditable: YES];
[buildTargetHostField setBezeled: YES];
[buildTargetHostField setDrawsBackground: YES];
[buildTargetHostField setStringValue:@"localhost"];
[buildTargetHostField setDelegate:self];
[buildTargetHostField setTarget:self];
[buildTargetHostField setAction:@selector(setHost:)];
[_c_view addSubview:[buildTargetHostField autorelease]];
// Args
textField = [[NSTextField alloc] initWithFrame:NSMakeRect(12,68,60,21)];
@ -282,19 +287,20 @@
[_c_view addSubview:[textField autorelease]];
// Args message
textField = [[NSTextField alloc] initWithFrame:NSMakeRect(72,68,184,21)];
[textField setAlignment: NSLeftTextAlignment];
[textField setBordered: NO];
[textField setEditable: YES];
[textField setBezeled: YES];
[textField setDrawsBackground: YES];
[textField setStringValue:@""];
[_c_view addSubview:[textField autorelease]];
buildTargetArgsField = [[NSTextField alloc] initWithFrame:NSMakeRect(72,68,184,21)];
[buildTargetArgsField setAlignment: NSLeftTextAlignment];
[buildTargetArgsField setBordered: NO];
[buildTargetArgsField setEditable: YES];
[buildTargetArgsField setBezeled: YES];
[buildTargetArgsField setDrawsBackground: YES];
[buildTargetArgsField setStringValue:@""];
[buildTargetArgsField setDelegate:self];
[buildTargetArgsField setTarget:self];
[buildTargetArgsField setAction:@selector(setArguments:)];
[_c_view addSubview:[buildTargetArgsField autorelease]];
// Redisplay!
[browser loadColumnZero];
_needsReleasing = YES;
}
@end
@ -308,18 +314,12 @@
- (id)init
{
if ((self = [super init])) {
_buildTarget = defaultTarget;
_target = defaultTarget;
_needsReleasing = NO;
buildOptions = [[NSMutableDictionary alloc] init];
[buildOptions setObject:TARGET_MAKE forKey:BUILD_KEY];
#if defined(GNUSTEP)
[self _initUI];
#else
if(![NSBundle loadNibNamed:@"Project.nib" owner:self]) {
[[NSException exceptionWithName:NIB_NOT_FOUND_EXCEPTION reason:@"Could not load Project.gmodel" userInfo:nil] raise];
return nil;
}
#endif
}
return self;
}
@ -351,11 +351,11 @@
[projectPath release];
[projectDict release];
if (_needsReleasing) {
[browserController release];
[projectWindow release];
[buildTargetPanel release];
}
[browserController release];
[projectWindow release];
[buildTargetPanel release];
[buildOptions release];
[super dealloc];
}
@ -369,6 +369,38 @@
return browserController;
}
- (NSString *)selectedRootCategory
{
return [self projectKeyForKeyPath:[browserController pathOfSelectedFile]];
}
- (NSArray *)fileExtensionsForCategory:(NSString *)key
{
if ([key isEqualToString:PCGModels]) {
return [NSArray arrayWithObjects:@"gmodel",@"gorm",nil];
}
else if ([key isEqualToString:PCClasses]) {
return [NSArray arrayWithObjects:@"m",nil];
}
else if ([key isEqualToString:PCHeaders]) {
return [NSArray arrayWithObjects:@"h",nil];
}
else if ([key isEqualToString:PCOtherSources]) {
return [NSArray arrayWithObjects:@"c",@"C",nil];
}
else if ([key isEqualToString:PCLibraries]) {
return [NSArray arrayWithObjects:@"so",@"a",@"lib",nil];
}
else if ([key isEqualToString:PCSubprojects]) {
return [NSArray arrayWithObjects:@"subproj",nil];
}
else if ([key isEqualToString:PCImages]) {
return [NSArray arrayWithObjects:@"tiff",@"TIFF",@"jpg",@"JPG",@"jpeg",@"JPEG",@"bmp",@"BMP",nil];
}
return nil;
}
- (void)setProjectName:(NSString *)aName
{
[projectName autorelease];
@ -408,13 +440,13 @@
- (void)setProjectBuilder:(id<ProjectBuilder>)aBuilder
{
[projectBuilder autorelease];
projectBuilder = [aBuilder retain];
[projectManager autorelease];
projectManager = [aBuilder retain];
}
- (id<ProjectBuilder>)projectBuilder
{
return projectBuilder;
return projectManager;
}
//===========================================================================================
@ -489,7 +521,7 @@
}
if ([files containsObject:newFile]) {
NSRunAlertPanel(@"Attention!",@"The file %@ is already contained in this project!",@"OK",nil,nil,newFile);
NSRunAlertPanel(@"Attention!",@"The file %@ is already part of this project!",@"OK",nil,nil,newFile);
return;
}
@ -522,6 +554,10 @@
NSString *file = [browserController nameOfSelectedFile];
NSMutableArray *array;
NSString *key;
NSString *otherKey;
NSString *ext;
NSString *fn;
BOOL ret = NO;
if (!file) {
return NO;
@ -530,11 +566,43 @@
key = [self projectKeyForKeyPath:[browserController pathOfSelectedFile]];
[self removeFile:file forKey:key];
if ([key isEqualToString:PCClasses]) {
otherKey = PCHeaders;
ext = [NSString stringWithString:@"h"];
fn = [file stringByDeletingPathExtension];
fn = [fn stringByAppendingPathExtension:ext];
if ([self doesAcceptFile:fn forKey:otherKey] == NO) {
ret = NSRunAlertPanel(@"Removing Header?",@"Should %@ be removed from the project %@ as well?",@"Yes",@"No",nil,fn,[self projectName]);
}
}
else if ([key isEqualToString:PCHeaders]) {
otherKey = PCClasses;
ext = [NSString stringWithString:@"m"];
fn = [file stringByDeletingPathExtension];
fn = [fn stringByAppendingPathExtension:ext];
if ([self doesAcceptFile:fn forKey:otherKey] == NO) {
ret = NSRunAlertPanel(@"Removing Class?",@"Should %@ be removed from the project %@ as well?",@"Yes",@"No",nil,fn,[self projectName]);
}
}
if (ret) {
[self removeFile:fn forKey:otherKey];
}
// Remove the file permanently?!
if (yn) {
NSString *pth = [projectPath stringByAppendingPathComponent:file];
[[NSFileManager defaultManager] removeFileAtPath:pth handler:nil];
if (ret) {
pth = [projectPath stringByAppendingPathComponent:fn];
[[NSFileManager defaultManager] removeFileAtPath:pth handler:nil];
}
}
return YES;
@ -641,7 +709,7 @@
- (void)showInspector:(id)sender
{
[projectBuilder showInspectorForProject:self];
[projectManager showInspectorForProject:self];
}
- (id)updatedAttributeView
@ -661,74 +729,41 @@
- (void)showBuildTargetPanel:(id)sender
{
[buildTargetPanel center];
if (![buildTargetPanel isVisible]) {
[buildTargetPanel center];
}
[buildTargetPanel makeKeyAndOrderFront:self];
}
- (void)setTarget:(id)sender
{
_buildTarget = [buildTargetPopup indexOfSelectedItem];
_target = [buildTargetPopup indexOfSelectedItem];
[buildOptions setObject:[NSNumber numberWithInt:_target] forKey:BUILD_KEY];
}
- (void)setHost:(id)sender
{
NSLog(@"Setting host...");
NSString *host = [buildTargetHostField stringValue];
[buildOptions setObject:host forKey:BUILD_HOST_KEY];
NSLog(@"New host %@",host);
}
- (void)setArguments:(id)sender
{
NSLog(@"Setting args...");
NSString *args = [buildTargetArgsField stringValue];
[buildOptions setObject:args forKey:BUILD_ARGS_KEY];
}
- (void)build:(id)sender
{
BOOL ret = YES;
NSString *target = [buildTargetPopup titleOfSelectedItem];
NSMutableDictionary *optionDict = [NSMutableDictionary dictionary];
[buildStatusField setStringValue:@"Building..."];
// Check the panel for this option!
if ([target isEqualToString:@"Debug"]) {
[optionDict setObject:TARGET_MAKE_DEBUG forKey:BUILD_KEY];
}
if ([target isEqualToString:@"Profile"]) {
[optionDict setObject:TARGET_MAKE_PROFILE forKey:BUILD_KEY];
}
if ([target isEqualToString:@"Install"]) {
[optionDict setObject:TARGET_MAKE_INSTALL forKey:BUILD_KEY];
}
else {
[optionDict setObject:TARGET_MAKE forKey:BUILD_KEY];
}
[[PCProjectBuilder sharedBuilder] buildProject:self options:optionDict];
if (ret) {
[buildStatusField setStringValue:@"Build completed!"];
}
else {
[buildStatusField setStringValue:@"Build failed!"];
}
[[PCProjectBuilder sharedBuilder] showPanelWithProject:self options:buildOptions];
}
- (void)clean:(id)sender
- (NSDictionary *)buildOptions
{
BOOL ret = YES;
NSMutableDictionary *optionDict = [NSMutableDictionary dictionary];
[buildStatusField setStringValue:@"Cleaning..."];
// Check the panel for this option!
[optionDict setObject:TARGET_MAKE_CLEAN forKey:BUILD_KEY];
[[PCProjectBuilder sharedBuilder] buildProject:self options:optionDict];
if (ret) {
[buildStatusField setStringValue:@"Cleaning completed!"];
}
else {
[buildStatusField setStringValue:@"Cleaning failed!"];
}
return (NSDictionary *)buildOptions;
}
@end
@ -758,7 +793,8 @@
}
key = [[keyPath componentsSeparatedByString:@"/"] lastObject];
if ([[rootCategories allKeys] containsObject:key] || [[projectDict objectForKey:PCSubprojects] containsObject:key]) {
if ([[rootCategories allKeys] containsObject:key] ||
[[projectDict objectForKey:PCSubprojects] containsObject:key]) {
return YES;
}
@ -767,9 +803,9 @@
- (NSString *)projectKeyForKeyPath:(NSString *)kp
{
NSString *type = [[kp componentsSeparatedByString:@"/"] objectAtIndex:1];
return [rootCategories objectForKey:type];
NSString *type = [[kp componentsSeparatedByString:@"/"] objectAtIndex:1];
return [rootCategories objectForKey:type];
}
@end
@ -778,23 +814,39 @@
- (void)windowDidBecomeKey:(NSNotification *)aNotification
{
[projectBuilder setActiveProject:self];
[projectManager setActiveProject:self];
}
- (void)windowDidBecomeMain:(NSNotification *)aNotification
{
[projectBuilder setActiveProject:self];
[projectManager setActiveProject:self];
}
- (void)windowWillClose:(NSNotification *)aNotification
{
id object = [aNotification object];
if (object == buildTargetPanel) {
}
else if (object == [self projectWindow]) {
if ([[self projectWindow] isDocumentEdited]) {
if (NSRunAlertPanel(@"Project changed!",@"The project %@ has unsaved files! Should they be saved before closing it?",@"Yes",@"No",nil,[self projectName])) {
[self save];
}
if (NSRunAlertPanel(@"Project changed!",@"The project %@ has unsaved files! Should they be saved before closing it?",@"Yes",@"No",nil,[self projectName])) {
[self save];
}
}
// The PCProjectController is our delegate!
[projectBuilder closeProject:self];
[projectManager closeProject:self];
}
}
@end
@implementation PCProject (TextDelegate)
- (void)textDidEndEditing:(NSNotification *)aNotification
{
}
@end

View file

@ -28,15 +28,6 @@
@class PCProject;
#define BUILD_KEY @"BuildKey"
#define BUILD_OPTIONS_KEY @"BuildOptionsKey"
#define TARGET_MAKE @"Make"
#define TARGET_MAKE_DEBUG @"MakeDebug"
#define TARGET_MAKE_PROFILE @"MakeProfile"
#define TARGET_MAKE_INSTALL @"MakeInstall"
#define TARGET_MAKE_CLEAN @"MakeClean"
@class NSWindow;
@class NSTextView;
@ -48,6 +39,9 @@
NSMutableDictionary *buildTasks;
NSString *makePath;
PCProject *currentProject;
NSDictionary *currentOptions;
}
+ (id)sharedBuilder;
@ -55,6 +49,16 @@
- (id)init;
- (void)dealloc;
- (BOOL)buildProject:(PCProject *)aProject options:(NSDictionary *)optionDict;
- (void)showPanelWithProject:(PCProject *)proj options:(NSDictionary *)options;
- (void)build:(id)sender;
- (void)clean:(id)sender;
- (void)install:(id)sender;
- (void)projectDidChange:(NSNotification *)aNotif;
@end

View file

@ -26,6 +26,7 @@
#import "PCProjectBuilder.h"
#import "PCProject.h"
#import "PCProjectManager.h"
#import <AppKit/AppKit.h>
@ -44,11 +45,12 @@
NSMiniaturizableWindowMask | NSResizableWindowMask;
NSSplitView *split;
NSScrollView *scrollView1;
NSScrollView *scrollView2;
NSTextView *textView2;
NSMatrix* matrix;
NSRect _w_frame;
NSButtonCell* buttonCell = [[[NSButtonCell alloc] init] autorelease];
id button;
/*
* Build Window
@ -69,7 +71,7 @@
[logOutput setVerticallyResizable:YES];
[logOutput setHorizontallyResizable:YES];
[logOutput setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[logOutput setBackgroundColor:[NSColor whiteColor]];
//[logOutput setBackgroundColor:[NSColor whiteColor]];
[[logOutput textContainer] setWidthTracksTextView:YES];
scrollView1 = [[NSScrollView alloc] initWithFrame:NSMakeRect (0,0,496,92)];
@ -111,6 +113,43 @@
_c_view = [buildWindow contentView];
[_c_view addSubview:split];
/*
* Buttons
*/
_w_frame = NSMakeRect(8,268,144,48);
matrix = [[[NSMatrix alloc] initWithFrame: _w_frame
mode: NSHighlightModeMatrix
prototype: buttonCell
numberOfRows: 1
numberOfColumns: 3] autorelease];
[matrix setSelectionByRect:YES];
[matrix setAutoresizingMask: (NSViewMaxXMargin | NSViewMinYMargin)];
[_c_view addSubview:matrix];
button = [matrix cellAtRow:0 column:0];
[button setImagePosition:NSImageOnly];
[button setImage:IMAGE(@"ProjectCentre_build.tiff")];
[button setButtonType:NSMomentaryPushButton];
[button setTarget:self];
[button setAction:@selector(build:)];
button = [matrix cellAtRow:0 column:1];
[button setImagePosition:NSImageOnly];
[button setImage:IMAGE(@"ProjectCentre_clean.tiff")];
[button setButtonType:NSMomentaryPushButton];
[button setTarget:self];
[button setAction:@selector(clean:)];
button = [matrix cellAtRow:0 column:2];
[button setImagePosition:NSImageOnly];
[button setImage:IMAGE(@"ProjectCentre_prefs.tiff")];
[button setTarget:self];
[button setAction:@selector(showBuildTarget:)];
[button setButtonType:NSMomentaryPushButton];
[button setTarget:self];
[button setAction:@selector(install:)];
}
@end
@ -133,12 +172,16 @@ static PCProjectBuilder *_builder;
[self _initUI];
makePath = [[NSString stringWithString:@"/usr/bin/make"] retain];
buildTasks = [[NSMutableDictionary dictionary] retain];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(projectDidChange:) name:ActiveProjectDidChangeNotification object:nil];
}
return self;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[buildWindow release];
[makePath release];
[buildTasks release];
@ -146,9 +189,21 @@ static PCProjectBuilder *_builder;
[super dealloc];
}
- (BOOL)buildProject:(PCProject *)aProject options:(NSDictionary *)optionDict
- (void)showPanelWithProject:(PCProject *)proj options:(NSDictionary *)options;
{
if (![buildWindow isVisible]) {
[buildWindow center];
}
[buildWindow makeKeyAndOrderFront:self];
currentProject = proj;
currentOptions = options;
[buildWindow setTitle:[proj projectName]];
}
- (void)build:(id)sender
{
BOOL ret = NO;
NSString *tg = nil;
NSTask *makeTask;
NSMutableArray *args;
@ -156,14 +211,18 @@ static PCProjectBuilder *_builder;
NSPipe *logPipe;
NSFileHandle *readHandle;
NSData *inData = nil;
NSDictionary *optionDict;
if (!currentProject) {
return;
}
logPipe = [NSPipe pipe];
readHandle = [logPipe fileHandleForReading];
NSAssert(aProject,@"No project provided!");
makeTask = [[NSTask alloc] init];
optionDict = [currentProject buildOptions];
if ((tg = [optionDict objectForKey:BUILD_KEY])) {
if ([tg isEqualToString:TARGET_MAKE_DEBUG]) {
args = [NSMutableArray array];
@ -176,28 +235,13 @@ static PCProjectBuilder *_builder;
[args addObject:@"static=YES"];
[makeTask setArguments:args];
}
else if ([tg isEqualToString:TARGET_MAKE_INSTALL]) {
args = [NSMutableArray array];
[args addObject:@"install"];
[makeTask setArguments:args];
}
else if ([tg isEqualToString:TARGET_MAKE_CLEAN]) {
args = [NSMutableArray array];
[args addObject:@"clean"];
[makeTask setArguments:args];
}
[makeTask setCurrentDirectoryPath:[aProject projectPath]];
[makeTask setCurrentDirectoryPath:[currentProject projectPath]];
[makeTask setLaunchPath:makePath];
[makeTask setStandardOutput:logPipe];
[makeTask setStandardError:logPipe];
if (![buildWindow isVisible]) {
[buildWindow center];
[buildWindow makeKeyAndOrderFront:self];
}
[makeTask launch];
/*
@ -212,17 +256,30 @@ static PCProjectBuilder *_builder;
}
[makeTask waitUntilExit];
ret = [makeTask terminationStatus];
#ifdef DEBUG
NSLog(@"Task terminated %@...",(ret)?@"successfully":@"not successfully");
#endif DEBUG
[makeTask autorelease];
}
return ret;
}
- (void)clean:(id)sender
{
}
- (void)install:(id)sender
{
}
- (void)projectDidChange:(NSNotification *)aNotif
{
PCProject *project = [aNotif object];
if (project) {
currentProject = project;
[buildWindow setTitle:[project projectName]];
}
else {
currentProject = nil;
[buildWindow orderOut:self];
}
}
@end

View file

@ -167,3 +167,7 @@
- (BOOL)projectManager:(id)sender shouldOpenProject:(PCProject *)aProject;
@end
extern NSString *ActiveProjectDidChangeNotification;

View file

@ -31,6 +31,8 @@
#import <AppKit/IMLoading.h>
#endif
NSString *ActiveProjectDidChangeNotification = @"ActiveProjectDidChange";
@interface PCProjectManager (CreateUI)
- (void)_initUI;
@ -155,18 +157,20 @@
- (void)setActiveProject:(PCProject *)aProject
{
if (aProject != activeProject) {
activeProject = aProject;
if (aProject != activeProject) {
activeProject = aProject;
//~ Is this needed?
if (activeProject) {
[[activeProject projectWindow] makeKeyAndOrderFront:self];
}
if ([inspector isVisible]) {
[self inspectorPopupDidChange:inspectorPopup];
}
[[NSNotificationCenter defaultCenter] postNotificationName:ActiveProjectDidChangeNotification object:activeProject];
//~ Is this needed?
if (activeProject) {
[[activeProject projectWindow] makeKeyAndOrderFront:self];
}
if ([inspector isVisible]) {
[self inspectorPopupDidChange:inspectorPopup];
}
}
}
- (void)saveAllProjects
@ -198,6 +202,8 @@
concretBuilder = [NSClassFromString([builders objectForKey:builderKey]) sharedCreator];
if ((project = [concretBuilder openProjectAt:aPath])) {
[[project projectWindow] center];
return project;
}
}
@ -250,6 +256,8 @@
return NO;
}
[[project projectWindow] center];
[project setProjectBuilder:self];
[loadedProjects setObject:project forKey:aPath];
[self setActiveProject:project];
@ -271,38 +279,31 @@
- (void)inspectorPopupDidChange:(id)sender
{
NSView *view = nil;
if (![self activeProject]) {
return;
}
switch([sender indexOfSelectedItem]) {
case 0:
view = [[[self activeProject] updatedAttributeView] retain];
break;
case 1:
view = [[[self activeProject] updatedProjectView] retain];
break;
case 2:
view = [[[self activeProject] updatedFilesView] retain];
break;
}
[(NSBox *)inspectorView setContentView:view];
[inspectorView display];
NSView *view = nil;
if (![self activeProject]) {
return;
}
switch([sender indexOfSelectedItem]) {
case 0:
view = [[[self activeProject] updatedAttributeView] retain];
break;
case 1:
view = [[[self activeProject] updatedProjectView] retain];
break;
case 2:
view = [[[self activeProject] updatedFilesView] retain];
break;
}
[(NSBox *)inspectorView setContentView:view];
[inspectorView display];
}
- (void)showInspectorForProject:(PCProject *)aProject
{
if (!inspectorPopup) {
#if defined(GNUSTEP)
[self _initUI];
#else
if(![NSBundle loadNibNamed:@"Inspector.nib" owner:self]) {
[[NSException exceptionWithName:NIB_NOT_FOUND_EXCEPTION reason:@"Could not load Inspector.gmodel" userInfo:nil] raise];
return nil;
}
#endif
[inspectorPopup removeAllItems];
[inspectorPopup addItemWithTitle:@"Build Attributes"];
@ -460,3 +461,5 @@
@end

View file

@ -42,7 +42,7 @@ extern NSString *PCProjectDidUpdateNotification;
extern NSString *PCFileAddedToProjectNotification;
extern NSString *PCFileRemovedFromProjectNotification;
extern NSString *PCFileWillOpenNotification;
extern NSString *PCFileDidOpenNotification;
extern NSString *PCFileDidOpenNotification;
extern NSString *PCFileWillCloseNotification;
extern NSString *PCFileDidCloseNotification;
@ -64,11 +64,28 @@ extern NSString *PCProjectBuildDidStopNotification;
@interface PCServer : NSObject <Server>
{
NSMutableArray *clients;
NSMutableArray *openDocuments;
}
//----------------------------------------------------------------------------
// Init and free
//----------------------------------------------------------------------------
- (id)init;
- (void)dealloc;
//----------------------------------------------------------------------------
// Miscellaneous
//----------------------------------------------------------------------------
- (void)fileShouldBeOpened:(NSNotification *)aNotif;
- (void)openFileInExternalEditor:(NSString *)file;
- (void)openFileInInternalEditor:(NSString *)file;
- (NSWindow *)editorForFile:(NSString *)aFile;
- (void)windowDidClose:(NSNotification *)aNotif;
//----------------------------------------------------------------------------
// Server
//----------------------------------------------------------------------------
@ -90,7 +107,7 @@ extern NSString *PCProjectBuildDidStopNotification;
- (NSArray*)touchedFiles;
// Both methods return full paths!
- (BOOL)querTouchedFiles;
- (BOOL)queryTouchedFiles;
// Prompts user to save all files and projects with dirtied buffers.
- (BOOL)addFileAt:(NSString*)filePath toProject:(PCProject *)projectPath;

View file

@ -26,23 +26,135 @@
#import "PCServer.h"
#import "ProjectCenter.h"
#import "PCBrowserController.h"
@implementation PCServer
//----------------------------------------------------------------------------
// Init and free
//----------------------------------------------------------------------------
- (id)init
{
if ((self = [super init])) {
clients = [[NSMutableArray alloc] init];
}
return self;
if ((self = [super init])) {
clients = [[NSMutableArray alloc] init];
openDocuments = [[NSMutableArray alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fileShouldBeOpened:) name:FileShouldOpenNotification object:nil];
}
return self;
}
- (void)dealloc
{
[clients release];
[super dealloc];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[openDocuments release];
[clients release];
[super dealloc];
}
//----------------------------------------------------------------------------
// Miscellaneous
//----------------------------------------------------------------------------
- (void)fileShouldBeOpened:(NSNotification *)aNotif
{
NSString *file = [[aNotif userInfo] objectForKey:@"FilePathKey"];
if ([[[NSUserDefaults standardUserDefaults] objectForKey:ExternalEditor] isEqualToString:@"YES"]) {
[self openFileInExternalEditor:file];
}
else {
[self openFileInInternalEditor:file];
}
}
- (void)openFileInExternalEditor:(NSString *)file
{
NSTask *editorTask;
NSMutableArray *args = [NSMutableArray array];
NSUserDefaults *udef = [NSUserDefaults standardUserDefaults];
NSString *editor = [udef objectForKey:Editor];
editorTask = [[[NSTask alloc] init] autorelease];
[editorTask setLaunchPath:editor];
[args addObject:file];
[editorTask setArguments:args];
[editorTask launch];
}
- (void)openFileInInternalEditor:(NSString *)file
{
NSWindow *editorWindow = [self editorForFile:file];
[editorWindow setDelegate:self];
[editorWindow center];
[editorWindow makeKeyAndOrderFront:self];
[openDocuments addObject:editorWindow];
}
- (NSWindow *)editorForFile:(NSString *)aFile
{
unsigned int style = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask;
NSRect rect = NSMakeRect(100,100,512,320);
NSWindow *window = [[NSWindow alloc] initWithContentRect:rect
styleMask:style
backing:NSBackingStoreBuffered
defer:NO];
NSTextView *textView;
NSScrollView *scrollView;
NSString *text = [NSString stringWithContentsOfFile:aFile];
[window setMinSize:NSMakeSize(512,320)];
[window setTitle:[aFile lastPathComponent]];
textView = [[NSTextView alloc] initWithFrame:NSMakeRect(0,0,498,306)];
[textView setMaxSize:NSMakeSize(1e7, 1e7)];
[textView setVerticallyResizable:YES];
[textView setHorizontallyResizable:YES];
[textView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[textView setBackgroundColor:[NSColor whiteColor]];
[[textView textContainer] setWidthTracksTextView:YES];
[textView autorelease];
scrollView = [[NSScrollView alloc] initWithFrame:NSMakeRect (-1,-1,514,322)];
[scrollView setDocumentView:textView];
[textView setMinSize:NSMakeSize(0.0,[scrollView contentSize].height)];
[[textView textContainer] setContainerSize:NSMakeSize([scrollView contentSize].width,1e7)];
[scrollView setHasHorizontalScroller: YES];
[scrollView setHasVerticalScroller: YES];
[scrollView setBorderType: NSBezelBorder];
[scrollView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
[scrollView autorelease];
[[window contentView] addSubview:scrollView];
/*
* Will be replaced when a real editor is available...
*/
[textView setText:text];
return [window autorelease];
}
- (void)windowDidClose:(NSNotification *)aNotif
{
NSWindow *window = [aNotif object];
[openDocuments removeObject:window];
}
//----------------------------------------------------------------------------
// Server
//----------------------------------------------------------------------------
- (BOOL)registerProjectSubmenu:(NSMenu *)menu
{
}
@ -91,7 +203,7 @@
{
}
- (BOOL)querTouchedFiles
- (BOOL)queryTouchedFiles
{
}

View file

@ -42,6 +42,7 @@
#define BundlePaths @"BundlePaths"
#define SuccessSound @"SuccessSound"
#define FailureSound @"FailureSound"
#define ExternalEditor @"ExternalEditor"
#define PCAppDidInitNotification @"PCAppDidInit"
#define PCAppWillTerminateNotification @"PCAppWillTerminate"

View file

@ -50,7 +50,7 @@
- (NSArray*)touchedFiles;
// Returns array of paths of files that are "unsaved" or nil if none.
- (BOOL)querTouchedFiles;
- (BOOL)queryTouchedFiles;
// Prompts user to save all files and projects with dirtied buffers.
- (BOOL)addFileAt:(NSString*)filePath toProject:(PCProject *)projectPath;