diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 2e54619d7bb244df750331f1a368d5724f4026ff..6ec64c8063ce70482a2b9cb6edc2b2a1356da355 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -135,6 +135,7 @@ class ExportProgressDialog : public Gtk::Dialog { }; static std::string create_filepath_from_id(Glib::ustring, const Glib::ustring &); +static std::string absolutize_path_from_document_location(SPDocument *doc, const std::string &filename); /** A list of strings that is used both in the preferences, and in the data fields to describe the various values of \c selection_type. */ @@ -577,6 +578,23 @@ Glib::RefPtr Export::createSpinbutton( gchar const * /*key*/, } // end of createSpinbutton() + +static std::string absolutize_path_from_document_location(SPDocument *doc, const std::string &filename) +{ + std::string path; + //Make relative paths go from the document location, if possible: + if (!Glib::path_is_absolute(filename) && doc->getDocumentURI()) { + auto dirname = Glib::path_get_dirname(doc->getDocumentURI()); + if (!dirname.empty()) { + path = Glib::build_filename(dirname, filename); + } + } + if (path.empty()) { + path = filename; + } + return path; +} + std::string create_filepath_from_id(Glib::ustring id, const Glib::ustring &file_entry_text) { if (id.empty()) @@ -605,6 +623,36 @@ std::string create_filepath_from_id(Glib::ustring id, const Glib::ustring &file_ return Glib::build_filename(directory, Glib::filename_from_utf8(id) + ".png"); } +std::string +create_filepath_from_id_with_suffix(Glib::ustring id, const Glib::ustring &file_entry_text) +{ + + std::string path = ""; + std::string temp_id; + // If file does not exist already return path without suffix + path = create_filepath_from_id(id, file_entry_text); + if (!Inkscape::IO::file_test(path.c_str(), G_FILE_TEST_EXISTS)) + { + return path; + } + + // Check if filename ($id_copy_$i) exist. If not, then return that path + // UINT_MAX to check for maximum value of i and also prevent infinite loop. + for(unsigned int i=1; igetDocumentURI()) { - auto dirname = Glib::path_get_dirname(doc->getDocumentURI()); - if (!dirname.empty()) { - path = Glib::build_filename(dirname, filename); - } - } - if (path.empty()) { - path = filename; - } - return path; -} - // Called when unit is changed void Export::onUnitChanged() { @@ -1032,6 +1064,7 @@ void Export::_export_raster(Inkscape::Extension::Output *extension) gint export_count = 0; auto itemlist= desktop->getSelection()->items(); + for(auto i = itemlist.begin();i!=itemlist.end() && !interrupted ;++i){ SPItem *item = *i; @@ -1040,18 +1073,20 @@ void Export::_export_raster(Inkscape::Extension::Output *extension) onProgressCallback(0.0, prog_dlg); // retrieve export filename hint - const gchar *filename = item->getRepr()->attribute("inkscape:export-filename"); + // temporary disabled as filename is preventing adding suffix + // const gchar *filename = item->getRepr()->attribute("inkscape:export-filename"); + std::string path; - if (!filename) { - auto id = item->getId(); - if (!id) { - g_warning("object has no id"); - continue; - } - path = create_filepath_from_id(id, filename_entry.get_text()); - } else { - path = absolutize_path_from_document_location(doc, filename); + + //creating path only from id. TODO: create path from filename + id. + auto id = item->getId(); + if (!id) { + g_warning("object has no id"); + continue; } + path = create_filepath_from_id_with_suffix(id, filename_entry.get_text()); + if(path.empty()) + continue; // retrieve export dpi hints const gchar *dpi_hint = item->getRepr()->attribute("inkscape:export-xdpi"); // only xdpi, ydpi is always the same now