commit 3913eba07e6028eda3872766b1f5acd06bdf649d
parent da7436d6b213afaa786a53a6ef2de4414d51f760
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sun, 17 Jul 2016 01:39:18 -0400
browser: replace type filter toggles by an exclusive type filter
Diffstat:
4 files changed, 25 insertions(+), 24 deletions(-)
diff --git a/src/browser.cpp b/src/browser.cpp
@@ -200,6 +200,10 @@ void Browser::onCommand(const int id, const int event)
case ACTION_MANAGE:
m_reapack->manageRemotes();
break;
+ case ACTION_FILTERTYPE:
+ m_typeFilter = boost::none;
+ fillList();
+ break;
case IDOK:
case IDAPPLY:
if(confirm()) {
@@ -217,8 +221,10 @@ void Browser::onCommand(const int id, const int event)
default:
if(id >> 8 == ACTION_VERSION)
installVersion(m_currentIndex, id & 0xff);
- else if(id >> 8 == ACTION_FILTERTYPE)
- toggleFiltered(static_cast<Package::Type>(id & 0xff));
+ else if(id >> 8 == ACTION_FILTERTYPE) {
+ m_typeFilter = static_cast<Package::Type>(id & 0xff);
+ fillList();
+ }
break;
}
}
@@ -383,9 +389,6 @@ void Browser::updateDisplayLabel()
void Browser::displayButton()
{
- RECT rect;
- GetWindowRect(m_displayBtn, &rect);
-
static map<const auto_char *, Package::Type> types = {
{AUTO_STR("&Scripts"), Package::ScriptType},
{AUTO_STR("&Effects"), Package::EffectType},
@@ -395,12 +398,17 @@ void Browser::displayButton()
};
Menu menu;
+
+ auto index = menu.addAction(AUTO_STR("&All packages"), ACTION_FILTERTYPE);
+ if(!m_typeFilter)
+ menu.checkRadio(index);
+
for(const auto &pair : types) {
- const auto index = menu.addAction(pair.first,
+ auto index = menu.addAction(pair.first,
pair.second | (ACTION_FILTERTYPE << 8));
- if(!isFiltered(pair.second))
- menu.check(index);
+ if(m_typeFilter && m_typeFilter == pair.second)
+ menu.checkRadio(index);
}
const auto config = m_reapack->config()->browser();
@@ -413,6 +421,9 @@ void Browser::displayButton()
menu.addAction(AUTO_STR("&Refresh repositories"), ACTION_REFRESH);
menu.addAction(AUTO_STR("&Manage repositories..."), ACTION_MANAGE);
+ RECT rect;
+ GetWindowRect(m_displayBtn, &rect);
+
menu.show(rect.left, rect.bottom - 1, handle());
}
@@ -430,6 +441,9 @@ void Browser::actionsButton()
bool Browser::isFiltered(Package::Type type) const
{
+ if(!m_typeFilter)
+ return false;
+
switch(type) {
case Package::ScriptType:
case Package::EffectType:
@@ -441,15 +455,7 @@ bool Browser::isFiltered(Package::Type type) const
break;
}
- const auto config = m_reapack->config()->browser();
- return ((config->typeFilter >> type) & 1) == 1;
-}
-
-void Browser::toggleFiltered(const Package::Type type)
-{
- auto config = m_reapack->config()->browser();
- config->typeFilter ^= 1 << type;
- fillList();
+ return m_typeFilter != type;
}
void Browser::toggleDescs()
diff --git a/src/browser.hpp b/src/browser.hpp
@@ -115,7 +115,6 @@ private:
void actionsButton();
void fillMenu(Menu &);
bool isFiltered(Package::Type) const;
- void toggleFiltered(Package::Type);
void toggleDescs();
void setTarget(const int index, const Version *, bool toggle = true);
void resetTarget(int index);
@@ -143,6 +142,7 @@ private:
int m_filterTimer;
Filter m_filter;
+ boost::optional<Package::Type> m_typeFilter;
std::vector<Entry> m_entries;
std::vector<size_t> m_visibleEntries;
std::unordered_set<Entry *> m_actions;
diff --git a/src/config.cpp b/src/config.cpp
@@ -35,7 +35,6 @@ static const auto_char *AUTOINSTALL_KEY = AUTO_STR("autoinstall");
static const auto_char *PRERELEASES_KEY = AUTO_STR("prereleases");
static const auto_char *BROWSER_GRP = AUTO_STR("browser");
-static const auto_char *TYPEFILTER_KEY = AUTO_STR("typefilter");
static const auto_char *SHOWDESCS_KEY = AUTO_STR("showdescs");
static const auto_char *STATE_KEY = AUTO_STR("state");
@@ -64,7 +63,7 @@ Config::Config()
void Config::resetOptions()
{
m_install = {false, false};
- m_browser = {0, true, ""};
+ m_browser = {true, ""};
m_network = {"", true};
}
@@ -135,8 +134,6 @@ void Config::read(const Path &path)
m_install.bleedingEdge = getUInt(INSTALL_GRP,
PRERELEASES_KEY, m_install.bleedingEdge) > 0;
- m_browser.typeFilter = getUInt(BROWSER_GRP,
- TYPEFILTER_KEY, m_browser.typeFilter);
m_browser.showDescs = getUInt(BROWSER_GRP,
SHOWDESCS_KEY, m_browser.showDescs) > 0;
m_browser.state = getString(BROWSER_GRP, STATE_KEY, m_browser.state);
@@ -157,7 +154,6 @@ void Config::write()
setUInt(INSTALL_GRP, AUTOINSTALL_KEY, m_install.autoInstall);
setUInt(INSTALL_GRP, PRERELEASES_KEY, m_install.bleedingEdge);
- setUInt(BROWSER_GRP, TYPEFILTER_KEY, m_browser.typeFilter);
setUInt(BROWSER_GRP, SHOWDESCS_KEY, m_browser.showDescs);
setString(BROWSER_GRP, STATE_KEY, m_browser.state);
diff --git a/src/config.hpp b/src/config.hpp
@@ -31,7 +31,6 @@ struct InstallOpts {
};
struct BrowserOpts {
- unsigned int typeFilter;
bool showDescs;
std::string state;
};