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