~ubuntu-branches/ubuntu/raring/lmms/raring-proposed

« back to all changes in this revision

Viewing changes to plugins/zynaddsubfx/fltk/src/Fl_Native_File_Chooser_MAC.cxx

  • Committer: Charlie Smotherman
  • Date: 2012-12-05 22:08:38 UTC
  • mfrom: (33.1.7 lmms_0.4.13)
  • Revision ID: cjsmo@cableone.net-20121205220838-09pjfzew9m5023hr
* New  Upstream release.
  - Minor tweaking to ZynAddSubFX, CALF, SWH plugins  and Stefan Fendt's RC
    filters.
  - Added UI fixes: Magnentic effect of knobs and Piano-roll fixes
  - Updated German localization and copyright year
* debian/lmms-common.install:
  - added /usr/share/applications so the lmms.desktop file will correctly
    install (LP: #863366)
  - This should also fix the Software Center not displaying lmms in sound
    and video (LP: #824231)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// "$Id: Fl_Native_File_Chooser_MAC.cxx 7354 2010-03-29 11:07:29Z matt $"
2
 
//
3
 
// FLTK native OS file chooser widget
4
 
//
5
 
// Copyright 1998-2005 by Bill Spitzak and others.
6
 
// Copyright 2004 Greg Ercolano.
7
 
//
8
 
// This library is free software; you can redistribute it and/or
9
 
// modify it under the terms of the GNU Library General Public
10
 
// License as published by the Free Software Foundation; either
11
 
// version 2 of the License, or (at your option) any later version.
12
 
//
13
 
// This library is distributed in the hope that it will be useful,
14
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
// Library General Public License for more details.
17
 
//
18
 
// You should have received a copy of the GNU Library General Public
19
 
// License along with this library; if not, write to the Free Software
20
 
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21
 
// USA.
22
 
//
23
 
// Please report all bugs and problems to:
24
 
//
25
 
//     http://www.fltk.org/str.php
26
 
//
27
 
 
28
 
// TODO:
29
 
//      o When doing 'open file', only dir is preset, not filename.
30
 
//        Possibly 'preset_file' could be used to select the filename.
31
 
//
32
 
 
33
 
#ifndef FL_DOXYGEN              // PREVENT DOXYGEN'S USE OF THIS FILE
34
 
 
35
 
#include "Fl_Native_File_Chooser_common.cxx"            // strnew/strfree/strapp/chrcat
36
 
#include <libgen.h>             // dirname(3)
37
 
#include <sys/types.h>          // stat(2)
38
 
#include <sys/stat.h>           // stat(2)
39
 
 
40
 
 
41
 
#include <FL/Fl.H>
42
 
#include <FL/Fl_Native_File_Chooser.H>
43
 
#include <FL/filename.H>
44
 
 
45
 
// FREE PATHNAMES ARRAY, IF IT HAS ANY CONTENTS
46
 
void Fl_Native_File_Chooser::clear_pathnames() {
47
 
  if ( _pathnames ) {
48
 
    while ( --_tpathnames >= 0 ) {
49
 
      _pathnames[_tpathnames] = strfree(_pathnames[_tpathnames]);
50
 
    }
51
 
    delete [] _pathnames;
52
 
    _pathnames = NULL;
53
 
  }
54
 
  _tpathnames = 0;
55
 
}
56
 
 
57
 
// SET A SINGLE PATHNAME
58
 
void Fl_Native_File_Chooser::set_single_pathname(const char *s) {
59
 
  clear_pathnames();
60
 
  _pathnames = new char*[1];
61
 
  _pathnames[0] = strnew(s);
62
 
  _tpathnames = 1;
63
 
}
64
 
 
65
 
// CONSTRUCTOR
66
 
Fl_Native_File_Chooser::Fl_Native_File_Chooser(int val) {
67
 
  _btype          = val;
68
 
  _panel = NULL;
69
 
  _options        = NO_OPTIONS;
70
 
  _pathnames      = NULL;
71
 
  _tpathnames     = 0;
72
 
  _title          = NULL;
73
 
  _filter         = NULL;
74
 
  _filt_names     = NULL;
75
 
  memset(_filt_patt, 0, sizeof(char*) * MAXFILTERS);
76
 
  _filt_total     = 0;
77
 
  _filt_value     = 0;
78
 
  _directory      = NULL;
79
 
  _preset_file    = NULL;
80
 
  _errmsg         = NULL;
81
 
}
82
 
 
83
 
// DESTRUCTOR
84
 
Fl_Native_File_Chooser::~Fl_Native_File_Chooser() {
85
 
  // _opts              // nothing to manage
86
 
  // _options           // nothing to manage
87
 
  // _keepstate         // nothing to manage
88
 
  // _tempitem          // nothing to manage
89
 
  clear_pathnames();
90
 
  _directory   = strfree(_directory);
91
 
  _title       = strfree(_title);
92
 
  _preset_file = strfree(_preset_file);
93
 
  _filter      = strfree(_filter);
94
 
  //_filt_names         // managed by clear_filters()
95
 
  //_filt_patt[i]       // managed by clear_filters()
96
 
  //_filt_total         // managed by clear_filters()
97
 
  clear_filters();
98
 
  //_filt_value         // nothing to manage
99
 
  _errmsg = strfree(_errmsg);
100
 
}
101
 
 
102
 
// GET TYPE OF BROWSER
103
 
int Fl_Native_File_Chooser::type() const {
104
 
  return(_btype);
105
 
}
106
 
 
107
 
// SET OPTIONS
108
 
void Fl_Native_File_Chooser::options(int val) {
109
 
  _options = val;
110
 
}
111
 
 
112
 
// GET OPTIONS
113
 
int Fl_Native_File_Chooser::options() const {
114
 
  return(_options);
115
 
}
116
 
 
117
 
// SHOW THE BROWSER WINDOW
118
 
//     Returns:
119
 
//         0 - user picked a file
120
 
//         1 - user cancelled
121
 
//        -1 - failed; errmsg() has reason
122
 
//
123
 
int Fl_Native_File_Chooser::show() {
124
 
 
125
 
  // Make sure fltk interface updates before posting our dialog
126
 
  Fl::flush();
127
 
  
128
 
  // POST BROWSER
129
 
  int err = post();
130
 
 
131
 
  _filt_total = 0;
132
 
 
133
 
  return(err);
134
 
}
135
 
 
136
 
// SET ERROR MESSAGE
137
 
//     Internal use only.
138
 
//
139
 
void Fl_Native_File_Chooser::errmsg(const char *msg) {
140
 
  _errmsg = strfree(_errmsg);
141
 
  _errmsg = strnew(msg);
142
 
}
143
 
 
144
 
// RETURN ERROR MESSAGE
145
 
const char *Fl_Native_File_Chooser::errmsg() const {
146
 
  return(_errmsg ? _errmsg : "No error");
147
 
}
148
 
 
149
 
// GET FILENAME
150
 
const char* Fl_Native_File_Chooser::filename() const {
151
 
  if ( _pathnames && _tpathnames > 0 ) return(_pathnames[0]);
152
 
  return("");
153
 
}
154
 
 
155
 
// GET FILENAME FROM LIST OF FILENAMES
156
 
const char* Fl_Native_File_Chooser::filename(int i) const {
157
 
  if ( _pathnames && i < _tpathnames ) return(_pathnames[i]);
158
 
  return("");
159
 
}
160
 
 
161
 
// GET TOTAL FILENAMES CHOSEN
162
 
int Fl_Native_File_Chooser::count() const {
163
 
  return(_tpathnames);
164
 
}
165
 
 
166
 
// PRESET PATHNAME
167
 
//     Value can be NULL for none.
168
 
//
169
 
void Fl_Native_File_Chooser::directory(const char *val) {
170
 
  _directory = strfree(_directory);
171
 
  _directory = strnew(val);
172
 
}
173
 
 
174
 
// GET PRESET PATHNAME
175
 
//     Returned value can be NULL if none set.
176
 
//
177
 
const char* Fl_Native_File_Chooser::directory() const {
178
 
  return(_directory);
179
 
}
180
 
 
181
 
// SET TITLE
182
 
//     Value can be NULL if no title desired.
183
 
//
184
 
void Fl_Native_File_Chooser::title(const char *val) {
185
 
  _title = strfree(_title);
186
 
  _title = strnew(val);
187
 
}
188
 
 
189
 
// GET TITLE
190
 
//     Returned value can be NULL if none set.
191
 
//
192
 
const char *Fl_Native_File_Chooser::title() const {
193
 
  return(_title);
194
 
}
195
 
 
196
 
// SET FILTER
197
 
//     Can be NULL if no filter needed
198
 
//
199
 
void Fl_Native_File_Chooser::filter(const char *val) {
200
 
  _filter = strfree(_filter);
201
 
  _filter = strnew(val);
202
 
 
203
 
  // Parse filter user specified
204
 
  //     IN: _filter = "C Files\t*.{cxx,h}\nText Files\t*.txt"
205
 
  //    OUT: _filt_names   = "C Files\tText Files"
206
 
  //         _filt_patt[0] = "*.{cxx,h}"
207
 
  //         _filt_patt[1] = "*.txt"
208
 
  //         _filt_total   = 2
209
 
  //
210
 
  parse_filter(_filter);
211
 
}
212
 
 
213
 
// GET FILTER
214
 
//     Returned value can be NULL if none set.
215
 
//
216
 
const char *Fl_Native_File_Chooser::filter() const {
217
 
  return(_filter);
218
 
}
219
 
 
220
 
// CLEAR ALL FILTERS
221
 
//    Internal use only.
222
 
//
223
 
void Fl_Native_File_Chooser::clear_filters() {
224
 
  _filt_names = strfree(_filt_names);
225
 
  for (int i=0; i<_filt_total; i++) {
226
 
    _filt_patt[i] = strfree(_filt_patt[i]);
227
 
  }
228
 
  _filt_total = 0;
229
 
}
230
 
 
231
 
// PARSE USER'S FILTER SPEC
232
 
//    Parses user specified filter ('in'),
233
 
//    breaks out into _filt_patt[], _filt_names, and _filt_total.
234
 
//
235
 
//    Handles:
236
 
//    IN:                                   OUT:_filt_names    OUT: _filt_patt
237
 
//    ------------------------------------  ------------------ ---------------
238
 
//    "*.{ma,mb}"                           "*.{ma,mb} Files"  "*.{ma,mb}"
239
 
//    "*.[abc]"                             "*.[abc] Files"    "*.[abc]"
240
 
//    "*.txt"                               "*.txt Files"      "*.c"
241
 
//    "C Files\t*.[ch]"                     "C Files"          "*.[ch]"
242
 
//    "C Files\t*.[ch]\nText Files\t*.cxx"  "C Files"          "*.[ch]"
243
 
//
244
 
//    Parsing Mode:
245
 
//         IN:"C Files\t*.{cxx,h}"
246
 
//             |||||||  |||||||||
247
 
//       mode: nnnnnnn  wwwwwwwww
248
 
//             \_____/  \_______/
249
 
//              Name     Wildcard
250
 
//
251
 
void Fl_Native_File_Chooser::parse_filter(const char *in) {
252
 
  clear_filters();
253
 
  if ( ! in ) return;
254
 
  int has_name = strchr(in, '\t') ? 1 : 0;
255
 
 
256
 
  char mode = has_name ? 'n' : 'w';     // parse mode: n=title, w=wildcard
257
 
  char wildcard[1024] = "";             // parsed wildcard
258
 
  char name[1024] = "";
259
 
 
260
 
  // Parse filter user specified
261
 
  for ( ; 1; in++ ) {
262
 
 
263
 
    //// DEBUG
264
 
    //// printf("WORKING ON '%c': mode=<%c> name=<%s> wildcard=<%s>\n",
265
 
    ////                    *in,  mode,     name,     wildcard);
266
 
    
267
 
    switch (*in) {
268
 
      // FINISHED PARSING NAME?
269
 
      case '\t':
270
 
        if ( mode != 'n' ) goto regchar;
271
 
        mode = 'w';
272
 
        break;
273
 
 
274
 
      // ESCAPE NEXT CHAR
275
 
      case '\\':
276
 
        ++in;
277
 
        goto regchar;
278
 
 
279
 
      // FINISHED PARSING ONE OF POSSIBLY SEVERAL FILTERS?
280
 
      case '\r':
281
 
      case '\n':
282
 
      case '\0':
283
 
        // TITLE
284
 
        //     If user didn't specify a name, make one
285
 
        //
286
 
        if ( name[0] == '\0' ) {
287
 
          sprintf(name, "%.*s Files", (int)sizeof(name)-10, wildcard);
288
 
        }
289
 
        // APPEND NEW FILTER TO LIST
290
 
        if ( wildcard[0] ) {
291
 
          // Add to filtername list
292
 
          //     Tab delimit if more than one. We later break
293
 
          //     tab delimited string into CFArray with 
294
 
          //     CFStringCreateArrayBySeparatingStrings()
295
 
          //
296
 
          if ( _filt_total ) {
297
 
              _filt_names = strapp(_filt_names, "\t");
298
 
          }
299
 
          _filt_names = strapp(_filt_names, name);
300
 
 
301
 
          // Add filter to the pattern array
302
 
          _filt_patt[_filt_total++] = strnew(wildcard);
303
 
        }
304
 
        // RESET
305
 
        wildcard[0] = name[0] = '\0';
306
 
        mode = strchr(in, '\t') ? 'n' : 'w';
307
 
        // DONE?
308
 
        if ( *in == '\0' ) return;      // done
309
 
        else continue;                  // not done yet, more filters
310
 
 
311
 
      // Parse all other chars
312
 
      default:                          // handle all non-special chars
313
 
      regchar:                          // handle regular char
314
 
        switch ( mode ) {
315
 
          case 'n': chrcat(name, *in);     continue;
316
 
          case 'w': chrcat(wildcard, *in); continue;
317
 
        }
318
 
        break;
319
 
    }
320
 
  }
321
 
  //NOTREACHED
322
 
}
323
 
 
324
 
// SET PRESET FILE
325
 
//     Value can be NULL for none.
326
 
//
327
 
void Fl_Native_File_Chooser::preset_file(const char* val) {
328
 
  _preset_file = strfree(_preset_file);
329
 
  _preset_file = strnew(val);
330
 
}
331
 
 
332
 
// PRESET FILE
333
 
//     Returned value can be NULL if none set.
334
 
//
335
 
const char* Fl_Native_File_Chooser::preset_file() {
336
 
  return(_preset_file);
337
 
}
338
 
 
339
 
#import <Cocoa/Cocoa.h>
340
 
#define UNLIKELYPREFIX "___fl_very_unlikely_prefix_"
341
 
#ifndef MAC_OS_X_VERSION_10_6
342
 
#define MAC_OS_X_VERSION_10_6 1060
343
 
#endif
344
 
 
345
 
int Fl_Native_File_Chooser::get_saveas_basename(void) {
346
 
  char *q = strdup( [[(NSSavePanel*)_panel filename] fileSystemRepresentation] );
347
 
  id delegate = [(NSSavePanel*)_panel delegate];
348
 
  if (delegate != nil) {
349
 
    const char *d = [[(NSSavePanel*)_panel directory] fileSystemRepresentation];
350
 
    int l = strlen(d) + 1;
351
 
    int lu = strlen(UNLIKELYPREFIX);
352
 
    // Remove UNLIKELYPREFIX between directory and filename parts
353
 
    memmove(q + l, q + l + lu, strlen(q + l + lu) + 1);
354
 
  }
355
 
  set_single_pathname( q );
356
 
  free(q);
357
 
  return 0;
358
 
}
359
 
 
360
 
// SET THE TYPE OF BROWSER
361
 
void Fl_Native_File_Chooser::type(int val) {
362
 
  _btype = val;
363
 
  switch (_btype) {
364
 
    case BROWSE_FILE:
365
 
    case BROWSE_MULTI_FILE:
366
 
    case BROWSE_DIRECTORY:
367
 
    case BROWSE_MULTI_DIRECTORY:
368
 
      _panel =  [NSOpenPanel openPanel];
369
 
      break;      
370
 
    case BROWSE_SAVE_DIRECTORY:
371
 
    case BROWSE_SAVE_FILE:
372
 
      _panel =  [NSSavePanel savePanel];
373
 
      break;
374
 
  }
375
 
}
376
 
  
377
 
@interface FLopenDelegate : NSObject 
378
 
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
379
 
<NSOpenSavePanelDelegate>
380
 
#endif
381
 
{
382
 
  NSPopUpButton *nspopup;
383
 
  char **filter_pattern;
384
 
}
385
 
- (FLopenDelegate*)setPopup:(NSPopUpButton*)popup filter_pattern:(char**)pattern;
386
 
- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename;
387
 
@end
388
 
@implementation FLopenDelegate
389
 
- (FLopenDelegate*)setPopup:(NSPopUpButton*)popup filter_pattern:(char**)pattern
390
 
{
391
 
  nspopup = popup;
392
 
  filter_pattern = pattern;
393
 
  return self;
394
 
}
395
 
- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename
396
 
{
397
 
  if ( [nspopup indexOfSelectedItem] == [nspopup numberOfItems] - 1) return YES;
398
 
  const char *pathname = [filename fileSystemRepresentation];
399
 
  if ( fl_filename_isdir(pathname) ) return YES;
400
 
  if ( fl_filename_match(pathname, filter_pattern[ [nspopup indexOfSelectedItem] ]) ) return YES;
401
 
  return NO;
402
 
}
403
 
@end
404
 
 
405
 
@interface FLsaveDelegate : NSObject 
406
 
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
407
 
<NSOpenSavePanelDelegate>
408
 
#endif
409
 
{
410
 
}
411
 
- (NSString *)panel:(id)sender userEnteredFilename:(NSString *)filename confirmed:(BOOL)okFlag;
412
 
@end
413
 
@implementation FLsaveDelegate
414
 
- (NSString *)panel:(id)sender userEnteredFilename:(NSString *)filename confirmed:(BOOL)okFlag
415
 
{
416
 
  if (! okFlag) return filename;
417
 
  // User has clicked save, and no overwrite confirmation should occur.
418
 
  // To get the latter, we need to change the name we return (hence the prefix):
419
 
  return [@ UNLIKELYPREFIX stringByAppendingString:filename];
420
 
}
421
 
@end
422
 
  
423
 
static NSPopUpButton *createPopupAccessory(NSSavePanel *panel, const char *filter, const char *title, int rank)
424
 
{
425
 
  NSPopUpButton *popup;
426
 
  NSRect rectview = NSMakeRect(5, 5, 350, 30 );
427
 
  NSView *view = [[[NSView alloc] initWithFrame:rectview] autorelease];
428
 
  NSRect rectbox = NSMakeRect(0, 3, 50, 1 );
429
 
  NSBox *box = [[[NSBox alloc] initWithFrame:rectbox] autorelease];
430
 
  NSRect rectpop = NSMakeRect(60, 0, 250, 30 );
431
 
  popup = [[[NSPopUpButton alloc ] initWithFrame:rectpop pullsDown:NO] autorelease];
432
 
  [view addSubview:box];
433
 
  [view addSubview:popup];
434
 
  [box setBorderType:NSNoBorder];
435
 
  NSString *nstitle = [[NSString alloc] initWithUTF8String:title];
436
 
  [box setTitle:nstitle];
437
 
  [nstitle release];
438
 
  NSFont *font = [NSFont controlContentFontOfSize:NSRegularControlSize];
439
 
  [box setTitleFont:font];
440
 
  [box sizeToFit];
441
 
  CFStringRef tab = CFSTR("\n");
442
 
  CFStringRef tmp_cfs;
443
 
  tmp_cfs = CFStringCreateWithCString(NULL, filter, kCFStringEncodingASCII);
444
 
  CFArrayRef array = CFStringCreateArrayBySeparatingStrings(NULL, tmp_cfs, tab);
445
 
  CFRelease(tmp_cfs);
446
 
  CFRelease(tab);
447
 
  [popup addItemsWithTitles:(NSArray*)array];
448
 
  NSMenuItem *item = [popup itemWithTitle:@""];
449
 
  if (item) [popup removeItemWithTitle:@""];
450
 
  CFRelease(array);
451
 
  [popup selectItemAtIndex:rank];
452
 
  [panel setAccessoryView:view];
453
 
  return popup;
454
 
}
455
 
  
456
 
// POST BROWSER
457
 
//     Internal use only.
458
 
//     Assumes '_opts' has been initialized.
459
 
//
460
 
//     Returns:
461
 
//         0 - user picked a file
462
 
//         1 - user cancelled
463
 
//        -1 - failed; errmsg() has reason
464
 
//     
465
 
int Fl_Native_File_Chooser::post() {
466
 
  // INITIALIZE BROWSER
467
 
  if ( _filt_total == 0 ) {     // Make sure they match
468
 
    _filt_value = 0;            // TBD: move to someplace more logical?
469
 
  }
470
 
  NSAutoreleasePool *localPool;
471
 
  localPool = [[NSAutoreleasePool alloc] init];
472
 
  int retval;
473
 
  NSString *nstitle = [NSString stringWithUTF8String: (_title ? _title : "No Title")];
474
 
  [(NSSavePanel*)_panel setTitle:nstitle];
475
 
  switch (_btype) {
476
 
    case BROWSE_MULTI_FILE:
477
 
      [(NSOpenPanel*)_panel setAllowsMultipleSelection:YES];
478
 
      break;
479
 
    case BROWSE_MULTI_DIRECTORY:
480
 
      [(NSOpenPanel*)_panel setAllowsMultipleSelection:YES];
481
 
    case BROWSE_DIRECTORY:
482
 
      [(NSOpenPanel*)_panel setCanChooseDirectories:YES];
483
 
      break;
484
 
    case BROWSE_SAVE_DIRECTORY:
485
 
      [(NSSavePanel*)_panel setCanCreateDirectories:YES];
486
 
      break;
487
 
  }
488
 
  
489
 
  // SHOW THE DIALOG
490
 
  if ( [(NSSavePanel*)_panel isKindOfClass:[NSOpenPanel class]] ) {
491
 
    NSPopUpButton *popup = nil;
492
 
    if (_filt_total) {
493
 
      char *p; p = _filter;
494
 
      char *q; q = new char[strlen(p) + 1];
495
 
      char *r, *s, *t;
496
 
      t = q;
497
 
      do {      // copy to t what is in _filter removing what is between \t and \n, if any
498
 
        r = strchr(p, '\n');
499
 
        if (!r) r = p + strlen(p) - 1;
500
 
        s = strchr(p, '\t');
501
 
        if (s && s < r) { memcpy(q, p, s - p); q += s - p; *(q++) = '\n'; }
502
 
        else { memcpy(q, p, r - p + 1); q += r - p + 1; }
503
 
        *q = 0;
504
 
        p = r + 1;
505
 
      } while(*p);
506
 
      popup = createPopupAccessory((NSSavePanel*)_panel, t, "Enable:", 0);
507
 
      delete t;
508
 
      [[popup menu] addItem:[NSMenuItem separatorItem]];
509
 
      [popup addItemWithTitle:@"All Documents"];
510
 
      [popup setAction:@selector(validateVisibleColumns)];
511
 
      [popup setTarget:(NSObject*)_panel];
512
 
      static FLopenDelegate *openDelegate = nil;
513
 
      if (openDelegate == nil) {
514
 
        // not to be ever freed
515
 
        openDelegate = [[FLopenDelegate alloc] init];
516
 
      }
517
 
      [openDelegate setPopup:popup filter_pattern:_filt_patt];
518
 
      [(NSOpenPanel*)_panel setDelegate:openDelegate];
519
 
    }
520
 
    NSString *dir = nil;
521
 
    NSString *fname = nil;
522
 
    NSString *preset = nil;
523
 
    if (_preset_file) {
524
 
      preset = [[NSString alloc] initWithUTF8String:_preset_file];
525
 
      if (strchr(_preset_file, '/') != NULL) 
526
 
        dir = [[NSString alloc] initWithString:[preset stringByDeletingLastPathComponent]];
527
 
      fname = [preset lastPathComponent];
528
 
    }
529
 
    if (_directory && !dir) dir = [[NSString alloc] initWithUTF8String:_directory];
530
 
    retval = [(NSOpenPanel*)_panel runModalForDirectory:dir file:fname types:nil];      
531
 
    [dir release];
532
 
    [preset release];
533
 
    if (_filt_total) {
534
 
      _filt_value = [popup indexOfSelectedItem];
535
 
    }
536
 
    if ( retval == NSOKButton ) {
537
 
      clear_pathnames();
538
 
      NSArray *array = [(NSOpenPanel*)_panel filenames];
539
 
      _tpathnames = [array count];
540
 
      _pathnames = new char*[_tpathnames];
541
 
      for(int i = 0; i < _tpathnames; i++) {
542
 
        _pathnames[i] = strnew([(NSString*)[array objectAtIndex:i] fileSystemRepresentation]);
543
 
      }
544
 
    }
545
 
  }
546
 
  else {
547
 
    NSString *dir = nil;
548
 
    NSString *fname = nil;
549
 
    NSString *preset = nil;
550
 
    NSPopUpButton *popup = nil;
551
 
    if ( !(_options & SAVEAS_CONFIRM) ) {
552
 
      static FLsaveDelegate *saveDelegate = nil;
553
 
      if (saveDelegate == nil)saveDelegate = [[FLsaveDelegate alloc] init]; // not to be ever freed
554
 
      [(NSSavePanel*)_panel setDelegate:saveDelegate];
555
 
    }
556
 
    if (_preset_file) {
557
 
      preset = [[NSString alloc] initWithUTF8String:_preset_file];
558
 
      if (strchr(_preset_file, '/') != NULL) {
559
 
        dir = [[NSString alloc] initWithString:[preset stringByDeletingLastPathComponent]];
560
 
      }
561
 
      fname = [preset lastPathComponent];
562
 
    }
563
 
    if (_directory && !dir) dir = [[NSString alloc] initWithUTF8String:_directory];
564
 
    if (_filt_total) {
565
 
      popup = createPopupAccessory((NSSavePanel*)_panel, _filter, "Format:", _filt_value);
566
 
    }
567
 
    retval = [(NSSavePanel*)_panel runModalForDirectory:dir file:fname];
568
 
    if (_filt_total) {
569
 
      _filt_value = [popup indexOfSelectedItem];
570
 
    }
571
 
    [dir release];
572
 
    [preset release];
573
 
    if ( retval == NSOKButton ) get_saveas_basename();
574
 
  }
575
 
  [localPool release];
576
 
  return (retval == NSOKButton ? 0 : 1);
577
 
}
578
 
 
579
 
#endif /*!FL_DOXYGEN*/
580
 
 
581
 
//
582
 
// End of "$Id: Fl_Native_File_Chooser_MAC.cxx 7354 2010-03-29 11:07:29Z matt $".
583
 
//