Let the user add a template description on saving session templates

This commit is contained in:
Johannes Mueller 2017-08-18 19:53:46 +02:00 committed by Robin Gareus
parent 908369ab3e
commit ae51d5fd4e
7 changed files with 151 additions and 37 deletions

View File

@ -169,6 +169,7 @@ typedef uint64_t microseconds_t;
#include "route_time_axis.h"
#include "route_params_ui.h"
#include "save_as_dialog.h"
#include "save_template_dialog.h"
#include "script_selector.h"
#include "session_archive_dialog.h"
#include "session_dialog.h"
@ -3158,60 +3159,43 @@ ARDOUR_UI::transport_rec_enable_blink (bool onoff)
}
}
bool
ARDOUR_UI::process_save_template_prompter (Prompter& prompter)
void
ARDOUR_UI::save_template_dialog_response (int response, SaveTemplateDialog* d)
{
string name;
if (response == RESPONSE_ACCEPT) {
const string name = d->get_template_name ();
const string desc = d->get_description ();
prompter.get_result (name);
if (name.length()) {
int failed = _session->save_template (name);
int failed = _session->save_template (name, desc);
if (failed == -2) { /* file already exists. */
bool overwrite = overwrite_file_dialog (prompter,
bool overwrite = overwrite_file_dialog (*d,
_("Confirm Template Overwrite"),
_("A template already exists with that name. Do you want to overwrite it?"));
if (overwrite) {
_session->save_template (name, true);
_session->save_template (name, desc, true);
}
else {
return false;
d->show ();
return;
}
}
}
return true;
delete d;
}
void
ARDOUR_UI::save_template ()
{
Prompter prompter (true);
if (!check_audioengine (_main_window)) {
return;
}
prompter.set_name (X_("Prompter"));
prompter.set_title (_("Save Template"));
prompter.set_prompt (_("Name for template:"));
prompter.set_initial_text(_session->name() + _("-template"));
prompter.add_button (Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
SaveTemplateDialog* d = new SaveTemplateDialog (*_session);
bool finished = false;
while (!finished) {
switch (prompter.run()) {
case RESPONSE_ACCEPT:
finished = process_save_template_prompter (prompter);
break;
default:
finished = true;
break;
}
}
d->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &ARDOUR_UI::save_template_dialog_response), d));
d->show ();
}
void ARDOUR_UI::manage_templates ()

View File

@ -127,6 +127,7 @@ class MainClock;
class Mixer_UI;
class PublicEditor;
class SaveAsDialog;
class SaveTemplateDialog;
class SessionDialog;
class SessionOptionEditorWindow;
class Splash;
@ -621,7 +622,7 @@ private:
void open_session ();
void open_recent_session ();
bool process_save_template_prompter (ArdourWidgets::Prompter& prompter);
void save_template_dialog_response (int response, SaveTemplateDialog* d);
void save_template ();
void manage_templates ();

View File

@ -0,0 +1,71 @@
/*
Copyright (C) 2017 Paul Davis
Author: Johannes Mueller
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <gtkmm/box.h>
#include <gtkmm/frame.h>
#include <gtkmm/label.h>
#include <gtkmm/stock.h>
#include "pbd/i18n.h"
#include "ardour/session.h"
#include "save_template_dialog.h"
using namespace Gtk;
using namespace ARDOUR;
SaveTemplateDialog::SaveTemplateDialog (const Session& s)
: ArdourDialog (_("Save as template"))
{
_name_editor.get_buffer()->set_text (s.name() + _("-template"));
_description_editor.set_wrap_mode (Gtk::WRAP_WORD);
_description_editor.set_size_request(400, 300);
HBox* hb = manage (new HBox);
hb->set_spacing (8);
Label* lb = manage (new Label(_("Template name:")));
hb->pack_start (*lb, false, true);
hb->pack_start (_name_editor, true, true);
Frame* fd = manage (new Frame(_("Description:")));
fd->add (_description_editor);
get_vbox()->set_spacing (8);
get_vbox()->pack_start (*fd);
get_vbox()->pack_start (*hb);
add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
show_all_children ();
}
std::string
SaveTemplateDialog::get_template_name () const
{
return _name_editor.get_buffer()->get_text();
}
std::string
SaveTemplateDialog::get_description () const
{
return _description_editor.get_buffer()->get_text();
}

View File

@ -0,0 +1,47 @@
/*
Copyright (C) 2017 Paul Davis
Author: Johannes Mueller
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __ardour_gtk_save_template_dialog_h__
#define __ardour_gtk_save_template_dialog_h__
#include <gtkmm/entry.h>
#include <gtkmm/textview.h>
#include "ardour_dialog.h"
namespace ARDOUR
{
class Session;
}
class SaveTemplateDialog : public ArdourDialog
{
public:
SaveTemplateDialog (const ARDOUR::Session& s);
std::string get_template_name () const;
std::string get_description () const;
private:
Gtk::Entry _name_editor;
Gtk::TextView _description_editor;
};
#endif /* __ardour_gtk_save_template_dialog_h__ */

View File

@ -218,6 +218,7 @@ gtk2_ardour_sources = [
'route_ui.cc',
'ruler_dialog.cc',
'save_as_dialog.cc',
'save_template_dialog.cc',
'search_path_option.cc',
'script_selector.cc',
'selection.cc',

View File

@ -259,7 +259,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
*/
RouteList new_route_from_template (uint32_t how_many, PresentationInfo::order_t insert_at, const std::string& template_path, const std::string& name, PlaylistDisposition pd = NewPlaylist);
RouteList new_route_from_template (uint32_t how_many, PresentationInfo::order_t insert_at, XMLNode&, const std::string& name, PlaylistDisposition pd = NewPlaylist);
std::vector<std::string> get_paths_for_new_sources (bool allow_replacing, const std::string& import_file_path,
std::vector<std::string> get_paths_for_new_sources (bool allow_replacing, const std::string& import_file_path,
uint32_t channels, std::vector<std::string> const & smf_track_names);
int bring_all_sources_into_session (boost::function<void(uint32_t,uint32_t,std::string)> callback);
@ -531,7 +531,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
int archive_session (const std::string&, const std::string&, ArchiveEncode compress_audio = FLAC_16BIT, bool only_used_sources = false, Progress* p = 0);
int restore_state (std::string snapshot_name);
int save_template (std::string template_name, bool replace_existing = false);
int save_template (const std::string& template_name, const std::string& description = "", bool replace_existing = false);
int save_history (std::string snapshot_name = "");
int restore_history (std::string snapshot_name);
void remove_state (std::string snapshot_name);

View File

@ -2356,7 +2356,7 @@ Session::XMLSourceFactory (const XMLNode& node)
}
int
Session::save_template (string template_name, bool replace_existing)
Session::save_template (const string& template_name, const string& description, bool replace_existing)
{
if ((_state_of_the_state & CannotSave) || template_name.empty ()) {
return -1;
@ -2411,12 +2411,22 @@ Session::save_template (string template_name, bool replace_existing)
SessionSaveUnderway (); /* EMIT SIGNAL */
XMLTree tree;
XMLNode* root;
{
PBD::Unwinder<std::string> uw (_template_state_dir, template_dir_path);
tree.set_root (&get_template());
root = &get_template();
}
if (!description.empty()) {
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);
}
tree.set_root (root);
if (!tree.write (template_file_path)) {
error << _("template not saved") << endmsg;
return -1;