2000-08-27 19:11:42 +00:00
|
|
|
/*
|
2001-08-03 14:23:25 +00:00
|
|
|
GNUstep ProjectCenter - http://www.gnustep.org
|
2000-08-27 19:11:42 +00:00
|
|
|
|
2002-11-27 18:41:07 +00:00
|
|
|
Copyright (C) 2000-2002 Free Software Foundation
|
2000-08-27 19:11:42 +00:00
|
|
|
|
2002-11-24 12:23:47 +00:00
|
|
|
Author: Philippe C.D. Robert <probert@siggraph.org>
|
2000-08-27 19:11:42 +00:00
|
|
|
|
2001-08-03 14:23:25 +00:00
|
|
|
This file is part of GNUstep.
|
2000-08-27 19:11:42 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
2003-04-21 13:46:10 +00:00
|
|
|
#include "PCBrowserController.h"
|
|
|
|
#include "PCProject.h"
|
|
|
|
#include "PCFileManager.h"
|
2000-09-17 12:13:10 +00:00
|
|
|
|
2000-08-27 19:11:42 +00:00
|
|
|
@implementation PCBrowserController
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
2000-09-17 12:13:10 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
2002-04-25 21:12:09 +00:00
|
|
|
|
2000-09-17 12:13:10 +00:00
|
|
|
[super dealloc];
|
2000-08-27 19:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)click:(id)sender
|
|
|
|
{
|
2002-02-16 20:46:26 +00:00
|
|
|
if ([[sender selectedCell] isLeaf])
|
|
|
|
{
|
2002-02-21 10:05:42 +00:00
|
|
|
NSString *ltitle = [[sender selectedCell] stringValue];
|
|
|
|
NSString *category = [[sender selectedCellInColumn:0] stringValue];
|
2000-08-28 19:04:15 +00:00
|
|
|
|
2003-01-26 03:43:19 +00:00
|
|
|
if ([self isEditableCategory:category file: ltitle])
|
2002-02-21 10:05:42 +00:00
|
|
|
{
|
2002-02-21 21:17:22 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"FileBecomesEditedNotification" object:ltitle];
|
|
|
|
|
2002-02-21 10:05:42 +00:00
|
|
|
[project browserDidClickFile:ltitle category:category];
|
|
|
|
}
|
2000-08-27 19:11:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)doubleClick:(id)sender
|
|
|
|
{
|
2002-02-21 10:05:42 +00:00
|
|
|
if ([[sender selectedCell] isLeaf])
|
2002-02-02 17:56:44 +00:00
|
|
|
{
|
2002-02-21 10:05:42 +00:00
|
|
|
NSString *category = [[sender selectedCellInColumn:0] stringValue];
|
|
|
|
NSString *fn = [self nameOfSelectedFile];
|
|
|
|
NSString *f = [[project projectPath] stringByAppendingPathComponent:fn];
|
2000-09-17 12:13:10 +00:00
|
|
|
|
2003-01-26 03:43:19 +00:00
|
|
|
if ([self isEditableCategory:category file: fn])
|
2002-02-02 17:56:44 +00:00
|
|
|
{
|
2002-02-21 10:05:42 +00:00
|
|
|
[project browserDidDblClickFile:f category:category];
|
2000-08-27 19:11:42 +00:00
|
|
|
}
|
2002-02-21 10:05:42 +00:00
|
|
|
else if([[NSWorkspace sharedWorkspace] openFile:f] == NO)
|
2002-02-02 17:56:44 +00:00
|
|
|
{
|
2002-02-21 10:05:42 +00:00
|
|
|
NSRunAlertPanel(@"Attention!",@"Could not open %@.",@"OK",nil,nil,f);
|
2001-01-07 14:07:35 +00:00
|
|
|
}
|
2000-09-17 12:13:10 +00:00
|
|
|
}
|
2002-02-02 17:56:44 +00:00
|
|
|
else
|
|
|
|
{
|
2000-09-17 12:13:10 +00:00
|
|
|
[[PCFileManager fileManager] showAddFileWindow];
|
|
|
|
}
|
2000-08-27 19:11:42 +00:00
|
|
|
}
|
|
|
|
|
2003-01-26 03:43:19 +00:00
|
|
|
- (BOOL)isEditableCategory:(NSString *)category file: (NSString *)title
|
2002-02-21 10:05:42 +00:00
|
|
|
{
|
|
|
|
NSString *k = [[project rootCategories] objectForKey:category];
|
|
|
|
|
|
|
|
if ([k isEqualToString:PCClasses] ||
|
|
|
|
[k isEqualToString:PCHeaders] ||
|
|
|
|
[k isEqualToString:PCOtherResources] ||
|
|
|
|
[k isEqualToString:PCSupportingFiles] ||
|
|
|
|
[k isEqualToString:PCDocuFiles] ||
|
|
|
|
[k isEqualToString:PCOtherSources])
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2003-01-26 03:43:19 +00:00
|
|
|
if ([k isEqualToString:PCGSMarkupFiles]
|
|
|
|
&& [[title pathExtension] isEqual: @"gorm"] == NO)
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2002-02-21 10:05:42 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2000-08-27 19:11:42 +00:00
|
|
|
- (void)projectDictDidChange:(NSNotification *)aNotif
|
|
|
|
{
|
2002-02-21 11:25:33 +00:00
|
|
|
if (browser)
|
|
|
|
{
|
|
|
|
[browser reloadColumn:[browser lastColumn]];
|
|
|
|
}
|
2000-08-27 19:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)nameOfSelectedFile
|
|
|
|
{
|
|
|
|
NSString *name = nil;
|
|
|
|
|
|
|
|
// Doesn't work with subprojects!
|
|
|
|
if ([browser selectedColumn] != 0) {
|
|
|
|
name = [[[browser path] componentsSeparatedByString:@"/"] lastObject];
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)pathOfSelectedFile
|
|
|
|
{
|
2000-09-17 12:13:10 +00:00
|
|
|
return [browser path];
|
2000-08-27 19:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setBrowser:(NSBrowser *)aBrowser
|
|
|
|
{
|
2002-04-26 03:12:50 +00:00
|
|
|
browser = aBrowser;
|
2000-08-27 19:11:42 +00:00
|
|
|
|
|
|
|
[browser setTitled:NO];
|
|
|
|
|
|
|
|
[browser setTarget:self];
|
|
|
|
[browser setAction:@selector(click:)];
|
|
|
|
[browser setDoubleAction:@selector(doubleClick:)];
|
|
|
|
|
2003-04-21 13:46:10 +00:00
|
|
|
[browser setMaxVisibleColumns:4];
|
|
|
|
[browser setSeparatesColumns:NO];
|
2000-08-27 19:11:42 +00:00
|
|
|
[browser setAllowsMultipleSelection:NO];
|
|
|
|
|
2002-02-16 20:46:26 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(projectDictDidChange:)
|
|
|
|
name:@"ProjectDictDidChangeNotification"
|
|
|
|
object:project];
|
2000-08-27 19:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setProject:(PCProject *)aProj
|
|
|
|
{
|
2002-02-21 21:17:22 +00:00
|
|
|
project = aProj;
|
2000-08-27 19:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation PCBrowserController (ProjectBrowserDelegate)
|
|
|
|
|
|
|
|
- (void)browser:(NSBrowser *)sender createRowsForColumn:(int)column inMatrix:(NSMatrix *)matrix
|
|
|
|
{
|
|
|
|
NSString *pathToCol = [sender pathToColumn:column];
|
|
|
|
NSArray *files = [project contentAtKeyPath:pathToCol];
|
|
|
|
int i;
|
|
|
|
int count = [files count];
|
|
|
|
|
2002-02-21 21:17:22 +00:00
|
|
|
if( sender != browser ) return;
|
2000-08-27 19:11:42 +00:00
|
|
|
|
2002-02-21 21:17:22 +00:00
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
{
|
2000-08-27 19:11:42 +00:00
|
|
|
NSMutableString *keyPath = [NSMutableString stringWithString:pathToCol];
|
|
|
|
id cell;
|
|
|
|
|
|
|
|
[matrix insertRow:i];
|
|
|
|
|
|
|
|
cell = [matrix cellAtRow:i column:0];
|
|
|
|
[cell setStringValue:[files objectAtIndex:i]];
|
|
|
|
|
|
|
|
[keyPath appendString:@"/"];
|
|
|
|
[keyPath appendString:[files objectAtIndex:i]];
|
|
|
|
|
|
|
|
[cell setLeaf:![project hasChildrenAtKeyPath:keyPath]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)browser:(NSBrowser *)sender willDisplayCell:(id)cell atRow:(int)row column:(int)column
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)browser:(NSBrowser *)sender selectCellWithString:(NSString *)title inColumn:(int)column
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|