Mercurial > projects > dwt-linux
annotate dwt/browser/FilePicker.d @ 348:9a4d7706df52
Test Update to fix linux XPCOM interface issues
author | John Reimer <terminal.node@gmail.com> |
---|---|
date | Fri, 31 Oct 2008 21:46:44 -0700 |
parents | 5abc6f7f7a95 |
children |
rev | line source |
---|---|
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
1 /******************************************************************************* |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2003, 2007 IBM Corporation and others. |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
3 * All rights reserved. This program and the accompanying materials |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
5 * which accompanies this distribution, and is available at |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
6 * http://www.eclipse.org/legal/epl-v10.html |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
7 * |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
8 * Contributors: |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
9 * IBM Corporation - initial API and implementation |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
10 * Port to the D programming language: |
286 | 11 * John Reimer <terminal.node@gmail.com> |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
12 *******************************************************************************/ |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
13 module dwt.browser.FilePicker; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
14 |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
15 import dwt.dwthelper.utils; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
16 |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
17 import dwt.DWT; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
18 |
341
942da4b6558a
Ongoing fixup for compile
John Reimer <terminal.node@gmail.com>
parents:
286
diff
changeset
|
19 import XPCOM = dwt.internal.mozilla.XPCOM; |
942da4b6558a
Ongoing fixup for compile
John Reimer <terminal.node@gmail.com>
parents:
286
diff
changeset
|
20 |
344 | 21 import dwt.internal.mozilla.Common; |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
22 import dwt.internal.mozilla.nsEmbedString; |
344 | 23 import dwt.internal.mozilla.nsISupports; |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
24 import dwt.internal.mozilla.nsID; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
25 import dwt.internal.mozilla.nsIFilePicker; |
286 | 26 import dwt.internal.mozilla.nsIFilePicker_1_8; |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
27 import dwt.internal.mozilla.nsILocalFile; |
344 | 28 import dwt.internal.mozilla.nsIFileURL; |
29 import dwt.internal.mozilla.nsIDOMWindow; | |
30 import dwt.internal.mozilla.nsISimpleEnumerator; | |
31 import dwt.internal.mozilla.nsStringAPI; | |
32 | |
345 | 33 import dwt.browser.Mozilla; |
34 | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
35 import dwt.widgets.DirectoryDialog; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
36 import dwt.widgets.Display; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
37 import dwt.widgets.FileDialog; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
38 import dwt.widgets.Shell; |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
39 |
286 | 40 class FilePicker : nsIFilePicker { |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
41 |
286 | 42 int refCount = 0; |
43 short mode; | |
44 nsIDOMWindow parentHandle; | |
45 String[] files, masks; | |
46 String defaultFilename, directory, title; | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
47 |
286 | 48 static final String SEPARATOR = System.getProperty ("file.separator"); //$NON-NLS-1$ |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
49 |
286 | 50 this () { |
51 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
52 |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
53 extern(System) |
286 | 54 nsrefcnt AddRef () { |
55 refCount++; | |
56 return refCount; | |
57 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
58 |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
59 extern(System) |
286 | 60 nsresult QueryInterface (nsID* riid, void** ppvObject) { |
345 | 61 if (riid is null || ppvObject is null) return XPCOM.NS_ERROR_NO_INTERFACE; |
286 | 62 |
345 | 63 if (*riid == nsISupports.IID) { |
286 | 64 *ppvObject = cast(void*)cast(nsISupports) this; |
65 AddRef (); | |
345 | 66 return XPCOM.NS_OK; |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
67 } |
345 | 68 if (*riid == nsIFilePicker.IID) { |
286 | 69 *ppvObject = cast(void*)cast(nsIFilePicker) this; |
70 AddRef (); | |
345 | 71 return XPCOM.NS_OK; |
286 | 72 } |
345 | 73 if (*riid == nsIFilePicker_1_8.IID) { |
286 | 74 *ppvObject = cast(void*)cast(nsIFilePicker_1_8) this; |
75 AddRef (); | |
345 | 76 return XPCOM.NS_OK; |
286 | 77 } |
78 *ppvObject = null; | |
345 | 79 return XPCOM.NS_ERROR_NO_INTERFACE; |
286 | 80 } |
81 | |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
82 extern(System) |
286 | 83 nsrefcnt Release () { |
84 refCount--; | |
85 if (refCount is 0) return 0; | |
86 return refCount; | |
87 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
88 |
286 | 89 /* |
90 * As of Mozilla 1.8 some of nsIFilePicker's string arguments changed type. This method | |
91 * answers a java string based on the type of string that is appropriate for the Mozilla | |
92 * version being used. | |
93 */ | |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
94 extern(D) |
344 | 95 String parseAString (nsAString* string) { |
286 | 96 return null; |
97 } | |
98 | |
99 /* nsIFilePicker */ | |
100 | |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
101 extern(System) |
286 | 102 nsresult Init (nsIDOMWindow parent, nsAString* title, PRInt16 mode) { |
103 parentHandle = parent; | |
104 this.mode = mode; | |
105 this.title = parseAString (title); | |
106 return XPCOM.NS_OK; | |
107 } | |
108 | |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
109 extern(System) |
345 | 110 nsresult Show (PRInt16* _retval) { |
286 | 111 if (mode is nsIFilePicker.modeGetFolder) { |
112 /* picking a directory */ | |
113 int result = showDirectoryPicker (); | |
345 | 114 *_retval = cast(int)cast(PRInt16)result; /* PRInt16 */ |
286 | 115 return XPCOM.NS_OK; |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
116 } |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
117 |
286 | 118 /* picking a file */ |
119 int style = mode is nsIFilePicker.modeSave ? DWT.SAVE : DWT.OPEN; | |
120 if (mode is nsIFilePicker.modeOpenMultiple) style |= DWT.MULTI; | |
121 Display display = Display.getCurrent (); | |
122 Shell parent = null; // TODO compute parent | |
123 if (parent is null) { | |
124 parent = new Shell (display); | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
125 } |
286 | 126 FileDialog dialog = new FileDialog (parent, style); |
127 if (title !is null) dialog.setText (title); | |
128 if (directory !is null) dialog.setFilterPath (directory); | |
129 if (masks !is null) dialog.setFilterExtensions (masks); | |
130 if (defaultFilename !is null) dialog.setFileName (defaultFilename); | |
131 String filename = dialog.open (); | |
132 files = dialog.getFileNames (); | |
133 directory = dialog.getFilterPath (); | |
134 title = defaultFilename = null; | |
135 masks = null; | |
136 int result = filename is null ? nsIFilePicker.returnCancel : nsIFilePicker.returnOK; | |
137 *_retval = cast(int)cast(short)result;; /* PRInt16 */ | |
138 return XPCOM.NS_OK; | |
139 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
140 |
286 | 141 int showDirectoryPicker () { |
142 Display display = Display.getCurrent (); | |
143 Shell parent = null; // TODO compute parent | |
144 if (parent is null) { | |
145 parent = new Shell (display); | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
146 } |
286 | 147 DirectoryDialog dialog = new DirectoryDialog (parent, DWT.NONE); |
148 if (title !is null) dialog.setText (title); | |
149 if (directory !is null) dialog.setFilterPath (directory); | |
150 directory = dialog.open (); | |
151 title = defaultFilename = null; | |
152 files = masks = null; | |
153 return directory is null ? nsIFilePicker.returnCancel : nsIFilePicker.returnOK; | |
154 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
155 |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
156 extern(System) |
286 | 157 nsresult GetFiles (nsISimpleEnumerator* aFiles) { |
158 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | |
159 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
160 |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
161 extern(System) |
345 | 162 nsresult GetFileURL ( nsIFileURL* aFileURL ) { |
286 | 163 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; |
164 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
165 |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
166 extern(System) |
286 | 167 nsresult GetFile (nsILocalFile* aFile) { |
168 String filename = ""; //$NON-NLS-1$ | |
169 if (directory !is null) filename ~= directory ~ SEPARATOR; | |
170 if (files !is null && files.length > 0) filename ~= files[0]; | |
345 | 171 scope auto path = new nsEmbedString (toString16(filename)); |
286 | 172 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)path, 1, aFile); |
173 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | |
174 if (aFile is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); | |
175 return XPCOM.NS_OK; | |
176 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
177 |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
178 extern(System) |
286 | 179 nsresult SetDisplayDirectory (nsILocalFile aDisplayDirectory) { |
180 if (aDisplayDirectory is null) return XPCOM.NS_OK; | |
181 scope auto pathname = new nsEmbedCString(); | |
182 aDisplayDirectory.GetNativePath (cast(nsACString*)pathname); | |
183 // wchar[] chars = MozillaDelegate.mbcsToWcs (null, bytes); | |
184 directory = pathname.toString; | |
185 return XPCOM.NS_OK; | |
186 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
187 |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
188 extern(System) |
286 | 189 nsresult GetDisplayDirectory (nsILocalFile* aDisplayDirectory) { |
190 String directoryName = directory !is null ? directory : ""; //$NON-NLS-1$ | |
191 scope auto path = new nsEmbedString (Utf.toString16(directoryName)); | |
192 int rc = XPCOM.NS_NewLocalFile (cast(nsAString*)path, 1, aDisplayDirectory); | |
193 if (rc !is XPCOM.NS_OK) Mozilla.error (rc); | |
194 if (aDisplayDirectory is null) Mozilla.error (XPCOM.NS_ERROR_NULL_POINTER); | |
195 return XPCOM.NS_OK; | |
196 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
197 |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
198 extern(System) |
286 | 199 nsresult SetFilterIndex (PRInt32 aFilterIndex) { |
200 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | |
201 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
202 |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
203 extern(System) |
286 | 204 nsresult GetFilterIndex (PRInt32* aFilterIndex) { |
205 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | |
206 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
207 |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
208 extern(System) |
286 | 209 nsresult SetDefaultExtension (nsAString* aDefaultExtension) { |
210 /* note that the type of argument 1 changed as of Mozilla 1.8 */ | |
211 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | |
212 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
213 |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
214 extern(System) |
286 | 215 nsresult GetDefaultExtension (nsAString* aDefaultExtension) { |
216 /* note that the type of argument 1 changed as of Mozilla 1.8 */ | |
217 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | |
218 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
219 |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
220 extern(System) |
286 | 221 nsresult SetDefaultString (nsAString* aDefaultString) { |
222 defaultFilename = parseAString (aDefaultString); | |
223 return XPCOM.NS_OK; | |
224 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
225 |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
226 extern(System) |
286 | 227 nsresult GetDefaultString (nsAString* aDefaultString) { |
228 /* note that the type of argument 1 changed as of Mozilla 1.8 */ | |
229 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | |
230 } | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
231 |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
232 extern(System) |
286 | 233 nsresult AppendFilter (nsAString* title, nsAString* filter) { |
234 /* note that the type of arguments 1 and 2 changed as of Mozilla 1.8 */ | |
235 return XPCOM.NS_ERROR_NOT_IMPLEMENTED; | |
236 } | |
237 | |
348
9a4d7706df52
Test Update to fix linux XPCOM interface issues
John Reimer <terminal.node@gmail.com>
parents:
345
diff
changeset
|
238 extern(System) |
286 | 239 nsresult AppendFilters (PRInt32 filterMask) { |
240 String[] addFilters = null; | |
241 switch (filterMask) { | |
242 case nsIFilePicker.filterAll: | |
243 case nsIFilePicker.filterApps: | |
244 masks = null; /* this is equivalent to no filter */ | |
245 break; | |
246 case nsIFilePicker.filterHTML: | |
247 addFilters[0] = "*.htm;*.html"; //$NON-NLS-1$ | |
248 break; | |
249 case nsIFilePicker.filterImages: | |
250 addFilters[0] = "*.gif;*.jpeg;*.jpg;*.png"; //$NON-NLS-1$ | |
251 break; | |
252 case nsIFilePicker.filterText: | |
253 addFilters[0] = "*.txt"; //$NON-NLS-1$ | |
254 break; | |
255 case nsIFilePicker.filterXML: | |
256 addFilters[0] = "*.xml"; //$NON-NLS-1$ | |
257 break; | |
258 case nsIFilePicker.filterXUL: | |
259 addFilters[0] = "*.xul"; //$NON-NLS-1$ | |
260 break; | |
261 } | |
262 if (masks is null) { | |
263 masks = addFilters; | |
264 } else { | |
265 if (addFilters !is null) { | |
266 masks ~= addFilters; | |
278
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
267 } |
93409d9838c5
Commit more browser/xpcom updates, including still uncoverted source.
John Reimer<terminal.node@gmail.com>
parents:
diff
changeset
|
268 } |
286 | 269 return XPCOM.NS_OK; |
270 } | |
271 } |