completion support for addgrouphl and rmgrouphl

This commit is contained in:
Maxime Coste 2012-01-18 11:33:58 +00:00
parent cffdbcb689
commit 541872cafa
5 changed files with 46 additions and 3 deletions

View File

@ -282,6 +282,12 @@ void HighlighterGroup::remove_highlighter(const std::string& id)
m_highlighters.remove(id); m_highlighters.remove(id);
} }
CandidateList HighlighterGroup::complete_highlighterid(const std::string& prefix,
size_t cursor_pos)
{
return m_highlighters.complete_id<str_to_str>(prefix, cursor_pos);
}
HighlighterAndId HighlighterGroup::create(Window& window, HighlighterAndId HighlighterGroup::create(Window& window,
const HighlighterParameters& params) const HighlighterParameters& params)
{ {

View File

@ -20,6 +20,9 @@ public:
void add_highlighter(HighlighterAndId&& highlighter); void add_highlighter(HighlighterAndId&& highlighter);
void remove_highlighter(const std::string& id); void remove_highlighter(const std::string& id);
CandidateList complete_highlighterid(const std::string& prefix,
size_t cursor_pos);
static HighlighterAndId create(Window& window, static HighlighterAndId create(Window& window,
const HighlighterParameters& params); const HighlighterParameters& params);
private: private:

View File

@ -966,14 +966,31 @@ int main(int argc, char* argv[])
PerArgumentCommandCompleter { PerArgumentCommandCompleter {
std::bind(&HighlighterRegistry::complete_highlighter, &highlighter_registry, _1, _2) std::bind(&HighlighterRegistry::complete_highlighter, &highlighter_registry, _1, _2)
}); });
command_manager.register_command(std::vector<std::string>{ "agh", "addgrouphl" }, add_group_highlighter); command_manager.register_command(std::vector<std::string>{ "agh", "addgrouphl" }, add_group_highlighter,
CommandManager::None,
PerArgumentCommandCompleter {
[&](const std::string& prefix, size_t cursor_pos)
{ return main_context.window().complete_highlighter_groupid(prefix, cursor_pos); },
std::bind(&HighlighterRegistry::complete_highlighter, &highlighter_registry, _1, _2)
});
command_manager.register_command(std::vector<std::string>{ "rh", "rmhl" }, rm_highlighter, command_manager.register_command(std::vector<std::string>{ "rh", "rmhl" }, rm_highlighter,
CommandManager::None, CommandManager::None,
PerArgumentCommandCompleter { PerArgumentCommandCompleter {
[&](const std::string& prefix, size_t cursor_pos) [&](const std::string& prefix, size_t cursor_pos)
{ return main_context.window().complete_highlighterid(prefix, cursor_pos); } { return main_context.window().complete_highlighterid(prefix, cursor_pos); }
}); });
command_manager.register_command(std::vector<std::string>{ "rgh", "rmgrouphl" }, rm_group_highlighter); command_manager.register_command(std::vector<std::string>{ "rgh", "rmgrouphl" }, rm_group_highlighter,
CommandManager::None,
[&](const CommandParameters& params, size_t token_to_complete, size_t pos_in_token)
{
Window& w = main_context.window();
const std::string& arg = token_to_complete < params.size() ?
params[token_to_complete] : std::string();
if (token_to_complete == 0)
return w.complete_highlighter_groupid(arg, pos_in_token);
else if (token_to_complete == 1)
return w.get_highlighter_group(params[0]).complete_highlighterid(arg, pos_in_token);
});
command_manager.register_command(std::vector<std::string>{ "af", "addfilter" }, add_filter, command_manager.register_command(std::vector<std::string>{ "af", "addfilter" }, add_filter,
CommandManager::None, CommandManager::None,
PerArgumentCommandCompleter { PerArgumentCommandCompleter {

View File

@ -424,6 +424,21 @@ CandidateList Window::complete_highlighterid(const std::string& prefix,
return m_highlighters.complete_id<str_to_str>(prefix, cursor_pos); return m_highlighters.complete_id<str_to_str>(prefix, cursor_pos);
} }
CandidateList Window::complete_highlighter_groupid(const std::string& prefix,
size_t cursor_pos)
{
CandidateList all = m_highlighters.complete_id<str_to_str>(prefix, cursor_pos);
CandidateList result;
for (auto& id : all)
{
auto group_it = m_highlighters.find(id);
if (group_it != m_highlighters.end() and
group_it->second.target<HighlighterGroup>())
result.push_back(id);
}
return result;
}
void Window::add_filter(FilterAndId&& filter) void Window::add_filter(FilterAndId&& filter)
{ {
if (m_filters.contains(filter.first)) if (m_filters.contains(filter.first))

View File

@ -107,7 +107,9 @@ public:
HighlighterGroup& get_highlighter_group(const std::string& id); HighlighterGroup& get_highlighter_group(const std::string& id);
CandidateList complete_highlighterid(const std::string& prefix, CandidateList complete_highlighterid(const std::string& prefix,
size_t cursor_pos = std::string::npos); size_t cursor_pos);
CandidateList complete_highlighter_groupid(const std::string& prefix,
size_t cursor_pos);
void add_filter(FilterAndId&& filter); void add_filter(FilterAndId&& filter);
void remove_filter(const std::string& id); void remove_filter(const std::string& id);