mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 19:10:37 +00:00
Rewritten a lot, in sync with parallel rewriting of NSSavePanel
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5394 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ad2983f3a7
commit
730d755454
1 changed files with 69 additions and 165 deletions
|
@ -48,34 +48,40 @@
|
||||||
#include <AppKit/NSMatrix.h>
|
#include <AppKit/NSMatrix.h>
|
||||||
#include <AppKit/NSOpenPanel.h>
|
#include <AppKit/NSOpenPanel.h>
|
||||||
|
|
||||||
/*
|
static NSOpenPanel *_gs_gui_open_panel = nil;
|
||||||
* TODO: Test Everything More, debug, make sure all delegate's methods
|
|
||||||
* are used; simplify, arrange so no code is repeated between NSOpenPanel
|
|
||||||
* and NSSavePanel; check better prompts, titles, textfield stuff.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Pacify the compiler
|
// Pacify the compiler
|
||||||
@interface NSFileManager (SavePanelExtensions)
|
@interface NSSavePanel (_PrivateMethods)
|
||||||
- (NSArray *) directoryContentsAtPath: (NSString *)path showHidden: (BOOL)flag;
|
- (void) _resetDefaults;
|
||||||
@end
|
|
||||||
|
|
||||||
@interface NSSavePanel (PrivateMethods)
|
|
||||||
- (void) _setDirectory: (NSString *)path updateBrowser: (BOOL)flag;
|
|
||||||
@end
|
@end
|
||||||
//
|
//
|
||||||
|
|
||||||
static NSOpenPanel *_gs_gui_open_panel = nil;
|
@interface NSOpenPanel (_PrivateMethods)
|
||||||
|
- (void) _resetDefaults;
|
||||||
@interface NSOpenPanel (PrivateMethods)
|
- (BOOL) _shouldShowExtension: (NSString *)extension;
|
||||||
- (void) _enableOKButton;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation NSOpenPanel (PrivateMethods)
|
@implementation NSOpenPanel (_PrivateMethods)
|
||||||
- (void) _enableOKButton
|
- (void) _resetDefaults
|
||||||
{
|
{
|
||||||
|
[super _resetDefaults];
|
||||||
|
[self setTitle: @"Open"];
|
||||||
|
[self setCanChooseFiles: YES];
|
||||||
|
[self setCanChooseDirectories: YES];
|
||||||
|
[self setAllowsMultipleSelection: NO];
|
||||||
[_okButton setEnabled: YES];
|
[_okButton setEnabled: YES];
|
||||||
}
|
}
|
||||||
|
// NB: Invoked only for files.
|
||||||
|
- (BOOL) _shouldShowExtension: (NSString *)extension;
|
||||||
|
{
|
||||||
|
if ((_fileTypes) && ([_fileTypes containsObject: extension] == NO))
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
if (_canChooseFiles == NO)
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation NSOpenPanel
|
@implementation NSOpenPanel
|
||||||
|
@ -99,19 +105,8 @@ static NSOpenPanel *_gs_gui_open_panel = nil;
|
||||||
if (!_gs_gui_open_panel)
|
if (!_gs_gui_open_panel)
|
||||||
_gs_gui_open_panel = [[NSOpenPanel alloc] init];
|
_gs_gui_open_panel = [[NSOpenPanel alloc] init];
|
||||||
|
|
||||||
[_gs_gui_open_panel setDirectory: [[NSFileManager defaultManager]
|
[_gs_gui_open_panel _resetDefaults];
|
||||||
currentDirectoryPath]];
|
|
||||||
[_gs_gui_open_panel setPrompt: @"Name:"];
|
|
||||||
[_gs_gui_open_panel setTitle: @"Open"];
|
|
||||||
[_gs_gui_open_panel setRequiredFileType: @""];
|
|
||||||
[_gs_gui_open_panel setTreatsFilePackagesAsDirectories: NO];
|
|
||||||
[_gs_gui_open_panel setDelegate: nil];
|
|
||||||
[_gs_gui_open_panel setAccessoryView: nil];
|
|
||||||
[_gs_gui_open_panel setCanChooseFiles: YES];
|
|
||||||
[_gs_gui_open_panel setCanChooseDirectories: YES];
|
|
||||||
[_gs_gui_open_panel setAllowsMultipleSelection: NO];
|
|
||||||
[_gs_gui_open_panel _enableOKButton];
|
|
||||||
|
|
||||||
return _gs_gui_open_panel;
|
return _gs_gui_open_panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +118,8 @@ static NSOpenPanel *_gs_gui_open_panel = nil;
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dealloc is the same as NSSavePanel
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Filtering Files
|
* Filtering Files
|
||||||
*/
|
*/
|
||||||
|
@ -139,6 +136,7 @@ static NSOpenPanel *_gs_gui_open_panel = nil;
|
||||||
- (void) setCanChooseDirectories: (BOOL)flag
|
- (void) setCanChooseDirectories: (BOOL)flag
|
||||||
{
|
{
|
||||||
_canChooseDirectories = flag;
|
_canChooseDirectories = flag;
|
||||||
|
// TODO: fix the following in NSBrowser
|
||||||
[_browser setAllowsBranchSelection: flag];
|
[_browser setAllowsBranchSelection: flag];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,24 +221,30 @@ static NSOpenPanel *_gs_gui_open_panel = nil;
|
||||||
{
|
{
|
||||||
ASSIGN (_fileTypes, fileTypes);
|
ASSIGN (_fileTypes, fileTypes);
|
||||||
|
|
||||||
|
if (path == nil)
|
||||||
|
{
|
||||||
|
if (_directory)
|
||||||
|
path = _directory;
|
||||||
|
else
|
||||||
|
path= [[NSFileManager defaultManager] currentDirectoryPath];
|
||||||
|
}
|
||||||
|
|
||||||
if (name == nil)
|
if (name == nil)
|
||||||
name = @"";
|
name = @"";
|
||||||
|
|
||||||
if (path == nil)
|
|
||||||
path = @"";
|
|
||||||
|
|
||||||
if (_canChooseDirectories == NO)
|
if (_canChooseDirectories == NO)
|
||||||
{
|
{
|
||||||
BOOL isDir;
|
BOOL isDir;
|
||||||
NSString *file = [path stringByAppendingPathComponent: name];
|
NSString *file = [path stringByAppendingPathComponent: name];
|
||||||
|
|
||||||
if ((![[NSFileManager defaultManager] fileExistsAtPath: file
|
if (([[NSFileManager defaultManager] fileExistsAtPath: file
|
||||||
isDirectory: &isDir])
|
isDirectory: &isDir] == NO)
|
||||||
|| isDir)
|
|| isDir)
|
||||||
[_okButton setEnabled: NO];
|
[_okButton setEnabled: NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [self runModalForDirectory: path file: name];
|
return [self runModalForDirectory: path
|
||||||
|
file: name];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -267,148 +271,48 @@ static NSOpenPanel *_gs_gui_open_panel = nil;
|
||||||
//
|
//
|
||||||
// NSOpenPanel browser delegate methods
|
// NSOpenPanel browser delegate methods
|
||||||
//
|
//
|
||||||
@interface NSOpenPanel (BrowserDelegate)
|
@interface NSOpenPanel (_BrowserDelegate)
|
||||||
- (void) browser: (id)sender
|
|
||||||
createRowsForColumn: (int)column
|
|
||||||
inMatrix: (NSMatrix *)matrix;
|
|
||||||
|
|
||||||
- (BOOL) browser: (NSBrowser *)sender
|
- (BOOL) browser: (NSBrowser *)sender
|
||||||
selectCellWithString: (NSString *)title
|
selectCellWithString: (NSString *)title
|
||||||
inColumn: (int)column;
|
inColumn: (int)column;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation NSOpenPanel (BrowserDelegate)
|
@implementation NSOpenPanel (_BrowserDelegate)
|
||||||
- (void) browser: (id)sender
|
|
||||||
createRowsForColumn: (int)column
|
|
||||||
inMatrix: (NSMatrix *)matrix
|
|
||||||
{
|
|
||||||
NSFileManager *fm = [NSFileManager defaultManager];
|
|
||||||
NSString *path = [sender pathToColumn: column], *file;
|
|
||||||
NSArray *files = [fm directoryContentsAtPath: path showHidden: NO];
|
|
||||||
NSArray *extArray = [NSArray arrayWithObjects: @"app",
|
|
||||||
@"bundle", @"debug", @"palette", @"profile", nil];
|
|
||||||
unsigned i, count;
|
|
||||||
BOOL exists, isDir;
|
|
||||||
NSBrowserCell *cell;
|
|
||||||
NSString *theFile;
|
|
||||||
NSString *theExtension;
|
|
||||||
unsigned int addedRows = 0;
|
|
||||||
|
|
||||||
// if array is empty, just return (nothing to display)
|
|
||||||
if ([files lastObject] == nil)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ([_fileTypes count] > 0)
|
|
||||||
{
|
|
||||||
extArray = [extArray arrayByAddingObjectsFromArray: _fileTypes];
|
|
||||||
}
|
|
||||||
|
|
||||||
// sort list of files to display
|
|
||||||
if (_delegateHasCompareFilter == YES)
|
|
||||||
{
|
|
||||||
int compare(id elem1, id elem2, void *context)
|
|
||||||
{
|
|
||||||
return (int)[_delegate panel: self
|
|
||||||
compareFilename: elem1
|
|
||||||
with: elem2
|
|
||||||
caseSensitive: YES];
|
|
||||||
}
|
|
||||||
files = [files sortedArrayUsingFunction: compare context: nil];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
files = [files sortedArrayUsingSelector: @selector(compare:)];
|
|
||||||
|
|
||||||
count = [files count];
|
|
||||||
for (i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
theFile = [files objectAtIndex: i];
|
|
||||||
theExtension = [theFile pathExtension];
|
|
||||||
|
|
||||||
file = [path stringByAppendingPathComponent: theFile];
|
|
||||||
exists = [fm fileExistsAtPath: file
|
|
||||||
isDirectory: &isDir];
|
|
||||||
|
|
||||||
if (_treatsFilePackagesAsDirectories == NO && isDir == YES)
|
|
||||||
{
|
|
||||||
if ([extArray containsObject: theExtension])
|
|
||||||
isDir = NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isDir)
|
|
||||||
{
|
|
||||||
[matrix insertRow: addedRows];
|
|
||||||
cell = [matrix cellAtRow: addedRows column: 0];
|
|
||||||
[cell setStringValue: theFile];
|
|
||||||
[cell setLeaf: NO];
|
|
||||||
addedRows++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (_canChooseFiles == YES)
|
|
||||||
{
|
|
||||||
if (_fileTypes)
|
|
||||||
if ([_fileTypes containsObject: theExtension] == NO)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
[matrix insertRow: addedRows];
|
|
||||||
cell = [matrix cellAtRow: addedRows column: 0];
|
|
||||||
[cell setStringValue: theFile];
|
|
||||||
[cell setLeaf: YES];
|
|
||||||
addedRows++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BOOL) browser: (NSBrowser *)sender
|
- (BOOL) browser: (NSBrowser *)sender
|
||||||
selectCellWithString: (NSString *)title
|
selectCellWithString: (NSString *)title
|
||||||
inColumn: (int)column
|
inColumn: (int)column
|
||||||
{
|
{
|
||||||
if (([_browser allowsMultipleSelection] == NO)
|
NSMatrix *m;
|
||||||
|| ([[_browser selectedCells] count] == 1))
|
NSArray *c;
|
||||||
|
|
||||||
|
m = [_browser matrixInColumn: column];
|
||||||
|
c = [m selectedCells];
|
||||||
|
|
||||||
|
if ([c count] == 1)
|
||||||
{
|
{
|
||||||
[self _setDirectory: [sender pathToColumn: [_browser lastColumn]]
|
BOOL isLeaf = [[c objectAtIndex: 0] isLeaf];
|
||||||
updateBrowser: NO];
|
|
||||||
|
if (_canChooseDirectories == NO)
|
||||||
ASSIGN (_fullFileName, [sender path]);
|
|
||||||
if (_canChooseDirectories)
|
|
||||||
{
|
{
|
||||||
if ([[sender selectedCell] isLeaf])
|
[_okButton setEnabled: isLeaf];
|
||||||
{
|
return [super browser: sender
|
||||||
[[_form cellAtIndex: 0] setStringValue: title];
|
selectCellWithString: title
|
||||||
[_form display];
|
inColumn: column];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else // _canChooseDirectories
|
||||||
{
|
{
|
||||||
if ([[sender selectedCell] isLeaf])
|
BOOL ret;
|
||||||
{
|
ret = [super browser: sender
|
||||||
[[_form cellAtIndex: 0] setStringValue: title];
|
selectCellWithString: title
|
||||||
[_form display];
|
inColumn: column];
|
||||||
[_okButton setEnabled: YES];
|
if (isLeaf == NO)
|
||||||
}
|
ASSIGN (_fullFileName, _directory);
|
||||||
else
|
return ret;
|
||||||
{
|
|
||||||
[[_form cellAtIndex: 0] setStringValue: nil];
|
|
||||||
[_form display];
|
|
||||||
[_okButton setEnabled: NO];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // Multiple Selection
|
else // Multiple Selection, and it is not the first item of the selection
|
||||||
{
|
{
|
||||||
// This will be useless when NSBrowser works.
|
return YES;
|
||||||
// NSBrowser, when we ask not to allow to select
|
|
||||||
// branches on multiple selections, should select only leaves
|
|
||||||
// when the user is doing a multiple selection.
|
|
||||||
// For now, use the following *unsatisfactory* hack.
|
|
||||||
// (unsatisfactory because if the user selects and then
|
|
||||||
// deselects a directory, we don't re-enable the OK button).
|
|
||||||
if (_canChooseDirectories)
|
|
||||||
if ([[sender selectedCell] isLeaf] == NO)
|
|
||||||
[_okButton setEnabled: NO];
|
|
||||||
}
|
}
|
||||||
return YES;
|
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue