Mercurial > projects > dwt-addons
annotate dwtx/jface/preference/PathEditor.d @ 90:7ffeace6c47f
Update 3.4M7 to 3.4
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 06 Jul 2008 23:30:07 +0200 |
parents | 7f9034e47984 |
children | dadb23ea55a6 |
rev | line source |
---|---|
34 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2006 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 dwtx.jface.preference.PathEditor; | |
14 | |
15 import dwtx.jface.preference.ListEditor; | |
16 | |
17 import tango.io.FilePath; | |
90 | 18 import tango.io.model.IFile; |
34 | 19 // import java.util.ArrayList; |
20 // import java.util.StringTokenizer; | |
21 | |
22 import dwt.widgets.Composite; | |
23 import dwt.widgets.DirectoryDialog; | |
24 | |
25 import dwt.dwthelper.utils; | |
26 import tango.text.Util; | |
27 | |
28 /** | |
29 * A field editor to edit directory paths. | |
30 */ | |
31 public class PathEditor : ListEditor { | |
32 | |
33 /** | |
34 * The last path, or <code>null</code> if none. | |
35 */ | |
36 private String lastPath; | |
37 | |
38 /** | |
39 * The special label text for directory chooser, | |
40 * or <code>null</code> if none. | |
41 */ | |
42 private String dirChooserLabelText; | |
43 | |
44 /** | |
45 * Creates a new path field editor | |
46 */ | |
47 protected this() { | |
48 } | |
49 | |
50 /** | |
51 * Creates a path field editor. | |
52 * | |
53 * @param name the name of the preference this field editor works on | |
54 * @param labelText the label text of the field editor | |
55 * @param dirChooserLabelText the label text displayed for the directory chooser | |
56 * @param parent the parent of the field editor's control | |
57 */ | |
58 public this(String name, String labelText, | |
59 String dirChooserLabelText, Composite parent) { | |
60 init(name, labelText); | |
61 this.dirChooserLabelText = dirChooserLabelText; | |
62 createControl(parent); | |
63 } | |
64 | |
65 /* (non-Javadoc) | |
66 * Method declared on ListEditor. | |
67 * Creates a single string from the given array by separating each | |
68 * string with the appropriate OS-specific path separator. | |
69 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
34
diff
changeset
|
70 protected override String createList(String[] items) { |
34 | 71 StringBuffer path = new StringBuffer("");//$NON-NLS-1$ |
72 | |
73 for (int i = 0; i < items.length; i++) { | |
74 path.append(items[i]); | |
50 | 75 path.append(FileConst.SystemPathString); |
34 | 76 } |
77 return path.toString(); | |
78 } | |
79 | |
80 /* (non-Javadoc) | |
81 * Method declared on ListEditor. | |
82 * Creates a new path element by means of a directory dialog. | |
83 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
34
diff
changeset
|
84 protected override String getNewInputObject() { |
34 | 85 |
86 DirectoryDialog dialog = new DirectoryDialog(getShell()); | |
87 if (dirChooserLabelText !is null) { | |
88 dialog.setMessage(dirChooserLabelText); | |
89 } | |
90 if (lastPath !is null) { | |
91 if ((new FilePath(lastPath)).exists()) { | |
92 dialog.setFilterPath(lastPath); | |
93 } | |
94 } | |
95 String dir = dialog.open(); | |
96 if (dir !is null) { | |
97 dir = dwt.dwthelper.utils.trim(dir); | |
98 if (dir.length is 0) { | |
99 return null; | |
100 } | |
101 lastPath = dir; | |
102 } | |
103 return dir; | |
104 } | |
105 | |
106 /* (non-Javadoc) | |
107 * Method declared on ListEditor. | |
108 */ | |
43
ea8ff534f622
Fix override and super aliases
Frank Benoit <benoit@tionex.de>
parents:
34
diff
changeset
|
109 protected override String[] parseString(String stringList) { |
50 | 110 return tango.text.Util.delimit(stringList.dup, FileConst.SystemPathString |
34 | 111 ~ "\n\r");//$NON-NLS-1$ |
112 } | |
113 } |