git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4125 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-04-23 16:15:11 +00:00
parent 2055a4b0e0
commit 3af213e955
5 changed files with 620 additions and 544 deletions

View file

@ -1,3 +1,12 @@
Fri Apr 23 16:30:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
Changes based on report by Marc.Champesme@lipn.univ-paris13.fr
* Source/NSOpenPanel.m: Tidied a little.
* Source/NSSavePanel.m: ditto
* Headers/AppKit/NSPanel.m: Added NS_ALERTDEFAULT etc.
* Headers/AppKit/NSSavePanel.m: Bracket MacOS-X method with
#ifndef STRICT_OPENSTEP
1999-04-22 Michael Hanni <mhanni@sprintmail.com> 1999-04-22 Michael Hanni <mhanni@sprintmail.com>
* Model/test.m: fixed NSGraphic's'Context type-o. * Model/test.m: fixed NSGraphic's'Context type-o.

View file

@ -45,6 +45,13 @@ enum {
NSAlertErrorReturn = -2 NSAlertErrorReturn = -2
}; };
#ifndef STRICT_OPENSTEP
#define NS_ALERTDEFAULT NSAlertDefaultReturn
#define NS_ALERTALTERNATE NSAlertAlternateReturn
#define NS_ALERTOTHER NSAlertOtherReturn
#define NS_ALERTERROR NSAlertErrorReturn
#endif
@interface NSPanel : NSWindow <NSCoding> @interface NSPanel : NSWindow <NSCoding>
{ {
// Attributes // Attributes

View file

@ -3,7 +3,7 @@
Standard save panel for saving files Standard save panel for saving files
Copyright (C) 1996, 1997 Free Software Foundation, Inc. Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com> Author: Scott Christley <scottc@net-community.com>
Date: 1996 Date: 1996
@ -56,134 +56,159 @@ enum {
@interface NSSavePanel : NSPanel <NSCoding> @interface NSSavePanel : NSPanel <NSCoding>
{ {
NSBrowser *browser;
id form;
id homeButton;
id okButton;
id mountButton;
id unmountButton;
id separator;
id titleField;
NSString *lastValidPath;
NSArray *requiredTypes;
NSSet *typeTable;
NSBrowser *browser; // from Daniel's source // Attributes
id form; id panelImage;
id homeButton; id panelTitleField;
id okButton; id panelPromptField;
id mountButton,unmountButton; id panelBrowser;
id separator; id panelFileNameField;
id titleField; NSString *_directory;
NSString *lastValidPath; NSString *_fileName;
NSArray *requiredTypes; NSString *_requiredType;
NSSet *typeTable; BOOL _filePackage;
BOOL _delegateRespondsToCompare;
BOOL _delegateRespondsToShow;
BOOL _delegateRespondsToValid;
NSView *_accessoryView;
BOOL treatsFilePackagesAsDirectories;
// Attributes // Reserved for back-end use
id panelImage; // from Scott's source void *be_save_reserved;
id panelTitleField;
id panelPromptField;
id panelBrowser;
id panelFileNameField;
NSString *_directory;
NSString *_fileName;
NSString *_requiredType;
BOOL _filePackage;
BOOL _delegateRespondsToCompare;
BOOL _delegateRespondsToShow;
BOOL _delegateRespondsToValid;
// to do finish integration, eliminate excess FAR
NSView *_accessoryView; // integrated by Felipe
BOOL treatsFilePackagesAsDirectories;
// Reserved for back-end use
void *be_save_reserved;
} }
// /*
// Creating an NSSavePanel * Creating an NSSavePanel
// */
+ (NSSavePanel *)savePanel; // Returns an instance of NSSavePanel, + (NSSavePanel *) savePanel;
// creating one if necessary.
//
// Customizing the NSSavePanel
//
- (void)setAccessoryView:(NSView *)aView;
- (NSView *)accessoryView;
// Sets the title of the NSSavePanel to title. By default,
// ªSaveº is the title string. If you adapt the NSSavePanel
// for other uses, its title should reflect the user action
// that brings it to the screen.
- (void)setTitle:(NSString *)title;
- (NSString *)title;
- (void)setPrompt:(NSString *)prompt;
// Returns the prompt of the Save panel field that holds
// the current pathname or file name. By default this
// prompt is ªName:º. *Note - currently no prompt is shown.
- (NSString *)prompt;
// /*
// Setting Directory and File Type * Customizing the NSSavePanel
// */
- (NSString *)requiredFileType; - (void) setAccessoryView: (NSView *)aView;
// Sets the current path name in the Save panel's browser. - (NSView *) accessoryView;
// The path argument must be an absolute path name.
- (void)setDirectory:(NSString *)path;
// Specifies the type, a file name extension to be appended to
// any selected files that don't already have that extension;
// The argument type should not include the period that begins
// the extension. Invoke this method each time the Save panel
// is used for another file type within the application.
- (void)setRequiredFileType:(NSString *)type;
// Sets the NSSavePanel's behavior for displaying file packages
// (for example, MyApp.app) to the user. If flag is YES, the
// user is shown files and subdirectories within a file
// package. If NO, the NSSavePanel shows each file package as
// a file, thereby giving no indication that it is a directory.
- (void)setTreatsFilePackagesAsDirectories:(BOOL)flag;
- (BOOL)treatsFilePackagesAsDirectories;
// Validates and possibly reloads the browser columns visible
// in the Save panel by causing the delegate method
// panel:shouldShowFilename: to be invoked. One situation in
// which this method would find use is whey you want the
// browser show only files with certain extensions based on the
// selection made in an accessory-view pop-up list. When the
// user changes the selection, you would invoke this method to
// revalidate the visible columns.
- (void)validateVisibleColumns;
// /*
// Running the NSSavePanel * Sets the title of the NSSavePanel to title. By default,
// * ªSaveº is the title string. If you adapt the NSSavePanel
// Initializes the panel to the directory specified by path * for other uses, its title should reflect the user action
// and, optionally, the file specified by filename, then * that brings it to the screen.
// displays it and begins its modal event loop; path and */
// filename can be empty strings, but cannot be nil. The - (void) setTitle: (NSString *)title;
// method invokes Application's runModalForWindow: method with - (NSString *) title;
// self as the argument. Returns NSOKButton (if the user - (void) setPrompt: (NSString *)prompt;
// clicks the OK button) or NSCancelButton (if the user clicks
// the Cancel button). Do not invoke filename or directory
// within a modal loop because the information that these
// methods fetch is updated only upon return.
- (int)runModalForDirectory:(NSString *)path file:(NSString *)filename;
- (int)runModal;
// /*
// Reading Save Information * Returns the prompt of the Save panel field that holds
// * the current pathname or file name. By default this
// Returns the absolute pathname of the directory currently * prompt is ªName: º. *Note - currently no prompt is shown.
// shown in the panel. Do not invoke this method within a */
// modal session (runModal or runModalForDirectory:file:) - (NSString *) prompt;
// because the directory information is only updated just
// before the modal session ends.
- (NSString *)directory;
- (NSString *)filename;
// /*
// Target and Action Methods * Setting Directory and File Type
// */
- (void)ok:(id)sender; // target/action of panel's OK button. - (NSString *) requiredFileType;
- (void)cancel:(id)sender; // target/action of panel's cancel button
// /*
// Responding to User Input * Sets the current path name in the Save panel's browser.
// * The path argument must be an absolute path name.
- (void)selectText:(id)sender; */
- (void) setDirectory: (NSString *)path;
// /*
// NSCoding protocol * Specifies the type, a file name extension to be appended to
// * any selected files that don't already have that extension;
- (void)encodeWithCoder:aCoder; * The argument type should not include the period that begins
- initWithCoder:aDecoder; * the extension. Invoke this method each time the Save panel
* is used for another file type within the application.
*/
- (void) setRequiredFileType: (NSString *)type;
/*
* Sets the NSSavePanel's behavior for displaying file packages
* (for example, MyApp.app) to the user. If flag is YES, the
* user is shown files and subdirectories within a file
* package. If NO, the NSSavePanel shows each file package as
* a file, thereby giving no indication that it is a directory.
*/
- (void) setTreatsFilePackagesAsDirectories: (BOOL)flag;
- (BOOL) treatsFilePackagesAsDirectories;
#ifndef STRICT_OPENSTEP
/*
* Validates and possibly reloads the browser columns visible
* in the Save panel by causing the delegate method
* panel: shouldShowFilename: to be invoked. One situation in
* which this method would find use is whey you want the
* browser show only files with certain extensions based on the
* selection made in an accessory-view pop-up list. When the
* user changes the selection, you would invoke this method to
* revalidate the visible columns.
*/
- (void) validateVisibleColumns;
#endif
/*
* Running the NSSavePanel
*/
/*
* Initializes the panel to the directory specified by path
* and, optionally, the file specified by filename, then
* displays it and begins its modal event loop; path and
* filename can be empty strings, but cannot be nil. The
* method invokes Application's runModalForWindow: method with
* self as the argument. Returns NSOKButton (if the user
* clicks the OK button) or NSCancelButton (if the user clicks
* the Cancel button). Do not invoke filename or directory
* within a modal loop because the information that these
* methods fetch is updated only upon return.
*/
- (int) runModalForDirectory: (NSString *)path file: (NSString *)filename;
- (int) runModal;
/*
* Reading Save Information
*/
/*
* Returns the absolute pathname of the directory currently
* shown in the panel. Do not invoke this method within a
* modal session (runModal or runModalForDirectory: file: )
* because the directory information is only updated just
* before the modal session ends.
*/
- (NSString *) directory;
- (NSString *) filename;
/*
* Target and Action Methods
*/
- (void) ok: (id)sender; /* target/action of panel's OK button. */
- (void) cancel: (id)sender; /* target/action of panel's cancel button. */
/*
* Responding to User Input
*/
- (void) selectText: (id)sender;
/*
* NSCoding protocol
*/
- (void) encodeWithCoder: (NSCoder*)aCoder;
- (id) initWithCoder: (NSCoder*)aDecoder;
@end @end
@ -191,21 +216,23 @@ enum {
// Methods Implemented by the Delegate // Methods Implemented by the Delegate
// //
@interface NSObject(NSSavePanelDelegate) @interface NSObject(NSSavePanelDelegate)
// The NSSavePanel sends this message just before the end of a /*
// modal session for each file name displayed or selected * The NSSavePanel sends this message just before the end of a
// (including file names in multiple selections). The delegate * modal session for each file name displayed or selected
// determines whether it wants the file identified by filename; * (including file names in multiple selections). The delegate
// it returns YES if the file name is valid, or NO if the * determines whether it wants the file identified by filename;
// NSSavePanel should stay in its modal loop and wait for the * it returns YES if the file name is valid, or NO if the
// user to type in or select a different file name or names. If * NSSavePanel should stay in its modal loop and wait for the
// the delegate refuses a file name in a multiple selection, * user to type in or select a different file name or names. If
// none of the file names in the selection are accepted. * the delegate refuses a file name in a multiple selection,
- (BOOL)panel:(id)sender isValidFilename:(NSString*)filename; * none of the file names in the selection are accepted.
- (NSComparisonResult)panel:(id)sender */
compareFilename:(NSString *)filename1 - (BOOL) panel: (id)sender isValidFilename: (NSString*)filename;
with:(NSString *)filename2 - (NSComparisonResult) panel: (id)sender
caseSensitive:(BOOL)caseSensitive; compareFilename: (NSString *)filename1
- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename; with: (NSString *)filename2
caseSensitive: (BOOL)caseSensitive;
- (BOOL) panel: (id)sender shouldShowFilename: (NSString *)filename;
@end @end

View file

@ -36,121 +36,148 @@
#include <Foundation/NSArray.h> #include <Foundation/NSArray.h>
#include <AppKit/NSOpenPanel.h> #include <AppKit/NSOpenPanel.h>
// toDo: - canChooseFiles unimplemented /*
// - allowsMultipleSelection untested * toDo: - canChooseFiles unimplemented
// - setCanChooseDirectories untested * - allowsMultipleSelection untested
* - setCanChooseDirectories untested
*/
static NSOpenPanel *gnustep_gui_open_panel = nil; static NSOpenPanel *gnustep_gui_open_panel = nil;
@implementation NSOpenPanel @implementation NSOpenPanel
// /*
// Class methods * Class methods
// */
+ (void)initialize + (void) initialize
{ {
if (self == [NSOpenPanel class]) if (self == [NSOpenPanel class])
[self setVersion:1]; // Initial version {
[self setVersion: 1];
}
} }
// /*
// Accessing the NSOpenPanel * Accessing the NSOpenPanel
// */
+ (NSOpenPanel *)openPanel + (NSOpenPanel *) openPanel
{ {
if (!gnustep_gui_open_panel) if (!gnustep_gui_open_panel)
{ {
// PanelLoader *pl = [PanelLoader panelLoader]; // PanelLoader *pl = [PanelLoader panelLoader];
// gnustep_gui_open_panel = [pl loadPanel: @"NSOpenPanel"]; // gnustep_gui_open_panel = [pl loadPanel: @"NSOpenPanel"];
gnustep_gui_open_panel = [[NSOpenPanel alloc] init]; gnustep_gui_open_panel = [[NSOpenPanel alloc] init];
} }
return gnustep_gui_open_panel; return gnustep_gui_open_panel;
} }
// /*
// Instance methods * Instance methods
// */
// /*
// Initialization * Initialization
// */
- init - (id) init
{ {
self = [super init]; self = [super init];
[self setTitle:@"Open"]; [self setTitle: @"Open"];
[self setCanChooseFiles:YES]; [self setCanChooseFiles: YES];
multiple_select = NO; multiple_select = NO;
return self; return self;
} }
// /*
// Filtering Files * Filtering Files
// */
- (void)setAllowsMultipleSelection:(BOOL)flag - (void) setAllowsMultipleSelection: (BOOL)flag
{ {
allowsMultipleSelection=flag; allowsMultipleSelection=flag;
[browser setAllowsMultipleSelection:flag]; [browser setAllowsMultipleSelection: flag];
} }
-(BOOL) allowsMultipleSelection { return allowsMultipleSelection; } - (BOOL) 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]; }
//
// Querying the Chosen Files
//
- (NSArray *)filenames
{ {
if(!allowsMultipleSelection) return 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;
}
} }
// - (void) setCanChooseDirectories: (BOOL)flag
// Running the NSOpenPanel
//
- (int)runModalForTypes:(NSArray *)fileTypes
{ {
return [self runModalForDirectory:[self directory] canChooseDirectories = flag;
file: nil
types: fileTypes];
} }
- (int)runModalForDirectory:(NSString *)path - (BOOL) canChooseDirectories
file:(NSString *)name
types:(NSArray *)fileTypes
{ {
if(requiredTypes) return canChooseDirectories;
[requiredTypes autorelease];
requiredTypes = [fileTypes retain];
return [self runModalForDirectory:path file:name];
} }
// - (void) setCanChooseFiles: (BOOL)flag
// Target and Action Methods {
// canChooseFiles = flag;
- (void)ok_ORIGINAL_NOT_USED:(id)sender // excess? fix me FAR }
- (BOOL) canChooseFiles
{
return canChooseFiles;
}
- (NSString*) filename
{
return [browser path];
}
/*
* Querying the Chosen Files
*/
- (NSArray *) filenames
{
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;
}
}
/*
* Running the NSOpenPanel
*/
- (int) runModalForTypes: (NSArray *)fileTypes
{
return [self runModalForDirectory: [self directory]
file: nil
types: fileTypes];
}
- (int) runModalForDirectory: (NSString *)path
file: (NSString *)name
types: (NSArray *)fileTypes
{
if (requiredTypes)
[requiredTypes autorelease];
requiredTypes = [fileTypes retain];
return [self runModalForDirectory: path file: name];
}
/*
* Target and Action Methods
*/
- (void) ok_ORIGINAL_NOT_USED: (id)sender // excess? fix me FAR
{ {
char *sp, files[4096], *p; char *sp, files[4096], *p;
NSMutableString *m; NSMutableString *m;
@ -163,42 +190,42 @@ static NSOpenPanel *gnustep_gui_open_panel = nil;
if (sp == NULL) if (sp == NULL)
{ {
// No space then only one file selected // No space then only one file selected
[the_filenames addObject:file_name]; [the_filenames addObject: file_name];
sp = strrchr(files, '\\'); sp = strrchr(files, '\\');
sp++; sp++;
*sp = '\0'; *sp = '\0';
directory = [NSString stringWithCString:files]; directory = [NSString stringWithCString: files];
} }
else else
{ {
// Multiple files selected // Multiple files selected
*sp = '\0'; *sp = '\0';
directory = [NSString stringWithCString:files]; directory = [NSString stringWithCString: files];
p = sp + 1; p = sp + 1;
sp = strchr(p, ' '); sp = strchr(p, ' ');
while (sp != NULL) while (sp != NULL)
{ {
*sp = '\0'; *sp = '\0';
m = [NSMutableString stringWithCString:files]; m = [NSMutableString stringWithCString: files];
[m appendString:@"\\"]; [m appendString: @"\\"];
[m appendString:[NSString stringWithCString:p]]; [m appendString: [NSString stringWithCString: p]];
[the_filenames addObject:m]; [the_filenames addObject: m];
p = sp + 1; p = sp + 1;
sp = strchr(p, ' '); sp = strchr(p, ' ');
}
if (strchr(p, '\0'))
{
m = [NSMutableString stringWithCString:files];
[m appendString:@"\\"];
[m appendString:[NSString stringWithCString:p]];
[the_filenames addObject:m];
}
} }
if (strchr(p, '\0'))
{
m = [NSMutableString stringWithCString: files];
[m appendString: @"\\"];
[m appendString: [NSString stringWithCString: p]];
[the_filenames addObject: m];
}
}
} }
// /*
// NSCoding protocol * NSCoding protocol
// */
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
[super encodeWithCoder: aCoder]; [super encodeWithCoder: aCoder];

