comparison dwt/widgets/FileDialog.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents e831403a80a9
children cce7edf30dae
comparison
equal deleted inserted replaced
44:ca5e494f2bbf 45:d8635bb48c7c
1 /******************************************************************************* 1 /*******************************************************************************
2 * Copyright (c) 2000, 2007 IBM Corporation and others. 2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
34 * Note: Only one of the styles SAVE and OPEN may be specified. 34 * Note: Only one of the styles SAVE and OPEN may be specified.
35 * </p><p> 35 * </p><p>
36 * IMPORTANT: This class is intended to be subclassed <em>only</em> 36 * IMPORTANT: This class is intended to be subclassed <em>only</em>
37 * within the DWT implementation. 37 * within the DWT implementation.
38 * </p> 38 * </p>
39 *
40 * @see <a href="http://www.eclipse.org/swt/snippets/#filedialog">FileDialog snippets</a>
41 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample, Dialog tab</a>
42 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
39 */ 43 */
40 public class FileDialog : Dialog { 44 public class FileDialog : Dialog {
41 String [] filterNames = new String [0]; 45 String [] filterNames = new String [0];
42 String [] filterExtensions = new String [0]; 46 String [] filterExtensions = new String [0];
43 String [] fileNames = new String[0]; 47 String [] fileNames = new String[0];
86 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> 90 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
87 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> 91 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
88 * </ul> 92 * </ul>
89 */ 93 */
90 public this (Shell parent, int style) { 94 public this (Shell parent, int style) {
91 super (parent, style); 95 super (parent, checkStyle (parent, style));
92 checkSubclass (); 96 checkSubclass ();
93 } 97 }
94 98
95 /** 99 /**
96 * Returns the path of the first file that was 100 * Returns the path of the first file that was
203 openPanel.setAllowsMultipleSelection((style & DWT.MULTI) !is 0); 207 openPanel.setAllowsMultipleSelection((style & DWT.MULTI) !is 0);
204 panel = openPanel; 208 panel = openPanel;
205 } 209 }
206 if (filterPath !is null) panel.setDirectory(NSString.stringWith(filterPath)); 210 if (filterPath !is null) panel.setDirectory(NSString.stringWith(filterPath));
207 panel.setTitle(NSString.stringWith(title !is null ? title : "")); 211 panel.setTitle(NSString.stringWith(title !is null ? title : ""));
208 int response = panel.runModal(); 212 int /*long*/ response = panel.runModal();
209 if (response is OS.NSFileHandlingPanelOKButton) { 213 if (response is OS.NSFileHandlingPanelOKButton) {
210 NSString filename = panel.filename(); 214 NSString filename = panel.filename();
211 char[] buffer = new char[filename.length()]; 215 fullPath = filename.getString();
212 filename.getCharacters_(buffer);
213 fullPath = new String(buffer);
214 if ((style & DWT.SAVE) is 0) { 216 if ((style & DWT.SAVE) is 0) {
215 NSArray filenames = (cast(NSOpenPanel)panel).filenames(); 217 NSArray filenames = (cast(NSOpenPanel)panel).filenames();
216 int count = filenames.count(); 218 int count = (int)/*64*/filenames.count();
217 fileNames = new String[count]; 219 fileNames = new String[count];
220
218 for (int i = 0; i < count; i++) { 221 for (int i = 0; i < count; i++) {
219 filename = new NSString(filenames.objectAtIndex(i)); 222 filename = new NSString(filenames.objectAtIndex(i));
220 buffer = new char[filename.length()]; 223 NSString filenameOnly = filename.lastPathComponent();
221 filename.getCharacters_(buffer); 224 NSString pathOnly = filename.stringByDeletingLastPathComponent();
222 fileNames[i] = new String(buffer); 225
226 if (i is 0) {
227 /* Filter path */
228 filterPath = pathOnly.getString();
229
230 /* File name */
231 fileName = fileNames [0] = filenameOnly.getString();
232 } else {
233 if (pathOnly.getString().equals (filterPath)) {
234 fileNames [i] = filenameOnly.getString();
235 } else {
236 fileNames [i] = filename.getString();
237 }
238 }
223 } 239 }
224 } 240 }
225 filterIndex = -1; 241 filterIndex = -1;
226 } 242 }
227 return fullPath; 243 return fullPath;
243 * Set the file extensions which the dialog will 259 * Set the file extensions which the dialog will
244 * use to filter the files it shows to the argument, 260 * use to filter the files it shows to the argument,
245 * which may be null. 261 * which may be null.
246 * <p> 262 * <p>
247 * The strings are platform specific. For example, on 263 * The strings are platform specific. For example, on
248 * Windows, an extension filter string is typically of 264 * some platforms, an extension filter string is typically
249 * the form "*.extension", where "*.*" matches all files. 265 * of the form "*.extension", where "*.*" matches all files.
266 * For filters with multiple extensions, use semicolon as
267 * a separator, e.g. "*.jpg;*.png".
250 * </p> 268 * </p>
251 * 269 *
252 * @param extensions the file extension filter 270 * @param extensions the file extension filter
253 * 271 *
254 * @see #setFilterNames to specify the user-friendly 272 * @see #setFilterNames to specify the user-friendly
277 public void setFilterIndex (int index) { 295 public void setFilterIndex (int index) {
278 filterIndex = index; 296 filterIndex = index;
279 } 297 }
280 298
281 /** 299 /**
282 * Sets the the names that describe the filter extensions 300 * Sets the names that describe the filter extensions
283 * which the dialog will use to filter the files it shows 301 * which the dialog will use to filter the files it shows
284 * to the argument, which may be null. 302 * to the argument, which may be null.
285 * <p> 303 * <p>
286 * Each name is a user-friendly short description shown for 304 * Each name is a user-friendly short description shown for
287 * its corresponding filter. The <code>names</code> array must 305 * its corresponding filter. The <code>names</code> array must