commit 0536b8034e03ba01dcb24d67104927734e48ce82
parent 0b732463e07593ca651beae1fdcc95218dde34a0
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sun, 29 Oct 2017 06:41:06 -0400
manager: toggle enabled status by clicking on the checkbox icon
Diffstat:
4 files changed, 34 insertions(+), 45 deletions(-)
diff --git a/src/listview.cpp b/src/listview.cpp
@@ -381,13 +381,16 @@ int ListView::selectionSize() const
return ListView_GetSelectedCount(handle());
}
-int ListView::itemUnderMouse() const
+int ListView::itemUnderMouse(bool *overIcon) const
{
LVHITTESTINFO info{};
GetCursorPos(&info.pt);
ScreenToClient(handle(), &info.pt);
ListView_HitTest(handle(), &info);
+ if(overIcon)
+ *overIcon = info.flags & (LVHT_ONITEMICON | LVHT_ONITEMSTATEICON);
+
return translateBack(info.iItem);
}
@@ -424,8 +427,9 @@ void ListView::onNotify(LPNMHDR info, LPARAM lParam)
case LVN_ITEMCHANGED:
m_onSelect();
break;
+ case NM_CLICK:
case NM_DBLCLK:
- handleDoubleClick();
+ handleClick(info->code == NM_DBLCLK);
break;
case LVN_COLUMNCLICK:
handleColumnClick(lParam);
@@ -486,16 +490,21 @@ bool ListView::onContextMenu(HWND dialog, int x, int y)
return true;
}
-void ListView::handleDoubleClick()
+void ListView::handleClick(const bool dbclick)
{
- // user double clicked on an item
- if(itemUnderMouse() > -1 && currentIndex() > -1)
- m_onActivate();
+ bool overIcon;
+
+ if(itemUnderMouse(&overIcon) > -1 && currentIndex() > -1) {
+ if(dbclick)
+ m_onActivate();
+ else if(overIcon)
+ m_onIconClick();
+ }
}
-void ListView::handleColumnClick(LPARAM lParam)
+void ListView::handleColumnClick(const LPARAM lParam)
{
- auto info = (LPNMLISTVIEW)lParam;
+ const auto info = reinterpret_cast<LPNMLISTVIEW>(lParam);
const int col = info->iSubItem;
SortOrder order = AscendingOrder;
diff --git a/src/listview.hpp b/src/listview.hpp
@@ -125,7 +125,7 @@ public:
void enableIcons();
int currentIndex() const;
- int itemUnderMouse() const;
+ int itemUnderMouse(bool *overIcon = nullptr) const;
int scroll() const;
void setScroll(int);
@@ -153,6 +153,7 @@ public:
void resetColumns();
void onSelect(const VoidSignal::slot_type &slot) { m_onSelect.connect(slot); }
+ void onIconClick(const VoidSignal::slot_type &slot) { m_onIconClick.connect(slot); }
void onActivate(const VoidSignal::slot_type &slot) { m_onActivate.connect(slot); }
void onContextMenu(const MenuSignal::slot_type &slot) { m_onContextMenu.connect(slot); }
@@ -183,7 +184,7 @@ private:
void setExStyle(int style, bool enable = true);
void setSortArrow(bool);
- void handleDoubleClick();
+ void handleClick(bool dbclick);
void handleColumnClick(LPARAM lpnmlistview);
int translate(int userIndex) const;
int translateBack(int internalIndex) const;
@@ -203,6 +204,7 @@ private:
boost::optional<Sort> m_defaultSort;
VoidSignal m_onSelect;
+ VoidSignal m_onIconClick;
VoidSignal m_onActivate;
MenuSignal m_onContextMenu;
};
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -39,12 +39,12 @@ static const Win32::char_type *ARCHIVE_EXT = L("ReaPackArchive");
using namespace std;
enum {
- ACTION_ENABLE = 80, ACTION_DISABLE, ACTION_UNINSTALL, ACTION_ABOUT,
- ACTION_REFRESH, ACTION_COPYURL, ACTION_SELECT, ACTION_UNSELECT,
- ACTION_AUTOINSTALL_GLOBAL, ACTION_AUTOINSTALL_OFF, ACTION_AUTOINSTALL_ON,
- ACTION_AUTOINSTALL, ACTION_BLEEDINGEDGE, ACTION_PROMPTOBSOLETE,
- ACTION_NETCONFIG, ACTION_RESETCONFIG, ACTION_IMPORT_REPO,
- ACTION_IMPORT_ARCHIVE, ACTION_EXPORT_ARCHIVE
+ ACTION_UNINSTALL = 80, ACTION_ABOUT, ACTION_REFRESH, ACTION_COPYURL,
+ ACTION_SELECT, ACTION_UNSELECT, ACTION_AUTOINSTALL_GLOBAL,
+ ACTION_AUTOINSTALL_OFF, ACTION_AUTOINSTALL_ON, ACTION_AUTOINSTALL,
+ ACTION_BLEEDINGEDGE, ACTION_PROMPTOBSOLETE, ACTION_NETCONFIG,
+ ACTION_RESETCONFIG, ACTION_IMPORT_REPO, ACTION_IMPORT_ARCHIVE,
+ ACTION_EXPORT_ARCHIVE,
};
Manager::Manager()
@@ -70,8 +70,9 @@ void Manager::onInit()
});
m_list->enableIcons();
- m_list->onActivate(bind(&Manager::aboutRepo, this, true));
m_list->onSelect(bind(&Dialog::startTimer, this, 100, 0, true));
+ m_list->onIconClick(bind(&Manager::toggleEnabled, this));
+ m_list->onActivate(bind(&Manager::aboutRepo, this, true));
m_list->onContextMenu(bind(&Manager::fillContextMenu, this, _1, _2));
setAnchor(m_list->handle(), AnchorRight | AnchorBottom);
@@ -121,12 +122,6 @@ void Manager::onCommand(const int id, int)
case IDC_OPTIONS:
options();
break;
- case ACTION_ENABLE:
- setRemoteEnabled(true);
- break;
- case ACTION_DISABLE:
- setRemoteEnabled(false);
- break;
case ACTION_REFRESH:
refreshIndex();
break;
@@ -215,14 +210,8 @@ bool Manager::fillContextMenu(Menu &menu, const int index) const
return true;
}
- const UINT enableAction =
- menu.addAction("&Enable", ACTION_ENABLE);
- const UINT disableAction =
- menu.addAction("&Disable", ACTION_DISABLE);
-
- menu.addSeparator();
-
menu.addAction("&Refresh", ACTION_REFRESH);
+ menu.addAction("&Copy URL", ACTION_COPYURL);
Menu autoInstallMenu = menu.addMenu("&Install new packages");
const UINT autoInstallGlobal = autoInstallMenu.addAction(
@@ -232,8 +221,6 @@ bool Manager::fillContextMenu(Menu &menu, const int index) const
const UINT autoInstallOn = autoInstallMenu.addAction(
"When synchronizing", ACTION_AUTOINSTALL_ON);
- menu.addAction("&Copy URL", ACTION_COPYURL);
-
const UINT uninstallAction =
menu.addAction("&Uninstall", ACTION_UNINSTALL);
@@ -242,8 +229,6 @@ bool Manager::fillContextMenu(Menu &menu, const int index) const
menu.addAction(String::format("&About %s", remote.name().c_str()),
index | (ACTION_ABOUT << 8));
- bool allEnabled = true;
- bool allDisabled = true;
bool allProtected = true;
bool allAutoInstallGlobal = true;
bool allAutoInstallOff = true;
@@ -251,11 +236,6 @@ bool Manager::fillContextMenu(Menu &menu, const int index) const
for(const int i : m_list->selection()) {
const Remote &r = getRemote(i);
- if(isRemoteEnabled(r))
- allDisabled = false;
- else
- allEnabled = false;
-
if(!r.isProtected())
allProtected = false;
@@ -273,10 +253,6 @@ bool Manager::fillContextMenu(Menu &menu, const int index) const
}
};
- if(allEnabled)
- menu.disable(enableAction);
- if(allDisabled)
- menu.disable(disableAction);
if(allProtected)
menu.disable(uninstallAction);
@@ -370,9 +346,11 @@ void Manager::setMods(const ModsCallback &cb, const bool updateRow)
}
}
-void Manager::setRemoteEnabled(const bool enabled)
+void Manager::toggleEnabled()
{
setMods([=](const Remote &remote, RemoteMods *mods) {
+ const bool enabled = !mods->enable.value_or(remote.isEnabled());
+
if(remote.isEnabled() == enabled)
mods->enable = boost::none;
else
diff --git a/src/manager.hpp b/src/manager.hpp
@@ -57,7 +57,7 @@ private:
Remote getRemote(int index) const;
bool fillContextMenu(Menu &, int index) const;
void setMods(const ModsCallback &, bool updateRow);
- void setRemoteEnabled(bool);
+ void toggleEnabled();
bool isRemoteEnabled(const Remote &) const;
void setRemoteAutoInstall(const tribool &);
tribool remoteAutoInstall(const Remote &) const;