From: Mikko Rasa Date: Tue, 14 Aug 2018 23:53:01 +0000 (+0300) Subject: Add show flag to filter blocks X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=873663c883acac8b3641fb58488fe78ad96dba1b;p=poefilter.git Add show flag to filter blocks The hide statement no longer erases blocks from the filter but rather adds blocks with the hide command. A new cancel statement does what hide used to do. The default hide command at the end has been removed and must be explicitly defined in filters. --- diff --git a/source/filter.cpp b/source/filter.cpp index 80ca193..0f7a20e 100644 --- a/source/filter.cpp +++ b/source/filter.cpp @@ -50,6 +50,7 @@ void Filter::write(IO::Base &out) const { list st; st.push_back(FilterStatement()); + st.back().set_show(i->show); i->appearance.add_lines(st.back()); i->category->create_statements(st); @@ -57,8 +58,6 @@ void Filter::write(IO::Base &out) const for(list::const_iterator j=st.begin(); j!=st.end(); ++j) j->write(out); } - - out.write("# unmatched\nHide\n"); } @@ -93,35 +92,7 @@ bool Filter::Loader::category_order(const Category *c1, const Category *c2) return c1->get_order()get_order(); } -void Filter::Loader::hide(const string &name) -{ - list categs; - if(name.find('*')!=string::npos) - { - poe.find_categories(glob_to_re(name), categs); - - if(categs.empty()) - throw key_error(name); - } - else - categs.push_back(&poe.get_category(name)); - - for(list::const_iterator i=categs.begin(); i!=categs.end(); ++i) - for(list::iterator j=obj.blocks.begin(); j!=obj.blocks.end(); ++j) - if(j->category==*i) - { - obj.blocks.erase(j); - break; - } -} - -void Filter::Loader::include(const string &name) -{ - const Filter &base = poe.get_filter(name); - obj.blocks.insert(obj.blocks.end(), base.blocks.begin(), base.blocks.end()); -} - -void Filter::Loader::show(const string &name) +void Filter::Loader::add_categories(const string &name, bool show) { list categs; if(name.find('*')!=string::npos) @@ -145,6 +116,7 @@ void Filter::Loader::show(const string &name) if(!found) { Block blk; + blk.show = show; blk.category = *i; blk.appearance = (*i)->get_appearance(); if(const Appearance *app = poe.get_theme().find_appearance((*i)->get_name())) @@ -153,3 +125,41 @@ void Filter::Loader::show(const string &name) } } } + +void Filter::Loader::cancel(const string &name) +{ + list categs; + if(name.find('*')!=string::npos) + { + poe.find_categories(glob_to_re(name), categs); + + if(categs.empty()) + throw key_error(name); + } + else + categs.push_back(&poe.get_category(name)); + + for(list::const_iterator i=categs.begin(); i!=categs.end(); ++i) + for(list::iterator j=obj.blocks.begin(); j!=obj.blocks.end(); ++j) + if(j->category==*i) + { + obj.blocks.erase(j); + break; + } +} + +void Filter::Loader::hide(const string &name) +{ + add_categories(name, false); +} + +void Filter::Loader::include(const string &name) +{ + const Filter &base = poe.get_filter(name); + obj.blocks.insert(obj.blocks.end(), base.blocks.begin(), base.blocks.end()); +} + +void Filter::Loader::show(const string &name) +{ + add_categories(name, true); +} diff --git a/source/filter.h b/source/filter.h index 492ff7d..8511fff 100644 --- a/source/filter.h +++ b/source/filter.h @@ -44,7 +44,9 @@ public: private: static std::string glob_to_re(const std::string &); static bool category_order(const Category *, const Category *); + void add_categories(const std::string &, bool); + void cancel(const std::string &); void hide(const std::string &); void include(const std::string &); void show(const std::string &); @@ -53,6 +55,7 @@ public: private: struct Block { + bool show; const Category *category; Appearance appearance; };