comparison dynamin/gui/windows_directory_dialog.d @ 18:836a064828e8

Implement FileDialog/DirectoryDialog with GTK and start a glib/gdk/gtk binding. Add invoke/invokeNow stubs to fix build on X.
author Jordan Miner <jminer7@gmail.com>
date Fri, 24 Jul 2009 00:35:42 -0500
parents
children 63cbfb167240
comparison
equal deleted inserted replaced
17:ef81af74a306 18:836a064828e8
1 // Written in the D programming language
2 // www.digitalmars.com/d/
3
4 /*
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Dynamin library.
16 *
17 * The Initial Developer of the Original Code is Jordan Miner.
18 * Portions created by the Initial Developer are Copyright (C) 2006-2009
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s):
22 * Jordan Miner <jminer7@gmail.com>
23 *
24 */
25
26 module dynamin.gui.windows_directory_dialog;
27
28 public import Utf = tango.text.convert.Utf;
29
30 template DirectoryDialogBackend() {
31 DialogResult backend_showDialog() {
32 BROWSEINFO bi;
33 //bi.hwndOwner = ;
34 bi.lpszTitle = "Choose a folder:";
35 bi.ulFlags |= BIF_RETURNONLYFSDIRS;
36 bi.ulFlags |= BIF_USENEWUI;
37
38 // TODO: I can't get this #!@#! COM stuff working...
39 //IShellFolder* shf;
40 //SHGetDesktopFolder(&shf);
41 //ITEMIDLIST* pidlInit;
42 //shf.ParseDisplayName(null, null, toWcharPointer(directory), null, &pidlInit, null);
43 //shf.Release();
44 //bi.pidlRoot = pidlInit;
45
46 ITEMIDLIST* pidl = SHBrowseForFolder(&bi);
47 //CoTaskMemFree(pidlInit);
48 if(!pidl)
49 return DialogResult.Cancel;
50 wchar[MAX_PATH+1] dirBuffer; // MAX_PATH is 260
51 if(!SHGetPathFromIDList(pidl, dirBuffer.ptr)) {
52 Stdout("GetPathFromIDList() failed").newline;
53 return DialogResult.Cancel;
54 }
55 CoTaskMemFree(pidl);
56 int index = MAX_PATH;
57 foreach(i, c; dirBuffer)
58 if(c == 0) { // find first null
59 index = i;
60 if(dirBuffer[i-1] != '\\') {
61 dirBuffer[i] = '\\';
62 index++;
63 }
64 break;
65 }
66 _directory = Utf.toString(dirBuffer[0..index]);
67 return DialogResult.OK;
68 }
69 }
70