From 5f4e2cf6f9e241205ab19c8310103db2bc6e8da6 Mon Sep 17 00:00:00 2001 From: joncruz Date: Sat, 3 Mar 2007 09:10:49 +0000 Subject: [PATCH] i18n cleanup and adding extension in more cases --- src/ui/dialog/filedialog.cpp | 42 +++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/ui/dialog/filedialog.cpp b/src/ui/dialog/filedialog.cpp index 26f20b9e6..894129795 100644 --- a/src/ui/dialog/filedialog.cpp +++ b/src/ui/dialog/filedialog.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -1140,6 +1141,11 @@ private: * Filename that was given */ Glib::ustring myFilename; + + /** + * List of known file extensions. + */ + std::set knownExtensions; }; @@ -1230,22 +1236,30 @@ void FileSaveDialogImpl::fileTypeChangedCallback() } Inkscape::Extension::Output* newOut = extension ? dynamic_cast(extension) : 0; + bool appendExtension = true; if ( newOut ) { - size_t pos = myFilename.rfind('.'); - if ( pos != Glib::ustring::npos ) { - Glib::ustring trail = myFilename.substr( pos ); - try { - Glib::ustring trailUtf8 = Glib::filename_to_utf8( trail ); - if ( trailUtf8.casefold() != Glib::ustring( newOut->get_extension() ).casefold() ) { - myFilename = myFilename.erase( pos ) + newOut->get_extension(); - change_path(myFilename); + try { + Glib::ustring utf8Name = Glib::filename_to_utf8( myFilename ); + size_t pos = utf8Name.rfind('.'); + if ( pos != Glib::ustring::npos ) { + Glib::ustring trail = utf8Name.substr( pos ); + Glib::ustring foldedTrail = trail.casefold(); + if ( (trail == ".") + | (foldedTrail != Glib::ustring( newOut->get_extension() ).casefold() + && ( knownExtensions.find(foldedTrail) != knownExtensions.end() ) ) ) { + utf8Name = utf8Name.erase( pos ); + } else { + appendExtension = false; } - } catch ( Glib::ConvertError& e ) { - // ignore } - } else { - myFilename = myFilename + newOut->get_extension(); - change_path(myFilename); + + if (appendExtension) { + utf8Name = utf8Name + newOut->get_extension(); + myFilename = Glib::filename_from_utf8( utf8Name ); + change_path(myFilename); + } + } catch ( Glib::ConvertError& e ) { + // ignore } } } @@ -1256,6 +1270,7 @@ void FileSaveDialogImpl::createFileTypeMenu() { Inkscape::Extension::DB::OutputList extension_list; Inkscape::Extension::db.get_output_list(extension_list); + knownExtensions.clear(); for (Inkscape::Extension::DB::OutputList::iterator current_item = extension_list.begin(); current_item != extension_list.end(); current_item++) @@ -1269,6 +1284,7 @@ void FileSaveDialogImpl::createFileTypeMenu() type.name = (_(omod->get_filetypename())); type.pattern = "*"; Glib::ustring extension = omod->get_extension(); + knownExtensions.insert( extension.casefold() ); fileDialogExtensionToPattern (type.pattern, extension); type.extension= omod; fileTypeComboBox.append_text(type.name); -- 2.30.2