summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Lebras <christophe.lebras@gmail.com>2017-07-01 17:58:21 +0000
committerChristophe Lebras <christophe.lebras@gmail.com>2017-07-02 03:11:49 +0000
commitb3419faaf2252a4e031db217f50edaf0531641ab (patch)
treecb5c238c1fa7f680889d8c59f5569ccc06590102
parentAdd Save Template Dialog (diff)
downloadinkscape-b3419faaf2252a4e031db217f50edaf0531641ab.tar.gz
inkscape-b3419faaf2252a4e031db217f50edaf0531641ab.zip
Add function to save template
Saves template as default. Does not save template informations yet.
-rw-r--r--src/file.cpp34
-rw-r--r--src/file.h5
-rw-r--r--src/ui/dialog/save-template-dialog.cpp24
-rw-r--r--src/ui/dialog/save-template-dialog.h4
-rw-r--r--src/verbs.cpp2
5 files changed, 46 insertions, 23 deletions
diff --git a/src/file.cpp b/src/file.cpp
index b9d896de0..958d2b620 100644
--- a/src/file.cpp
+++ b/src/file.cpp
@@ -69,6 +69,7 @@
using Inkscape::DocumentUndo;
using Inkscape::IO::Resource::TEMPLATES;
+using Inkscape::IO::Resource::USER;
#ifdef WITH_GNOME_VFS
# include <libgnomevfs/gnome-vfs.h>
@@ -122,7 +123,7 @@ SPDesktop *sp_file_new(const std::string &templ)
{
SPDocument *doc = SPDocument::createNewDoc( !templ.empty() ? templ.c_str() : 0 , TRUE, true );
g_return_val_if_fail(doc != NULL, NULL);
-
+
// Remove all the template info from xml tree
Inkscape::XML::Node *myRoot = doc->getReprRoot();
Inkscape::XML::Node *nodeToRemove = sp_repr_lookup_name(myRoot, "inkscape:_templateinfo");
@@ -132,11 +133,11 @@ SPDesktop *sp_file_new(const std::string &templ)
delete nodeToRemove;
DocumentUndo::setUndoSensitive(doc, true);
}
-
+
SPDesktop *olddesktop = SP_ACTIVE_DESKTOP;
if (olddesktop)
olddesktop->setWaitingCursor();
-
+
SPViewWidget *dtw = sp_desktop_widget_new(sp_document_namedview(doc, NULL)); // TODO this will trigger broken link warnings, etc.
g_return_val_if_fail(dtw != NULL, NULL);
sp_create_window(dtw, TRUE);
@@ -145,12 +146,12 @@ SPDesktop *sp_file_new(const std::string &templ)
doc->doUnref();
sp_namedview_window_from_document(desktop);
- sp_namedview_update_layers_from_document(desktop);
+ sp_namedview_update_layers_from_document(desktop);
#ifdef WITH_DBUS
Inkscape::Extension::Dbus::dbus_init_desktop_interface(desktop);
#endif
-
+
if (olddesktop)
olddesktop->clearWaitingCursor();
if (desktop)
@@ -1006,6 +1007,21 @@ sp_file_save_a_copy(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*d
return sp_file_save_dialog(parentWindow, SP_ACTIVE_DOCUMENT, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_COPY);
}
+/**
+ * Save a copy of a document as template.
+ */
+void
+sp_file_save_template(Gtk::Window &parentWindow)
+{
+ if (!SP_ACTIVE_DOCUMENT)
+ return;
+
+ ///auto filename = Inkscape::IO::Resource::get_filename(TEMPLATES, "default.svg");
+ auto filename = Inkscape::IO::Resource::get_path_ustring(USER, TEMPLATES, "default.svg");
+ file_save(parentWindow, SP_ACTIVE_DOCUMENT, filename, Inkscape::Extension::db.get(".svg"), false, false, Inkscape::Extension::FILE_SAVE_METHOD_INKSCAPE_SVG);
+}
+
+
/*######################
## I M P O R T
@@ -1069,7 +1085,7 @@ void sp_import_document(SPDesktop *desktop, SPDocument *clipdoc, bool in_place)
SPLPEItem * pasted_lpe_item = dynamic_cast<SPLPEItem *>(pasted);
if (pasted_lpe_item){
pasted_lpe_item->forkPathEffectsIfNecessary(1);
- }
+ }
pasted_objects_not.push_back(obj_copy);
}
Inkscape::Selection *selection = desktop->getSelection();
@@ -1127,7 +1143,7 @@ file_import(SPDocument *in_doc, const Glib::ustring &uri,
{
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
bool cancelled = false;
-
+
//DEBUG_MESSAGE( fileImport, "file_import( in_doc:%p uri:[%s], key:%p", in_doc, uri, key );
SPDocument *doc;
try {
@@ -1660,7 +1676,7 @@ Inkscape::UI::Dialog::OCAL::ImportDialog* import_ocal_dialog = NULL;
void on_import_from_ocal_response(Glib::ustring filename)
{
SPDocument *doc = SP_ACTIVE_DOCUMENT;
-
+
if (!filename.empty()) {
Inkscape::Extension::Extension *selection = import_ocal_dialog->get_selection_type();
file_import(doc, filename, selection);
@@ -1686,7 +1702,7 @@ sp_file_import_from_ocal(Gtk::Window &parent_window)
import_ocal_dialog->signal_response().connect(
sigc::ptr_fun(&on_import_from_ocal_response));
}
-
+
import_ocal_dialog->show_all();
}
diff --git a/src/file.h b/src/file.h
index c6ff61c25..010bff94f 100644
--- a/src/file.h
+++ b/src/file.h
@@ -110,6 +110,11 @@ bool sp_file_save_as (Gtk::Window &parentWindow, void* object, void* data);
*/
bool sp_file_save_a_copy (Gtk::Window &parentWindow, void* object, void* data);
+/**
+ * Save a copy of a document as template.
+ */
+void
+sp_file_save_template(Gtk::Window &parentWindow);
/**
* Saves the given document. Displays a file select dialog
diff --git a/src/ui/dialog/save-template-dialog.cpp b/src/ui/dialog/save-template-dialog.cpp
index a351a9cfa..e60648fd5 100644
--- a/src/ui/dialog/save-template-dialog.cpp
+++ b/src/ui/dialog/save-template-dialog.cpp
@@ -70,18 +70,20 @@ void SaveTemplate::on_name_changed() {
}
}
-void SaveTemplate::save_template() {
-
- std::cout
- << "Save template: "
- << name_text.get_text() << " "
- << author_text.get_text() << " "
- << description_text.get_text() << " "
- << keywords_text.get_text() << " "
- << is_default_template.get_active() << std::endl;
+void SaveTemplate::save_template(Gtk::Window &parentWindow) {
+
+ // std::cout
+ // << "Save template: "
+ // << name_text.get_text() << " "
+ // << author_text.get_text() << " "
+ // << description_text.get_text() << " "
+ // << keywords_text.get_text() << " "
+ // << is_default_template.get_active() << std::endl;
+
+ sp_file_save_template(parentWindow);
}
-void SaveTemplate::save_document_as_template() {
+void SaveTemplate::save_document_as_template(Gtk::Window &parentWindow) {
SaveTemplate dialog;
@@ -91,7 +93,7 @@ void SaveTemplate::save_document_as_template() {
case Gtk::RESPONSE_OK:
- dialog.save_template();
+ dialog.save_template(parentWindow);
break;
default:
diff --git a/src/ui/dialog/save-template-dialog.h b/src/ui/dialog/save-template-dialog.h
index eba786e96..9f38c499d 100644
--- a/src/ui/dialog/save-template-dialog.h
+++ b/src/ui/dialog/save-template-dialog.h
@@ -17,7 +17,7 @@ class SaveTemplate : public Gtk::Dialog
public:
- static void save_document_as_template();
+ static void save_document_as_template(Gtk::Window &parentWindow);
protected:
@@ -42,7 +42,7 @@ private:
Gtk::CheckButton is_default_template;
SaveTemplate();
- void save_template();
+ void save_template(Gtk::Window &parentWindow);
};
}
diff --git a/src/verbs.cpp b/src/verbs.cpp
index 9394aeb81..4827ba631 100644
--- a/src/verbs.cpp
+++ b/src/verbs.cpp
@@ -894,7 +894,7 @@ void FileVerb::perform(SPAction *action, void *data)
sp_file_save_a_copy(*parent, NULL, NULL);
break;
case SP_VERB_FILE_SAVE_TEMPLATE:
- Inkscape::UI::Dialog::SaveTemplate::save_document_as_template();
+ Inkscape::UI::Dialog::SaveTemplate::save_document_as_template(*parent);
break;
case SP_VERB_FILE_PRINT:
sp_file_print(*parent);