Remove the template description XMLNode before saving the template
authorJohannes Mueller <github@johannes-mueller.org>
Sat, 19 Aug 2017 17:45:08 +0000 (19:45 +0200)
committerRobin Gareus <robin@gareus.org>
Sun, 20 Aug 2017 19:09:30 +0000 (21:09 +0200)
... to avoid that the new template description is concatenated to the old one.

gtk2_ardour/template_dialog.cc
libs/ardour/route.cc
libs/ardour/session_state.cc

index cce8d2eb3f96d814b91325b379943b22eb97ac44..6002089aa66222bb62b4f55444d6ff3d084932c1 100644 (file)
@@ -256,14 +256,14 @@ TemplateManager::save_template_desc ()
                return;
        }
 
-       XMLNode* desc = tree.root()->child (X_("description"));
-       if (!desc) {
-               desc = new XMLNode (X_("description"));
-               tree.root()->add_child_nocopy (*desc);
-       }
+       tree.root()->remove_nodes (X_("description"));
+       XMLNode* desc = new XMLNode (X_("description"));
+
        XMLNode* dn = new XMLNode (X_("content"), desc_txt);
        desc->add_child_nocopy (*dn);
 
+       tree.root()->add_child_nocopy (*desc);
+
        if (!tree.write ()) {
                error << string_compose(X_("Could not write to template file \"%1\"."), file_path) << endmsg;
                return;
index 5cd9b576a578eedf4f6fcf40a7ad2a8d5f8ca21c..e89b9b8b912582eabefed8f6feebc61ef59a0fb9 100644 (file)
@@ -4022,6 +4022,7 @@ Route::save_as_template (const string& path, const string& name, const string& d
        XMLNode& node (state (false));
        node.set_property (X_("name"), name);
 
+       node.remove_nodes (X_("description"));
        if (!description.empty()) {
                XMLNode* desc = new XMLNode(X_("description"));
                XMLNode* desc_cont = new XMLNode(X_("content"), description);
index 0bf09f76c696e7a0c48c3f55b20a91a591aadd69..287822a6a6b9d476ec5c3026d877dd2183e16884 100644 (file)
@@ -2414,12 +2414,13 @@ Session::save_template (const string& template_name, const string& description,
        XMLNode* root;
        {
                PBD::Unwinder<std::string> uw (_template_state_dir, template_dir_path);
-               root = &get_template();
+               root = &get_template ();
        }
 
+       root->remove_nodes (X_("description"));
        if (!description.empty()) {
-               XMLNode* desc = new XMLNode(X_("description"));
-               XMLNode* desc_cont = new XMLNode(X_("content"), description);
+               XMLNode* desc = new XMLNode (X_("description"));
+               XMLNode* desc_cont = new XMLNode (X_("content"), description);
                desc->add_child_nocopy (*desc_cont);
 
                root->add_child_nocopy (*desc);