Mercurial > projects > dynamin
annotate dynamin/gui/directory_dialog.d @ 5:4029d5af7542
Add blank lines and rewrap some comments.
author | Jordan Miner <jminer7@gmail.com> |
---|---|
date | Sat, 20 Jun 2009 12:26:40 -0500 |
parents | aa4efef0f0b1 |
children | 836a064828e8 |
rev | line source |
---|---|
0 | 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 } | |
5
4029d5af7542
Add blank lines and rewrap some comments.
Jordan Miner <jminer7@gmail.com>
parents:
0
diff
changeset
|
53 |
0 | 54 DialogResult showDialog() { |
55 BROWSEINFO bi; | |
56 //bi.hwndOwner = ; | |
57 bi.lpszTitle = "Choose a folder:"; | |
58 bi.ulFlags |= BIF_RETURNONLYFSDIRS; | |
59 bi.ulFlags |= BIF_USENEWUI; | |
60 | |
61 // TODO: I can't get this #!@#! COM stuff working... | |
62 //IShellFolder* shf; | |
63 //SHGetDesktopFolder(&shf); | |
64 //ITEMIDLIST* pidlInit; | |
65 //shf.ParseDisplayName(null, null, toWcharPointer(directory), null, &pidlInit, null); | |
66 //shf.Release(); | |
67 //bi.pidlRoot = pidlInit; | |
68 | |
69 ITEMIDLIST* pidl = SHBrowseForFolder(&bi); | |
70 //CoTaskMemFree(pidlInit); | |
71 if(!pidl) | |
72 return DialogResult.Cancel; | |
73 wchar[MAX_PATH+1] dirBuffer; // MAX_PATH is 260 | |
74 if(!SHGetPathFromIDList(pidl, dirBuffer.ptr)) { | |
75 Stdout("GetPathFromIDList() failed").newline; | |
76 return DialogResult.Cancel; | |
77 } | |
78 CoTaskMemFree(pidl); | |
79 int index = MAX_PATH; | |
80 foreach(i, c; dirBuffer) | |
81 if(c == 0) { // find first null | |
82 index = i; | |
83 if(dirBuffer[i-1] != '\\') { | |
84 dirBuffer[i] = '\\'; | |
85 index++; | |
86 } | |
87 break; | |
88 } | |
89 _directory = Utf.toString(dirBuffer[0..index]); | |
90 return DialogResult.OK; | |
91 } | |
92 } |