# HG changeset patch # User Jordan Miner # Date 1248995449 18000 # Node ID 4eebc294a3ac157ba2a651bd6bb096d503a4e331 # Parent ad551ec36b755d80d05faf950cba9fdc30e25e44 Rename DirectoryDialog to FolderDialog. diff -r ad551ec36b75 -r 4eebc294a3ac dynamin/all_gui.d --- a/dynamin/all_gui.d Thu Jul 30 18:05:50 2009 -0500 +++ b/dynamin/all_gui.d Thu Jul 30 18:10:49 2009 -0500 @@ -36,8 +36,8 @@ public import dynamin.gui.cursor; public import dynamin.gui.clipboard; public import dynamin.gui.screen; -public import dynamin.gui.directory_dialog; public import dynamin.gui.file_dialog; +public import dynamin.gui.folder_dialog; public import dynamin.gui.label; public import dynamin.gui.button; diff -r ad551ec36b75 -r 4eebc294a3ac dynamin/gui/directory_dialog.d --- a/dynamin/gui/directory_dialog.d Thu Jul 30 18:05:50 2009 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -// 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 - * - */ - -module dynamin.gui.directory_dialog; - -import dynamin.all_core; -import dynamin.gui_backend; - -/** - * - * - * The appearance of a directory dialog with Windows Classic: - * - * $(IMAGE ../web/example_directory_dialog.png) - */ -class DirectoryDialog { // TODO: rename to FolderDialog -private: - mixin DirectoryDialogBackend; - string _text; - string _directory; -public: - /// Gets or sets the text that is displayed in the dialog's title bar. - string text() { return _text; } - /// ditto - void text(string str) { _text = str; } - - /// Gets or sets the selected directory. - string directory() { - return _directory; - } - /// ditto - void directory(string str) { - _directory = str; - } - - DialogResult showDialog() { - return backend_showDialog(); - } -} diff -r ad551ec36b75 -r 4eebc294a3ac dynamin/gui/folder_dialog.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dynamin/gui/folder_dialog.d Thu Jul 30 18:10:49 2009 -0500 @@ -0,0 +1,61 @@ +// 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 + * + */ + +module dynamin.gui.folder_dialog; + +import dynamin.all_core; +import dynamin.gui_backend; + +/** + * + * + * The appearance of a directory dialog with Windows Classic: + * + * $(IMAGE ../web/example_directory_dialog.png) + */ +class FolderDialog { +private: + mixin FolderDialogBackend; + string _text; + string _directory; +public: + /// Gets or sets the text that is displayed in the dialog's title bar. + string text() { return _text; } + /// ditto + void text(string str) { _text = str; } + + /// Gets or sets the selected directory. + string directory() { + return _directory; + } + /// ditto + void directory(string str) { + _directory = str; + } + + DialogResult showDialog() { + return backend_showDialog(); + } +} diff -r ad551ec36b75 -r 4eebc294a3ac dynamin/gui/windows_directory_dialog.d --- a/dynamin/gui/windows_directory_dialog.d Thu Jul 30 18:05:50 2009 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -// 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 - * - */ - -module dynamin.gui.windows_directory_dialog; - -public import Utf = tango.text.convert.Utf; - -template DirectoryDialogBackend() { - extern(Windows) static int setSelectedDirectory(HWND hwnd, - UINT uMsg, LPARAM lParam, LPARAM lpData) { - if(uMsg == BFFM_INITIALIZED) - SendMessage(hwnd, BFFM_SETSELECTION, true, lpData); - return 0; - } - - DialogResult backend_showDialog() { - BROWSEINFO bi; - //bi.hwndOwner = ; - bi.lpszTitle = "Choose a folder:"; - bi.ulFlags |= BIF_RETURNONLYFSDIRS; - bi.ulFlags |= BIF_USENEWUI; - if(directory) { - bi.lpfn = &setSelectedDirectory; - bi.lParam = cast(LPARAM)toWcharPtr(directory); - } - - ITEMIDLIST* pidl = SHBrowseForFolder(&bi); - 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; - } -} - diff -r ad551ec36b75 -r 4eebc294a3ac dynamin/gui/windows_folder_dialog.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dynamin/gui/windows_folder_dialog.d Thu Jul 30 18:10:49 2009 -0500 @@ -0,0 +1,72 @@ +// 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 + * + */ + +module dynamin.gui.windows_folder_dialog; + +public import Utf = tango.text.convert.Utf; + +template FolderDialogBackend() { + extern(Windows) static int setSelectedDirectory(HWND hwnd, + UINT uMsg, LPARAM lParam, LPARAM lpData) { + if(uMsg == BFFM_INITIALIZED) + SendMessage(hwnd, BFFM_SETSELECTION, true, lpData); + return 0; + } + + DialogResult backend_showDialog() { + BROWSEINFO bi; + //bi.hwndOwner = ; + bi.lpszTitle = "Choose a folder:"; + bi.ulFlags |= BIF_RETURNONLYFSDIRS; + bi.ulFlags |= BIF_USENEWUI; + if(directory) { + bi.lpfn = &setSelectedDirectory; + bi.lParam = cast(LPARAM)toWcharPtr(directory); + } + + ITEMIDLIST* pidl = SHBrowseForFolder(&bi); + 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; + } +} + diff -r ad551ec36b75 -r 4eebc294a3ac dynamin/gui/x_directory_dialog.d --- a/dynamin/gui/x_directory_dialog.d Thu Jul 30 18:05:50 2009 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -// 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) 2009 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Jordan Miner - * - */ - -module dynamin.gui.x_directory_dialog; - -public import Utf = tango.text.convert.Utf; -public import dynamin.c.glib; -public import dynamin.c.gtk; - -template DirectoryDialogBackend() { - DialogResult backend_showDialog() { - string title = text ? text : "Select Folder"; - auto dialog = gtk_file_chooser_dialog_new(toCharPtr(title), null, - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, null); - if(_directory) - gtk_file_chooser_set_current_folder(dialog, toCharPtr(_directory)); - scope(exit) { - gtk_widget_destroy(dialog); - while(gtk_events_pending()) - gtk_main_iteration(); - } - if(gtk_dialog_run(dialog) == GTK_RESPONSE_ACCEPT) { - char* folder = gtk_file_chooser_get_filename(dialog); - _directory = folder[0..strlen(folder)].dup; - g_free(folder); - return DialogResult.OK; - } - return DialogResult.Cancel; - } -} - diff -r ad551ec36b75 -r 4eebc294a3ac dynamin/gui/x_folder_dialog.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dynamin/gui/x_folder_dialog.d Thu Jul 30 18:10:49 2009 -0500 @@ -0,0 +1,55 @@ +// 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) 2009 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Jordan Miner + * + */ + +module dynamin.gui.x_folder_dialog; + +public import Utf = tango.text.convert.Utf; +public import dynamin.c.glib; +public import dynamin.c.gtk; + +template FolderDialogBackend() { + DialogResult backend_showDialog() { + string title = text ? text : "Select Folder"; + auto dialog = gtk_file_chooser_dialog_new(toCharPtr(title), null, + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, null); + if(_directory) + gtk_file_chooser_set_current_folder(dialog, toCharPtr(_directory)); + scope(exit) { + gtk_widget_destroy(dialog); + while(gtk_events_pending()) + gtk_main_iteration(); + } + if(gtk_dialog_run(dialog) == GTK_RESPONSE_ACCEPT) { + char* folder = gtk_file_chooser_get_filename(dialog); + _directory = folder[0..strlen(folder)].dup; + g_free(folder); + return DialogResult.OK; + } + return DialogResult.Cancel; + } +} + diff -r ad551ec36b75 -r 4eebc294a3ac dynamin/gui_backend.d --- a/dynamin/gui_backend.d Thu Jul 30 18:05:50 2009 -0500 +++ b/dynamin/gui_backend.d Thu Jul 30 18:10:49 2009 -0500 @@ -28,15 +28,15 @@ version(Windows) { public import dynamin.gui.windows_clipboard; public import dynamin.gui.windows_cursor; - public import dynamin.gui.windows_directory_dialog; public import dynamin.gui.windows_file_dialog; + public import dynamin.gui.windows_folder_dialog; //public import dynamin.gui.windows_screen; public import dynamin.gui.windows_window; } else { public import dynamin.gui.x_clipboard; public import dynamin.gui.x_cursor; - public import dynamin.gui.x_directory_dialog; public import dynamin.gui.x_file_dialog; + public import dynamin.gui.x_folder_dialog; //public import dynamin.gui.x_screen; public import dynamin.gui.x_window; }