Mercurial > projects > dynamin
comparison dynamin/gui/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 | 4029d5af7542 |
children |
comparison
equal
deleted
inserted
replaced
17:ef81af74a306 | 18:836a064828e8 |
---|---|
23 * | 23 * |
24 */ | 24 */ |
25 | 25 |
26 module dynamin.gui.directory_dialog; | 26 module dynamin.gui.directory_dialog; |
27 | 27 |
28 import dynamin.c.windows; | |
29 import dynamin.all_core; | 28 import dynamin.all_core; |
30 import dynamin.gui.window; | 29 import dynamin.gui_backend; |
31 import tango.io.Stdout; | |
32 import Utf = tango.text.convert.Utf; | |
33 //import std.c.windows.com; | |
34 | 30 |
35 /** | 31 /** |
36 * | 32 * |
37 * | 33 * |
38 * The appearance of a directory dialog with Windows Classic: | 34 * The appearance of a directory dialog with Windows Classic: |
39 * | 35 * |
40 * $(IMAGE ../web/example_directory_dialog.png) | 36 * $(IMAGE ../web/example_directory_dialog.png) |
41 */ | 37 */ |
42 class DirectoryDialog { // use FILE_CHOOSER_ACTION_SELECT_FOLDER | 38 class DirectoryDialog { // TODO: rename to FolderDialog |
43 private: | 39 private: |
40 mixin DirectoryDialogBackend; | |
41 string _text; | |
44 string _directory; | 42 string _directory; |
45 public: | 43 public: |
44 /// Gets or sets the text that is displayed in the dialog's title bar. | |
45 string text() { return _text; } | |
46 /// ditto | |
47 void text(string str) { _text = str; } | |
48 | |
49 /// Gets or sets the selected directory. | |
46 string directory() { | 50 string directory() { |
47 return _directory; | 51 return _directory; |
48 } | 52 } |
53 /// ditto | |
49 void directory(string str) { | 54 void directory(string str) { |
50 throw new Exception("Sorry, DirectoryDialog.directory(string) not yet working"); | |
51 _directory = str; | 55 _directory = str; |
52 } | 56 } |
53 | 57 |
54 DialogResult showDialog() { | 58 DialogResult showDialog() { |
55 BROWSEINFO bi; | 59 return backend_showDialog(); |
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 } | 60 } |
92 } | 61 } |