Save This Page
Home » Eclipse-SWT-3.5.1 » org.eclipse.swt.widgets » [javadoc | source]
    1   /*******************************************************************************
    2    * Copyright (c) 2000, 2009 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    *******************************************************************************/
   11   package org.eclipse.swt.widgets;
   12   
   13   
   14   import org.eclipse.swt.internal;
   15   import org.eclipse.swt.internal.win32;
   16   import org.eclipse.swt;
   17   
   18   /**
   19    * Instances of this class allow the user to navigate
   20    * the file system and select or enter a file name.
   21    * <dl>
   22    * <dt><b>Styles:</b></dt>
   23    * <dd>SAVE, OPEN, MULTI</dd>
   24    * <dt><b>Events:</b></dt>
   25    * <dd>(none)</dd>
   26    * </dl>
   27    * <p>
   28    * Note: Only one of the styles SAVE and OPEN may be specified.
   29    * </p><p>
   30    * IMPORTANT: This class is intended to be subclassed <em>only</em>
   31    * within the SWT implementation.
   32    * </p>
   33    * 
   34    * @see <a href="http://www.eclipse.org/swt/snippets/#filedialog">FileDialog snippets</a>
   35    * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a>
   36    * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
   37    * @noextend This class is not intended to be subclassed by clients.
   38    */
   39   public class FileDialog extends Dialog {
   40   	String [] filterNames = new String [0];
   41   	String [] filterExtensions = new String [0];
   42   	String [] fileNames = new String [0];
   43   	String filterPath = "", fileName = "";
   44   	int filterIndex = 0;
   45   	boolean overwrite = false;
   46   	static final String FILTER = "*.*";
   47   	static int BUFFER_SIZE = 1024 * 32;
   48   	static boolean USE_HOOK = true;
   49   	static {
   50   		/*
   51   		*  Feature in Vista.  When OFN_ENABLEHOOK is set in the
   52   		*  save or open file dialog,  Vista uses the old XP look
   53   		*  and feel.  OFN_ENABLEHOOK is used to grow the file
   54   		*  name buffer in a multi-select file dialog.  The fix
   55   		*  is to only use OFN_ENABLEHOOK when the buffer has
   56   		*  overrun.
   57   		*/
   58   		if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
   59   			USE_HOOK = false;
   60   		}
   61   	}
   62   
   63   /**
   64    * Constructs a new instance of this class given only its parent.
   65    *
   66    * @param parent a shell which will be the parent of the new instance
   67    *
   68    * @exception IllegalArgumentException <ul>
   69    *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
   70    * </ul>
   71    * @exception SWTException <ul>
   72    *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
   73    *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
   74    * </ul>
   75    */
   76   public FileDialog (Shell parent) {
   77   	this (parent, SWT.APPLICATION_MODAL);
   78   }
   79   
   80   /**
   81    * Constructs a new instance of this class given its parent
   82    * and a style value describing its behavior and appearance.
   83    * <p>
   84    * The style value is either one of the style constants defined in
   85    * class <code>SWT</code> which is applicable to instances of this
   86    * class, or must be built by <em>bitwise OR</em>'ing together 
   87    * (that is, using the <code>int</code> "|" operator) two or more
   88    * of those <code>SWT</code> style constants. The class description
   89    * lists the style constants that are applicable to the class.
   90    * Style bits are also inherited from superclasses.
   91    * </p>
   92    *
   93    * @param parent a shell which will be the parent of the new instance
   94    * @param style the style of dialog to construct
   95    *
   96    * @exception IllegalArgumentException <ul>
   97    *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
   98    * </ul>
   99    * @exception SWTException <ul>
  100    *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
  101    *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
  102    * </ul>
  103    * 
  104    * @see SWT#SAVE
  105    * @see SWT#OPEN
  106    * @see SWT#MULTI
  107    */
  108   public FileDialog (Shell parent, int style) {
  109   	super (parent, checkStyle (parent, style));
  110   	checkSubclass ();
  111   }
  112   
  113   /**
  114    * Returns the path of the first file that was
  115    * selected in the dialog relative to the filter path, or an
  116    * empty string if no such file has been selected.
  117    * 
  118    * @return the relative path of the file
  119    */
  120   public String getFileName () {
  121   	return fileName;
  122   }
  123   
  124   /**
  125    * Returns a (possibly empty) array with the paths of all files
  126    * that were selected in the dialog relative to the filter path.
  127    * 
  128    * @return the relative paths of the files
  129    */
  130   public String [] getFileNames () {
  131   	return fileNames;
  132   }
  133   
  134   /**
  135    * Returns the file extensions which the dialog will
  136    * use to filter the files it shows.
  137    *
  138    * @return the file extensions filter
  139    */
  140   public String [] getFilterExtensions () {
  141   	return filterExtensions;
  142   }
  143   
  144   /**
  145    * Get the 0-based index of the file extension filter
  146    * which was selected by the user, or -1 if no filter
  147    * was selected.
  148    * <p>
  149    * This is an index into the FilterExtensions array and
  150    * the FilterNames array.
  151    * </p>
  152    *
  153    * @return index the file extension filter index
  154    * 
  155    * @see #getFilterExtensions
  156    * @see #getFilterNames
  157    * 
  158    * @since 3.4
  159    */
  160   public int getFilterIndex () {
  161   	return filterIndex;
  162   }
  163   
  164   /**
  165    * Returns the names that describe the filter extensions
  166    * which the dialog will use to filter the files it shows.
  167    *
  168    * @return the list of filter names
  169    */
  170   public String [] getFilterNames () {
  171   	return filterNames;
  172   }
  173   
  174   /**
  175    * Returns the directory path that the dialog will use, or an empty
  176    * string if this is not set.  File names in this path will appear
  177    * in the dialog, filtered according to the filter extensions.
  178    *
  179    * @return the directory path string
  180    * 
  181    * @see #setFilterExtensions
  182    */
  183   public String getFilterPath () {
  184   	return filterPath;
  185   }
  186   
  187   /**
  188    * Returns the flag that the dialog will use to
  189    * determine whether to prompt the user for file
  190    * overwrite if the selected file already exists.
  191    *
  192    * @return true if the dialog will prompt for file overwrite, false otherwise
  193    * 
  194    * @since 3.4
  195    */
  196   public boolean getOverwrite () {
  197   	return overwrite;
  198   }
  199   
  200   int /*long*/ OFNHookProc (int /*long*/ hdlg, int /*long*/ uiMsg, int /*long*/ wParam, int /*long*/ lParam) {
  201   	switch ((int)/*64*/uiMsg) {
  202   		case OS.WM_NOTIFY:
  203   			OFNOTIFY ofn = new OFNOTIFY ();
  204   			OS.MoveMemory (ofn, lParam, OFNOTIFY.sizeof);
  205   			if (ofn.code == OS.CDN_SELCHANGE) {
  206   				int lResult = (int)/*64*/OS.SendMessage (ofn.hwndFrom, OS.CDM_GETSPEC, 0, 0);
  207   				if (lResult > 0) {
  208   					lResult += OS.MAX_PATH;
  209   					OPENFILENAME lpofn = new OPENFILENAME ();
  210   					OS.MoveMemory (lpofn, ofn.lpOFN, OPENFILENAME.sizeof);
  211   					if (lpofn.nMaxFile < lResult) {
  212   						int /*long*/ hHeap = OS.GetProcessHeap ();
  213   						int /*long*/ lpstrFile = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, lResult * TCHAR.sizeof);
  214   						if (lpstrFile != 0) {
  215   							if (lpofn.lpstrFile != 0) OS.HeapFree (hHeap, 0, lpofn.lpstrFile);
  216   							lpofn.lpstrFile = lpstrFile;
  217   							lpofn.nMaxFile = lResult;
  218   							OS.MoveMemory (ofn.lpOFN, lpofn, OPENFILENAME.sizeof);
  219   						}
  220   					}
  221   			  }
  222   		  }
  223   		  break;
  224   	}
  225   	return 0;
  226   }
  227   
  228   /**
  229    * Makes the dialog visible and brings it to the front
  230    * of the display.
  231    *
  232    * @return a string describing the absolute path of the first selected file,
  233    *         or null if the dialog was cancelled or an error occurred
  234    *
  235    * @exception SWTException <ul>
  236    *    <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
  237    *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
  238    * </ul>
  239    */
  240   public String open () {
  241   	int /*long*/ hHeap = OS.GetProcessHeap ();
  242   	
  243   	/* Get the owner HWND for the dialog */
  244   	int /*long*/ hwndOwner = parent.handle;
  245   	int /*long*/ hwndParent = parent.handle;
  246   	
  247   	/*
  248   	* Feature in Windows.  There is no API to set the orientation of a
  249   	* file dialog.  It is always inherited from the parent.  The fix is
  250   	* to create a hidden parent and set the orientation in the hidden
  251   	* parent for the dialog to inherit.
  252   	*/
  253   	boolean enabled = false;
  254   	if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
  255   		int dialogOrientation = style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
  256   		int parentOrientation = parent.style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
  257   		if (dialogOrientation != parentOrientation) {
  258   			int exStyle = OS.WS_EX_NOINHERITLAYOUT;
  259   			if (dialogOrientation == SWT.RIGHT_TO_LEFT) exStyle |= OS.WS_EX_LAYOUTRTL;
  260   			hwndOwner = OS.CreateWindowEx (
  261   				exStyle,
  262   				Shell.DialogClass,
  263   				null,
  264   				0,
  265   				OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0,
  266   				hwndParent,
  267   				0,
  268   				OS.GetModuleHandle (null),
  269   				null);
  270   			enabled = OS.IsWindowEnabled (hwndParent);
  271   			if (enabled) OS.EnableWindow (hwndParent, false);
  272   		}
  273   	}
  274   		
  275   	/* Convert the title and copy it into lpstrTitle */
  276   	if (title == null) title = "";	
  277   	/* Use the character encoding for the default locale */
  278   	TCHAR buffer3 = new TCHAR (0, title, true);
  279   	int byteCount3 = buffer3.length () * TCHAR.sizeof;
  280   	int /*long*/ lpstrTitle = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount3);
  281   	OS.MoveMemory (lpstrTitle, buffer3, byteCount3); 
  282   
  283   	/* Compute filters and copy into lpstrFilter */
  284   	String strFilter = "";
  285   	if (filterNames == null) filterNames = new String [0];
  286   	if (filterExtensions == null) filterExtensions = new String [0];
  287   	for (int i=0; i<filterExtensions.length; i++) {
  288   		String filterName = filterExtensions [i];
  289   		if (i < filterNames.length) filterName = filterNames [i];
  290   		strFilter = strFilter + filterName + '\0' + filterExtensions [i] + '\0';
  291   	}
  292   	if (filterExtensions.length == 0) {
  293   		strFilter = strFilter + FILTER + '\0' + FILTER + '\0';
  294   	}
  295   	/* Use the character encoding for the default locale */
  296   	TCHAR buffer4 = new TCHAR (0, strFilter, true);
  297   	int byteCount4 = buffer4.length () * TCHAR.sizeof;
  298   	int /*long*/ lpstrFilter = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount4);
  299   	OS.MoveMemory (lpstrFilter, buffer4, byteCount4);
  300   	
  301   	/* Convert the fileName and filterName to C strings */
  302   	if (fileName == null) fileName = "";
  303   	/* Use the character encoding for the default locale */
  304   	TCHAR name = new TCHAR (0, fileName, true);
  305   
  306   	/*
  307   	* Copy the name into lpstrFile and ensure that the
  308   	* last byte is NULL and the buffer does not overrun.
  309   	*/
  310   	int nMaxFile = OS.MAX_PATH;
  311   	if ((style & SWT.MULTI) != 0) nMaxFile = Math.max (nMaxFile, BUFFER_SIZE);
  312   	int byteCount = nMaxFile * TCHAR.sizeof;
  313   	int /*long*/ lpstrFile = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
  314   	int byteCountFile = Math.min (name.length () * TCHAR.sizeof, byteCount - TCHAR.sizeof);
  315   	OS.MoveMemory (lpstrFile, name, byteCountFile);
  316   
  317   	/*
  318   	* Copy the path into lpstrInitialDir and ensure that
  319   	* the last byte is NULL and the buffer does not overrun.
  320   	*/
  321   	if (filterPath == null) filterPath = "";
  322   	/* Use the character encoding for the default locale */
  323   	TCHAR path = new TCHAR (0, filterPath.replace ('/', '\\'), true);
  324   	int byteCount5 = OS.MAX_PATH * TCHAR.sizeof;
  325   	int /*long*/ lpstrInitialDir = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount5);
  326   	int byteCountDir = Math.min (path.length () * TCHAR.sizeof, byteCount5 - TCHAR.sizeof);
  327   	OS.MoveMemory (lpstrInitialDir, path, byteCountDir);
  328   
  329   	/* Create the file dialog struct */
  330   	OPENFILENAME struct = new OPENFILENAME ();
  331   	struct.lStructSize = OPENFILENAME.sizeof;
  332   	struct.Flags = OS.OFN_HIDEREADONLY | OS.OFN_NOCHANGEDIR;
  333   	boolean save = (style & SWT.SAVE) != 0;
  334   	if (save && overwrite) struct.Flags |= OS.OFN_OVERWRITEPROMPT;
  335   	Callback callback = null;
  336   	if ((style & SWT.MULTI) != 0) {
  337   		struct.Flags |= OS.OFN_ALLOWMULTISELECT | OS.OFN_EXPLORER | OS.OFN_ENABLESIZING;
  338   		if (!OS.IsWinCE && USE_HOOK) {
  339   			callback = new Callback (this, "OFNHookProc", 4); //$NON-NLS-1$
  340   			int /*long*/ lpfnHook = callback.getAddress ();
  341   			if (lpfnHook == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
  342   			struct.lpfnHook = lpfnHook;
  343   			struct.Flags |= OS.OFN_ENABLEHOOK;
  344   		}
  345   	}
  346   	struct.hwndOwner = hwndOwner;
  347   	struct.lpstrTitle = lpstrTitle;
  348   	struct.lpstrFile = lpstrFile;
  349   	struct.nMaxFile = nMaxFile;
  350   	struct.lpstrInitialDir = lpstrInitialDir;
  351   	struct.lpstrFilter = lpstrFilter;
  352   	struct.nFilterIndex = filterIndex == 0 ? filterIndex : filterIndex + 1;
  353   
  354   	/*
  355   	* Set the default extension to an empty string.  If the
  356   	* user fails to type an extension and this extension is
  357   	* empty, Windows uses the current value of the filter
  358   	* extension at the time that the dialog is closed.
  359   	*/
  360   	int /*long*/ lpstrDefExt = 0;
  361   	if (save) {
  362   		lpstrDefExt = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof);
  363   		struct.lpstrDefExt = lpstrDefExt;
  364   	}
  365   	
  366   	/* Make the parent shell be temporary modal */
  367   	Dialog oldModal = null;
  368   	Display display = parent.getDisplay ();
  369   	if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
  370   		oldModal = display.getModalDialog ();
  371   		display.setModalDialog (this);
  372   	}
  373   	
  374   	/*
  375   	* Feature in Windows.  For some reason, the WH_MSGFILTER filter
  376   	* does not run for GetSaveFileName() or GetOpenFileName().  The
  377   	* fix is to allow async messages to run in the WH_FOREGROUNDIDLE
  378   	* hook instead.
  379   	* 
  380   	* Bug in Windows 98.  For some reason, when certain operating
  381   	* system calls such as Shell_NotifyIcon(), GetOpenFileName()
  382   	* and GetSaveFileName() are made during the WH_FOREGROUNDIDLE
  383   	* hook, Windows hangs.  The fix is to disallow async messages
  384   	* during WH_FOREGROUNDIDLE.
  385   	*/
  386   	boolean oldRunMessagesInIdle = display.runMessagesInIdle;
  387   	display.runMessagesInIdle = !OS.IsWin95;
  388   	/*
  389   	* Open the dialog.  If the open fails due to an invalid
  390   	* file name, use an empty file name and open it again.
  391   	*/
  392   	boolean success = (save) ? OS.GetSaveFileName (struct) : OS.GetOpenFileName (struct);
  393   	switch (OS.CommDlgExtendedError ()) {
  394   		case OS.FNERR_INVALIDFILENAME:
  395   			OS.MoveMemory (lpstrFile, new TCHAR (0, "", true), TCHAR.sizeof);
  396   			success = (save) ? OS.GetSaveFileName (struct) : OS.GetOpenFileName (struct);
  397   			break;
  398   		case OS.FNERR_BUFFERTOOSMALL: 
  399   			USE_HOOK = true;
  400   			break;
  401   	}
  402   	display.runMessagesInIdle = oldRunMessagesInIdle;
  403   	
  404   	/* Clear the temporary dialog modal parent */
  405   	if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) {
  406   		display.setModalDialog (oldModal);
  407   	}
  408   
  409   	/* Dispose the callback and reassign the buffer */
  410   	if (callback != null) callback.dispose ();
  411   	lpstrFile = struct.lpstrFile;
  412   
  413   	/* Set the new path, file name and filter */
  414   	fileNames = new String [0];
  415   	String fullPath = null;
  416   	if (success) {
  417   		
  418   		/* Use the character encoding for the default locale */
  419   		TCHAR buffer = new TCHAR (0, struct.nMaxFile);
  420   		int byteCount1 = buffer.length () * TCHAR.sizeof;
  421   		OS.MoveMemory (buffer, lpstrFile, byteCount1);
  422   		
  423   		/*
  424   		* Bug in WinCE.  For some reason, nFileOffset and nFileExtension
  425   		* are always zero on WinCE HPC. nFileOffset is always zero on
  426   		* WinCE PPC when using GetSaveFileName().  nFileOffset is correctly
  427   		* set on WinCE PPC when using OpenFileName().  The fix is to parse
  428   		* lpstrFile to calculate nFileOffset.
  429   		* 
  430   		* Note: WinCE does not support multi-select file dialogs.
  431   		*/
  432   		int nFileOffset = struct.nFileOffset;
  433   		if (OS.IsWinCE && nFileOffset == 0) {
  434   			int index = 0; 
  435   			while (index < buffer.length ()) {
  436   				int ch = buffer.tcharAt (index);
  437   				if (ch == 0) break;
  438   				if (ch == '\\') nFileOffset = index + 1;
  439   				index++;
  440   			}
  441   		}
  442   		if (nFileOffset > 0) {
  443   		
  444   			/* Use the character encoding for the default locale */
  445   			TCHAR prefix = new TCHAR (0, nFileOffset - 1);
  446   			int byteCount2 = prefix.length () * TCHAR.sizeof;
  447   			OS.MoveMemory (prefix, lpstrFile, byteCount2);
  448   			filterPath = prefix.toString (0, prefix.length ());
  449   			
  450   			/*
  451   			* Get each file from the buffer.  Files are delimited
  452   			* by a NULL character with 2 NULL characters at the end.
  453   			*/
  454   			int count = 0;
  455   			fileNames = new String [(style & SWT.MULTI) != 0 ? 4 : 1];
  456   			int start = nFileOffset;
  457   			do {
  458   				int end = start;
  459   				while (end < buffer.length () && buffer.tcharAt (end) != 0) end++;
  460   				String string = buffer.toString (start, end - start);
  461   				start = end;
  462   				if (count == fileNames.length) {
  463   					String [] newFileNames = new String [fileNames.length + 4];
  464   					System.arraycopy (fileNames, 0, newFileNames, 0, fileNames.length);
  465   					fileNames = newFileNames;
  466   				}
  467   				fileNames [count++] = string;
  468   				if ((style & SWT.MULTI) == 0) break;
  469   				start++;
  470   			} while (start < buffer.length () && buffer.tcharAt (start) != 0);
  471   			
  472   			if (fileNames.length > 0) fileName = fileNames  [0];
  473   			String separator = "";
  474   			int length = filterPath.length ();
  475   			if (length > 0 && filterPath.charAt (length - 1) != '\\') {
  476   				separator = "\\";
  477   			}
  478   			fullPath = filterPath + separator + fileName;
  479   			if (count < fileNames.length) {
  480   				String [] newFileNames = new String [count];
  481   				System.arraycopy (fileNames, 0, newFileNames, 0, count);
  482   				fileNames = newFileNames;
  483   			}
  484   		}
  485   		filterIndex = struct.nFilterIndex - 1;
  486   	}
  487   	
  488   	/* Free the memory that was allocated. */
  489   	OS.HeapFree (hHeap, 0, lpstrFile);
  490   	OS.HeapFree (hHeap, 0, lpstrFilter);
  491   	OS.HeapFree (hHeap, 0, lpstrInitialDir);
  492   	OS.HeapFree (hHeap, 0, lpstrTitle);
  493   	if (lpstrDefExt != 0) OS.HeapFree (hHeap, 0, lpstrDefExt);
  494   
  495   	/* Destroy the BIDI orientation window */
  496   	if (hwndParent != hwndOwner) {
  497   		if (enabled) OS.EnableWindow (hwndParent, true);
  498   		OS.SetActiveWindow (hwndParent);
  499   		OS.DestroyWindow (hwndOwner);
  500   	}
  501   	
  502   	/*
  503   	* This code is intentionally commented.  On some
  504   	* platforms, the owner window is repainted right
  505   	* away when a dialog window exits.  This behavior
  506   	* is currently unspecified.
  507   	*/
  508   //	if (hwndOwner != 0) OS.UpdateWindow (hwndOwner);
  509   	
  510   	/* Answer the full path or null */
  511   	return fullPath;
  512   }
  513   
  514   /**
  515    * Set the initial filename which the dialog will
  516    * select by default when opened to the argument,
  517    * which may be null.  The name will be prefixed with
  518    * the filter path when one is supplied.
  519    * 
  520    * @param string the file name
  521    */
  522   public void setFileName (String string) {
  523   	fileName = string;
  524   }
  525   
  526   /**
  527    * Set the file extensions which the dialog will
  528    * use to filter the files it shows to the argument,
  529    * which may be null.
  530    * <p>
  531    * The strings are platform specific. For example, on
  532    * some platforms, an extension filter string is typically
  533    * of the form "*.extension", where "*.*" matches all files.
  534    * For filters with multiple extensions, use semicolon as
  535    * a separator, e.g. "*.jpg;*.png".
  536    * </p>
  537    *
  538    * @param extensions the file extension filter
  539    * 
  540    * @see #setFilterNames to specify the user-friendly
  541    * names corresponding to the extensions
  542    */
  543   public void setFilterExtensions (String [] extensions) {
  544   	filterExtensions = extensions;
  545   }
  546   
  547   /**
  548    * Set the 0-based index of the file extension filter
  549    * which the dialog will use initially to filter the files
  550    * it shows to the argument.
  551    * <p>
  552    * This is an index into the FilterExtensions array and
  553    * the FilterNames array.
  554    * </p>
  555    *
  556    * @param index the file extension filter index
  557    * 
  558    * @see #setFilterExtensions
  559    * @see #setFilterNames
  560    * 
  561    * @since 3.4
  562    */
  563   public void setFilterIndex (int index) {
  564   	filterIndex = index;
  565   }
  566   
  567   /**
  568    * Sets the names that describe the filter extensions
  569    * which the dialog will use to filter the files it shows
  570    * to the argument, which may be null.
  571    * <p>
  572    * Each name is a user-friendly short description shown for
  573    * its corresponding filter. The <code>names</code> array must
  574    * be the same length as the <code>extensions</code> array.
  575    * </p>
  576    *
  577    * @param names the list of filter names, or null for no filter names
  578    * 
  579    * @see #setFilterExtensions
  580    */
  581   public void setFilterNames (String [] names) {
  582   	filterNames = names;
  583   }
  584   
  585   /**
  586    * Sets the directory path that the dialog will use
  587    * to the argument, which may be null. File names in this
  588    * path will appear in the dialog, filtered according
  589    * to the filter extensions. If the string is null,
  590    * then the operating system's default filter path
  591    * will be used.
  592    * <p>
  593    * Note that the path string is platform dependent.
  594    * For convenience, either '/' or '\' can be used
  595    * as a path separator.
  596    * </p>
  597    *
  598    * @param string the directory path
  599    * 
  600    * @see #setFilterExtensions
  601    */
  602   public void setFilterPath (String string) {
  603   	filterPath = string;
  604   }
  605   
  606   /**
  607    * Sets the flag that the dialog will use to
  608    * determine whether to prompt the user for file
  609    * overwrite if the selected file already exists.
  610    *
  611    * @param overwrite true if the dialog will prompt for file overwrite, false otherwise
  612    * 
  613    * @since 3.4
  614    */
  615   public void setOverwrite (boolean overwrite) {
  616   	this.overwrite = overwrite;
  617   }
  618   }

Save This Page
Home » Eclipse-SWT-3.5.1 » org.eclipse.swt.widgets » [javadoc | source]