commit adc16e2621594c8bf64e2eb197c1e9d3d5a0fdc9
parent 71de9d5e8b21a4f22f3d0d16b841479380e9e70b
Author: cfillion <cfillion@users.noreply.github.com>
Date: Mon, 25 Jan 2016 20:33:45 -0800
deduce the Action List section from the package's category
Diffstat:
4 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/src/path.cpp b/src/path.cpp
@@ -124,6 +124,22 @@ string Path::join(const char sep) const
return path;
}
+string Path::first() const
+{
+ if(empty())
+ return {};
+
+ return m_parts.front();
+}
+
+string Path::last() const
+{
+ if(empty())
+ return {};
+
+ return m_parts.back();
+}
+
bool Path::operator==(const Path &o) const
{
return m_parts == o.m_parts;
diff --git a/src/path.hpp b/src/path.hpp
@@ -43,6 +43,8 @@ public:
std::string basename() const;
std::string dirname() const;
std::string join(const char sep = 0) const;
+ std::string first() const;
+ std::string last() const;
bool operator==(const Path &) const;
bool operator!=(const Path &) const;
diff --git a/src/transaction.cpp b/src/transaction.cpp
@@ -23,6 +23,7 @@
#include "remote.hpp"
#include "task.hpp"
+#include <boost/algorithm/string.hpp>
#include <fstream>
#include <reaper_plugin_functions.h>
@@ -308,15 +309,24 @@ void Transaction::registerScriptsInHost()
return;
}
+ enum Section { MainSection = 0, MidiEditorSection = 32060 };
+
while(!m_scriptRegs.empty()) {
const HostRegistration ® = m_scriptRegs.front();
+ const Registry::Entry &entry = reg.entry;
const std::string &path = Path::prefixRoot(reg.file).join();
const bool isLast = m_scriptRegs.size() == 1;
+ Section section = MainSection;
+
+ string category = Path(entry.category).first();
+ boost::algorithm::to_lower(category);
- if(!AddRemoveReaScript(reg.add, 0, path.c_str(), isLast) && reg.add)
+ if(category == "midi editor")
+ section = MidiEditorSection;
+
+ if(!AddRemoveReaScript(reg.add, section, path.c_str(), isLast) && reg.add)
addError("Script could not be registered in REAPER.", reg.file);
m_scriptRegs.pop();
}
}
-
diff --git a/test/path.cpp b/test/path.cpp
@@ -184,3 +184,12 @@ TEST_CASE("path generation utilities", M) {
REQUIRE(Path::prefixRoot(path) == Path("world"));
}
+
+TEST_CASE("first and last path component", M) {
+ REQUIRE(Path().first().empty());
+ REQUIRE(Path().last().empty());
+
+ const Path path("hello/world/chunky/bacon");
+ REQUIRE(path.first() == "hello");
+ REQUIRE(path.last() == "bacon");
+}