BOOL CConfigShortcuts::OnApply()
{
	CAccelerator *pAccel = theApp.GetAccelerator();

	std::unordered_map<int, int> m;		// // // check for conflicts
	for (int i = 0; i < CAccelerator::ACCEL_COUNT; ++i) {
		int KeyVal = (m_iKeys[i] & 0xFF) | (m_iMods[i] << 8);
		if (!KeyVal) continue;
		auto it = m.find(KeyVal);
		if (it == m.end())
			m[KeyVal] = i;
		else {
			AfxMessageBox(FormattedW(L"These two commands are assigned to the same shortcut (%s):\n- %s\n- %s",
				(LPCWSTR)AssembleKeyString(m_iMods[i], m_iKeys[i]),
				CAccelerator::DEFAULT_TABLE[it->second].name,
				CAccelerator::DEFAULT_TABLE[i].name), MB_ICONERROR);
			return FALSE;
		}
	}

	// Store keys
	for (int i = 0; i < CAccelerator::ACCEL_COUNT; ++i)
		pAccel->StoreShortcut(i, m_iKeys[i], m_iMods[i]);

	pAccel->Setup();

	theApp.UpdateMenuShortcuts();		// // //

	return CPropertyPage::OnApply();
}
Example #2
0
BOOL CConfigShortcuts::OnApply()
{
	CAccelerator *pAccel = theApp.GetAccelerator();
	CListCtrl *pListView = (CListCtrl*)GetDlgItem(IDC_SHORTCUTS);

	// Store keys
	for (int i = 0; i < CAccelerator::ACCEL_COUNT; ++i)
		pAccel->StoreShortcut(i, m_iKeys[i], m_iMods[i]);

	pAccel->Setup();

	CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
	pMainFrame->UpdateMenus();

	return CPropertyPage::OnApply();
}