commit 97be2e0f9ee7df7fc12488a4b24d2f0f7d01fddb
parent 4f27bed8b0b9b36262ae5ccc20f35a6879da62cb
Author: cfillion <cfillion@users.noreply.github.com>
Date: Thu, 31 Dec 2015 16:17:44 -0500
enable/disable the Uninstall button when the selection change
Diffstat:
7 files changed, 87 insertions(+), 9 deletions(-)
diff --git a/src/dialog.cpp b/src/dialog.cpp
@@ -58,6 +58,9 @@ WDL_DLGRET Dialog::Proc(HWND handle, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_COMMAND:
dlg->onCommand(wParam, lParam);
break;
+ case WM_NOTIFY:
+ dlg->onNotify((LPNMHDR)lParam, lParam);
+ break;
case WM_DESTROY:
dlg->onDestroy();
break;
@@ -142,9 +145,19 @@ void Dialog::setFocus()
SetFocus(m_handle);
}
-void Dialog::setEnabled(const bool enabled)
+void Dialog::enable(HWND handle)
+{
+ setEnabled(true, handle);
+}
+
+void Dialog::disable(HWND handle)
+{
+ setEnabled(false, handle);
+}
+
+void Dialog::setEnabled(const bool enabled, HWND handle)
{
- EnableWindow(m_handle, enabled);
+ EnableWindow(handle ? handle : m_handle, enabled);
}
HWND Dialog::getItem(const int idc)
@@ -168,6 +181,10 @@ void Dialog::onCommand(WPARAM, LPARAM)
{
}
+void Dialog::onNotify(LPNMHDR, LPARAM)
+{
+}
+
void Dialog::onDestroy()
{
}
diff --git a/src/dialog.hpp b/src/dialog.hpp
@@ -59,7 +59,9 @@ public:
HWND handle() const { return m_handle; }
bool isVisible() const { return m_isVisible; }
- void setEnabled(const bool);
+ void enable(HWND = 0);
+ void disable(HWND = 0);
+ void setEnabled(const bool, HWND = 0);
void show();
void hide();
@@ -78,6 +80,7 @@ protected:
virtual void onHide();
virtual void onTimer();
virtual void onCommand(WPARAM, LPARAM);
+ virtual void onNotify(LPNMHDR, LPARAM);
virtual void onDestroy();
private:
diff --git a/src/listview.cpp b/src/listview.cpp
@@ -69,3 +69,17 @@ void ListView::clear()
m_rowSize = 0;
}
+
+int ListView::selectedIndex() const
+{
+ return ListView_GetNextItem(m_handle, -1, LVNI_SELECTED);
+}
+
+void ListView::onNotify(LPNMHDR info, LPARAM)
+{
+ switch(info->code) {
+ case LVN_ITEMCHANGED:
+ m_onSelect();
+ break;
+ };
+}
diff --git a/src/listview.hpp b/src/listview.hpp
@@ -24,6 +24,7 @@
#include <swell/swell.h>
#endif
+#include <boost/signals2.hpp>
#include <vector>
#include "encoding.hpp"
@@ -34,17 +35,29 @@ public:
typedef std::vector<const Column> Columns;
typedef std::vector<const auto_char *> Row;
+ typedef boost::signals2::signal<void ()> Signal;
+ typedef Signal::slot_type Callback;
+
ListView(const Columns &, HWND handle);
+ HWND handle() const { return m_handle; }
+
void addRow(const Row &);
void clear();
+ int selectedIndex() const;
+
+ void onSelect(const Callback &callback) { m_onSelect.connect(callback); }
+ void onNotify(LPNMHDR, LPARAM);
+
private:
void addColumn(const auto_char *text, const int width);
HWND m_handle;
size_t m_columnSize;
size_t m_rowSize;
+
+ Signal m_onSelect;
};
#endif
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -22,8 +22,7 @@
#include "reapack.hpp"
#include "resource.hpp"
-const auto_char *NAME = AUTO_STR("Name");
-const auto_char *URL = AUTO_STR("URL");
+using namespace std;
Manager::Manager(ReaPack *reapack)
: Dialog(IDD_CONFIG_DIALOG), m_reapack(reapack), m_list(0)
@@ -42,6 +41,10 @@ void Manager::onInit()
{AUTO_STR("URL"), 360},
{AUTO_STR("State"), 60},
}, getItem(IDC_LIST));
+
+ m_list->onSelect(bind(&Manager::selectionChanged, this));
+
+ disable(m_uninstall = getItem(IDC_UNINSTALL));
}
void Manager::onCommand(WPARAM wParam, LPARAM)
@@ -51,8 +54,7 @@ void Manager::onCommand(WPARAM wParam, LPARAM)
m_reapack->importRemote();
break;
case IDC_UNINSTALL:
- MessageBox(handle(), AUTO_STR("Not Implemented"),
- AUTO_STR("Uninstall"), MB_OK);
+ uninstall();
break;
case IDOK:
apply();
@@ -62,6 +64,15 @@ void Manager::onCommand(WPARAM wParam, LPARAM)
}
}
+void Manager::onNotify(LPNMHDR info, LPARAM lParam)
+{
+ switch(info->idFrom) {
+ case IDC_LIST:
+ m_list->onNotify(info, lParam);
+ break;
+ }
+}
+
void Manager::refresh()
{
m_list->clear();
@@ -75,6 +86,22 @@ void Manager::refresh()
}
}
+void Manager::selectionChanged()
+{
+ setEnabled(m_list->selectedIndex() > -1, m_uninstall);
+}
+
+void Manager::uninstall()
+{
+ const int index = m_list->selectedIndex();
+
+ if(index < 0)
+ return;
+
+ MessageBox(handle(), to_autostring(index).c_str(),
+ AUTO_STR("Uninstall"), MB_OK);
+}
+
void Manager::apply()
{
}
diff --git a/src/manager.hpp b/src/manager.hpp
@@ -34,12 +34,16 @@ public:
protected:
void onInit() override;
void onCommand(WPARAM, LPARAM) override;
+ void onNotify(LPNMHDR, LPARAM) override;
private:
+ void selectionChanged();
+ void uninstall();
void apply();
ReaPack *m_reapack;
ListView *m_list;
+ HWND m_uninstall;
};
#endif
diff --git a/src/reapack.cpp b/src/reapack.cpp
@@ -184,14 +184,14 @@ Transaction *ReaPack::createTransaction()
if(m_transaction->isCancelled())
return;
- m_progress->setEnabled(false);
+ m_progress->disable();
if(m_transaction->packages().empty() && m_transaction->errors().empty())
ShowMessageBox("Nothing to do!", "ReaPack", 0);
else
Dialog::Show<Report>(m_instance, m_mainWindow, m_transaction);
- m_progress->setEnabled(true);
+ m_progress->enable();
m_progress->hide();
m_config->write();