ColorRegistry: permit overriding an alias
This commit is contained in:
parent
4d369d6290
commit
a92a6dc7f3
|
@ -35,9 +35,10 @@ const ColorPair& ColorRegistry::operator[](const String& colordesc)
|
|||
m_aliases[colordesc] = colpair;
|
||||
}
|
||||
|
||||
void ColorRegistry::register_alias(const String& name, const String& colordesc)
|
||||
void ColorRegistry::register_alias(const String& name, const String& colordesc,
|
||||
bool override)
|
||||
{
|
||||
if (m_aliases.find(name) != m_aliases.end())
|
||||
if (not override and m_aliases.find(name) != m_aliases.end())
|
||||
throw runtime_error("alias '" + name + "' already defined");
|
||||
|
||||
if (std::find_if(name.begin(), name.end(),
|
||||
|
|
|
@ -15,7 +15,8 @@ class ColorRegistry : public Singleton<ColorRegistry>
|
|||
{
|
||||
public:
|
||||
const ColorPair& operator[](const String& colordesc);
|
||||
void register_alias(const String& name, const String& colordesc);
|
||||
void register_alias(const String& name, const String& colordesc,
|
||||
bool override = false);
|
||||
|
||||
private:
|
||||
std::unordered_map<String, ColorPair> m_aliases;
|
||||
|
|
|
@ -750,6 +750,15 @@ void try_catch(const CommandParameters& params, Context& context)
|
|||
}
|
||||
}
|
||||
|
||||
void define_color_alias(const CommandParameters& params, Context& context)
|
||||
{
|
||||
ParametersParser parser(params, { { "allow-override", false } });
|
||||
if (parser.positional_count() != 2)
|
||||
throw wrong_argument_count();
|
||||
ColorRegistry::instance().register_alias(
|
||||
parser[0], parser[1], parser.has_option("allow-override"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void register_commands()
|
||||
|
@ -863,11 +872,7 @@ void register_commands()
|
|||
{ return context.window().option_manager().complete_option_name(prefix, cursor_pos); }
|
||||
}));
|
||||
|
||||
cm.register_commands({"ca", "colalias"},
|
||||
[](const CommandParameters& params, Context&) {
|
||||
if (params.size() != 2) throw wrong_argument_count();
|
||||
ColorRegistry::instance().register_alias(params[0], params[1]);
|
||||
});
|
||||
cm.register_commands({"ca", "colalias"}, define_color_alias);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user