Revision: 4505 http://geany.svn.sourceforge.net/geany/?rev=4505&view=rev Author: eht16 Date: 2009-12-20 21:49:23 +0000 (Sun, 20 Dec 2009)
Log Message: ----------- Rename win32_show_file_dialog() to win32_show_document_open_dialog() as it is specialised for opening documents. Implement win32_show_file_dialog() as a generic file open dialog and use it with ui_path_box_new().
Modified Paths: -------------- trunk/ChangeLog trunk/src/dialogs.c trunk/src/ui_utils.c trunk/src/win32.c trunk/src/win32.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2009-12-20 21:03:28 UTC (rev 4504) +++ trunk/ChangeLog 2009-12-20 21:49:23 UTC (rev 4505) @@ -29,6 +29,11 @@ Rename win32_show_project_folder_dialog() to win32_show_folder_dialog() as it is not related and not used by any project management related code. + * src/ui_utils.c, src/win32.c, src/win32.h, src/dialogs.c: + Rename win32_show_file_dialog() to win32_show_document_open_dialog() + as it is specialised for opening documents. + Implement win32_show_file_dialog() as a generic file open dialog and + use it with ui_path_box_new().
2009-12-20 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
Modified: trunk/src/dialogs.c =================================================================== --- trunk/src/dialogs.c 2009-12-20 21:03:28 UTC (rev 4504) +++ trunk/src/dialogs.c 2009-12-20 21:49:23 UTC (rev 4505) @@ -222,7 +222,7 @@ setptr(initdir, utils_get_locale_from_utf8(initdir));
#if GEANY_USE_WIN32_DIALOG - win32_show_file_dialog(TRUE, initdir); + win32_show_document_open_dialog(TRUE, initdir); #else /* X11, not win32: use GTK_FILE_CHOOSER */
/* We use the same file selection widget each time, so first of all we create it
Modified: trunk/src/ui_utils.c =================================================================== --- trunk/src/ui_utils.c 2009-12-20 21:03:28 UTC (rev 4504) +++ trunk/src/ui_utils.c 2009-12-20 21:49:23 UTC (rev 4505) @@ -1662,7 +1662,7 @@ if (action == GTK_FILE_CHOOSER_ACTION_OPEN) { #ifdef G_OS_WIN32 - utf8_path = win32_show_folder_dialog(ui_widgets.prefs_dialog, title, + utf8_path = win32_show_file_dialog(GTK_WINDOW(ui_widgets.prefs_dialog), title, gtk_entry_get_text(GTK_ENTRY(entry))); #else utf8_path = run_file_chooser(title, action, gtk_entry_get_text(GTK_ENTRY(entry))); @@ -1672,9 +1672,8 @@ { gchar *path = g_path_get_dirname(gtk_entry_get_text(GTK_ENTRY(entry))); #ifdef G_OS_WIN32 - /* TODO this doesn't work on Windows yet, we need a more generic win32_show_file_dialog() */ - /*utf8_path = win32_show_file_dialog(TRUE, ui_widgets.prefs_dialog, path);*/ - utf8_path = NULL; + utf8_path = win32_show_folder_dialog(ui_widgets.prefs_dialog, title, + gtk_entry_get_text(GTK_ENTRY(entry))); #else utf8_path = run_file_chooser(title, action, path); #endif
Modified: trunk/src/win32.c =================================================================== --- trunk/src/win32.c 2009-12-20 21:03:28 UTC (rev 4504) +++ trunk/src/win32.c 2009-12-20 21:49:23 UTC (rev 4505) @@ -313,7 +313,7 @@
/* initial_dir can be NULL to use the current working directory. * Returns: TRUE if the dialog was not cancelled. */ -gboolean win32_show_file_dialog(gboolean file_open, const gchar *initial_dir) +gboolean win32_show_document_open_dialog(gboolean file_open, const gchar *initial_dir) { OPENFILENAMEW of; gint retval; @@ -412,6 +412,59 @@ }
+/* initial_dir can be NULL to use the current working directory. + * Returns: the selected filename */ +gchar *win32_show_file_dialog(GtkWindow *parent, const gchar *title, const gchar *initial_file) +{ + OPENFILENAMEW of; + gint retval; + gchar tmp[MAX_PATH]; + wchar_t w_file[MAX_PATH]; + wchar_t w_title[512]; + guint x; + + w_file[0] = '\0'; + + if (initial_file != NULL) + MultiByteToWideChar(CP_UTF8, 0, initial_file, -1, w_file, sizeof(w_file)); + + MultiByteToWideChar(CP_UTF8, 0, title, -1, w_title, sizeof(w_title)); + + /* initialise file dialog info struct */ + memset(&of, 0, sizeof of); +#ifdef OPENFILENAME_SIZE_VERSION_400 + of.lStructSize = OPENFILENAME_SIZE_VERSION_400; +#else + of.lStructSize = sizeof of; +#endif + of.hwndOwner = GDK_WINDOW_HWND(GTK_WIDGET(parent)->window); + + of.lpstrFile = w_file; + of.nMaxFile = 2048; + of.lpstrFileTitle = NULL; + of.lpstrTitle = w_title; + of.lpstrDefExt = L""; + of.Flags = OFN_FILEMUSTEXIST | OFN_EXPLORER; + retval = GetOpenFileNameW(&of); + + if (! retval) + { + if (CommDlgExtendedError()) + { + gchar *error = g_strdup_printf( + "File dialog box error (%x)", (gint) CommDlgExtendedError()); + win32_message_dialog(NULL, GTK_MESSAGE_ERROR, error); + g_free(error); + } + return NULL; + } + + WideCharToMultiByte(CP_UTF8, 0, w_file, -1, tmp, sizeof(tmp), NULL, NULL); + + return g_strdup(tmp); +} + + void win32_show_font_dialog(void) { gint retval;
Modified: trunk/src/win32.h =================================================================== --- trunk/src/win32.h 2009-12-20 21:03:28 UTC (rev 4504) +++ trunk/src/win32.h 2009-12-20 21:49:23 UTC (rev 4505) @@ -27,8 +27,10 @@
void win32_show_pref_file_dialog(GtkEntry *item);
-gboolean win32_show_file_dialog(gboolean file_open, const gchar *initial_dir); +gchar *win32_show_file_dialog(GtkWindow *parent, const gchar *title, const gchar *initial_dir);
+gboolean win32_show_document_open_dialog(gboolean file_open, const gchar *initial_dir); + void win32_show_font_dialog(void);
void win32_show_color_dialog(const gchar *colour); @@ -43,8 +45,7 @@ const gchar *initial_dir, gboolean allow_new_file, gboolean project_file_filter);
-gchar *win32_show_project_folder_dialog(GtkWidget *parent, const gchar *title, - const gchar *initial_dir); +gchar *win32_show_folder_dialog(GtkWidget *parent, const gchar *title, const gchar *initial_dir);
gint win32_check_write_permission(const gchar *dir);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.