X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ffilter.cpp;h=02f8c3f6ccf278b1ab974e894f7aa2f09ff1304f;hb=d0663f70ea5caea2db3c6d3c846ec67410db3498;hp=70a126b5c8eeaf5464c1b8540915fcea5c8054d5;hpb=74086c211f082f6f47c3d038dd308a257a81e006;p=poefilter.git diff --git a/source/filter.cpp b/source/filter.cpp index 70a126b..02f8c3f 100644 --- a/source/filter.cpp +++ b/source/filter.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include "category.h" @@ -46,16 +46,18 @@ Filter::Filter(): void Filter::write(IO::Base &out) const { - for(list::const_iterator i=categories.begin(); i!=categories.end(); ++i) + for(list::const_iterator i=blocks.begin(); i!=blocks.end(); ++i) { list st; - //IO::print(out, "# %s\n", i->first); - (*i)->create_statements(st); + st.push_back(FilterStatement()); + st.back().set_show(i->show); + i->appearance.add_lines(st.back()); + i->category->create_statements(st); + + IO::print(out, "# %s\n", i->category->get_name()); for(list::const_iterator j=st.begin(); j!=st.end(); ++j) j->write(out); } - - out.write("# unmatched\nHide\n"); } @@ -90,49 +92,74 @@ bool Filter::Loader::category_order(const Category *c1, const Category *c2) return c1->get_order()get_order(); } -void Filter::Loader::hide(const string &name) +void Filter::Loader::add_categories(const string &name, bool show) { - list categs; + vector categs; if(name.find('*')!=string::npos) { poe.find_categories(glob_to_re(name), categs); if(categs.empty()) throw key_error(name); + + sort(categs, &category_order); } else categs.push_back(&poe.get_category(name)); - for(list::const_iterator i=categs.begin(); i!=categs.end(); ++i) + for(vector::const_iterator i=categs.begin(); i!=categs.end(); ++i) { - list::iterator j = find(obj.categories.begin(), obj.categories.end(), *i); - if(j!=obj.categories.end()) - obj.categories.erase(j); + bool found = false; + for(list::const_iterator j=obj.blocks.begin(); (!found && j!=obj.blocks.end()); ++j) + found = (j->category==*i); + + 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())) + blk.appearance.merge_from(*app); + obj.blocks.push_back(blk); + } } } -void Filter::Loader::include(const string &name) -{ - const Filter &base = poe.get_filter(name); - obj.categories.insert(obj.categories.end(), base.categories.begin(), base.categories.end()); -} - -void Filter::Loader::show(const string &name) +void Filter::Loader::cancel(const string &name) { - list categs; + vector categs; if(name.find('*')!=string::npos) { poe.find_categories(glob_to_re(name), categs); if(categs.empty()) throw key_error(name); - - categs.sort(&category_order); } else categs.push_back(&poe.get_category(name)); - for(list::const_iterator i=categs.begin(); i!=categs.end(); ++i) - if(find(obj.categories.begin(), obj.categories.end(), *i)==obj.categories.end()) - obj.categories.push_back(*i); + for(vector::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); }