javauis/eswt_qt/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/FileDialog.java
changeset 26 dc7c549001d5
parent 21 2a9601315dfc
child 87 1627c337e51e
equal deleted inserted replaced
23:98ccebc37403 26:dc7c549001d5
    48 	String dialogID;
    48 	String dialogID;
    49 	static int dialogCount;
    49 	static int dialogCount;
    50 
    50 
    51 	/**
    51 	/**
    52 	 * Constructs a new instance of this class given only its parent.
    52 	 * Constructs a new instance of this class given only its parent.
    53 	 * 
    53 	 *
    54 	 * @param parent
    54 	 * @param parent
    55 	 *            a shell which will be the parent of the new instance
    55 	 *            a shell which will be the parent of the new instance
    56 	 * 
    56 	 *
    57 	 * @exception IllegalArgumentException
    57 	 * @exception IllegalArgumentException
    58 	 *                <ul>
    58 	 *                <ul>
    59 	 *                <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
    59 	 *                <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
    60 	 *                </ul>
    60 	 *                </ul>
    61 	 * @exception SWTException
    61 	 * @exception SWTException
    79 	 * be built by <em>bitwise OR</em>'ing together (that is, using the
    79 	 * be built by <em>bitwise OR</em>'ing together (that is, using the
    80 	 * <code>int</code> "|" operator) two or more of those <code>SWT</code>
    80 	 * <code>int</code> "|" operator) two or more of those <code>SWT</code>
    81 	 * style constants. The class description lists the style constants that are
    81 	 * style constants. The class description lists the style constants that are
    82 	 * applicable to the class. Style bits are also inherited from superclasses.
    82 	 * applicable to the class. Style bits are also inherited from superclasses.
    83 	 * </p>
    83 	 * </p>
    84 	 * 
    84 	 *
    85 	 * @param parent
    85 	 * @param parent
    86 	 *            a shell which will be the parent of the new instance
    86 	 *            a shell which will be the parent of the new instance
    87 	 * @param style
    87 	 * @param style
    88 	 *            the style of dialog to construct
    88 	 *            the style of dialog to construct
    89 	 * 
    89 	 *
    90 	 * @exception IllegalArgumentException
    90 	 * @exception IllegalArgumentException
    91 	 *                <ul>
    91 	 *                <ul>
    92 	 *                <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
    92 	 *                <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
    93 	 *                </ul>
    93 	 *                </ul>
    94 	 * @exception SWTException
    94 	 * @exception SWTException
   132 
   132 
   133 	/**
   133 	/**
   134 	 * Returns the path of the first file that was selected in the dialog
   134 	 * Returns the path of the first file that was selected in the dialog
   135 	 * relative to the filter path, or an empty string if no such file has been
   135 	 * relative to the filter path, or an empty string if no such file has been
   136 	 * selected.
   136 	 * selected.
   137 	 * 
   137 	 *
   138 	 * @return the relative path of the file
   138 	 * @return the relative path of the file
   139 	 */
   139 	 */
   140 	public String getFileName() {
   140 	public String getFileName() {
   141 		return fileName;
   141 		return fileName;
   142 	}
   142 	}
   143 
   143 
   144 	/**
   144 	/**
   145 	 * Returns a (possibly empty) array with the paths of all files that were
   145 	 * Returns a (possibly empty) array with the paths of all files that were
   146 	 * selected in the dialog relative to the filter path.
   146 	 * selected in the dialog relative to the filter path.
   147 	 * 
   147 	 *
   148 	 * @return the relative paths of the files
   148 	 * @return the relative paths of the files
   149 	 */
   149 	 */
   150 	public String[] getFileNames() {
   150 	public String[] getFileNames() {
   151 		return fileNames;
   151 		return fileNames;
   152 	}
   152 	}
   153 
   153 
   154 	/**
   154 	/**
   155 	 * Returns the file extensions which the dialog will use to filter the files
   155 	 * Returns the file extensions which the dialog will use to filter the files
   156 	 * it shows.
   156 	 * it shows.
   157 	 * 
   157 	 *
   158 	 * @return the file extensions filter
   158 	 * @return the file extensions filter
   159 	 */
   159 	 */
   160 	public String[] getFilterExtensions() {
   160 	public String[] getFilterExtensions() {
   161 		return filterExtensions;
   161 		return filterExtensions;
   162 	}
   162 	}
   166 	 * the user, or -1 if no filter was selected.
   166 	 * the user, or -1 if no filter was selected.
   167 	 * <p>
   167 	 * <p>
   168 	 * This is an index into the FilterExtensions array and the FilterNames
   168 	 * This is an index into the FilterExtensions array and the FilterNames
   169 	 * array.
   169 	 * array.
   170 	 * </p>
   170 	 * </p>
   171 	 * 
   171 	 *
   172 	 * @return index the file extension filter index
   172 	 * @return index the file extension filter index
   173 	 * 
   173 	 *
   174 	 * @see #getFilterExtensions
   174 	 * @see #getFilterExtensions
   175 	 * @see #getFilterNames
   175 	 * @see #getFilterNames
   176 	 * 
   176 	 *
   177 	 * @since 3.4
   177 	 * @since 3.4
   178 	 */
   178 	 */
   179 	public int getFilterIndex() {
   179 	public int getFilterIndex() {
   180 		return filterIndex;
   180 		return filterIndex;
   181 	}
   181 	}
   182 
   182 
   183 	/**
   183 	/**
   184 	 * Returns the names that describe the filter extensions which the dialog
   184 	 * Returns the names that describe the filter extensions which the dialog
   185 	 * will use to filter the files it shows.
   185 	 * will use to filter the files it shows.
   186 	 * 
   186 	 *
   187 	 * @return the list of filter names
   187 	 * @return the list of filter names
   188 	 */
   188 	 */
   189 	public String[] getFilterNames() {
   189 	public String[] getFilterNames() {
   190 		return filterNames;
   190 		return filterNames;
   191 	}
   191 	}
   192 
   192 
   193 	/**
   193 	/**
   194 	 * Returns the directory path that the dialog will use, or an empty string
   194 	 * Returns the directory path that the dialog will use, or an empty string
   195 	 * if this is not set. File names in this path will appear in the dialog,
   195 	 * if this is not set. File names in this path will appear in the dialog,
   196 	 * filtered according to the filter extensions.
   196 	 * filtered according to the filter extensions.
   197 	 * 
   197 	 *
   198 	 * @return the directory path string
   198 	 * @return the directory path string
   199 	 * 
   199 	 *
   200 	 * @see #setFilterExtensions
   200 	 * @see #setFilterExtensions
   201 	 */
   201 	 */
   202 	public String getFilterPath() {
   202 	public String getFilterPath() {
   203 		return filterPath;
   203 		return filterPath;
   204 	}
   204 	}
   205 
   205 
   206 	/**
   206 	/**
   207 	 * Makes the dialog visible and brings it to the front of the display.
   207 	 * Makes the dialog visible and brings it to the front of the display.
   208 	 * 
   208 	 *
   209 	 * @return a string describing the absolute path of the first selected file,
   209 	 * @return a string describing the absolute path of the first selected file,
   210 	 *         or null if the dialog was cancelled or an error occurred
   210 	 *         or null if the dialog was cancelled or an error occurred
   211 	 * 
   211 	 *
   212 	 * @exception SWTException
   212 	 * @exception SWTException
   213 	 *                <ul>
   213 	 *                <ul>
   214 	 *                <li>ERROR_WIDGET_DISPOSED - if the dialog has been
   214 	 *                <li>ERROR_WIDGET_DISPOSED - if the dialog has been
   215 	 *                disposed</li>
   215 	 *                disposed</li>
   216 	 *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
   216 	 *                <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
   297 				resultStrings = OS.QFileDialog_swt_getOpenFileName(
   297 				resultStrings = OS.QFileDialog_swt_getOpenFileName(
   298 						parent.handle, title, fullPath, filter, selectedFilter,
   298 						parent.handle, title, fullPath, filter, selectedFilter,
   299 						dialogID, qtLayoutDirection);
   299 						dialogID, qtLayoutDirection);
   300 			}
   300 			}
   301 		}
   301 		}
   302 		
   302 
   303 		if (parent != null && !parent.isDisposed()) {
   303 		if (parent != null && !parent.isDisposed()) {
   304 			parent.removeDisposeListener(listener);
   304 			parent.removeDisposeListener(listener);
   305 		}
   305 		}
   306 
   306 
   307 		parseResult(resultStrings);
   307 		parseResult(resultStrings);
   355 		}
   355 		}
   356 
   356 
   357 		/*
   357 		/*
   358 		 * get filter index
   358 		 * get filter index
   359 		 */
   359 		 */
   360 		int filterCount = filterExtensions.length;
   360 		int filterCount = filterExtensions==null ? 0 : filterExtensions.length;
   361 		String selectedFilter = result[count - 1];
   361 		String selectedFilter = result[count - 1];
   362 		filterIndex = -1;
   362 		filterIndex = -1;
   363 		if (filterCount > 0 && selectedFilter != null) {
   363 		if (filterCount > 0 && selectedFilter != null) {
   364 			selectedFilter = selectedFilter.substring(selectedFilter
   364 			selectedFilter = selectedFilter.substring(selectedFilter
   365 					.indexOf('(') + 1);
   365 					.indexOf('(') + 1);
   378 
   378 
   379 	/**
   379 	/**
   380 	 * Set the initial filename which the dialog will select by default when
   380 	 * Set the initial filename which the dialog will select by default when
   381 	 * opened to the argument, which may be null. The name will be prefixed with
   381 	 * opened to the argument, which may be null. The name will be prefixed with
   382 	 * the filter path when one is supplied.
   382 	 * the filter path when one is supplied.
   383 	 * 
   383 	 *
   384 	 * @param string
   384 	 * @param string
   385 	 *            the file name
   385 	 *            the file name
   386 	 */
   386 	 */
   387 	public void setFileName(String string) {
   387 	public void setFileName(String string) {
   388 		fileName = string;
   388 		fileName = string;
   394 	 * <p>
   394 	 * <p>
   395 	 * The strings are platform specific. For example, on Windows, an extension
   395 	 * The strings are platform specific. For example, on Windows, an extension
   396 	 * filter string is typically of the form "*.extension", where "*.*" matches
   396 	 * filter string is typically of the form "*.extension", where "*.*" matches
   397 	 * all files.
   397 	 * all files.
   398 	 * </p>
   398 	 * </p>
   399 	 * 
   399 	 *
   400 	 * @param extensions
   400 	 * @param extensions
   401 	 *            the file extension filter
   401 	 *            the file extension filter
   402 	 * 
   402 	 *
   403 	 * @see #setFilterNames to specify the user-friendly names corresponding to
   403 	 * @see #setFilterNames to specify the user-friendly names corresponding to
   404 	 *      the extensions
   404 	 *      the extensions
   405 	 */
   405 	 */
   406 	public void setFilterExtensions(String[] extensions) {
   406 	public void setFilterExtensions(String[] extensions) {
   407 		filterExtensions = extensions;
   407 		filterExtensions = extensions;
   412 	 * use initially to filter the files it shows to the argument.
   412 	 * use initially to filter the files it shows to the argument.
   413 	 * <p>
   413 	 * <p>
   414 	 * This is an index into the FilterExtensions array and the FilterNames
   414 	 * This is an index into the FilterExtensions array and the FilterNames
   415 	 * array.
   415 	 * array.
   416 	 * </p>
   416 	 * </p>
   417 	 * 
   417 	 *
   418 	 * @param index
   418 	 * @param index
   419 	 *            the file extension filter index
   419 	 *            the file extension filter index
   420 	 * 
   420 	 *
   421 	 * @see #setFilterExtensions
   421 	 * @see #setFilterExtensions
   422 	 * @see #setFilterNames
   422 	 * @see #setFilterNames
   423 	 * 
   423 	 *
   424 	 * @since 3.4
   424 	 * @since 3.4
   425 	 */
   425 	 */
   426 	public void setFilterIndex(int index) {
   426 	public void setFilterIndex(int index) {
   427 		filterIndex = index;
   427 		filterIndex = index;
   428 	}
   428 	}
   433 	 * <p>
   433 	 * <p>
   434 	 * Each name is a user-friendly short description shown for its
   434 	 * Each name is a user-friendly short description shown for its
   435 	 * corresponding filter. The <code>names</code> array must be the same
   435 	 * corresponding filter. The <code>names</code> array must be the same
   436 	 * length as the <code>extensions</code> array.
   436 	 * length as the <code>extensions</code> array.
   437 	 * </p>
   437 	 * </p>
   438 	 * 
   438 	 *
   439 	 * @param names
   439 	 * @param names
   440 	 *            the list of filter names, or null for no filter names
   440 	 *            the list of filter names, or null for no filter names
   441 	 * 
   441 	 *
   442 	 * @see #setFilterExtensions
   442 	 * @see #setFilterExtensions
   443 	 */
   443 	 */
   444 	public void setFilterNames(String[] names) {
   444 	public void setFilterNames(String[] names) {
   445 		filterNames = names;
   445 		filterNames = names;
   446 	}
   446 	}
   452 	 * operating system's default filter path will be used.
   452 	 * operating system's default filter path will be used.
   453 	 * <p>
   453 	 * <p>
   454 	 * Note that the path string is platform dependent. For convenience, either
   454 	 * Note that the path string is platform dependent. For convenience, either
   455 	 * '/' or '\' can be used as a path separator.
   455 	 * '/' or '\' can be used as a path separator.
   456 	 * </p>
   456 	 * </p>
   457 	 * 
   457 	 *
   458 	 * @param string
   458 	 * @param string
   459 	 *            the directory path
   459 	 *            the directory path
   460 	 * 
   460 	 *
   461 	 * @see #setFilterExtensions
   461 	 * @see #setFilterExtensions
   462 	 */
   462 	 */
   463 	public void setFilterPath(String string) {
   463 	public void setFilterPath(String string) {
   464 		filterPath = string;
   464 		filterPath = string;
   465 	}
   465 	}