diff options
| author | Christophe Lebras <christophe.lebras@gmail.com> | 2018-08-31 06:51:38 +0000 |
|---|---|---|
| committer | Christophe Lebras <christophe.lebras@gmail.com> | 2018-08-31 06:51:38 +0000 |
| commit | 55ccf247cd5c150afb00837a6e3b1a6a4610b52d (patch) | |
| tree | 6a3d6539826ade73ed6c812930b7d0bf686acdf1 /src/file.cpp | |
| parent | Fix bug 1789010 - Sanitize template's file name (diff) | |
| download | inkscape-55ccf247cd5c150afb00837a6e3b1a6a4610b52d.tar.gz inkscape-55ccf247cd5c150afb00837a6e3b1a6a4610b52d.zip | |
Fix bug 1789838 - Ask for confirmation before overwriting template
Diffstat (limited to 'src/file.cpp')
| -rw-r--r-- | src/file.cpp | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/file.cpp b/src/file.cpp index d32d104ac..051389307 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -956,13 +956,13 @@ sp_file_save_a_copy(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*d /** * Save a copy of a document as template. */ -void +bool sp_file_save_template(Gtk::Window &parentWindow, Glib::ustring name, Glib::ustring author, Glib::ustring description, Glib::ustring keywords, bool isDefault) { if (!SP_ACTIVE_DOCUMENT || name.length() == 0) - return; + return true; auto document = SP_ACTIVE_DOCUMENT; @@ -1018,23 +1018,30 @@ sp_file_save_template(Gtk::Window &parentWindow, Glib::ustring name, root->appendChild(templateinfo_node); - if (isDefault) { - - auto filename = Inkscape::IO::Resource::get_path_ustring(USER, - TEMPLATES, "default.svg"); - file_save(parentWindow, document, filename, - Inkscape::Extension::db.get(".svg"), false, false, - Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG); - } - auto encodedName = Glib::uri_escape_string(name); encodedName.append(".svg"); auto filename = Inkscape::IO::Resource::get_path_ustring(USER, TEMPLATES, encodedName.c_str()); - file_save(parentWindow, document, filename, - Inkscape::Extension::db.get(".svg"), false, false, - Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG); + + auto operation_confirmed = sp_ui_overwrite_file(filename.c_str()); + + if (operation_confirmed) { + + file_save(parentWindow, document, filename, + Inkscape::Extension::db.get(".svg"), false, false, + Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG); + + if (isDefault) { + + filename = Inkscape::IO::Resource::get_path_ustring(USER, + TEMPLATES, "default.svg"); + + file_save(parentWindow, document, filename, + Inkscape::Extension::db.get(".svg"), false, false, + Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG); + } + } auto nodeToRemove = sp_repr_lookup_name(root, "inkscape:_templateinfo"); @@ -1045,6 +1052,8 @@ sp_file_save_template(Gtk::Window &parentWindow, Glib::ustring name, } DocumentUndo::setUndoSensitive(document, true); + + return operation_confirmed; } |