View file

@ -46,119 +46,122 @@
#include <AppKit/IMLoading.h> #include <AppKit/IMLoading.h>
#include <AppKit/GMArchiver.h> #include <AppKit/GMArchiver.h>
// toDo: /*
// - interactive directory creation in SavePanel * toDo:
// - accessory view support * - interactive directory creation in SavePanel
// - parse ".hidden" files; array of suffixes of directories treated as single * - accessory view support
// files * - parse ".hidden" files; array of suffixes of directories treated as single
* files
*/
// /*
// Fake class for gmodel * Fake class for gmodel
// */
// /*
// Class variables * Class variables
// */
static NSSavePanel *gnustep_gui_save_panel = nil; static NSSavePanel *gnustep_gui_save_panel = nil;
@interface _SavePanel : NSObject @interface _SavePanel : NSObject
-(void)browser :(NSBrowser *)sender createRowsForColumn:(int)column -(void)browser : (NSBrowser *)sender createRowsForColumn: (int)column
inMatrix:(NSMatrix *)matrix; inMatrix: (NSMatrix *)matrix;
-(void)browser :(NSBrowser *)sender willDisplayCell:(id)cell -(void)browser : (NSBrowser *)sender willDisplayCell: (id)cell
atRow:(int)row atRow: (int)row
column:(int)column; column: (int)column;
@end @end
//====================================================================== /*
// _SavePanel: used for loading gmodels, NSBrowser delegate * _SavePanel: used for loading gmodels, NSBrowser delegate
//====================================================================== */
@implementation _SavePanel @implementation _SavePanel
+ (id)init + (id) init
{ {
NSLog(@"asdasdasd"); NSLog(@"asdasdasd");
return (self = [super init]); return (self = [super init]);
} }
// /*
// Model stuff * Model stuff
// */
- (id)initWithModelUnarchiver :(GMUnarchiver*)unarchiver - (id) initWithModelUnarchiver : (GMUnarchiver*)unarchiver
{ {
if (!gnustep_gui_save_panel) if (!gnustep_gui_save_panel)
gnustep_gui_save_panel = [unarchiver decodeObjectWithName:@"panel"]; gnustep_gui_save_panel = [unarchiver decodeObjectWithName: @"panel"];
return self; return self;
} }
- (void)encodeWithModelArchiver :(GMArchiver *)archiver - (void) encodeWithModelArchiver : (GMArchiver *)archiver
{ {
if (gnustep_gui_save_panel) if (gnustep_gui_save_panel)
[archiver encodeObject:gnustep_gui_save_panel withName:@"panel"]; [archiver encodeObject: gnustep_gui_save_panel withName: @"panel"];
} }
// //
// Browser stuff // Browser stuff
- (void)browser:(NSBrowser*)sender createRowsForColumn:(int)column - (void) browser: (NSBrowser*)sender createRowsForColumn: (int)column
inMatrix:(NSMatrix*)matrix inMatrix: (NSMatrix*)matrix
{ {
NSFileManager *fm = [NSFileManager defaultManager]; NSFileManager *fm = [NSFileManager defaultManager];
NSString *ptc = [sender pathToColumn: column]; NSString *ptc = [sender pathToColumn: column];
NSArray *files = [fm directoryContentsAtPath: ptc]; NSArray *files = [fm directoryContentsAtPath: ptc];
int i, count = [files count]; unsigned i, count = [files count];
if (!count) if (!count)
return; return;
[matrix addColumn]; [matrix addColumn];
for (i=0 ; i<count ; ++i) { for (i =0; i<count; ++i)
id cell; {
BOOL exists = NO, is_dir = NO; id cell;
NSMutableString *s = [[[NSMutableString alloc] initWithString: ptc] BOOL exists = NO, is_dir = NO;
autorelease]; NSMutableString *s = [[[NSMutableString alloc] initWithString: ptc]
autorelease];
if (i != 0) if (i != 0)
[matrix insertRow:i]; [matrix insertRow: i];
cell = [matrix cellAtRow:i column:0]; cell = [matrix cellAtRow: i column: 0];
[cell setStringValue:[files objectAtIndex:i]]; [cell setStringValue: [files objectAtIndex: i]];
[s appendString: @"/"]; [s appendString: @"/"];
[s appendString: [files objectAtIndex: i]]; [s appendString: [files objectAtIndex: i]];
exists = [fm fileExistsAtPath: s isDirectory: &is_dir]; exists = [fm fileExistsAtPath: s isDirectory: &is_dir];
if (exists && is_dir) if (exists && is_dir)
[cell setLeaf:NO]; [cell setLeaf: NO];
else else
[cell setLeaf:YES]; [cell setLeaf: YES];
} }
} }
- (void)browser:(NSBrowser*)sender willDisplayCell:(id)cell - (void) browser: (NSBrowser*)sender willDisplayCell: (id)cell
atRow:(int)row atRow: (int)row
column:(int)column column: (int)column
{ {
} }
- (BOOL)browser:(NSBrowser *)sender selectCellWithString:(NSString *)title - (BOOL) browser: (NSBrowser *)sender selectCellWithString: (NSString *)title
inColumn:(int)column inColumn: (int)column
{ {
NSString *ptc = [sender pathToColumn: column]; NSString *ptc = [sender pathToColumn: column];
NSMutableString *s = [[[NSMutableString alloc] initWithString:ptc] NSMutableString *s = [[[NSMutableString alloc] initWithString: ptc]
autorelease]; autorelease];
NSLog(@"-browser:selectCellWithString {%@}", title); NSLog(@"-browser: selectCellWithString {%@}", title);
if (column > 0) if (column > 0)
[s appendString: @"/"]; [s appendString: @"/"];
[s appendString:title]; [s appendString: title];
NSLog(@"-browser: source path: %@", s); NSLog(@"-browser: source path: %@", s);
} }
- (BOOL)fileManager:(NSFileManager*)fileManager - (BOOL) fileManager: (NSFileManager*)fileManager
shouldProceedAfterError:(NSDictionary*)errorDictionary shouldProceedAfterError: (NSDictionary*)errorDictionary
{ {
return YES; return YES;
} }
@end @end
@ -166,268 +169,271 @@ static NSSavePanel *gnustep_gui_save_panel = nil;
// Save panel // Save panel
@implementation NSSavePanel @implementation NSSavePanel
// /*
// Class methods * Class methods
// */
+ (void)initialize + (void) initialize
{ {
if (self == [NSSavePanel class]) if (self == [NSSavePanel class])
[self setVersion:1]; //initial version [self setVersion: 1]; //initial version
} }
// /*
// Creating an NSSavePanel * Creating an NSSavePanel
// */
+ (NSSavePanel *)savePanel + (NSSavePanel *) savePanel
{ {
if(!gnustep_gui_save_panel) { if (!gnustep_gui_save_panel)
if (![GMModel loadIMFile :@"SavePanel" owner:[_SavePanel alloc]]) { {
fprintf(stderr, "Cannot open save panel model file\n"); if (![GMModel loadIMFile : @"SavePanel" owner: [_SavePanel alloc]])
exit(1); {
NSLog(@"Cannot open save panel model file\n");
exit(1);
} }
} }
return gnustep_gui_save_panel; return gnustep_gui_save_panel;
} }
// /*
// Instance methods * Instance methods
// */
// /*
// Initialization * Initialization
// */
- (void)setDefaults - (void) setDefaults
{ {
directory = @"\\"; directory = @"\\";
file_name = @""; file_name = @"";
_accessoryView = nil; _accessoryView = nil;
panel_title = @"Save File"; panel_title = @"Save File";
panel_prompt = @""; panel_prompt = @"";
required_type = nil; required_type = nil;
treatsFilePackagesAsDirectories = YES; treatsFilePackagesAsDirectories = YES;
} }
- init - (id) init
{ {
[super init]; [super init];
[self setDefaults]; [self setDefaults];
return self; return self;
} }
// /*
// Customizing the NSSavePanel * Customizing the NSSavePanel
// */
- (void)setAccessoryView:(NSView *)aView - (void) setAccessoryView: (NSView *)aView
{ {
_accessoryView = aView; _accessoryView = aView;
} }
- (NSView *)accessoryView - (NSView *) accessoryView
{ {
return _accessoryView; return _accessoryView;
} }
-(void) validateVisibleColumns -(void) validateVisibleColumns
{ {
} }
- (void)setTitle:(NSString *)title - (void) setTitle: (NSString *)title
{ {
[titleField setStringValue:title]; [titleField setStringValue: title];
} }
- (NSString *)title - (NSString *) title
{ {
return [titleField stringValue]; return [titleField stringValue];
} }
- (void)setPrompt:(NSString *)prompt - (void) setPrompt: (NSString *)prompt
{ // does currently not work since i went with NSTextField instead of NSForm {
[[form cell] setTitle:prompt]; // does currently not work since i went with NSTextField instead of NSForm
[[form cell] setTitle: prompt];
} }
- (NSString *)prompt - (NSString *) prompt
{ {
return [[form cell] title]; return [[form cell] title];
} }
//
// Setting Directory and File Type
//
- (NSString *)requiredFileType
{
if(!requiredTypes || ![requiredTypes count])
return nil;
return [requiredTypes objectAtIndex:0];
}
- (void)setDirectory:(NSString *)path
{
NSString *standardizedPath=[path stringByStandardizingPath];
if(standardizedPath)
{
[browser setPath:standardizedPath];
if(lastValidPath)
[lastValidPath autorelease];
lastValidPath=[path retain];
}
}
- (void)setRequiredFileType:(NSString *)type
{
if(requiredTypes)
[requiredTypes autorelease];
requiredTypes=[[NSArray arrayWithObject:type] retain];
}
- (void)setTreatsFilePackagesAsDirectories:(BOOL)flag
{
treatsFilePackagesAsDirectories=flag;
}
- (BOOL)treatsFilePackagesAsDirectories
{
return treatsFilePackagesAsDirectories;
}
//
// Running the NSSavePanel
//
- (int)runModalForDirectory:(NSString *)path file:(NSString *)name
{
int ret;
//[browser loadColumnZero];
[self setDirectory:path];
//[browser setPath:[NSString stringWithFormat:@"%@/%@",
//[self directory], name]];
//[form setStringValue:name];
[self selectText:self]; // or should it be browser?
/* /*
if([self class] == [NSOpenPanel class]) * Setting Directory and File Type
[okButton setEnabled: */
([browser selectedCell] && [self canChooseDirectories]) || - (NSString *) requiredFileType
[[browser selectedCell] isLeaf]]; {
if (!requiredTypes || ![requiredTypes count])
return nil;
return [requiredTypes objectAtIndex: 0];
}
- (void) setDirectory: (NSString *)path
{
NSString *standardizedPath = [path stringByStandardizingPath];
if (standardizedPath)
{
[browser setPath: standardizedPath];
if (lastValidPath)
[lastValidPath autorelease];
lastValidPath = [path retain];
}
}
- (void) setRequiredFileType: (NSString *)type
{
if (requiredTypes)
[requiredTypes autorelease];
requiredTypes = [[NSArray arrayWithObject: type] retain];
}
- (void) setTreatsFilePackagesAsDirectories: (BOOL)flag
{
treatsFilePackagesAsDirectories = flag;
}
- (BOOL) treatsFilePackagesAsDirectories
{
return treatsFilePackagesAsDirectories;
}
/*
* Running the NSSavePanel
*/
- (int) runModalForDirectory: (NSString *)path file: (NSString *)name
{
int ret;
//[browser loadColumnZero];
[self setDirectory: path];
//[browser setPath: [NSString stringWithFormat: @"%@/%@",
//[self directory], name]];
//[form setStringValue: name];
[self selectText: self]; // or should it be browser?
/*
if ([self class] == [NSOpenPanel class])
[okButton setEnabled:
([browser selectedCell] && [self canChooseDirectories]) ||
[[browser selectedCell] isLeaf]];
*/ */
[self makeKeyAndOrderFront:self]; [self makeKeyAndOrderFront: self];
ret = [[NSApplication sharedApplication] runModalForWindow:self]; ret = [[NSApplication sharedApplication] runModalForWindow: self];
// replace warning // replace warning
/* /*
if([self class] == [NSSavePanel class] && if ([self class] == [NSSavePanel class]
[[browser selectedCell] isLeaf] && ret == NSOKButton) { && [[browser selectedCell] isLeaf] && ret == NSOKButton)
//if(NSRunAlertPanel(@"Save",@"The file %@ in %@ exists. Replace it?", {
//dafplace",@"Cancel",nil,[form stringValue], //if (NSRunAlertPanel(@"Save",@"The file %@ in %@ exists. Replace it?",
// [self directory]) == NSAlertAlternateReturn) //dafplace",@"Cancel",nil,[form stringValue],
return NSCancelButton; // [self directory]) == NSAlertAlternateReturn)
return NSCancelButton;
} }
*/ */
return ret; return ret;
} }
- (int)runModal - (int) runModal
{ {
return [self runModalForDirectory:[self directory] file:@""]; return [self runModalForDirectory: [self directory] file: @""];
} }
// /*
// Reading Save Information * Reading Save Information
// */
- (NSString *)directory - (NSString *) directory
{ {
NSString *path; NSString *path;
if([[browser selectedCell] isLeaf]) // remove file component of path if ([[browser selectedCell] isLeaf]) // remove file component of path
path=[[browser path] stringByDeletingLastPathComponent]; path = [[browser path] stringByDeletingLastPathComponent];
else else
path=[browser path]; path = [browser path];
if(![path length]) if (![path length])
return lastValidPath; return lastValidPath;
else else
return path; return path;
} }
- (NSString *)filename - (NSString *) filename
{ {
NSString *ret = [NSString stringWithFormat:@"%@/%@",[self directory], NSString *ret = [NSString stringWithFormat: @"%@/%@",[self directory],
[form stringValue]]; [form stringValue]];
// if path does not exist ask the user to
// create each missing directory
if([[self requiredFileType] length] && ![ret hasSuffix:[NSString
stringWithFormat:@".%@",[self requiredFileType]]])
ret = [NSString stringWithFormat:@"%@.%@",ret,[self requiredFileType]];
return [ret stringByExpandingTildeInPath]; /* if path does not exist ask the user to create each missing directory */
if ([[self requiredFileType] length] && ![ret hasSuffix: [NSString
stringWithFormat: @".%@",[self requiredFileType]]])
ret = [NSString stringWithFormat: @"%@.%@",ret,[self requiredFileType]];
return [ret stringByExpandingTildeInPath];
} }
// /*
// Target and Action Methods * Target and Action Methods
// */
- (void)ok:(id)sender - (void) ok: (id)sender
{ // iterate through selection if a multiple selection
if(![self panel:self isValidFilename:[self filename]])
return;
[[NSApplication sharedApplication] stopModalWithCode:NSOKButton];
[self orderOut:self];
}
- (void)cancel:(id)sender
{ {
[[NSApplication sharedApplication] stopModalWithCode:NSCancelButton]; if (![self panel: self isValidFilename: [self filename]])
[self orderOut:self]; return;
[[NSApplication sharedApplication] stopModalWithCode: NSOKButton];
[self orderOut: self];
} }
// - (void) cancel: (id)sender
// Responding to User Input
//
- (void)selectText:(id)sender
{ {
[form selectText:sender]; [[NSApplication sharedApplication] stopModalWithCode: NSCancelButton];
[self orderOut: self];
} }
// /*
// Methods Implemented by the Delegate * Responding to User Input
// */
- (NSComparisonResult)panel:(id)sender - (void) selectText: (id)sender
compareFilename:(NSString *)filename1
with:(NSString *)filename2
caseSensitive:(BOOL)caseSensitive
{ {
if ([delegate respondsToSelector: [form selectText: sender];
@selector(panel:compareFilename:with:caseSensitive:)])
return [delegate panel:sender
compareFilename:filename1
with:filename2
caseSensitive:caseSensitive];
return NSOrderedSame;
} }
- (BOOL)panel:(id)sender /*
shouldShowFilename:(NSString *)filename * Methods Implemented by the Delegate
*/
- (NSComparisonResult) panel: (id)sender
compareFilename: (NSString *)filename1
with: (NSString *)filename2
caseSensitive: (BOOL)caseSensitive
{ {
if ([delegate respondsToSelector:@selector(panel:shouldShowFilename:)]) if ([delegate respondsToSelector:
return [delegate panel:sender shouldShowFilename:filename]; @selector(panel: compareFilename: with: caseSensitive: )])
return [delegate panel: sender
compareFilename: filename1
with: filename2
caseSensitive: caseSensitive];
return NSOrderedSame;
}
- (BOOL) panel: (id)sender shouldShowFilename: (NSString *)filename
{
if ([delegate respondsToSelector: @selector(panel: shouldShowFilename: )])
return [delegate panel: sender shouldShowFilename: filename];
return NO; return NO;
} }
- (BOOL)panel:(id)sender isValidFilename:(NSString*)filename - (BOOL) panel: (id)sender isValidFilename: (NSString*)filename
{ {
if([self delegate] && [[self delegate] if ([self delegate] && [[self delegate]
respondsToSelector:@selector(panel:isValidFilename:)]) respondsToSelector: @selector(panel: isValidFilename: )])
return [[self delegate] panel:sender isValidFilename:filename]; return [[self delegate] panel: sender isValidFilename: filename];
return YES; return YES;
} }
// /*
// NSCoding protocol * NSCoding protocol
// */
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
[aCoder encodeObject: _accessoryView]; [aCoder encodeObject: _accessoryView];
@ -436,7 +442,7 @@ shouldShowFilename:(NSString *)filename
[aCoder encodeObject: directory]; [aCoder encodeObject: directory];
[aCoder encodeObject: file_name]; [aCoder encodeObject: file_name];
[aCoder encodeObject: required_type]; [aCoder encodeObject: required_type];
[aCoder encodeValueOfObjCType: @encode(BOOL) at:&required_type]; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &required_type];
[aCoder encodeConditionalObject: delegate]; [aCoder encodeConditionalObject: delegate];
} }
@ -448,7 +454,7 @@ shouldShowFilename:(NSString *)filename
directory = [aDecoder decodeObject]; directory = [aDecoder decodeObject];
file_name = [aDecoder decodeObject]; file_name = [aDecoder decodeObject];
required_type = [aDecoder decodeObject]; required_type = [aDecoder decodeObject];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at:&required_type]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &required_type];
delegate = [aDecoder decodeObject]; delegate = [aDecoder decodeObject];
return self; return self;