[geany/geany] bd6db9: Windows: add default extension to native save dialogs

Colomban Wendling git-noreply at xxxxx
Tue Mar 11 14:50:39 UTC 2014


Branch:      refs/heads/master
Author:      Colomban Wendling <ban at herbesfolles.org>
Committer:   Colomban Wendling <ban at herbesfolles.org>
Date:        Tue, 11 Mar 2014 14:50:39 UTC
Commit:      bd6db90e297116e0b4168216a644fe1dbee8969f
             https://github.com/geany/geany/commit/bd6db90e297116e0b4168216a644fe1dbee8969f

Log Message:
-----------
Windows: add default extension to native save dialogs

Fixes bug #1021.

Based on an initial work by Steven Valsesia, thanks!


Modified Paths:
--------------
    src/dialogs.c
    src/win32.c
    src/win32.h

Modified: src/dialogs.c
2 files changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -665,7 +665,7 @@ gboolean dialogs_show_save_as(void)
 	if (interface_prefs.use_native_windows_dialogs)
 	{
 		gchar *utf8_name = win32_show_document_save_as_dialog(GTK_WINDOW(main_widgets.window),
-						_("Save File"), DOC_FILENAME(doc));
+						_("Save File"), doc);
 		if (utf8_name != NULL)
 			result = handle_save_as(utf8_name, FALSE);
 	}


Modified: src/win32.c
15 files changed, 12 insertions(+), 3 deletions(-)
===================================================================
@@ -419,18 +419,27 @@ gboolean win32_show_document_open_dialog(GtkWindow *parent, const gchar *title,
 
 
 gchar *win32_show_document_save_as_dialog(GtkWindow *parent, const gchar *title,
-										  const gchar *initial_file)
+										  GeanyDocument *doc)
 {
 	OPENFILENAMEW of;
 	gint retval;
 	gchar tmp[MAX_PATH];
 	wchar_t w_file[MAX_PATH];
 	wchar_t w_title[512];
+	int n;
 
 	w_file[0] = '\0';
 
-	if (initial_file != NULL)
-		MultiByteToWideChar(CP_UTF8, 0, initial_file, -1, w_file, G_N_ELEMENTS(w_file));
+	/* Convert the name of the file for of.lpstrFile */
+	n = MultiByteToWideChar(CP_UTF8, 0, DOC_FILENAME(doc), -1, w_file, G_N_ELEMENTS(w_file));
+
+	/* If creating a new file name, convert and append the extension if any */
+	if (! doc->file_name && doc->file_type && doc->file_type->extension && n + 1 < G_N_ELEMENTS(w_file))
+	{
+		w_file[n - 1] = L'.';
+		MultiByteToWideChar(CP_UTF8, 0, doc->file_type->extension, -1, &w_file[n],
+				G_N_ELEMENTS(w_file) - n - 1);
+	}
 
 	MultiByteToWideChar(CP_UTF8, 0, title, -1, w_title, G_N_ELEMENTS(w_title));
 


Modified: src/win32.h
2 files changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -30,7 +30,7 @@
 gboolean win32_show_document_open_dialog(GtkWindow *parent, const gchar *title, const gchar *initial_dir);
 
 gchar *win32_show_document_save_as_dialog(GtkWindow *parent, const gchar *title,
-										  const gchar *initial_file);
+										  GeanyDocument *doc);
 
 void win32_show_font_dialog(void);
 



--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).


More information about the Commits mailing list