reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit 4499739dfaf35de9d75d88f61a3284e0c9cf7489
parent e467536cf372b034676b451d016d1502cbc93c09
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sun,  5 Jun 2016 15:40:36 -0400

browser: implement Ctrl+C shortcut for copying name of selected package

Diffstat:
Msrc/browser.cpp | 14++++++++++++++
Msrc/browser.hpp | 1+
Msrc/dialog.cpp | 40++++++++++++++++++++++++++++++++++++++--
Msrc/dialog.hpp | 8++++++++
4 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/src/browser.cpp b/src/browser.cpp @@ -189,6 +189,20 @@ void Browser::onCommand(const int id, const int event) } } +bool Browser::onKeyDown(const int key, const int mods) +{ + if(GetFocus() == m_list->handle() && mods & MOD_CONTROL && key == 'C') { + const Entry *entry = getEntry(m_list->currentIndex()); + + if(entry) + setClipboard(getValue(NameColumn, *entry)); + + return true; + } + + return false; +} + void Browser::onTimer(const int id) { if(id == m_filterTimer) diff --git a/src/browser.hpp b/src/browser.hpp @@ -50,6 +50,7 @@ protected: void onCommand(int, int) override; void onContextMenu(HWND, int x, int y) override; void onTimer(int) override; + bool onKeyDown(int, int) override; private: enum Flag { diff --git a/src/dialog.cpp b/src/dialog.cpp @@ -22,6 +22,7 @@ #include <algorithm> #include <boost/range/adaptor/map.hpp> +#include <reaper_plugin_functions.h> using namespace std; @@ -85,15 +86,39 @@ WDL_DLGRET Dialog::Proc(HWND handle, UINT msg, WPARAM wParam, LPARAM lParam) return false; } +int Dialog::HandleKey(MSG *msg, accelerator_register_t *accel) +{ + Dialog *dialog = reinterpret_cast<Dialog *>(accel->user); + if(!dialog || !dialog->hasFocus()) + return 0; // not our window + + int modifiers = 0; + + if(GetAsyncKeyState(VK_CONTROL) & 0x8000) + modifiers |= MOD_CONTROL; + + if(msg->message == WM_KEYDOWN && dialog->onKeyDown(msg->wParam, modifiers)) + return 1; + else + return -1; +} + Dialog::Dialog(const int templateId) : m_template(templateId), m_isVisible(false), m_isEnabled(true), m_instance(nullptr), m_parent(nullptr), m_handle(nullptr) { - // can't call reimplemented virtual methods here during object construction + m_accel.translateAccel = HandleKey; + m_accel.isLocal = true; + m_accel.user = this; + plugin_register("accelerator", &m_accel); + + // don't call reimplemented virtual methods here during object construction } Dialog::~Dialog() { + plugin_register("-accelerator", &m_accel); + s_instances.erase(m_handle); for(Control *control : m_controls | boost::adaptors::map_values) @@ -189,6 +214,12 @@ void Dialog::center() SetWindowPos(m_handle, HWND_TOP, max(0, left), max(0, top), 0, 0, SWP_NOSIZE); } +bool Dialog::hasFocus() const +{ + const HWND focused = GetFocus(); + return focused == m_handle || IsChild(m_handle, focused); +} + void Dialog::setFocus() { show(); // hack to unminimize the window on OS X @@ -230,7 +261,7 @@ void Dialog::setClipboard(const string &text) memcpy(GlobalLock(mem), data.c_str(), length); GlobalUnlock(mem); - OpenClipboard(handle()); + OpenClipboard(m_handle); EmptyClipboard(); #ifdef _WIN32 SetClipboardData(CF_UNICODETEXT, mem); @@ -282,3 +313,8 @@ void Dialog::onNotify(LPNMHDR info, LPARAM lParam) void Dialog::onContextMenu(HWND, int, int) { } + +bool Dialog::onKeyDown(int, int) +{ + return false; +} diff --git a/src/dialog.hpp b/src/dialog.hpp @@ -85,6 +85,7 @@ public: void setVisible(bool, HWND); void close(INT_PTR = 0); void center(); + bool hasFocus() const; void setFocus(); int startTimer(int elapse, int id = 0); void stopTimer(int id); @@ -93,6 +94,10 @@ public: void setCloseHandler(const CloseHandler &cb) { m_closeHandler = cb; } protected: + enum Modifiers { + MOD_CONTROL = 1<<1, + }; + Dialog(int templateId); virtual ~Dialog(); @@ -119,9 +124,11 @@ protected: virtual void onCommand(int id, int event); virtual void onNotify(LPNMHDR, LPARAM); virtual void onContextMenu(HWND, int x, int y); + virtual bool onKeyDown(int key, int mods); private: static WDL_DLGRET Proc(HWND, UINT, WPARAM, LPARAM); + static int HandleKey(MSG *, accelerator_register_t *); static DialogMap s_instances; const int m_template; @@ -137,6 +144,7 @@ private: std::set<int> m_timers; CloseHandler m_closeHandler; + accelerator_register_t m_accel; }; class LockDialog {