From 516de2813ef99889cf76c14dc00183fe3459298f Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Mon, 7 Jun 2004 14:19:54 +0000 Subject: Fix setting default filename in the !modeSave case. 2004-06-07 Christian Persch * embed/mozilla/FilePicker.cpp: Fix setting default filename in the !modeSave case. --- embed/mozilla/FilePicker.cpp | 55 +++++++++++++++++++------------------------- embed/mozilla/FilePicker.h | 2 ++ 2 files changed, 26 insertions(+), 31 deletions(-) (limited to 'embed/mozilla') diff --git a/embed/mozilla/FilePicker.cpp b/embed/mozilla/FilePicker.cpp index 816eadee5..c129a29d3 100644 --- a/embed/mozilla/FilePicker.cpp +++ b/embed/mozilla/FilePicker.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2001 Philip Langdale - * Copyright (C) 2003 Christian Persch + * Copyright (C) 2003, 2004 Christian Persch * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -241,25 +241,11 @@ NS_IMETHODIMP GFilePicker::GetDefaultString(PRUnichar **aDefaultString) LOG ("GFilePicker::GetDefaultString") - char *filename, *converted; - filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (mDialog)); - if (filename != NULL) - { - converted = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); - - nsEmbedString defaultString; #if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) - NS_CStringToUTF16 (nsEmbedCString(converted), - NS_CSTRING_ENCODING_UTF8, aDefaultString); + aDefaultString = mDefaultString; #else - NS_CStringToUTF16 (nsEmbedCString(converted), - NS_CSTRING_ENCODING_UTF8, defaultString); - *aDefaultString = NS_StringCloneData (defaultString); + *aDefaultString = NS_StringCloneData (mDefaultString); #endif - - g_free (filename); - g_free (converted); - } return NS_OK; } @@ -272,25 +258,18 @@ NS_IMETHODIMP GFilePicker::SetDefaultString(const PRUnichar *aDefaultString) { NS_ENSURE_TRUE (mDialog, NS_ERROR_FAILURE); - if (mMode != nsIFilePicker::modeSave) return NS_ERROR_FAILURE; + mDefaultString.Assign (aDefaultString); -#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) - if (aDefaultString.Length()) -#else - if (aDefaultString) -#endif + if (mMode == nsIFilePicker::modeSave) { nsEmbedCString defaultString; -#if MOZILLA_CHECK_VERSION4 (1, 8, MOZILLA_ALPHA, 1) - NS_UTF16ToCString (aDefaultString, NS_CSTRING_ENCODING_UTF8, + NS_UTF16ToCString (mDefaultString, NS_CSTRING_ENCODING_UTF8, defaultString); -#else - NS_UTF16ToCString (nsEmbedString(aDefaultString), - NS_CSTRING_ENCODING_UTF8, defaultString); -#endif LOG ("GFilePicker::SetDefaultString %s", defaultString.get()) + if (!defaultString.Length()) return NS_ERROR_FAILURE; + /* set_current_name takes UTF-8, not a filename */ gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (mDialog), defaultString.get()); @@ -367,8 +346,22 @@ NS_IMETHODIMP GFilePicker::SetDisplayDirectory(nsILocalFile *aDisplayDirectory) LOG ("GFilePicker::SetDisplayDirectory to %s", dir.get()) - gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (mDialog), - dir.get()); + if (mDefaultString.Length() && mMode != nsIFilePicker::modeSave) + { + nsEmbedCString defaultString; + NS_UTF16ToCString (mDefaultString, NS_CSTRING_ENCODING_NATIVE_FILESYSTEM, + defaultString); + + char *filename = g_build_filename (dir.get(), defaultString.get(), NULL); + LOG ("Setting filename to %s", filename); + gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (mDialog), filename); + g_free (filename); + } + else + { + gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (mDialog), + dir.get()); + } return NS_OK; } diff --git a/embed/mozilla/FilePicker.h b/embed/mozilla/FilePicker.h index cf6a7f68f..a0578a860 100644 --- a/embed/mozilla/FilePicker.h +++ b/embed/mozilla/FilePicker.h @@ -24,6 +24,7 @@ #include #include +#include #include "ephy-file-chooser.h" @@ -54,6 +55,7 @@ public: private: EphyFileChooser *mDialog; PRInt16 mMode; + nsEmbedString mDefaultString; }; #endif -- cgit v1.2.3