Give private member variable _panel of class Fl_Quartz_Native_File_Chooser_Driver its true type, NSSavePanel*.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12971 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
b8e97d7c28
commit
ca4601031c
@ -29,12 +29,13 @@
|
|||||||
#include <FL/Fl_File_Chooser.H>
|
#include <FL/Fl_File_Chooser.H>
|
||||||
#include <FL/filename.H>
|
#include <FL/filename.H>
|
||||||
#define MAXFILTERS 80
|
#define MAXFILTERS 80
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
class Fl_Quartz_Native_File_Chooser_Driver : public Fl_Native_File_Chooser_Driver {
|
class Fl_Quartz_Native_File_Chooser_Driver : public Fl_Native_File_Chooser_Driver {
|
||||||
private:
|
private:
|
||||||
int _btype; // kind-of browser to show()
|
int _btype; // kind-of browser to show()
|
||||||
int _options; // general options
|
int _options; // general options
|
||||||
void *_panel;
|
NSSavePanel *_panel;
|
||||||
char **_pathnames; // array of pathnames
|
char **_pathnames; // array of pathnames
|
||||||
int _tpathnames; // total pathnames
|
int _tpathnames; // total pathnames
|
||||||
char *_directory; // default pathname to use
|
char *_directory; // default pathname to use
|
||||||
@ -399,13 +400,12 @@ int Fl_Quartz_Native_File_Chooser_Driver::filters() const {
|
|||||||
return(_filt_total);
|
return(_filt_total);
|
||||||
}
|
}
|
||||||
|
|
||||||
#import <Cocoa/Cocoa.h>
|
|
||||||
#define UNLIKELYPREFIX "___fl_very_unlikely_prefix_"
|
#define UNLIKELYPREFIX "___fl_very_unlikely_prefix_"
|
||||||
|
|
||||||
int Fl_Quartz_Native_File_Chooser_Driver::get_saveas_basename(void) {
|
int Fl_Quartz_Native_File_Chooser_Driver::get_saveas_basename(void) {
|
||||||
char *q = strdup( [[[(NSSavePanel*)_panel URL] path] UTF8String] );
|
char *q = strdup( [[[_panel URL] path] UTF8String] );
|
||||||
if ( !(_options & Fl_Native_File_Chooser::SAVEAS_CONFIRM) ) {
|
if ( !(_options & Fl_Native_File_Chooser::SAVEAS_CONFIRM) ) {
|
||||||
const char *d = [[[[(NSSavePanel*)_panel URL] path] stringByDeletingLastPathComponent] UTF8String];
|
const char *d = [[[[_panel URL] path] stringByDeletingLastPathComponent] UTF8String];
|
||||||
int l = (int)strlen(d) + 1;
|
int l = (int)strlen(d) + 1;
|
||||||
if (strcmp(d, "/") == 0) l = 1;
|
if (strcmp(d, "/") == 0) l = 1;
|
||||||
int lu = strlen(UNLIKELYPREFIX);
|
int lu = strlen(UNLIKELYPREFIX);
|
||||||
@ -604,7 +604,7 @@ int Fl_Quartz_Native_File_Chooser_Driver::runmodal()
|
|||||||
if (fl_mac_os_version >= 100600) {
|
if (fl_mac_os_version >= 100600) {
|
||||||
bool usepath = false;
|
bool usepath = false;
|
||||||
NSString *path = nil;
|
NSString *path = nil;
|
||||||
if (dir && fname && [(NSSavePanel*)_panel isKindOfClass:[NSOpenPanel class]]) {
|
if (dir && fname && [_panel isKindOfClass:[NSOpenPanel class]]) {
|
||||||
// STR #3406: If both dir + fname specified, combine and pass to setDirectoryURL
|
// STR #3406: If both dir + fname specified, combine and pass to setDirectoryURL
|
||||||
path = [[NSString alloc] initWithFormat:@"%@/%@", dir, fname]; // dir+fname -> path
|
path = [[NSString alloc] initWithFormat:@"%@/%@", dir, fname]; // dir+fname -> path
|
||||||
// See if full path to file exists
|
// See if full path to file exists
|
||||||
@ -613,15 +613,15 @@ int Fl_Quartz_Native_File_Chooser_Driver::runmodal()
|
|||||||
//
|
//
|
||||||
if ( [[NSFileManager defaultManager] fileExistsAtPath:path] ) usepath = true;
|
if ( [[NSFileManager defaultManager] fileExistsAtPath:path] ) usepath = true;
|
||||||
}
|
}
|
||||||
if (usepath) {
|
if (usepath) {
|
||||||
// Set only if full path exists
|
// Set only if full path exists
|
||||||
[(NSSavePanel*)_panel performSelector:@selector(setDirectoryURL:) withObject:[NSURL fileURLWithPath:path]];
|
[_panel performSelector:@selector(setDirectoryURL:) withObject:[NSURL fileURLWithPath:path]];
|
||||||
} else { // didn't setDirectoryURL to full path? Set dir + fname separately..
|
} else { // didn't setDirectoryURL to full path? Set dir + fname separately..
|
||||||
if (dir) [(NSSavePanel*)_panel performSelector:@selector(setDirectoryURL:) withObject:[NSURL fileURLWithPath:dir]];
|
if (dir) [_panel performSelector:@selector(setDirectoryURL:) withObject:[NSURL fileURLWithPath:dir]];
|
||||||
if (fname) [(NSSavePanel*)_panel performSelector:@selector(setNameFieldStringValue:) withObject:fname];
|
if (fname) [_panel performSelector:@selector(setNameFieldStringValue:) withObject:fname];
|
||||||
}
|
}
|
||||||
[path release];
|
[path release];
|
||||||
retval = [(NSSavePanel*)_panel runModal];
|
retval = [_panel runModal];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
retval = [(id)_panel runModalForDirectory:dir file:fname];
|
retval = [(id)_panel runModalForDirectory:dir file:fname];
|
||||||
@ -660,11 +660,11 @@ int Fl_Quartz_Native_File_Chooser_Driver::post() {
|
|||||||
_panel = [NSSavePanel savePanel];
|
_panel = [NSSavePanel savePanel];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
BOOL is_open_panel = [(NSSavePanel*)_panel isKindOfClass:[NSOpenPanel class]];
|
BOOL is_open_panel = [_panel isKindOfClass:[NSOpenPanel class]];
|
||||||
if (_title) {
|
if (_title) {
|
||||||
SEL title_or_message = (is_open_panel && fl_mac_os_version >= 101200) ?
|
SEL title_or_message = (is_open_panel && fl_mac_os_version >= 101200) ?
|
||||||
@selector(setMessage:) : @selector(setTitle:);
|
@selector(setMessage:) : @selector(setTitle:);
|
||||||
[(NSSavePanel*)_panel performSelector:title_or_message withObject:[NSString stringWithUTF8String:_title]];
|
[_panel performSelector:title_or_message withObject:[NSString stringWithUTF8String:_title]];
|
||||||
}
|
}
|
||||||
switch (_btype) {
|
switch (_btype) {
|
||||||
case Fl_Native_File_Chooser::BROWSE_MULTI_FILE:
|
case Fl_Native_File_Chooser::BROWSE_MULTI_FILE:
|
||||||
@ -677,7 +677,7 @@ int Fl_Quartz_Native_File_Chooser_Driver::post() {
|
|||||||
[(NSOpenPanel*)_panel setCanChooseDirectories:YES];
|
[(NSOpenPanel*)_panel setCanChooseDirectories:YES];
|
||||||
break;
|
break;
|
||||||
case Fl_Native_File_Chooser::BROWSE_SAVE_DIRECTORY:
|
case Fl_Native_File_Chooser::BROWSE_SAVE_DIRECTORY:
|
||||||
[(NSSavePanel*)_panel setCanCreateDirectories:YES];
|
[_panel setCanCreateDirectories:YES];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -687,7 +687,7 @@ int Fl_Quartz_Native_File_Chooser_Driver::post() {
|
|||||||
if ( is_open_panel ) {
|
if ( is_open_panel ) {
|
||||||
if (_filt_total) {
|
if (_filt_total) {
|
||||||
char *t = prepareMacFilter(_filt_total, _filter, _filt_patt);
|
char *t = prepareMacFilter(_filt_total, _filter, _filt_patt);
|
||||||
popup = createPopupAccessory((NSSavePanel*)_panel, t, Fl_File_Chooser::show_label, 0);
|
popup = createPopupAccessory(_panel, t, Fl_File_Chooser::show_label, 0);
|
||||||
delete[] t;
|
delete[] t;
|
||||||
[[popup menu] addItem:[NSMenuItem separatorItem]];
|
[[popup menu] addItem:[NSMenuItem separatorItem]];
|
||||||
[popup addItemWithTitle:[NSString stringWithUTF8String:Fl_File_Chooser::all_files_label]];
|
[popup addItemWithTitle:[NSString stringWithUTF8String:Fl_File_Chooser::all_files_label]];
|
||||||
@ -695,25 +695,25 @@ int Fl_Quartz_Native_File_Chooser_Driver::post() {
|
|||||||
[popup setTarget:(NSObject*)_panel];
|
[popup setTarget:(NSObject*)_panel];
|
||||||
FLopenDelegate *openDelegate = [[[FLopenDelegate alloc] init] autorelease];
|
FLopenDelegate *openDelegate = [[[FLopenDelegate alloc] init] autorelease];
|
||||||
[openDelegate setPopup:popup filter_pattern:_filt_patt];
|
[openDelegate setPopup:popup filter_pattern:_filt_patt];
|
||||||
[(NSOpenPanel*)_panel setDelegate:openDelegate];
|
[_panel setDelegate:openDelegate];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
FLsaveDelegate *saveDelegate = [[[FLsaveDelegate alloc] init] autorelease];
|
FLsaveDelegate *saveDelegate = [[[FLsaveDelegate alloc] init] autorelease];
|
||||||
[(NSSavePanel*)_panel setAllowsOtherFileTypes:YES];
|
[_panel setAllowsOtherFileTypes:YES];
|
||||||
[(NSSavePanel*)_panel setDelegate:saveDelegate];
|
[_panel setDelegate:saveDelegate];
|
||||||
[saveDelegate option:(_options & Fl_Native_File_Chooser::SAVEAS_CONFIRM)];
|
[saveDelegate option:(_options & Fl_Native_File_Chooser::SAVEAS_CONFIRM)];
|
||||||
if (_filt_total) {
|
if (_filt_total) {
|
||||||
if (_filt_value >= _filt_total) _filt_value = _filt_total - 1;
|
if (_filt_value >= _filt_total) _filt_value = _filt_total - 1;
|
||||||
char *t = prepareMacFilter(_filt_total, _filter, _filt_patt);
|
char *t = prepareMacFilter(_filt_total, _filter, _filt_patt);
|
||||||
popup = createPopupAccessory((NSSavePanel*)_panel, t, [[(NSSavePanel*)_panel nameFieldLabel] UTF8String], _filt_value);
|
popup = createPopupAccessory(_panel, t, [[_panel nameFieldLabel] UTF8String], _filt_value);
|
||||||
delete[] t;
|
delete[] t;
|
||||||
if (_options & Fl_Native_File_Chooser::USE_FILTER_EXT) {
|
if (_options & Fl_Native_File_Chooser::USE_FILTER_EXT) {
|
||||||
[popup setAction:@selector(changedPopup:)];
|
[popup setAction:@selector(changedPopup:)];
|
||||||
[popup setTarget:saveDelegate];
|
[popup setTarget:saveDelegate];
|
||||||
[saveDelegate panel:(NSSavePanel*)_panel];
|
[saveDelegate panel:(NSSavePanel*)_panel];
|
||||||
}
|
}
|
||||||
[(NSSavePanel*)_panel setCanSelectHiddenExtension:YES];
|
[_panel setCanSelectHiddenExtension:YES];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int retval = runmodal();
|
int retval = runmodal();
|
||||||
|
Loading…
Reference in New Issue
Block a user