Skip to content

Commit

Permalink
check if a hotkey is already assigned
Browse files Browse the repository at this point in the history
  • Loading branch information
cbucher committed Dec 17, 2013
1 parent a738056 commit 375d6e3
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions Console/DlgSettingsHotkeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,43 @@ LRESULT DlgSettingsHotkeys::OnBtnAssign(WORD /*wNotifyCode*/, WORD /*wID*/, HWND

HotKeys::CommandData* pCommandData = reinterpret_cast<HotKeys::CommandData*>(selectedItem.lParam);

BYTE fVirt = FVIRTKEY;
bool bExtended = false;
bool bWin = false;

if (wModifiers & HOTKEYF_CONTROL) fVirt |= FCONTROL;
if (wModifiers & HOTKEYF_SHIFT) fVirt |= FSHIFT;
if (wModifiers & HOTKEYF_ALT) fVirt |= FALT;
if (wModifiers & HOTKEYF_EXT) bExtended = true;
if (wModifiers & FAKE_HOTKEYF_WIN) bWin = true;

if( uiVirtualKeyCode )
{
for(auto it = m_hotKeys.commands.begin(); it != m_hotKeys.commands.end(); ++it)
{
if( (*it)->wCommandID != pCommandData->wCommandID )
{
if( (*it)->accelHotkey.key != static_cast<WORD>(uiVirtualKeyCode) ) continue;
if( (*it)->accelHotkey.fVirt != fVirt ) continue;
if( (*it)->bExtended != bExtended ) continue;
if( (*it)->bWin != bWin ) continue;

std::wstring error =
std::wstring(L"Hotkey is already assigned to '") +
(*it)->strDescription +
std::wstring(L"' command!");

::MessageBox(m_hWnd, error.c_str(), L"error", MB_OK);
return 0;
}
}
}

pCommandData->accelHotkey.cmd = pCommandData->wCommandID;
pCommandData->accelHotkey.key = static_cast<WORD>(uiVirtualKeyCode);
pCommandData->accelHotkey.fVirt = FVIRTKEY;
pCommandData->bExtended = false;
pCommandData->bWin = false;

if (wModifiers & HOTKEYF_CONTROL) pCommandData->accelHotkey.fVirt |= FCONTROL;
if (wModifiers & HOTKEYF_SHIFT) pCommandData->accelHotkey.fVirt |= FSHIFT;
if (wModifiers & HOTKEYF_ALT) pCommandData->accelHotkey.fVirt |= FALT;
if (wModifiers & HOTKEYF_EXT) pCommandData->bExtended = true;
if (wModifiers & FAKE_HOTKEYF_WIN) pCommandData->bWin = true;
pCommandData->accelHotkey.fVirt = fVirt;
pCommandData->bExtended = bExtended;
pCommandData->bWin = bWin;

m_listCtrl.SetItemText(m_listCtrl.GetSelectedIndex(), 1, m_hotKeyEdit.GetHotKeyName());

Expand Down

0 comments on commit 375d6e3

Please sign in to comment.