commit 6e717f3fe94f7f3de600863f2af8166ef65683c7
parent 3458fdaf58d6dfa5a5f1cb7709988291e2d92804
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sun, 5 Jun 2016 14:48:02 -0400
refactor clipboard handling
Diffstat:
3 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/src/dialog.cpp b/src/dialog.cpp
@@ -18,6 +18,7 @@
#include "dialog.hpp"
#include "control.hpp"
+#include "encoding.hpp"
#include <algorithm>
#include <boost/range/adaptor/map.hpp>
@@ -220,6 +221,25 @@ void Dialog::stopTimer(int id)
m_timers.erase(id);
}
+void Dialog::setClipboard(const string &text)
+{
+ const auto_string &data = make_autostring(text);
+ const size_t length = (data.size() * sizeof(auto_char)) + 1; // null terminator
+
+ HANDLE mem = GlobalAlloc(GMEM_MOVEABLE, length);
+ memcpy(GlobalLock(mem), data.c_str(), length);
+ GlobalUnlock(mem);
+
+ OpenClipboard(handle());
+ EmptyClipboard();
+#ifdef _WIN32
+ SetClipboardData(CF_UNICODETEXT, mem);
+#else
+ SetClipboardData(CF_TEXT, mem);
+#endif
+ CloseClipboard();
+}
+
HWND Dialog::getControl(const int idc)
{
return GetDlgItem(m_handle, idc);
diff --git a/src/dialog.hpp b/src/dialog.hpp
@@ -88,6 +88,7 @@ public:
void setFocus();
int startTimer(int elapse, int id = 0);
void stopTimer(int id);
+ void setClipboard(const std::string &);
void setCloseHandler(const CloseHandler &cb) { m_closeHandler = cb; }
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -272,24 +272,8 @@ void Manager::copyUrl(const int index)
{
const Remote &remote = getRemote(index);
- if(remote.isNull())
- return;
-
- const auto_string &data = make_autostring(remote.url());
- const size_t length = (data.size() * sizeof(auto_char)) + 1; // null terminator
-
- HANDLE mem = GlobalAlloc(GMEM_MOVEABLE, length);
- memcpy(GlobalLock(mem), data.c_str(), length);
- GlobalUnlock(mem);
-
- OpenClipboard(handle());
- EmptyClipboard();
-#ifdef _WIN32
- SetClipboardData(CF_UNICODETEXT, mem);
-#else
- SetClipboardData(CF_TEXT, mem);
-#endif
- CloseClipboard();
+ if(remote)
+ setClipboard(remote.url());
}
void Manager::options()