1 /*******************************************************************************
2  * Copyright (c) 2000, 2008 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  * Port to the D programming language:
11  *     Frank Benoit <benoit@tionex.de>
12  *******************************************************************************/
13 module org.eclipse.swt.widgets.FileDialog;
14 
15 
16 
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.SWTException;
19 import org.eclipse.swt.internal.gtk.OS;
20 import org.eclipse.swt.widgets.Dialog;
21 import org.eclipse.swt.widgets.Shell;
22 import org.eclipse.swt.widgets.Display;
23 import java.lang.all;
24 
25 version(Tango){
26     static import tango.io.model.IFile;
27 } else { // Phobos
28     static import std.path;
29 }
30 
31 /**
32  * Instances of this class allow the user to navigate
33  * the file system and select or enter a file name.
34  * <dl>
35  * <dt><b>Styles:</b></dt>
36  * <dd>SAVE, OPEN, MULTI</dd>
37  * <dt><b>Events:</b></dt>
38  * <dd>(none)</dd>
39  * </dl>
40  * <p>
41  * Note: Only one of the styles SAVE and OPEN may be specified.
42  * </p><p>
43  * IMPORTANT: This class is intended to be subclassed <em>only</em>
44  * within the SWT implementation.
45  * </p>
46  *
47  * @see <a href="http://www.eclipse.org/swt/snippets/#filedialog">FileDialog snippets</a>
48  * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
49  * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
50  */
51 public class FileDialog : Dialog {
52     String [] filterNames;
53     String [] filterExtensions;
54     String filterPath = "";
55     String fileName = "";
56     String[] fileNames;
57     String fullPath = "";
58     int filterIndex = -1;
59     bool overwrite = false;
60     GtkWidget* handle;
61     version(Tango){
62         static const char SEPARATOR = tango.io.model.IFile.FileConst.PathSeparatorChar;
63     } else { // Phobos
64         static const char SEPARATOR = std.path.dirSeparator[0];
65     }
66     static const char EXTENSION_SEPARATOR = ';';
67 
68 /**
69  * Constructs a new instance of this class given only its parent.
70  *
71  * @param parent a shell which will be the parent of the new instance
72  *
73  * @exception IllegalArgumentException <ul>
74  *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
75  * </ul>
76  * @exception SWTException <ul>
77  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
78  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
79  * </ul>
80  */
81 public this (Shell parent) {
82     this (parent, SWT.APPLICATION_MODAL);
83 }
84 /**
85  * Constructs a new instance of this class given its parent
86  * and a style value describing its behavior and appearance.
87  * <p>
88  * The style value is either one of the style constants defined in
89  * class <code>SWT</code> which is applicable to instances of this
90  * class, or must be built by <em>bitwise OR</em>'ing together
91  * (that is, using the <code>int</code> "|" operator) two or more
92  * of those <code>SWT</code> style constants. The class description
93  * lists the style constants that are applicable to the class.
94  * Style bits are also inherited from superclasses.
95  * </p>
96  *
97  * @param parent a shell which will be the parent of the new instance
98  * @param style the style of dialog to construct
99  *
100  * @exception IllegalArgumentException <ul>
101  *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
102  * </ul>
103  * @exception SWTException <ul>
104  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
105  *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
106  * </ul>
107  */
108 public this (Shell parent, int style) {
109     super (parent, checkStyle (parent, style));
110     checkSubclass ();
111 }
112 String computeResultChooserDialog () {
113     /* MULTI is only valid if the native dialog's action is Open */
114     fullPath = null;
115     if ((style & (SWT.SAVE | SWT.MULTI)) is SWT.MULTI) {
116         auto list = OS.gtk_file_chooser_get_filenames (handle);
117         int listLength = OS.g_slist_length (list);
118         fileNames = new String [listLength];
119         auto current = list;
120         int writePos = 0;
121         for (int i = 0; i < listLength; i++) {
122             auto name = cast(char*)OS.g_slist_data (current);
123             size_t items_written;
124             char* utf8Ptr = OS.g_filename_to_utf8 (name, -1, null, &items_written, null);
125             OS.g_free (name);
126             if (utf8Ptr !is null) {
127                 fullPath = utf8Ptr[ 0 .. items_written ]._idup();
128                 int start = fullPath.lastIndexOf( SEPARATOR);
129                 fileNames [writePos++] = fullPath[ start + 1 .. $ ]._idup();
130                 OS.g_free (utf8Ptr);
131             }
132             current = OS.g_slist_next (current);
133         }
134         if (writePos !is 0 && writePos !is listLength) {
135             String [] validFileNames = new String [writePos];
136             System.arraycopy (fileNames, 0, validFileNames, 0, writePos);
137             fileNames = validFileNames;
138         }
139         OS.g_slist_free (list);
140     } else {
141         auto path = OS.gtk_file_chooser_get_filename (handle);
142         if (path !is null) {
143             size_t items_written;
144             auto utf8Ptr = OS.g_filename_to_utf8 (path, -1, null, &items_written, null);
145             OS.g_free (path);
146             if (utf8Ptr !is null) {
147                 fullPath = utf8Ptr[ 0 .. items_written ]._idup();
148                 fileNames = new String [1];
149                 int start = fullPath.lastIndexOf( SEPARATOR);
150                 fileNames[0] = fullPath[ start + 1 .. $ ];
151                 OS.g_free (utf8Ptr);
152             }
153         }
154     }
155     filterIndex = -1;
156     auto filter = OS.gtk_file_chooser_get_filter (handle);
157     if (filter !is null) {
158         auto filterNamePtr = OS.gtk_file_filter_get_name (filter);
159         if (filterNamePtr !is null) {
160             String filterName = fromStringz(filterNamePtr)._idup();
161             //OS.g_free (filterNamePtr); //GTK owns this pointer - do not free
162             for (int i = 0; i < filterExtensions.length; i++) {
163                 if (filterNames.length > 0) {
164                     if (filterNames[i].equals(filterName)) {
165                         filterIndex = i;
166                         break;
167                     }
168                 } else {
169                     if (filterExtensions[i].equals(filterName)) {
170                         filterIndex = i;
171                         break;
172                     }
173                 }
174             }
175         }
176     }
177     if (fullPath !is null) {
178         int separatorIndex = fullPath.lastIndexOf( SEPARATOR);
179         fileName = fullPath[separatorIndex + 1 .. $ ];
180         filterPath = fullPath[0 .. separatorIndex ];
181     }
182     return fullPath;
183 }
184 String computeResultClassicDialog () {
185     filterIndex = -1;
186     GtkFileSelection* selection = cast(GtkFileSelection*)handle;
187     auto entry = selection.selection_entry;
188     auto entryText = OS.gtk_entry_get_text (entry);
189     String txt = fromStringz( entryText )._idup();
190     if (txt.length is 0) {
191         auto fileList = selection.file_list;
192         auto listSelection = OS.gtk_tree_view_get_selection (fileList);
193         void* model;
194         auto selectedList = OS.gtk_tree_selection_get_selected_rows (listSelection, &model);
195         if (selectedList is null) return null;
196         int listLength = OS.g_list_length (selectedList);
197         if (listLength is 0) {
198             OS.g_list_free (selectedList);
199             return null;
200         }
201         auto path = OS.g_list_nth_data (selectedList, 0);
202         char* ptr;
203         GtkTreeIter iter;
204         if (OS.gtk_tree_model_get_iter (&model, &iter, path)) {
205             OS.gtk_tree_model_get1 (&model, &iter, 0, cast(void**)&ptr);
206         }
207         for (int i = 0; i < listLength; i++) {
208             OS.gtk_tree_path_free (OS.g_list_nth_data (selectedList, i));
209         }
210         OS.g_list_free (selectedList);
211         if (ptr is null) return null;
212         OS.gtk_entry_set_text (entry, ptr);
213         OS.g_free (ptr);
214     }
215 
216     auto fileNamePtr = OS.gtk_file_selection_get_filename (handle);
217     size_t items_written;
218     auto utf8Ptr = OS.g_filename_to_utf8 (fileNamePtr, -1, null, &items_written, null);
219     String osAnswer = utf8Ptr[ 0 .. items_written ]._idup();
220     OS.g_free (utf8Ptr);
221 
222     if (osAnswer.length is 0) return null;
223     int separatorIndex = osAnswer.lastIndexOf( SEPARATOR);
224     if (separatorIndex+1 is osAnswer.length ) return null;
225 
226     String answer = fullPath = osAnswer;
227     fileName = fullPath[ separatorIndex+1 .. $ ];
228     filterPath = fullPath[ 0 .. separatorIndex ];
229     if ((style & SWT.MULTI) is 0) {
230         fileNames = [ fileName ];
231     } else {
232         auto namesPtr = OS.gtk_file_selection_get_selections (handle);
233         auto namesPtr1 = namesPtr;
234         char* namePtr = namesPtr1[0];
235         int length_ = 0;
236         while (namePtr !is null) {
237             length_++;
238             namePtr = namesPtr1[length_];
239         }
240         fileNames = new String[](length_);
241         for (int i = 0; i < length_; i++) {
242             utf8Ptr = OS.g_filename_to_utf8 (namesPtr [i], -1, null, &items_written, null);
243             String name = utf8Ptr[ 0 .. items_written ]._idup();
244             int start = name.lastIndexOf( SEPARATOR);
245             fileNames [i] = name[ start + 1 .. $ ]._idup();
246             OS.g_free (utf8Ptr);
247         }
248         OS.g_strfreev (namesPtr);
249     }
250     return answer;
251 }
252 /**
253  * Returns the path of the first file that was
254  * selected in the dialog relative to the filter path, or an
255  * empty string if no such file has been selected.
256  *
257  * @return the relative path of the file
258  */
259 public String getFileName () {
260     return fileName;
261 }
262 /**
263  * Returns a (possibly empty) array with the paths of all files
264  * that were selected in the dialog relative to the filter path.
265  *
266  * @return the relative paths of the files
267  */
268 public String [] getFileNames () {
269     return fileNames;
270 }
271 /**
272  * Returns the file extensions which the dialog will
273  * use to filter the files it shows.
274  *
275  * @return the file extensions filter
276  */
277 public String [] getFilterExtensions () {
278     return filterExtensions;
279 }
280 /**
281  * Get the 0-based index of the file extension filter
282  * which was selected by the user, or -1 if no filter
283  * was selected.
284  * <p>
285  * This is an index into the FilterExtensions array and
286  * the FilterNames array.
287  * </p>
288  *
289  * @return index the file extension filter index
290  *
291  * @see #getFilterExtensions
292  * @see #getFilterNames
293  *
294  * @since 3.4
295  */
296 public int getFilterIndex () {
297     return filterIndex;
298 }
299 /**
300  * Returns the names that describe the filter extensions
301  * which the dialog will use to filter the files it shows.
302  *
303  * @return the list of filter names
304  */
305 public String [] getFilterNames () {
306     return filterNames;
307 }
308 /**
309  * Returns the directory path that the dialog will use, or an empty
310  * string if this is not set.  File names in this path will appear
311  * in the dialog, filtered according to the filter extensions.
312  *
313  * @return the directory path string
314  *
315  * @see #setFilterExtensions
316  */
317 public String getFilterPath () {
318     return filterPath;
319 }
320 /**
321  * Returns the flag that the dialog will use to
322  * determine whether to prompt the user for file
323  * overwrite if the selected file already exists.
324  *
325  * @return true if the dialog will prompt for file overwrite, false otherwise
326  *
327  * @since 3.4
328  */
329 public bool getOverwrite () {
330     return overwrite;
331 }
332 /**
333  * Makes the dialog visible and brings it to the front
334  * of the display.
335  *
336  * @return a string describing the absolute path of the first selected file,
337  *         or null if the dialog was cancelled or an error occurred
338  *
339  * @exception SWTException <ul>
340  *    <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
341  *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
342  * </ul>
343  */
344 public String open () {
345     bool useChooserDialog = OS.GTK_VERSION >= OS.buildVERSION (2, 4, 10);
346     if (useChooserDialog) {
347         return openChooserDialog ();
348     } else {
349         return openClassicDialog ();
350     }
351 }
352 String openChooserDialog () {
353     char* titleBytes = toStringz( title );
354     int action = (style & SWT.SAVE) !is 0 ?
355         OS.GTK_FILE_CHOOSER_ACTION_SAVE :
356         OS.GTK_FILE_CHOOSER_ACTION_OPEN;
357     auto shellHandle = parent.topHandle ();
358     handle = OS.gtk_file_chooser_dialog_new2 (
359         titleBytes,
360         shellHandle,
361         action,
362         OS.GTK_STOCK_CANCEL (), OS.GTK_RESPONSE_CANCEL,
363         OS.GTK_STOCK_OK (), OS.GTK_RESPONSE_OK);
364     auto pixbufs = OS.gtk_window_get_icon_list (shellHandle);
365     if (pixbufs !is null) {
366         OS.gtk_window_set_icon_list (handle, pixbufs);
367         OS.g_list_free (pixbufs);
368     }
369     presetChooserDialog ();
370     Display display = parent !is null ? parent.getDisplay (): Display.getCurrent ();
371     display.addIdleProc ();
372     String answer = null;
373     Dialog oldModal = null;
374     if (OS.gtk_window_get_modal (handle)) {
375         oldModal = display.getModalDialog ();
376         display.setModalDialog (this);
377     }
378     int signalId = 0;
379     ptrdiff_t hookId = 0;
380     CallbackData emissionData;
381     emissionData.display = display;
382     if ((style & SWT.RIGHT_TO_LEFT) !is 0) {
383         signalId = OS.g_signal_lookup (OS.map.ptr, OS.GTK_TYPE_WIDGET());
384         emissionData.data = handle;
385         hookId = OS.g_signal_add_emission_hook (signalId, 0, &Display.emissionFunc, &emissionData, null);
386     }
387     int response = OS.gtk_dialog_run (handle);
388     if ((style & SWT.RIGHT_TO_LEFT) !is 0) {
389         OS.g_signal_remove_emission_hook (signalId, hookId);
390     }
391     if (OS.gtk_window_get_modal (handle)) {
392         display.setModalDialog (oldModal);
393     }
394     if (response is OS.GTK_RESPONSE_OK) {
395         answer = computeResultChooserDialog ();
396     }
397     display.removeIdleProc ();
398     OS.gtk_widget_destroy (handle);
399     return answer;
400 }
401 String openClassicDialog () {
402     char* titleBytes = toStringz( title );
403     handle = OS.gtk_file_selection_new (titleBytes);
404     if (parent !is null) {
405         auto shellHandle = parent.topHandle ();
406         OS.gtk_window_set_transient_for (handle, shellHandle);
407         auto pixbufs = OS.gtk_window_get_icon_list (shellHandle);
408         if (pixbufs !is null) {
409             OS.gtk_window_set_icon_list (handle, pixbufs);
410             OS.g_list_free (pixbufs);
411         }
412     }
413     presetClassicDialog ();
414     Display display = parent !is null ? parent.getDisplay (): Display.getCurrent ();
415     display.addIdleProc ();
416     String answer = null;
417     Dialog oldModal = null;
418     if (OS.gtk_window_get_modal (handle)) {
419         oldModal = display.getModalDialog ();
420         display.setModalDialog (this);
421     }
422     int signalId = 0;
423     ptrdiff_t hookId = 0;
424     CallbackData emissionData;
425     emissionData.display = display;
426     if ((style & SWT.RIGHT_TO_LEFT) !is 0) {
427         signalId = OS.g_signal_lookup (OS.map.ptr, OS.GTK_TYPE_WIDGET());
428         emissionData.data = handle;
429         hookId = OS.g_signal_add_emission_hook (signalId, 0, &Display.emissionFunc, &emissionData, null);
430     }
431     int response = OS.gtk_dialog_run (handle);
432     if ((style & SWT.RIGHT_TO_LEFT) !is 0) {
433         OS.g_signal_remove_emission_hook (signalId, hookId);
434     }
435     if (OS.gtk_window_get_modal (handle)) {
436         display.setModalDialog (oldModal);
437     }
438     if (response is OS.GTK_RESPONSE_OK) {
439         answer = computeResultClassicDialog ();
440     }
441     display.removeIdleProc ();
442     OS.gtk_widget_destroy (handle);
443     return answer;
444 }
445 void presetChooserDialog () {
446     /* MULTI is only valid if the native dialog's action is Open */
447     if ((style & (SWT.SAVE | SWT.MULTI)) is SWT.MULTI) {
448         OS.gtk_file_chooser_set_select_multiple (handle, true);
449     }
450     if (filterPath is null) filterPath = "";
451     if (fileName is null) fileName = "";
452     if (filterPath.length > 0) {
453         StringBuffer stringBuffer = new StringBuffer();
454         /* filename must be a full path */
455         if (filterPath[0] !is SEPARATOR) {
456             stringBuffer.append (SEPARATOR);
457         }
458         stringBuffer.append (filterPath);
459         if (fileName.length > 0 && (style & SWT.SAVE) is 0) {
460             if (filterPath[filterPath.length - 1 ] !is SEPARATOR) {
461                 stringBuffer.append (SEPARATOR);
462             }
463             stringBuffer.append (fileName);
464         char* buffer = toStringz( stringBuffer.toString ());
465             /*
466             * Bug in GTK. GtkFileChooser may crash on GTK versions 2.4.10 to 2.6
467             * when setting a file name that is not a true canonical path.
468             * The fix is to use the canonical path.
469             */
470         auto ptr = OS.realpath (buffer, null);
471         if (ptr !is null) {
472                 OS.gtk_file_chooser_set_filename (handle, ptr);
473                 OS.g_free (ptr);
474             }
475         } else {
476             char* buffer = toStringz( stringBuffer.toString () );
477             /*
478             * Bug in GTK. GtkFileChooser may crash on GTK versions 2.4.10 to 2.6
479             * when setting a file name that is not a true canonical path.
480             * The fix is to use the canonical path.
481             */
482             auto ptr = OS.realpath (buffer, null);
483             if (ptr !is null) {
484                 OS.gtk_file_chooser_set_current_folder (handle, ptr);
485                 OS.g_free (ptr);
486             }
487         }
488     } else {
489         if (fileName.length > 0) {
490             if (fileName[0] is SEPARATOR) {
491                 char* buffer = toStringz(fileName);
492 
493                 /*
494                 * Bug in GTK. GtkFileChooser may crash on GTK versions 2.4.10 to 2.6
495                 * when setting a file name that is not a true canonical path.
496                 * The fix is to use the canonical path.
497                 */
498                 auto ptr = OS.realpath (buffer, null);
499                 if (ptr !is null) {
500                     OS.gtk_file_chooser_set_filename (handle, ptr);
501                     OS.g_free (ptr);
502                 }
503             }
504         }
505     }
506     if ((style & SWT.SAVE) !is 0 && fileName.length > 0) {
507         char* buffer = toStringz(fileName);
508         OS.gtk_file_chooser_set_current_name (handle, buffer);
509     }
510     if ((style & SWT.SAVE) !is 0) {
511         if (OS.GTK_VERSION >= OS.buildVERSION (2, 8, 0)) {
512             OS.gtk_file_chooser_set_do_overwrite_confirmation (handle, overwrite);
513         }
514     }
515 
516     /* Set the extension filters */
517     if (filterNames is null) filterNames = null;
518     if (filterExtensions is null) filterExtensions = null;
519     GtkFileFilter* initialFilter = null;
520     for (int i = 0; i < filterExtensions.length; i++) {
521         if (filterExtensions [i] !is null) {
522             auto filter = OS.gtk_file_filter_new ();
523             if (filterNames.length > i && filterNames [i] !is null) {
524                 char* name = toStringz(filterNames [i]);
525                 OS.gtk_file_filter_set_name (filter, name);
526             } else {
527                 char* name = toStringz(filterExtensions [i]);
528                 OS.gtk_file_filter_set_name (filter, name);
529             }
530             int start = 0;
531             int index = filterExtensions [i].indexOf( EXTENSION_SEPARATOR );
532             while (index !is -1 ) {
533                 String current = filterExtensions [i][ start .. index ];
534                 char* filterString = toStringz(current);
535                 OS.gtk_file_filter_add_pattern (filter, filterString);
536                 start = index + 1;
537                 index = filterExtensions [i].indexOf( EXTENSION_SEPARATOR, start);
538             }
539             String current = filterExtensions [i][ start .. $ ];
540             char* filterString = toStringz(current);
541             OS.gtk_file_filter_add_pattern (filter, filterString);
542             OS.gtk_file_chooser_add_filter (handle, filter);
543             if (i is filterIndex) {
544                 initialFilter = filter;
545             }
546         }
547     }
548     if (initialFilter !is null) {
549         OS.gtk_file_chooser_set_filter(handle, initialFilter);
550     }
551     fullPath = null;
552     fileNames = null;
553 }
554 void presetClassicDialog () {
555     OS.gtk_file_selection_set_select_multiple(handle, (style & SWT.MULTI) !is 0);
556 
557     /* Calculate the fully-specified file name and convert to bytes */
558     StringBuffer stringBuffer = new StringBuffer();
559     if (filterPath is null) {
560         filterPath = "";
561     } else {
562         if (filterPath.length > 0) {
563             stringBuffer.append (filterPath);
564             if (filterPath[filterPath.length - 1] !is SEPARATOR) {
565                 stringBuffer.append (SEPARATOR);
566             }
567         }
568     }
569     if (fileName is null) {
570         fileName = "";
571     } else {
572         stringBuffer.append (fileName);
573     }
574     fullPath = stringBuffer.toString ();
575     auto fileNamePtr = OS.g_filename_from_utf8 (toStringz( fullPath ), -1, null, null, null);
576     OS.gtk_file_selection_set_filename (handle, fileNamePtr);
577     OS.g_free (fileNamePtr);
578 
579     if (filterNames is null) filterNames = null;
580     if (filterExtensions is null) filterExtensions = null;
581     fullPath = null;
582     fileNames = null;
583 }
584 /**
585  * Set the initial filename which the dialog will
586  * select by default when opened to the argument,
587  * which may be null.  The name will be prefixed with
588  * the filter path when one is supplied.
589  *
590  * @param string the file name
591  */
592 public void setFileName (String string) {
593     fileName = string;
594 }
595 /**
596  * Set the file extensions which the dialog will
597  * use to filter the files it shows to the argument,
598  * which may be null.
599  * <p>
600  * The strings are platform specific. For example, on
601  * some platforms, an extension filter string is typically
602  * of the form "*.extension", where "*.*" matches all files.
603  * For filters with multiple extensions, use semicolon as
604  * a separator, e.g. "*.jpg;*.png".
605  * </p>
606  *
607  * @param extensions the file extension filter
608  *
609  * @see #setFilterNames to specify the user-friendly
610  * names corresponding to the extensions
611  */
612 public void setFilterExtensions (String [] extensions) {
613     filterExtensions = extensions;
614 }
615 /**
616  * Set the 0-based index of the file extension filter
617  * which the dialog will use initially to filter the files
618  * it shows to the argument.
619  * <p>
620  * This is an index into the FilterExtensions array and
621  * the FilterNames array.
622  * </p>
623  *
624  * @param index the file extension filter index
625  *
626  * @see #setFilterExtensions
627  * @see #setFilterNames
628  *
629  * @since 3.4
630  */
631 public void setFilterIndex (int index) {
632     filterIndex = index;
633 }
634 /**
635  * Sets the names that describe the filter extensions
636  * which the dialog will use to filter the files it shows
637  * to the argument, which may be null.
638  * <p>
639  * Each name is a user-friendly short description shown for
640  * its corresponding filter. The <code>names</code> array must
641  * be the same length as the <code>extensions</code> array.
642  * </p>
643  *
644  * @param names the list of filter names, or null for no filter names
645  *
646  * @see #setFilterExtensions
647  */
648 public void setFilterNames (String [] names) {
649     filterNames = names;
650 }
651 /**
652  * Sets the directory path that the dialog will use
653  * to the argument, which may be null. File names in this
654  * path will appear in the dialog, filtered according
655  * to the filter extensions. If the string is null,
656  * then the operating system's default filter path
657  * will be used.
658  * <p>
659  * Note that the path string is platform dependent.
660  * For convenience, either '/' or '\' can be used
661  * as a path separator.
662  * </p>
663  *
664  * @param string the directory path
665  *
666  * @see #setFilterExtensions
667  */
668 public void setFilterPath (String string) {
669     filterPath = string;
670 }
671 
672 /**
673  * Sets the flag that the dialog will use to
674  * determine whether to prompt the user for file
675  * overwrite if the selected file already exists.
676  *
677  * @param overwrite true if the dialog will prompt for file overwrite, false otherwise
678  *
679  * @since 3.4
680  */
681 public void setOverwrite (bool overwrite) {
682     this.overwrite = overwrite;
683 }
684 }