1998-11-19 21:54:38 +00:00
|
|
|
|
/* -*- C++ -*-
|
1996-05-30 20:03:15 +00:00
|
|
|
|
NSOpenPanel.m
|
|
|
|
|
|
|
|
|
|
Standard open panel for opening files
|
|
|
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
|
|
Author: Scott Christley <scottc@net-community.com>
|
|
|
|
|
Date: 1996
|
1998-08-19 09:00:26 +00:00
|
|
|
|
Author: Daniel B<EFBFBD>hringer <boehring@biomed.ruhr-uni-bochum.de>
|
|
|
|
|
Date: August 1998
|
|
|
|
|
Source by Daniel B<EFBFBD>hringer integrated into Scott Christley's preliminary
|
|
|
|
|
implementation by Felipe A. Rodriguez <far@ix.netcom.com>
|
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This library 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 Library General Public
|
1996-10-18 17:14:13 +00:00
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
|
If not, write to the Free Software Foundation,
|
|
|
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1996-05-30 20:03:15 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1997-09-23 22:43:24 +00:00
|
|
|
|
#include <gnustep/gui/config.h>
|
1997-02-18 00:29:25 +00:00
|
|
|
|
#include <string.h>
|
1997-08-18 17:10:23 +00:00
|
|
|
|
#include <Foundation/NSString.h>
|
1997-02-18 00:29:25 +00:00
|
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
|
#include <AppKit/NSOpenPanel.h>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
1998-08-19 09:00:26 +00:00
|
|
|
|
// toDo: - canChooseFiles unimplemented
|
|
|
|
|
// - allowsMultipleSelection untested
|
|
|
|
|
// - setCanChooseDirectories untested
|
|
|
|
|
|
|
|
|
|
static NSOpenPanel *gnustep_gui_open_panel = nil;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
|
|
@implementation NSOpenPanel
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Class methods
|
|
|
|
|
//
|
|
|
|
|
+ (void)initialize
|
|
|
|
|
{
|
1998-08-19 09:00:26 +00:00
|
|
|
|
if (self == [NSOpenPanel class])
|
|
|
|
|
[self setVersion:1]; // Initial version
|
1996-05-30 20:03:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Accessing the NSOpenPanel
|
|
|
|
|
//
|
|
|
|
|
+ (NSOpenPanel *)openPanel
|
|
|
|
|
{
|
1998-08-19 09:00:26 +00:00
|
|
|
|
if (!gnustep_gui_open_panel)
|
|
|
|
|
{
|
|
|
|
|
// PanelLoader *pl = [PanelLoader panelLoader];
|
|
|
|
|
// gnustep_gui_open_panel = [pl loadPanel: @"NSOpenPanel"];
|
|
|
|
|
gnustep_gui_open_panel = [[NSOpenPanel alloc] init];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return gnustep_gui_open_panel;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Instance methods
|
|
|
|
|
//
|
1998-08-19 09:00:26 +00:00
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
|
//
|
|
|
|
|
// Initialization
|
|
|
|
|
//
|
|
|
|
|
- init
|
1998-08-19 09:00:26 +00:00
|
|
|
|
{
|
|
|
|
|
self = [super init];
|
|
|
|
|
[self setTitle:@"Open"];
|
|
|
|
|
[self setCanChooseFiles:YES];
|
|
|
|
|
multiple_select = NO;
|
|
|
|
|
|
|
|
|
|
return self;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Filtering Files
|
|
|
|
|
//
|
|
|
|
|
- (void)setAllowsMultipleSelection:(BOOL)flag
|
1998-08-19 09:00:26 +00:00
|
|
|
|
{
|
|
|
|
|
allowsMultipleSelection=flag;
|
|
|
|
|
[browser setAllowsMultipleSelection:flag];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-08-19 09:00:26 +00:00
|
|
|
|
-(BOOL) allowsMultipleSelection { return allowsMultipleSelection; }
|
|
|
|
|
-(void) setCanChooseDirectories:(BOOL)flag { canChooseDirectories = flag; }
|
|
|
|
|
-(BOOL) canChooseDirectories { return canChooseDirectories; }
|
|
|
|
|
-(void) setCanChooseFiles:(BOOL)flag { canChooseFiles = flag; }
|
|
|
|
|
-(BOOL) canChooseFiles { return canChooseFiles; }
|
|
|
|
|
-(NSString*) filename { return [browser path]; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Querying the Chosen Files
|
|
|
|
|
//
|
|
|
|
|
- (NSArray *)filenames
|
1998-08-19 09:00:26 +00:00
|
|
|
|
{
|
|
|
|
|
if(!allowsMultipleSelection)
|
|
|
|
|
return [NSArray arrayWithObject:[self filename]];
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
NSArray *cells=[browser selectedCells];
|
|
|
|
|
NSEnumerator *cellEnum;
|
|
|
|
|
id currCell;
|
|
|
|
|
NSMutableArray *ret = [NSMutableArray array];
|
|
|
|
|
NSString *dir=[self directory];
|
|
|
|
|
|
|
|
|
|
for(cellEnum=[cells objectEnumerator];currCell=[cellEnum nextObject];)
|
|
|
|
|
{
|
|
|
|
|
[ret addObject:[NSString
|
|
|
|
|
stringWithFormat:@"%@/%@",dir,[currCell stringValue]]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Running the NSOpenPanel
|
|
|
|
|
//
|
|
|
|
|
- (int)runModalForTypes:(NSArray *)fileTypes
|
1998-08-19 09:00:26 +00:00
|
|
|
|
{
|
|
|
|
|
return [self runModalForDirectory:[self directory]
|
|
|
|
|
file: nil
|
|
|
|
|
types: fileTypes];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-08-19 09:00:26 +00:00
|
|
|
|
- (int)runModalForDirectory:(NSString *)path
|
|
|
|
|
file:(NSString *)name
|
|
|
|
|
types:(NSArray *)fileTypes
|
|
|
|
|
{
|
|
|
|
|
if(requiredTypes)
|
|
|
|
|
[requiredTypes autorelease];
|
|
|
|
|
requiredTypes = [fileTypes retain];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
1998-08-19 09:00:26 +00:00
|
|
|
|
return [self runModalForDirectory:path file:name];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Target and Action Methods
|
|
|
|
|
//
|
1998-08-19 09:00:26 +00:00
|
|
|
|
- (void)ok_ORIGINAL_NOT_USED:(id)sender // excess? fix me FAR
|
1996-05-30 20:03:15 +00:00
|
|
|
|
{
|
|
|
|
|
char *sp, files[4096], *p;
|
|
|
|
|
NSMutableString *m;
|
|
|
|
|
|
|
|
|
|
if (the_filenames) [the_filenames release];
|
|
|
|
|
the_filenames = [NSMutableArray array];
|
|
|
|
|
// Search for space
|
|
|
|
|
strcpy(files, [file_name cString]);
|
|
|
|
|
sp = strchr(files, ' ');
|
|
|
|
|
if (sp == NULL)
|
|
|
|
|
{
|
|
|
|
|
// No space then only one file selected
|
|
|
|
|
[the_filenames addObject:file_name];
|
|
|
|
|
sp = strrchr(files, '\\');
|
|
|
|
|
sp++;
|
|
|
|
|
*sp = '\0';
|
|
|
|
|
directory = [NSString stringWithCString:files];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Multiple files selected
|
|
|
|
|
*sp = '\0';
|
|
|
|
|
directory = [NSString stringWithCString:files];
|
|
|
|
|
p = sp + 1;
|
|
|
|
|
sp = strchr(p, ' ');
|
|
|
|
|
while (sp != NULL)
|
|
|
|
|
{
|
|
|
|
|
*sp = '\0';
|
|
|
|
|
m = [NSMutableString stringWithCString:files];
|
|
|
|
|
[m appendString:@"\\"];
|
|
|
|
|
[m appendString:[NSString stringWithCString:p]];
|
|
|
|
|
[the_filenames addObject:m];
|
|
|
|
|
p = sp + 1;
|
|
|
|
|
sp = strchr(p, ' ');
|
|
|
|
|
}
|
|
|
|
|
if (strchr(p, '\0'))
|
|
|
|
|
{
|
|
|
|
|
m = [NSMutableString stringWithCString:files];
|
|
|
|
|
[m appendString:@"\\"];
|
|
|
|
|
[m appendString:[NSString stringWithCString:p]];
|
|
|
|
|
[the_filenames addObject:m];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// NSCoding protocol
|
|
|
|
|
//
|
|
|
|
|
- (void)encodeWithCoder:aCoder
|
|
|
|
|
{
|
|
|
|
|
[super encodeWithCoder:aCoder];
|
|
|
|
|
|
|
|
|
|
[aCoder encodeObject: the_filenames];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &multiple_select];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &choose_dir];
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &choose_file];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- initWithCoder:aDecoder
|
|
|
|
|
{
|
|
|
|
|
[super initWithCoder:aDecoder];
|
|
|
|
|
|
|
|
|
|
the_filenames = [aDecoder decodeObject];
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &multiple_select];
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &choose_dir];
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &choose_file];
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|