From 3f2171532556797514c7410f4ae3a893411c96b6 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Mon, 2 Jan 2012 14:48:23 +0100 Subject: file saving: fix appending of extension for files in directories with periods in name. (patch by David Xiong) Fixed bugs: - https://launchpad.net/bugs/408566 (bzr r10821) --- src/file.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/file.cpp') diff --git a/src/file.cpp b/src/file.cpp index 4feb36f9d..189e1d261 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -10,9 +10,10 @@ * Stephen Silver * Jon A. Cruz * Abhishek Sharma + * David Xiong * * Copyright (C) 2006 Johan Engelen - * Copyright (C) 1999-2008 Authors + * Copyright (C) 1999-2012 Authors * Copyright (C) 2004 David Turner * Copyright (C) 2001-2002 Ximian, Inc. * @@ -730,6 +731,19 @@ file_save_remote(SPDocument */*doc*/, } +/** + * Check if a string ends with another string. + * \todo Find a better code file to put this general purpose method + */ +static bool hasEnding (Glib::ustring const &fullString, Glib::ustring const &ending) +{ + if (fullString.length() > ending.length()) { + return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending)); + } else { + return false; + } +} + /** * Display a SaveAs dialog. Save the document if OK pressed. */ @@ -842,6 +856,13 @@ sp_file_save_dialog(Gtk::Window &parentWindow, SPDocument *doc, Inkscape::Extens else g_warning( "Error converting save filename to UTF-8." ); + Inkscape::Extension::Output *omod = dynamic_cast(selectionType); + Glib::ustring save_extension = (std::string)omod->get_extension(); + + if ( !hasEnding(fileName, save_extension.c_str()) ) { + fileName += save_extension.c_str(); + } + // FIXME: does the argument !is_copy really convey the correct meaning here? success = file_save(parentWindow, doc, fileName, selectionType, TRUE, !is_copy, save_method); -- cgit v1.2.3