commit 0c79395d8fa39cc5a7d53a1f4f53dd3aac3a3a2c
parent 22a73cfd5838d7e31715bfce2b32e776bb11f6d9
Author: cfillion <cfillion@users.noreply.github.com>
Date: Fri, 1 Jan 2016 21:47:42 -0500
prepare modification of remotes
Diffstat:
10 files changed, 106 insertions(+), 62 deletions(-)
diff --git a/src/config.cpp b/src/config.cpp
@@ -78,7 +78,7 @@ void Config::write()
writeRegistry();
}
-void Config::addRemote(Remote remote)
+void Config::addRemote(const Remote &remote)
{
m_remotes[remote.first] = remote.second;
}
diff --git a/src/config.hpp b/src/config.hpp
@@ -32,7 +32,7 @@ public:
void read(const Path &);
void write();
- void addRemote(Remote);
+ void addRemote(const Remote &);
const RemoteMap &remotes() const { return m_remotes; }
Registry *registry() { return &m_registry; }
diff --git a/src/encoding.cpp b/src/encoding.cpp
@@ -22,15 +22,23 @@
auto_string make_autostring(const std::string &input)
{
- const char *cstr = input.c_str();
- const int size = MultiByteToWideChar(CP_UTF8, 0, cstr, -1, nullptr, 0);
+ const int size = MultiByteToWideChar(CP_UTF8, 0, &input[0], -1, nullptr, 0);
- wchar_t *output = new wchar_t[size];
- MultiByteToWideChar(CP_UTF8, 0, cstr, -1, output, size);
+ auto_string output(size, 0);
+ MultiByteToWideChar(CP_UTF8, 0, &input[0], -1, &output[0], size);
- auto_string string(output);
- delete[] output;
+ return output;
+}
+
+std::string from_autostring(const auto_string &input)
+{
+ const int size = WideCharToMultiByte(CP_UTF8, 0,
+ &input[0], -1, nullptr, 0, nullptr, nullptr);
+
+ std::string output(size, 0);
+ WideCharToMultiByte(CP_UTF8, 0,
+ &input[0], -1, &output[0], size, nullptr, nullptr);
- return string;
+ return output;
}
#endif
diff --git a/src/encoding.hpp b/src/encoding.hpp
@@ -32,6 +32,7 @@ typedef std::wstring auto_string;
#define AUTO_STR(text) L##text
#define to_autostring std::to_wstring
auto_string make_autostring(const std::string &);
+std::string from_autostring(const auto_string &);
#else
@@ -41,6 +42,7 @@ typedef std::string auto_string;
#define AUTO_STR(text) text
#define to_autostring std::to_string
#define make_autostring(string) string
+#define from_autostring(string) string
#endif
diff --git a/src/listview.cpp b/src/listview.cpp
@@ -34,37 +34,60 @@ ListView::ListView(const Columns &columns, HWND handle)
LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
}
-void ListView::addColumn(const auto_char *text, const int width)
+void ListView::addColumn(const auto_string &text, const int width)
{
- LVCOLUMN col = {0};
+ LVCOLUMN col{};
col.mask |= LVCF_WIDTH;
col.cx = width;
col.mask |= LVCF_TEXT;
- col.pszText = const_cast<auto_char *>(text);
+ col.pszText = const_cast<auto_char *>(text.c_str());
ListView_InsertColumn(m_handle, m_columnSize++, &col);
}
-void ListView::addRow(const Row &content)
+int ListView::addRow(const Row &content)
{
- LVITEM item = {0};
- item.iItem = (int)m_rowSize++;
+ LVITEM item{};
+ item.iItem = m_rowSize++;
ListView_InsertItem(m_handle, &item);
- const size_t cols = min(m_columnSize, content.size());
+ replaceRow(item.iItem, content);
- for(size_t i = 0; i < cols; i++) {
- auto_char *text = const_cast<auto_char *>(content[i]);
- ListView_SetItemText(m_handle, item.iItem, (int)i, text);
+ return item.iItem;
+}
+
+void ListView::replaceRow(const int index, const Row &content)
+{
+ LVITEM item{};
+ item.iItem = index;
+
+ const int cols = min(m_columnSize, (int)content.size());
+
+ for(int i = 0; i < cols; i++) {
+ auto_char *text = const_cast<auto_char *>(content[i].c_str());
+ ListView_SetItemText(m_handle, item.iItem, i, text);
}
}
+ListView::Row ListView::getRow(const int rowIndex) const
+{
+ Row row(m_columnSize);
+
+ for(int i = 0; i < m_columnSize; i++) {
+ auto_char buf[4096];
+ ListView_GetItemText(m_handle, rowIndex, i, buf, sizeof(buf));
+ row[i] = buf;
+ }
+
+ return row;
+}
+
void ListView::clear()
{
- for(size_t i = 0; i < m_rowSize; i++)
+ for(int i = 0; i < m_rowSize; i++)
ListView_DeleteItem(m_handle, 0);
m_rowSize = 0;
diff --git a/src/listview.hpp b/src/listview.hpp
@@ -31,9 +31,9 @@
class ListView {
public:
- typedef std::pair<const auto_char *, int> Column;
- typedef std::vector<const Column> Columns;
- typedef std::vector<const auto_char *> Row;
+ typedef std::pair<auto_string, int> Column;
+ typedef std::vector<Column> Columns;
+ typedef std::vector<auto_string> Row;
typedef boost::signals2::signal<void ()> Signal;
typedef Signal::slot_type Callback;
@@ -42,7 +42,9 @@ public:
HWND handle() const { return m_handle; }
- void addRow(const Row &);
+ int addRow(const Row &);
+ Row getRow(const int index) const;
+ void replaceRow(const int index, const Row &);
void clear();
bool hasSelection() const;
@@ -52,11 +54,11 @@ public:
void onNotify(LPNMHDR, LPARAM);
private:
- void addColumn(const auto_char *text, const int width);
+ void addColumn(const auto_string &text, const int width);
HWND m_handle;
- size_t m_columnSize;
- size_t m_rowSize;
+ int m_columnSize;
+ int m_rowSize;
Signal m_onSelect;
};
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -23,9 +23,6 @@
#include "reapack.hpp"
#include "resource.hpp"
-static const int ACTION_ENABLE = 300;
-static const int ACTION_DISABLE = 301;
-
using namespace std;
Manager::Manager(ReaPack *reapack)
@@ -45,20 +42,20 @@ 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)
{
+ const int cmdId = LOWORD(wParam);
+
switch(LOWORD(wParam)) {
case IDC_IMPORT:
m_reapack->importRemote();
break;
- case IDC_UNINSTALL:
- uninstall();
+ case Enable:
+ case Disable:
+ case Uninstall:
+ markFor(static_cast<Action>(cmdId));
break;
case IDOK:
apply();
@@ -84,14 +81,14 @@ void Manager::onContextMenu(HWND target, const int x, const int y)
Menu menu;
- menu.addAction(AUTO_STR("Enable"), ACTION_ENABLE);
+ menu.addAction(AUTO_STR("Enable"), Enable);
const UINT disableAction =
- menu.addAction(AUTO_STR("Disable"), ACTION_DISABLE);
+ menu.addAction(AUTO_STR("Disable"), Disable);
menu.addSeparator();
const UINT uninstallAction =
- menu.addAction(AUTO_STR("Uninstall"), IDC_UNINSTALL);
+ menu.addAction(AUTO_STR("Uninstall"), Uninstall);
menu.disable();
@@ -110,30 +107,35 @@ void Manager::refresh()
m_list->clear();
const RemoteMap remotes = m_reapack->config()->remotes();
- for(auto it = remotes.begin(); it != remotes.end(); it++) {
- const auto_string &name = make_autostring(it->first);
- const auto_string &url = make_autostring(it->second);
-
- m_list->addRow({name.c_str(), url.c_str(), AUTO_STR("Enabled")});
- }
+ for(auto it = remotes.begin(); it != remotes.end(); it++)
+ m_list->addRow(makeRow(*it));
}
-void Manager::selectionChanged()
-{
- setEnabled(m_list->hasSelection(), m_uninstall);
-}
-
-void Manager::uninstall()
+void Manager::markFor(const Action action)
{
const int index = m_list->currentIndex();
if(index < 0)
return;
- MessageBox(handle(), to_autostring(index).c_str(),
- AUTO_STR("Uninstall"), MB_OK);
+ const string &remoteName = from_autostring(m_list->getRow(index)[0]);
+ const Remote remote =
+ {"aaaaaaa", m_reapack->config()->remotes().at(remoteName)};
+
+ MessageBox(handle(), to_autostring(action).c_str(),
+ m_list->getRow(index)[0].c_str(), MB_OK);
+
+ m_list->replaceRow(index, makeRow(remote));
}
void Manager::apply()
{
}
+
+ListView::Row Manager::makeRow(const Remote &remote)
+{
+ const auto_string name = make_autostring(remote.first);
+ const auto_string url = make_autostring(remote.second);
+
+ return {name, url, AUTO_STR("Enabled")};
+}
diff --git a/src/manager.hpp b/src/manager.hpp
@@ -21,6 +21,7 @@
#include "dialog.hpp"
#include "listview.hpp"
+#include "remote.hpp"
class Menu;
class ReaPack;
@@ -39,8 +40,16 @@ protected:
void onContextMenu(HWND, int x, int y) override;
private:
+ static ListView::Row makeRow(const Remote &remote);
+
+ enum Action {
+ Enable = 300,
+ Disable = 301,
+ Uninstall = 302,
+ };
+
void selectionChanged();
- void uninstall();
+ void markFor(Action action);
void apply();
ReaPack *m_reapack;
diff --git a/src/resource.hpp b/src/resource.hpp
@@ -33,11 +33,10 @@
#define IDD_REPORT_DIALOG 101
#define IDD_CONFIG_DIALOG 102
-#define IDC_LABEL 200
-#define IDC_PROGRESS 201
-#define IDC_REPORT 202
-#define IDC_LIST 203
-#define IDC_IMPORT 204
-#define IDC_UNINSTALL 205
+#define IDC_LABEL 200
+#define IDC_PROGRESS 201
+#define IDC_REPORT 202
+#define IDC_LIST 203
+#define IDC_IMPORT 204
#endif
diff --git a/src/resource.rc b/src/resource.rc
@@ -32,8 +32,7 @@ BEGIN
LTEXT "Remote repositories:", IDC_LABEL, 5, 5, 320, 10
CONTROL "", IDC_LIST, WC_LISTVIEW, LVS_REPORT | LVS_SINGLESEL |
LVS_SHOWSELALWAYS | WS_BORDER | WS_TABSTOP, 5, 18, 320, 136
- PUSHBUTTON "Import", IDC_IMPORT, 5, 160, 40, 14
- PUSHBUTTON "Uninstall", IDC_UNINSTALL, 48, 160, 40, 14
+ PUSHBUTTON "Import...", IDC_IMPORT, 5, 160, 45, 14
DEFPUSHBUTTON "OK", IDOK, 240, 160, 40, 14
PUSHBUTTON "Cancel", IDCANCEL, 284, 160, 40, 14
END