summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/file.cpp37
-rw-r--r--src/file.h2
-rw-r--r--src/ui/dialog/save-template-dialog.cpp19
-rw-r--r--src/ui/dialog/save-template-dialog.h2
4 files changed, 37 insertions, 23 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;
}
diff --git a/src/file.h b/src/file.h
index c24ecdf6f..ccfc93e1c 100644
--- a/src/file.h
+++ b/src/file.h
@@ -106,7 +106,7 @@ bool sp_file_save_a_copy (Gtk::Window &parentWindow, void* object, void* data);
/**
* 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);
diff --git a/src/ui/dialog/save-template-dialog.cpp b/src/ui/dialog/save-template-dialog.cpp
index 5b7540039..6c58c6f71 100644
--- a/src/ui/dialog/save-template-dialog.cpp
+++ b/src/ui/dialog/save-template-dialog.cpp
@@ -4,11 +4,11 @@
#include "save-template-dialog.h"
#include "file.h"
+#include "io/resource.h"
+#include "ui/interface.h"
#include <glibmm/i18n.h>
-#include <iostream>
-
namespace Inkscape {
namespace UI {
namespace Dialog {
@@ -67,9 +67,9 @@ void SaveTemplate::on_name_changed() {
}
}
-void SaveTemplate::save_template(Gtk::Window &parentWindow) {
+bool SaveTemplate::save_template(Gtk::Window &parentWindow) {
- sp_file_save_template(parentWindow, name_text.get_text(),
+ return sp_file_save_template(parentWindow, name_text.get_text(),
author_text.get_text(), description_text.get_text(),
keywords_text.get_text(), is_default_template.get_active());
}
@@ -78,11 +78,16 @@ void SaveTemplate::save_document_as_template(Gtk::Window &parentWindow) {
SaveTemplate dialog;
- auto result = dialog.run();
+ auto operation_done = false;
+
+ while (operation_done == false) {
- if (result == Gtk::RESPONSE_OK){
+ auto user_response = dialog.run();
- dialog.save_template(parentWindow);
+ if (user_response == Gtk::RESPONSE_OK)
+ operation_done = dialog.save_template(parentWindow);
+ else
+ operation_done = true;
}
}
diff --git a/src/ui/dialog/save-template-dialog.h b/src/ui/dialog/save-template-dialog.h
index 9f38c499d..3f2cbddc1 100644
--- a/src/ui/dialog/save-template-dialog.h
+++ b/src/ui/dialog/save-template-dialog.h
@@ -42,7 +42,7 @@ private:
Gtk::CheckButton is_default_template;
SaveTemplate();
- void save_template(Gtk::Window &parentWindow);
+ bool save_template(Gtk::Window &parentWindow);
};
}