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().


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@4505 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2009-12-20 21:49:23 +00:00
parent b7b4de41f4
commit ba94d0ce6f
5 changed files with 67 additions and 9 deletions

View File

@ -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>

View File

@ -222,7 +222,7 @@ void dialogs_show_open_file()
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

View File

@ -1662,7 +1662,7 @@ static void ui_path_box_open_clicked(GtkButton *button, gpointer user_data)
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 @@ static void ui_path_box_open_clicked(GtkButton *button, gpointer user_data)
{
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

View File

@ -313,7 +313,7 @@ gchar *win32_show_project_open_dialog(GtkWidget *parent, const gchar *title,
/* 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 @@ gboolean win32_show_file_dialog(gboolean file_open, const gchar *initial_dir)
}
/* 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;

View File

@ -27,7 +27,9 @@
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);
@ -43,8 +45,7 @@ gchar *win32_show_project_open_dialog(GtkWidget *parent, const gchar *title,
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);