Ensure option UI is sorted: Tabs by names, items by keys.

pull/1191/head
John Ralls 5 years ago
parent 10381d42e0
commit b361582cf2

@ -138,6 +138,12 @@ private:
GncOptionUIItemPtr m_ui_item{nullptr};
};
inline bool
operator<(const GncOption& right, const GncOption& left)
{
return right.get_key() < left.get_key();
}
inline std::ostream&
operator<<(std::ostream& oss, const GncOption& opt)
{

@ -63,6 +63,13 @@ public:
};
using GncOptionSectionPtr = std::shared_ptr<GncOptionSection>;
inline bool
operator<(const GncOptionSectionPtr& right, const GncOptionSectionPtr& left)
{
return right->get_name() < left->get_name();
}
using GncOptionDBChangeCallback = void (*)(void* user_data);
struct GncOptionDBCallback

@ -132,7 +132,9 @@ GncOptionSection::foreach_option(std::function<void(const GncOption&)> func) con
void
GncOptionSection::add_option(GncOption&& option)
{
m_options.emplace_back(std::move(option));
m_options.push_back(std::move(option));
if (!std::is_sorted(m_options.begin(), m_options.end()))
std::sort(m_options.begin(), m_options.end());
}
void
@ -176,8 +178,10 @@ GncOptionDB::register_option(const char* sectname, GncOption&& option)
return;
}
m_sections.emplace_back(std::make_shared<GncOptionSection>(sectname));
m_sections.push_back(std::make_shared<GncOptionSection>(sectname));
m_sections.back()->add_option(std::move(option));
if (!std::is_sorted(m_sections.begin(), m_sections.end()))
std::sort(m_sections.begin(), m_sections.end());
}
void

Loading…
Cancel
Save