2011-11-08 15:27:21 +01:00
|
|
|
#include "filter_registry.hh"
|
|
|
|
|
|
|
|
#include "exception.hh"
|
2011-11-10 00:56:22 +01:00
|
|
|
#include "window.hh"
|
2011-11-08 15:27:21 +01:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
struct factory_not_found : public runtime_error
|
|
|
|
{
|
|
|
|
factory_not_found() : runtime_error("factory not found") {}
|
|
|
|
};
|
|
|
|
|
|
|
|
void FilterRegistry::register_factory(const std::string& name,
|
|
|
|
const FilterFactory& factory)
|
|
|
|
{
|
|
|
|
assert(m_factories.find(name) == m_factories.end());
|
|
|
|
m_factories[name] = factory;
|
|
|
|
}
|
|
|
|
|
2011-11-10 00:56:22 +01:00
|
|
|
void FilterRegistry::add_filter_to_window(Window& window,
|
|
|
|
const std::string& name,
|
|
|
|
const FilterParameters& parameters)
|
2011-11-08 15:27:21 +01:00
|
|
|
{
|
|
|
|
auto it = m_factories.find(name);
|
|
|
|
if (it == m_factories.end())
|
|
|
|
throw factory_not_found();
|
|
|
|
|
2011-11-10 00:56:22 +01:00
|
|
|
window.add_filter(it->second(window, parameters));
|
2011-11-08 15:27:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|