diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dynamin/gui/windows_directory_dialog.d	Fri Jul 24 00:35:42 2009 -0500
@@ -0,0 +1,70 @@
+// Written in the D programming language
+// www.digitalmars.com/d/
+
+/*
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is the Dynamin library.
+ *
+ * The Initial Developer of the Original Code is Jordan Miner.
+ * Portions created by the Initial Developer are Copyright (C) 2006-2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Jordan Miner <jminer7@gmail.com>
+ *
+ */
+
+module dynamin.gui.windows_directory_dialog;
+
+public import Utf = tango.text.convert.Utf;
+
+template DirectoryDialogBackend() {
+	DialogResult backend_showDialog() {
+		BROWSEINFO bi;
+		//bi.hwndOwner = ;
+		bi.lpszTitle = "Choose a folder:";
+		bi.ulFlags |= BIF_RETURNONLYFSDIRS;
+		bi.ulFlags |= BIF_USENEWUI;
+
+		// TODO: I can't get this #!@#! COM stuff working...
+		//IShellFolder* shf;
+		//SHGetDesktopFolder(&shf);
+		//ITEMIDLIST* pidlInit;
+		//shf.ParseDisplayName(null, null, toWcharPointer(directory), null, &pidlInit, null);
+		//shf.Release();
+		//bi.pidlRoot = pidlInit;
+
+		ITEMIDLIST* pidl = SHBrowseForFolder(&bi);
+		//CoTaskMemFree(pidlInit);
+		if(!pidl)
+			return DialogResult.Cancel;
+		wchar[MAX_PATH+1] dirBuffer; // MAX_PATH is 260
+		if(!SHGetPathFromIDList(pidl, dirBuffer.ptr)) {
+			Stdout("GetPathFromIDList() failed").newline;
+			return DialogResult.Cancel;
+		}
+		CoTaskMemFree(pidl);
+		int index = MAX_PATH;
+		foreach(i, c; dirBuffer)
+			if(c == 0) { // find first null
+				index = i;
+				if(dirBuffer[i-1] != '\\') {
+					dirBuffer[i] = '\\';
+					index++;
+				}
+				break;
+			}
+		_directory = Utf.toString(dirBuffer[0..index]);
+		return DialogResult.OK;
+	}
+}
+