summaryrefslogtreecommitdiffstats
path: root/src/file.cpp
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2012-01-02 13:48:23 +0000
committerJohan Engelen <goejendaagh@zonnet.nl>2012-01-02 13:48:23 +0000
commit3f2171532556797514c7410f4ae3a893411c96b6 (patch)
tree2e2d7506f039383e725a26f18c3e5ae5f28ba94e /src/file.cpp
parentwin32 saving: clean up filename handling on opening save dialog (diff)
downloadinkscape-3f2171532556797514c7410f4ae3a893411c96b6.tar.gz
inkscape-3f2171532556797514c7410f4ae3a893411c96b6.zip
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)
Diffstat (limited to 'src/file.cpp')
-rw-r--r--src/file.cpp23
1 files changed, 22 insertions, 1 deletions
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 <sasilver@users.sourceforge.net>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
+ * David Xiong
*
* Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
- * Copyright (C) 1999-2008 Authors
+ * Copyright (C) 1999-2012 Authors
* Copyright (C) 2004 David Turner
* Copyright (C) 2001-2002 Ximian, Inc.
*
@@ -731,6 +732,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.
*/
bool
@@ -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<Inkscape::Extension::Output *>(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);