mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 13:10:59 +00:00
Changfes suggested by Marc.Champesme@lipn.univ-paris13.fr
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4125 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
39c0e63fbf
commit
6d2240bb29
5 changed files with 620 additions and 544 deletions
|
@ -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>
|
||||
|
||||
* Model/test.m: fixed NSGraphic's'Context type-o.
|
||||
|
|
|
@ -45,6 +45,13 @@ enum {
|
|||
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>
|
||||
{
|
||||
// Attributes
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
|
||||
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>
|
||||
Date: 1996
|
||||
Author: Daniel Bðhringer <boehring@biomed.ruhr-uni-bochum.de>
|
||||
Date: August 1998
|
||||
Source by Daniel Bðhringer integrated into Scott Christley's preliminary
|
||||
implementation by Felipe A. Rodriguez <far@ix.netcom.com>
|
||||
implementation by Felipe A. Rodriguez <far@ix.netcom.com>
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -56,156 +56,183 @@ enum {
|
|||
|
||||
@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
|
||||
id form;
|
||||
id homeButton;
|
||||
id okButton;
|
||||
id mountButton,unmountButton;
|
||||
id separator;
|
||||
id titleField;
|
||||
NSString *lastValidPath;
|
||||
NSArray *requiredTypes;
|
||||
NSSet *typeTable;
|
||||
// Attributes
|
||||
id panelImage;
|
||||
id panelTitleField;
|
||||
id panelPromptField;
|
||||
id panelBrowser;
|
||||
id panelFileNameField;
|
||||
NSString *_directory;
|
||||
NSString *_fileName;
|
||||
NSString *_requiredType;
|
||||
BOOL _filePackage;
|
||||
BOOL _delegateRespondsToCompare;
|
||||
BOOL _delegateRespondsToShow;
|
||||
BOOL _delegateRespondsToValid;
|
||||
NSView *_accessoryView;
|
||||
BOOL treatsFilePackagesAsDirectories;
|
||||
|
||||
// Attributes
|
||||
id panelImage; // from Scott's source
|
||||
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;
|
||||
// Reserved for back-end use
|
||||
void *be_save_reserved;
|
||||
}
|
||||
|
||||
//
|
||||
// Creating an NSSavePanel
|
||||
//
|
||||
+ (NSSavePanel *)savePanel; // Returns an instance of NSSavePanel,
|
||||
// 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;
|
||||
/*
|
||||
* Creating an NSSavePanel
|
||||
*/
|
||||
+ (NSSavePanel *) savePanel;
|
||||
|
||||
//
|
||||
// Setting Directory and File Type
|
||||
//
|
||||
- (NSString *)requiredFileType;
|
||||
// Sets the current path name in the Save panel's browser.
|
||||
// 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;
|
||||
/*
|
||||
* Customizing the NSSavePanel
|
||||
*/
|
||||
- (void) setAccessoryView: (NSView *)aView;
|
||||
- (NSView *) accessoryView;
|
||||
|
||||
//
|
||||
// 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;
|
||||
/*
|
||||
* 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;
|
||||
|
||||
//
|
||||
// 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;
|
||||
/*
|
||||
* 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;
|
||||
|
||||
//
|
||||
// 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
|
||||
/*
|
||||
* Setting Directory and File Type
|
||||
*/
|
||||
- (NSString *) requiredFileType;
|
||||
|
||||
//
|
||||
// Responding to User Input
|
||||
//
|
||||
- (void)selectText:(id)sender;
|
||||
/*
|
||||
* Sets the current path name in the Save panel's browser.
|
||||
* The path argument must be an absolute path name.
|
||||
*/
|
||||
- (void) setDirectory: (NSString *)path;
|
||||
|
||||
//
|
||||
// NSCoding protocol
|
||||
//
|
||||
- (void)encodeWithCoder:aCoder;
|
||||
- initWithCoder:aDecoder;
|
||||
/*
|
||||
* 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;
|
||||
|
||||
#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
|
||||
|
||||
//
|
||||
// Methods Implemented by the Delegate
|
||||
// Methods Implemented by the Delegate
|
||||
//
|
||||
@interface NSObject(NSSavePanelDelegate)
|
||||
// The NSSavePanel sends this message just before the end of a
|
||||
// modal session for each file name displayed or selected
|
||||
// (including file names in multiple selections). The delegate
|
||||
// determines whether it wants the file identified by filename;
|
||||
// it returns YES if the file name is valid, or NO if the
|
||||
// NSSavePanel should stay in its modal loop and wait for the
|
||||
// user to type in or select a different file name or names. If
|
||||
// the delegate refuses a file name in a multiple selection,
|
||||
// none of the file names in the selection are accepted.
|
||||
- (BOOL)panel:(id)sender isValidFilename:(NSString*)filename;
|
||||
- (NSComparisonResult)panel:(id)sender
|
||||
compareFilename:(NSString *)filename1
|
||||
with:(NSString *)filename2
|
||||
caseSensitive:(BOOL)caseSensitive;
|
||||
- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename;
|
||||
/*
|
||||
* The NSSavePanel sends this message just before the end of a
|
||||
* modal session for each file name displayed or selected
|
||||
* (including file names in multiple selections). The delegate
|
||||
* determines whether it wants the file identified by filename;
|
||||
* it returns YES if the file name is valid, or NO if the
|
||||
* NSSavePanel should stay in its modal loop and wait for the
|
||||
* user to type in or select a different file name or names. If
|
||||
* the delegate refuses a file name in a multiple selection,
|
||||
* none of the file names in the selection are accepted.
|
||||
*/
|
||||
- (BOOL) panel: (id)sender isValidFilename: (NSString*)filename;
|
||||
- (NSComparisonResult) panel: (id)sender
|
||||
compareFilename: (NSString *)filename1
|
||||
with: (NSString *)filename2
|
||||
caseSensitive: (BOOL)caseSensitive;
|
||||
- (BOOL) panel: (id)sender shouldShowFilename: (NSString *)filename;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -10,15 +10,15 @@
|
|||
Author: Daniel Bðhringer <boehring@biomed.ruhr-uni-bochum.de>
|
||||
Date: August 1998
|
||||
Source by Daniel Bðhringer integrated into Scott Christley's preliminary
|
||||
implementation by Felipe A. Rodriguez <far@ix.netcom.com>
|
||||
|
||||
implementation by Felipe A. Rodriguez <far@ix.netcom.com>
|
||||
|
||||
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
|
||||
|
@ -28,7 +28,7 @@
|
|||
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.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <gnustep/gui/config.h>
|
||||
#include <string.h>
|
||||
|
@ -36,121 +36,148 @@
|
|||
#include <Foundation/NSArray.h>
|
||||
#include <AppKit/NSOpenPanel.h>
|
||||
|
||||
// toDo: - canChooseFiles unimplemented
|
||||
// - allowsMultipleSelection untested
|
||||
// - setCanChooseDirectories untested
|
||||
/*
|
||||
* toDo: - canChooseFiles unimplemented
|
||||
* - allowsMultipleSelection untested
|
||||
* - setCanChooseDirectories untested
|
||||
*/
|
||||
|
||||
static NSOpenPanel *gnustep_gui_open_panel = nil;
|
||||
|
||||
@implementation NSOpenPanel
|
||||
|
||||
//
|
||||
// Class methods
|
||||
//
|
||||
+ (void)initialize
|
||||
/*
|
||||
* Class methods
|
||||
*/
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSOpenPanel class])
|
||||
[self setVersion:1]; // Initial version
|
||||
if (self == [NSOpenPanel class])
|
||||
{
|
||||
[self setVersion: 1];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Accessing the NSOpenPanel
|
||||
//
|
||||
+ (NSOpenPanel *)openPanel
|
||||
/*
|
||||
* Accessing the NSOpenPanel
|
||||
*/
|
||||
+ (NSOpenPanel *) openPanel
|
||||
{
|
||||
if (!gnustep_gui_open_panel)
|
||||
{
|
||||
if (!gnustep_gui_open_panel)
|
||||
{
|
||||
// PanelLoader *pl = [PanelLoader panelLoader];
|
||||
// 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
|
||||
//
|
||||
- init
|
||||
{
|
||||
self = [super init];
|
||||
[self setTitle:@"Open"];
|
||||
[self setCanChooseFiles:YES];
|
||||
multiple_select = NO;
|
||||
/*
|
||||
* Initialization
|
||||
*/
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
[self setTitle: @"Open"];
|
||||
[self setCanChooseFiles: YES];
|
||||
multiple_select = NO;
|
||||
|
||||
return self;
|
||||
return self;
|
||||
}
|
||||
|
||||
//
|
||||
// Filtering Files
|
||||
//
|
||||
- (void)setAllowsMultipleSelection:(BOOL)flag
|
||||
{
|
||||
allowsMultipleSelection=flag;
|
||||
[browser setAllowsMultipleSelection:flag];
|
||||
/*
|
||||
* Filtering Files
|
||||
*/
|
||||
- (void) setAllowsMultipleSelection: (BOOL)flag
|
||||
{
|
||||
allowsMultipleSelection=flag;
|
||||
[browser setAllowsMultipleSelection: flag];
|
||||
}
|
||||
|
||||
-(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]; }
|
||||
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
- (BOOL) allowsMultipleSelection
|
||||
{
|
||||
return allowsMultipleSelection;
|
||||
}
|
||||
|
||||
//
|
||||
// Running the NSOpenPanel
|
||||
//
|
||||
- (int)runModalForTypes:(NSArray *)fileTypes
|
||||
{
|
||||
return [self runModalForDirectory:[self directory]
|
||||
file: nil
|
||||
types: fileTypes];
|
||||
- (void) setCanChooseDirectories: (BOOL)flag
|
||||
{
|
||||
canChooseDirectories = flag;
|
||||
}
|
||||
|
||||
- (int)runModalForDirectory:(NSString *)path
|
||||
file:(NSString *)name
|
||||
types:(NSArray *)fileTypes
|
||||
{
|
||||
if(requiredTypes)
|
||||
[requiredTypes autorelease];
|
||||
requiredTypes = [fileTypes retain];
|
||||
|
||||
return [self runModalForDirectory:path file:name];
|
||||
- (BOOL) canChooseDirectories
|
||||
{
|
||||
return canChooseDirectories;
|
||||
}
|
||||
|
||||
//
|
||||
// Target and Action Methods
|
||||
//
|
||||
- (void)ok_ORIGINAL_NOT_USED:(id)sender // excess? fix me FAR
|
||||
- (void) setCanChooseFiles: (BOOL)flag
|
||||
{
|
||||
canChooseFiles = flag;
|
||||
}
|
||||
|
||||
- (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;
|
||||
NSMutableString *m;
|
||||
|
@ -163,42 +190,42 @@ static NSOpenPanel *gnustep_gui_open_panel = nil;
|
|||
if (sp == NULL)
|
||||
{
|
||||
// No space then only one file selected
|
||||
[the_filenames addObject:file_name];
|
||||
[the_filenames addObject: file_name];
|
||||
sp = strrchr(files, '\\');
|
||||
sp++;
|
||||
*sp = '\0';
|
||||
directory = [NSString stringWithCString:files];
|
||||
directory = [NSString stringWithCString: files];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Multiple files selected
|
||||
*sp = '\0';
|
||||
directory = [NSString stringWithCString:files];
|
||||
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];
|
||||
}
|
||||
{
|
||||
*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
|
||||
//
|
||||
/*
|
||||
* NSCoding protocol
|
||||
*/
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[super encodeWithCoder: aCoder];
|
||||
|
|
|
@ -10,15 +10,15 @@
|
|||
Author: Daniel Bðhringer <boehring@biomed.ruhr-uni-bochum.de>
|
||||
Date: August 1998
|
||||
Source by Daniel Bðhringer integrated into Scott Christley's preliminary
|
||||
implementation by Felipe A. Rodriguez <far@ix.netcom.com>
|
||||
|
||||
implementation by Felipe A. Rodriguez <far@ix.netcom.com>
|
||||
|
||||
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
|
||||
|
@ -28,7 +28,7 @@
|
|||
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.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <gnustep/gui/config.h>
|
||||
#include <string.h>
|
||||
|
@ -46,119 +46,122 @@
|
|||
#include <AppKit/IMLoading.h>
|
||||
#include <AppKit/GMArchiver.h>
|
||||
|
||||
// toDo:
|
||||
// - interactive directory creation in SavePanel
|
||||
// - accessory view support
|
||||
// - parse ".hidden" files; array of suffixes of directories treated as single
|
||||
// files
|
||||
/*
|
||||
* toDo:
|
||||
* - interactive directory creation in SavePanel
|
||||
* - accessory view support
|
||||
* - parse ".hidden" files; array of suffixes of directories treated as single
|
||||
* files
|
||||
*/
|
||||
|
||||
|
||||
//
|
||||
// Fake class for gmodel
|
||||
//
|
||||
//
|
||||
// Class variables
|
||||
//
|
||||
/*
|
||||
* Fake class for gmodel
|
||||
*/
|
||||
/*
|
||||
* Class variables
|
||||
*/
|
||||
static NSSavePanel *gnustep_gui_save_panel = nil;
|
||||
|
||||
@interface _SavePanel : NSObject
|
||||
-(void)browser :(NSBrowser *)sender createRowsForColumn:(int)column
|
||||
inMatrix:(NSMatrix *)matrix;
|
||||
-(void)browser :(NSBrowser *)sender willDisplayCell:(id)cell
|
||||
atRow:(int)row
|
||||
column:(int)column;
|
||||
-(void)browser : (NSBrowser *)sender createRowsForColumn: (int)column
|
||||
inMatrix: (NSMatrix *)matrix;
|
||||
-(void)browser : (NSBrowser *)sender willDisplayCell: (id)cell
|
||||
atRow: (int)row
|
||||
column: (int)column;
|
||||
@end
|
||||
|
||||
//======================================================================
|
||||
// _SavePanel: used for loading gmodels, NSBrowser delegate
|
||||
//======================================================================
|
||||
/*
|
||||
* _SavePanel: used for loading gmodels, NSBrowser delegate
|
||||
*/
|
||||
@implementation _SavePanel
|
||||
|
||||
+ (id)init
|
||||
+ (id) init
|
||||
{
|
||||
NSLog(@"asdasdasd");
|
||||
return (self = [super init]);
|
||||
NSLog(@"asdasdasd");
|
||||
return (self = [super init]);
|
||||
}
|
||||
//
|
||||
// Model stuff
|
||||
//
|
||||
- (id)initWithModelUnarchiver :(GMUnarchiver*)unarchiver
|
||||
/*
|
||||
* Model stuff
|
||||
*/
|
||||
- (id) initWithModelUnarchiver : (GMUnarchiver*)unarchiver
|
||||
{
|
||||
if (!gnustep_gui_save_panel)
|
||||
gnustep_gui_save_panel = [unarchiver decodeObjectWithName:@"panel"];
|
||||
if (!gnustep_gui_save_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)
|
||||
[archiver encodeObject:gnustep_gui_save_panel withName:@"panel"];
|
||||
if (gnustep_gui_save_panel)
|
||||
[archiver encodeObject: gnustep_gui_save_panel withName: @"panel"];
|
||||
}
|
||||
|
||||
//
|
||||
// Browser stuff
|
||||
- (void)browser:(NSBrowser*)sender createRowsForColumn:(int)column
|
||||
inMatrix:(NSMatrix*)matrix
|
||||
- (void) browser: (NSBrowser*)sender createRowsForColumn: (int)column
|
||||
inMatrix: (NSMatrix*)matrix
|
||||
{
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
NSString *ptc = [sender pathToColumn: column];
|
||||
NSArray *files = [fm directoryContentsAtPath: ptc];
|
||||
int i, count = [files count];
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
NSString *ptc = [sender pathToColumn: column];
|
||||
NSArray *files = [fm directoryContentsAtPath: ptc];
|
||||
unsigned i, count = [files count];
|
||||
|
||||
if (!count)
|
||||
return;
|
||||
if (!count)
|
||||
return;
|
||||
|
||||
[matrix addColumn];
|
||||
for (i=0 ; i<count ; ++i) {
|
||||
id cell;
|
||||
BOOL exists = NO, is_dir = NO;
|
||||
NSMutableString *s = [[[NSMutableString alloc] initWithString: ptc]
|
||||
autorelease];
|
||||
[matrix addColumn];
|
||||
for (i =0; i<count; ++i)
|
||||
{
|
||||
id cell;
|
||||
BOOL exists = NO, is_dir = NO;
|
||||
NSMutableString *s = [[[NSMutableString alloc] initWithString: ptc]
|
||||
autorelease];
|
||||
|
||||
if (i != 0)
|
||||
[matrix insertRow:i];
|
||||
|
||||
cell = [matrix cellAtRow:i column:0];
|
||||
[cell setStringValue:[files objectAtIndex:i]];
|
||||
|
||||
[s appendString: @"/"];
|
||||
[s appendString: [files objectAtIndex: i]];
|
||||
exists = [fm fileExistsAtPath: s isDirectory: &is_dir];
|
||||
|
||||
if (exists && is_dir)
|
||||
[cell setLeaf:NO];
|
||||
else
|
||||
[cell setLeaf:YES];
|
||||
if (i != 0)
|
||||
[matrix insertRow: i];
|
||||
|
||||
cell = [matrix cellAtRow: i column: 0];
|
||||
[cell setStringValue: [files objectAtIndex: i]];
|
||||
|
||||
[s appendString: @"/"];
|
||||
[s appendString: [files objectAtIndex: i]];
|
||||
exists = [fm fileExistsAtPath: s isDirectory: &is_dir];
|
||||
|
||||
if (exists && is_dir)
|
||||
[cell setLeaf: NO];
|
||||
else
|
||||
[cell setLeaf: YES];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)browser:(NSBrowser*)sender willDisplayCell:(id)cell
|
||||
atRow:(int)row
|
||||
column:(int)column
|
||||
- (void) browser: (NSBrowser*)sender willDisplayCell: (id)cell
|
||||
atRow: (int)row
|
||||
column: (int)column
|
||||
{
|
||||
}
|
||||
|
||||
- (BOOL)browser:(NSBrowser *)sender selectCellWithString:(NSString *)title
|
||||
inColumn:(int)column
|
||||
- (BOOL) browser: (NSBrowser *)sender selectCellWithString: (NSString *)title
|
||||
inColumn: (int)column
|
||||
{
|
||||
NSString *ptc = [sender pathToColumn: column];
|
||||
NSMutableString *s = [[[NSMutableString alloc] initWithString:ptc]
|
||||
autorelease];
|
||||
NSString *ptc = [sender pathToColumn: column];
|
||||
NSMutableString *s = [[[NSMutableString alloc] initWithString: ptc]
|
||||
autorelease];
|
||||
|
||||
NSLog(@"-browser:selectCellWithString {%@}", title);
|
||||
NSLog(@"-browser: selectCellWithString {%@}", title);
|
||||
|
||||
if (column > 0)
|
||||
[s appendString: @"/"];
|
||||
[s appendString:title];
|
||||
if (column > 0)
|
||||
[s appendString: @"/"];
|
||||
[s appendString: title];
|
||||
|
||||
NSLog(@"-browser: source path: %@", s);
|
||||
NSLog(@"-browser: source path: %@", s);
|
||||
}
|
||||
|
||||
- (BOOL)fileManager:(NSFileManager*)fileManager
|
||||
shouldProceedAfterError:(NSDictionary*)errorDictionary
|
||||
- (BOOL) fileManager: (NSFileManager*)fileManager
|
||||
shouldProceedAfterError: (NSDictionary*)errorDictionary
|
||||
{
|
||||
return YES;
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -166,268 +169,271 @@ static NSSavePanel *gnustep_gui_save_panel = nil;
|
|||
// Save panel
|
||||
@implementation NSSavePanel
|
||||
|
||||
//
|
||||
// Class methods
|
||||
//
|
||||
+ (void)initialize
|
||||
/*
|
||||
* Class methods
|
||||
*/
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSSavePanel class])
|
||||
[self setVersion:1]; //initial version
|
||||
[self setVersion: 1]; //initial version
|
||||
}
|
||||
|
||||
//
|
||||
// Creating an NSSavePanel
|
||||
//
|
||||
+ (NSSavePanel *)savePanel
|
||||
{
|
||||
if(!gnustep_gui_save_panel) {
|
||||
if (![GMModel loadIMFile :@"SavePanel" owner:[_SavePanel alloc]]) {
|
||||
fprintf(stderr, "Cannot open save panel model file\n");
|
||||
exit(1);
|
||||
/*
|
||||
* Creating an NSSavePanel
|
||||
*/
|
||||
+ (NSSavePanel *) savePanel
|
||||
{
|
||||
if (!gnustep_gui_save_panel)
|
||||
{
|
||||
if (![GMModel loadIMFile : @"SavePanel" owner: [_SavePanel alloc]])
|
||||
{
|
||||
NSLog(@"Cannot open save panel model file\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
return gnustep_gui_save_panel;
|
||||
return gnustep_gui_save_panel;
|
||||
}
|
||||
|
||||
//
|
||||
// Instance methods
|
||||
//
|
||||
//
|
||||
// Initialization
|
||||
//
|
||||
- (void)setDefaults
|
||||
/*
|
||||
* Instance methods
|
||||
*/
|
||||
/*
|
||||
* Initialization
|
||||
*/
|
||||
- (void) setDefaults
|
||||
{
|
||||
directory = @"\\";
|
||||
file_name = @"";
|
||||
_accessoryView = nil;
|
||||
panel_title = @"Save File";
|
||||
panel_prompt = @"";
|
||||
required_type = nil;
|
||||
treatsFilePackagesAsDirectories = YES;
|
||||
directory = @"\\";
|
||||
file_name = @"";
|
||||
_accessoryView = nil;
|
||||
panel_title = @"Save File";
|
||||
panel_prompt = @"";
|
||||
required_type = nil;
|
||||
treatsFilePackagesAsDirectories = YES;
|
||||
}
|
||||
|
||||
- init
|
||||
- (id) init
|
||||
{
|
||||
[super init];
|
||||
|
||||
[self setDefaults];
|
||||
return self;
|
||||
[super init];
|
||||
|
||||
[self setDefaults];
|
||||
return self;
|
||||
}
|
||||
|
||||
//
|
||||
// Customizing the NSSavePanel
|
||||
//
|
||||
- (void)setAccessoryView:(NSView *)aView
|
||||
/*
|
||||
* Customizing the NSSavePanel
|
||||
*/
|
||||
- (void) setAccessoryView: (NSView *)aView
|
||||
{
|
||||
_accessoryView = aView;
|
||||
_accessoryView = aView;
|
||||
}
|
||||
|
||||
- (NSView *)accessoryView
|
||||
- (NSView *) accessoryView
|
||||
{
|
||||
return _accessoryView;
|
||||
return _accessoryView;
|
||||
}
|
||||
|
||||
-(void) validateVisibleColumns
|
||||
{
|
||||
}
|
||||
|
||||
- (void)setTitle:(NSString *)title
|
||||
{
|
||||
[titleField setStringValue:title];
|
||||
- (void) setTitle: (NSString *)title
|
||||
{
|
||||
[titleField setStringValue: title];
|
||||
}
|
||||
|
||||
- (NSString *)title
|
||||
{
|
||||
return [titleField stringValue];
|
||||
- (NSString *) title
|
||||
{
|
||||
return [titleField stringValue];
|
||||
}
|
||||
|
||||
- (void)setPrompt:(NSString *)prompt
|
||||
{ // does currently not work since i went with NSTextField instead of NSForm
|
||||
[[form cell] setTitle:prompt];
|
||||
- (void) setPrompt: (NSString *)prompt
|
||||
{
|
||||
// does currently not work since i went with NSTextField instead of NSForm
|
||||
[[form cell] setTitle: prompt];
|
||||
}
|
||||
|
||||
- (NSString *)prompt
|
||||
{
|
||||
return [[form cell] title];
|
||||
- (NSString *) prompt
|
||||
{
|
||||
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])
|
||||
[okButton setEnabled:
|
||||
([browser selectedCell] && [self canChooseDirectories]) ||
|
||||
[[browser selectedCell] isLeaf]];
|
||||
* 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])
|
||||
[okButton setEnabled:
|
||||
([browser selectedCell] && [self canChooseDirectories]) ||
|
||||
[[browser selectedCell] isLeaf]];
|
||||
*/
|
||||
[self makeKeyAndOrderFront:self];
|
||||
ret = [[NSApplication sharedApplication] runModalForWindow:self];
|
||||
|
||||
// replace warning
|
||||
[self makeKeyAndOrderFront: self];
|
||||
ret = [[NSApplication sharedApplication] runModalForWindow: self];
|
||||
|
||||
// replace warning
|
||||
/*
|
||||
if([self class] == [NSSavePanel class] &&
|
||||
[[browser selectedCell] isLeaf] && ret == NSOKButton) {
|
||||
//if(NSRunAlertPanel(@"Save",@"The file %@ in %@ exists. Replace it?",
|
||||
//dafplace",@"Cancel",nil,[form stringValue],
|
||||
// [self directory]) == NSAlertAlternateReturn)
|
||||
return NSCancelButton;
|
||||
if ([self class] == [NSSavePanel class]
|
||||
&& [[browser selectedCell] isLeaf] && ret == NSOKButton)
|
||||
{
|
||||
//if (NSRunAlertPanel(@"Save",@"The file %@ in %@ exists. Replace it?",
|
||||
//dafplace",@"Cancel",nil,[form stringValue],
|
||||
// [self directory]) == NSAlertAlternateReturn)
|
||||
return NSCancelButton;
|
||||
}
|
||||
*/
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
- (int)runModal
|
||||
{
|
||||
return [self runModalForDirectory:[self directory] file:@""];
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Save Information
|
||||
//
|
||||
- (NSString *)directory
|
||||
{
|
||||
NSString *path;
|
||||
|
||||
if([[browser selectedCell] isLeaf]) // remove file component of path
|
||||
path=[[browser path] stringByDeletingLastPathComponent];
|
||||
else
|
||||
path=[browser path];
|
||||
|
||||
if(![path length])
|
||||
return lastValidPath;
|
||||
else
|
||||
return path;
|
||||
}
|
||||
|
||||
- (NSString *)filename
|
||||
{
|
||||
NSString *ret = [NSString stringWithFormat:@"%@/%@",[self directory],
|
||||
[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];
|
||||
}
|
||||
|
||||
//
|
||||
// Target and Action Methods
|
||||
//
|
||||
- (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];
|
||||
[self orderOut:self];
|
||||
}
|
||||
|
||||
//
|
||||
// Responding to User Input
|
||||
//
|
||||
- (void)selectText:(id)sender
|
||||
{
|
||||
[form selectText:sender];
|
||||
}
|
||||
|
||||
//
|
||||
// Methods Implemented by the Delegate
|
||||
//
|
||||
- (NSComparisonResult)panel:(id)sender
|
||||
compareFilename:(NSString *)filename1
|
||||
with:(NSString *)filename2
|
||||
caseSensitive:(BOOL)caseSensitive
|
||||
- (int) runModal
|
||||
{
|
||||
if ([delegate respondsToSelector:
|
||||
@selector(panel:compareFilename:with:caseSensitive:)])
|
||||
return [delegate panel:sender
|
||||
compareFilename:filename1
|
||||
with:filename2
|
||||
caseSensitive:caseSensitive];
|
||||
|
||||
return NSOrderedSame;
|
||||
return [self runModalForDirectory: [self directory] file: @""];
|
||||
}
|
||||
|
||||
- (BOOL)panel:(id)sender
|
||||
shouldShowFilename:(NSString *)filename
|
||||
/*
|
||||
* Reading Save Information
|
||||
*/
|
||||
- (NSString *) directory
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(panel:shouldShowFilename:)])
|
||||
return [delegate panel:sender shouldShowFilename:filename];
|
||||
NSString *path;
|
||||
|
||||
if ([[browser selectedCell] isLeaf]) // remove file component of path
|
||||
path = [[browser path] stringByDeletingLastPathComponent];
|
||||
else
|
||||
path = [browser path];
|
||||
|
||||
if (![path length])
|
||||
return lastValidPath;
|
||||
else
|
||||
return path;
|
||||
}
|
||||
|
||||
- (NSString *) filename
|
||||
{
|
||||
NSString *ret = [NSString stringWithFormat: @"%@/%@",[self directory],
|
||||
[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];
|
||||
}
|
||||
|
||||
/*
|
||||
* Target and Action Methods
|
||||
*/
|
||||
- (void) ok: (id)sender
|
||||
{
|
||||
if (![self panel: self isValidFilename: [self filename]])
|
||||
return;
|
||||
|
||||
[[NSApplication sharedApplication] stopModalWithCode: NSOKButton];
|
||||
[self orderOut: self];
|
||||
}
|
||||
|
||||
- (void) cancel: (id)sender
|
||||
{
|
||||
[[NSApplication sharedApplication] stopModalWithCode: NSCancelButton];
|
||||
[self orderOut: self];
|
||||
}
|
||||
|
||||
/*
|
||||
* Responding to User Input
|
||||
*/
|
||||
- (void) selectText: (id)sender
|
||||
{
|
||||
[form selectText: sender];
|
||||
}
|
||||
|
||||
/*
|
||||
* Methods Implemented by the Delegate
|
||||
*/
|
||||
- (NSComparisonResult) panel: (id)sender
|
||||
compareFilename: (NSString *)filename1
|
||||
with: (NSString *)filename2
|
||||
caseSensitive: (BOOL)caseSensitive
|
||||
{
|
||||
if ([delegate respondsToSelector:
|
||||
@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;
|
||||
}
|
||||
|
||||
- (BOOL)panel:(id)sender isValidFilename:(NSString*)filename
|
||||
{
|
||||
if([self delegate] && [[self delegate]
|
||||
respondsToSelector:@selector(panel:isValidFilename:)])
|
||||
return [[self delegate] panel:sender isValidFilename:filename];
|
||||
- (BOOL) panel: (id)sender isValidFilename: (NSString*)filename
|
||||
{
|
||||
if ([self delegate] && [[self delegate]
|
||||
respondsToSelector: @selector(panel: isValidFilename: )])
|
||||
return [[self delegate] panel: sender isValidFilename: filename];
|
||||
|
||||
return YES;
|
||||
return YES;
|
||||
}
|
||||
|
||||
//
|
||||
// NSCoding protocol
|
||||
//
|
||||
/*
|
||||
* NSCoding protocol
|
||||
*/
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[aCoder encodeObject: _accessoryView];
|
||||
|
@ -436,7 +442,7 @@ shouldShowFilename:(NSString *)filename
|
|||
[aCoder encodeObject: directory];
|
||||
[aCoder encodeObject: file_name];
|
||||
[aCoder encodeObject: required_type];
|
||||
[aCoder encodeValueOfObjCType: @encode(BOOL) at:&required_type];
|
||||
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &required_type];
|
||||
[aCoder encodeConditionalObject: delegate];
|
||||
}
|
||||
|
||||
|
@ -448,7 +454,7 @@ shouldShowFilename:(NSString *)filename
|
|||
directory = [aDecoder decodeObject];
|
||||
file_name = [aDecoder decodeObject];
|
||||
required_type = [aDecoder decodeObject];
|
||||
[aDecoder decodeValueOfObjCType: @encode(BOOL) at:&required_type];
|
||||
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &required_type];
|
||||
delegate = [aDecoder decodeObject];
|
||||
|
||||
return self;
|
||||
|
|
Loading…
Reference in a new issue