Mercurial > projects > dynamin
comparison dynamin/gui/directory_dialog.d @ 0:aa4efef0f0b1
Initial commit of code.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Mon, 15 Jun 2009 22:10:48 -0500 |
parents | |
children | 4029d5af7542 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:aa4efef0f0b1 |
---|---|
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.directory_dialog; | |
27 | |
28 import dynamin.c.windows; | |
29 import dynamin.all_core; | |
30 import dynamin.gui.window; | |
31 import tango.io.Stdout; | |
32 import Utf = tango.text.convert.Utf; | |
33 //import std.c.windows.com; | |
34 | |
35 /** | |
36 * | |
37 * | |
38 * The appearance of a directory dialog with Windows Classic: | |
39 * | |
40 * $(IMAGE ../web/example_directory_dialog.png) | |
41 */ | |
42 class DirectoryDialog { // use FILE_CHOOSER_ACTION_SELECT_FOLDER | |
43 private: | |
44 string _directory; | |
45 public: | |
46 string directory() { | |
47 return _directory; | |
48 } | |
49 void directory(string str) { | |
50 throw new Exception("Sorry, DirectoryDialog.directory(string) not yet working"); | |
51 _directory = str; | |
52 } | |
53 DialogResult showDialog() { | |
54 BROWSEINFO bi; | |
55 //bi.hwndOwner = ; | |
56 bi.lpszTitle = "Choose a folder:"; | |
57 bi.ulFlags |= BIF_RETURNONLYFSDIRS; | |
58 bi.ulFlags |= BIF_USENEWUI; | |
59 | |
60 // TODO: I can't get this #!@#! COM stuff working... | |
61 //IShellFolder* shf; | |
62 //SHGetDesktopFolder(&shf); | |
63 //ITEMIDLIST* pidlInit; | |
64 //shf.ParseDisplayName(null, null, toWcharPointer(directory), null, &pidlInit, null); | |
65 //shf.Release(); | |
66 //bi.pidlRoot = pidlInit; | |
67 | |
68 ITEMIDLIST* pidl = SHBrowseForFolder(&bi); | |
69 //CoTaskMemFree(pidlInit); | |
70 if(!pidl) | |
71 return DialogResult.Cancel; | |
72 wchar[MAX_PATH+1] dirBuffer; // MAX_PATH is 260 | |
73 if(!SHGetPathFromIDList(pidl, dirBuffer.ptr)) { | |
74 Stdout("GetPathFromIDList() failed").newline; | |
75 return DialogResult.Cancel; | |
76 } | |
77 CoTaskMemFree(pidl); | |
78 int index = MAX_PATH; | |
79 foreach(i, c; dirBuffer) | |
80 if(c == 0) { // find first null | |
81 index = i; | |
82 if(dirBuffer[i-1] != '\\') { | |
83 dirBuffer[i] = '\\'; | |
84 index++; | |
85 } | |
86 break; | |
87 } | |
88 _directory = Utf.toString(dirBuffer[0..index]); | |
89 return DialogResult.OK; | |
90 } | |
91 } |