implement rename, remove and promote right-click functions for local snapshots

This commit is contained in:
Nikolaus Gullotta 2019-07-31 14:49:12 -05:00 committed by Nikolaus Gullotta
parent e64b1368e0
commit 4342159c30
No known key found for this signature in database
GPG key ID: 565F60578092AA31
2 changed files with 71 additions and 1 deletions

View file

@ -40,6 +40,12 @@ public:
void create_snapshot(std::string const& label, RouteList& rl, bool global);
void create_snapshot(std::string const& label, std::string const& from_path, bool global);
bool rename_snapshot(MixerSnapshot*, const std::string&);
bool remove_snapshot(MixerSnapshot*);
bool promote(ARDOUR::MixerSnapshot*);
bool demote(ARDOUR::MixerSnapshot*);
MixerSnapshot* get_snapshot_by_name(const std::string&, bool);
std::string get_global_path() {return _global_path;}

View file

@ -20,9 +20,11 @@
#include <stdio.h>
#include <glibmm.h>
#include <glibmm/miscutils.h>
#include "ardour/directory_names.h"
#include "ardour/filename_extensions.h"
#include "ardour/filesystem_paths.h"
#include "ardour/mixer_snapshot_manager.h"
#include "ardour/mixer_snapshot.h"
#include "ardour/search_paths.h"
@ -71,7 +73,7 @@ void MixerSnapshotManager::refresh()
snap->set_label(info.name);
snap->set_path(info.path);
_global_snapshots.insert(snap);
printf("Global - name: %s\n", snap->get_label().c_str());
printf("Global - path: %s\n", info.path.c_str());
}
@ -103,6 +105,68 @@ void MixerSnapshotManager::refresh()
}
}
bool MixerSnapshotManager::promote(MixerSnapshot* snapshot) {
if(!snapshot) {
return false;
}
const string path = snapshot->get_path();
if(Glib::file_test(path.c_str(), Glib::FILE_TEST_EXISTS)) {
const string dir = Glib::build_filename(user_config_directory(-1), route_templates_dir_name);
//this will just write the snapshot to the global dir
snapshot->write(dir);
_global_snapshots.insert(snapshot);
}
return true;
}
bool MixerSnapshotManager::rename_snapshot(MixerSnapshot* snapshot, const string& new_name) {
if(!snapshot) {
return false;
}
if(new_name.empty()) {
return false;
}
const string old_path = snapshot->get_path();
const string dir = Glib::path_get_dirname(old_path);
snapshot->set_label(new_name);
const string new_path = Glib::build_filename(dir, snapshot->get_label() + string(template_suffix));
::g_rename(old_path.c_str(), new_path.c_str());
snapshot->set_path(new_path);
return true;
}
bool MixerSnapshotManager::remove_snapshot(MixerSnapshot* snapshot) {
if(!snapshot) {
return false;
}
const string path = snapshot->get_path();
const string dir = Glib::path_get_dirname(path);
::g_remove(path.c_str());
set<MixerSnapshot*>::iterator iter;
if(dir == _global_path) {
iter = _global_snapshots.find(snapshot);
if(iter != _global_snapshots.end()) {
_global_snapshots.erase(iter);
}
} else {
iter = _local_snapshots.find(snapshot);
if(iter != _local_snapshots.end()) {
_local_snapshots.erase(iter);
}
}
return true;
}
bool MixerSnapshotManager::demote(MixerSnapshot* snapshot) {
return true;
}
MixerSnapshot* MixerSnapshotManager::get_snapshot_by_name(const string& name, bool global)
{
set<MixerSnapshot*> snapshots_list = global ? _global_snapshots : _local_snapshots;