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