Revision: 4897 http://geany.svn.sourceforge.net/geany/?rev=4897&view=rev Author: eht16 Date: 2010-05-10 21:52:43 +0000 (Mon, 10 May 2010)
Log Message: ----------- (Re-)Implement a (still basic) native Windows Save As dialog when compiled with GEANY_USE_WIN32_DIALOG.
Modified Paths: -------------- trunk/ChangeLog trunk/src/dialogs.c trunk/src/win32.c trunk/src/win32.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-05-10 17:36:19 UTC (rev 4896) +++ trunk/ChangeLog 2010-05-10 21:52:43 UTC (rev 4897) @@ -2,6 +2,9 @@
* src/dialogs.c: Fix Cancel on Goto Line dialog (patch by Dimitar Zhekov, thanks). + * src/dialogs.c, src/win32.c, src/win32.h: + (Re-)Implement a (still basic) native Windows Save As dialog when + compiled with GEANY_USE_WIN32_DIALOG.
2010-05-09 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/src/dialogs.c =================================================================== --- trunk/src/dialogs.c 2010-05-10 17:36:19 UTC (rev 4896) +++ trunk/src/dialogs.c 2010-05-10 21:52:43 UTC (rev 4897) @@ -65,6 +65,10 @@ GEANY_RESPONSE_VIEW };
+ +static gboolean handle_save_as(const gchar *utf8_filename, gboolean open_new_tab, + gboolean rename_file); + #if ! GEANY_USE_WIN32_DIALOG static GtkWidget *add_file_open_extra_widget(void);
@@ -333,7 +337,6 @@ #endif
-#if ! GEANY_USE_WIN32_DIALOG static gboolean handle_save_as(const gchar *utf8_filename, gboolean open_new_tab, gboolean rename_file) { GeanyDocument *doc = document_get_current(); @@ -366,6 +369,7 @@ }
+#if ! GEANY_USE_WIN32_DIALOG static void on_file_save_dialog_response (GtkDialog *dialog, gint response, @@ -550,7 +554,10 @@ gboolean result;
#if GEANY_USE_WIN32_DIALOG - result = win32_show_file_dialog(FALSE, utils_get_default_dir_utf8()); + GeanyDocument *doc = document_get_current(); + gchar *utf8_name = win32_show_document_save_as_dialog(GTK_WINDOW(main_widgets.window), + _("Save File"), DOC_FILENAME(doc)); + result = handle_save_as(utf8_name, FALSE, FALSE); #else result = gtk_show_save_as(); #endif
Modified: trunk/src/win32.c =================================================================== --- trunk/src/win32.c 2010-05-10 17:36:19 UTC (rev 4896) +++ trunk/src/win32.c 2010-05-10 21:52:43 UTC (rev 4897) @@ -413,6 +413,62 @@ }
+gchar *win32_show_document_save_as_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.lpstrFilter = get_file_filters(); + of.lpstrCustomFilter = NULL; + of.nFilterIndex = GEANY_FILETYPES_NONE + 1; + + of.lpstrFile = w_file; + of.nMaxFile = 2048; + of.lpstrFileTitle = NULL; + of.lpstrTitle = w_title; + of.lpstrDefExt = L""; + of.Flags = OFN_FILEMUSTEXIST | OFN_EXPLORER; + retval = GetSaveFileNameW(&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); +} + + /* 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)
Modified: trunk/src/win32.h =================================================================== --- trunk/src/win32.h 2010-05-10 17:36:19 UTC (rev 4896) +++ trunk/src/win32.h 2010-05-10 21:52:43 UTC (rev 4897) @@ -31,6 +31,9 @@
gboolean win32_show_document_open_dialog(gboolean file_open, const gchar *initial_dir);
+gchar *win32_show_document_save_as_dialog(GtkWindow *parent, const gchar *title, + const gchar *initial_file); + void win32_show_font_dialog(void);
void win32_show_color_dialog(const gchar *colour);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.