diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp index 24046c4d..9583dfa3 100644 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp @@ -174,6 +174,7 @@ void ShortcutMapper::fillOutBabyGrid() isMarker = _babygrid.setMarker(false); } ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_MODIFY), true); + ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_CLEAR), true); ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_DELETE), false); break; } case STATE_MACRO: { @@ -192,6 +193,7 @@ void ShortcutMapper::fillOutBabyGrid() } bool shouldBeEnabled = nrItems > 0; ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_MODIFY), shouldBeEnabled); + ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_CLEAR), shouldBeEnabled); ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_DELETE), shouldBeEnabled); break; } case STATE_USER: { @@ -210,6 +212,7 @@ void ShortcutMapper::fillOutBabyGrid() } bool shouldBeEnabled = nrItems > 0; ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_MODIFY), shouldBeEnabled); + ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_CLEAR), shouldBeEnabled); ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_DELETE), shouldBeEnabled); break; } case STATE_PLUGIN: { @@ -228,6 +231,7 @@ void ShortcutMapper::fillOutBabyGrid() } bool shouldBeEnabled = nrItems > 0; ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_MODIFY), shouldBeEnabled); + ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_CLEAR), shouldBeEnabled); ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_DELETE), false); break; } case STATE_SCINTILLA: { @@ -255,6 +259,7 @@ void ShortcutMapper::fillOutBabyGrid() isMarker = _babygrid.setMarker(false); } ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_MODIFY), true); + ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_CLEAR), false); ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_DELETE), false); break; } } @@ -352,6 +357,120 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM return TRUE; } + case IDM_BABYGRID_CLEAR : + { + if (_babygrid.getNumberRows() < 1) + return TRUE; + + NppParameters *nppParam = NppParameters::getInstance(); + int row = _babygrid.getSelectedRow(); + bool isModified = false; + + switch(_currentState) + { + case STATE_MENU: + { + //Get CommandShortcut corresponding to row + vector & shortcuts = nppParam->getUserShortcuts(); + CommandShortcut csc = shortcuts[row - 1]; + csc.clear(); + shortcuts[row - 1] = csc; + //shortcut was altered + nppParam->addUserModifiedIndex(row-1); + + //save the current view + _lastHomeRow[_currentState] = _babygrid.getHomeRow(); + _lastCursorRow[_currentState] = _babygrid.getSelectedRow(); + fillOutBabyGrid(); + + isModified = true; + + //Notify current Accelerator class to update everything + nppParam->getAccelerator()->updateShortcuts(); + nppParam->setShortcutDirty(); + break; + } + case STATE_MACRO: + { + //Get MacroShortcut corresponding to row + vector & shortcuts = nppParam->getMacroList(); + MacroShortcut msc = shortcuts[row - 1]; + msc.clear(); + shortcuts[row - 1] = msc; + //save the current view + _lastHomeRow[_currentState] = _babygrid.getHomeRow(); + _lastCursorRow[_currentState] = _babygrid.getSelectedRow(); + fillOutBabyGrid(); + + isModified = true; + + //Notify current Accelerator class to update everything + nppParam->getAccelerator()->updateShortcuts(); + nppParam->setShortcutDirty(); + break; + } + case STATE_USER: + { + //Get UserCommand corresponding to row + vector & shortcuts = nppParam->getUserCommandList(); + UserCommand ucmd = shortcuts[row - 1]; + ucmd.clear(); + + //shortcut was altered + shortcuts[row - 1] = ucmd; + + //save the current view + _lastHomeRow[_currentState] = _babygrid.getHomeRow(); + _lastCursorRow[_currentState] = _babygrid.getSelectedRow(); + fillOutBabyGrid(); + + isModified = true; + + //Notify current Accelerator class to update everything + nppParam->getAccelerator()->updateShortcuts(); + nppParam->setShortcutDirty(); + break; + } + case STATE_PLUGIN: + { + //Get PluginCmdShortcut corresponding to row + vector & shortcuts = nppParam->getPluginCommandList(); + PluginCmdShortcut pcsc = shortcuts[row - 1]; + pcsc.clear(); + //shortcut was altered + nppParam->addPluginModifiedIndex(row-1); + shortcuts[row - 1] = pcsc; + + //save the current view + _lastHomeRow[_currentState] = _babygrid.getHomeRow(); + _lastCursorRow[_currentState] = _babygrid.getSelectedRow(); + fillOutBabyGrid(); + + isModified = true; + + //Notify current Accelerator class to update everything + nppParam->getAccelerator()->updateShortcuts(); + unsigned long cmdID = pcsc.getID(); + ShortcutKey shortcut; + shortcut._isAlt = FALSE; + shortcut._isCtrl = FALSE; + shortcut._isShift = FALSE; + shortcut._key = '\0'; + + ::SendMessage(_hParent, NPPM_INTERNAL_PLUGINSHORTCUTMOTIFIED, cmdID, reinterpret_cast(&shortcut)); + nppParam->setShortcutDirty(); + break; + } + case STATE_SCINTILLA: + { + // Do nothing + break; + } + } + if (not isModified) + ::SendMessage(_hSelf, WM_COMMAND, MAKEWPARAM(IDD_BABYGRID_ID1, BGN_ROWCHANGED), row); + return TRUE; + } case IDM_BABYGRID_MODIFY : { if (_babygrid.getNumberRows() < 1) @@ -639,6 +758,7 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM vector itemUnitArray; itemUnitArray.push_back(MenuItemUnit(IDM_BABYGRID_MODIFY, TEXT("Modify"))); itemUnitArray.push_back(MenuItemUnit(IDM_BABYGRID_DELETE, TEXT("Delete"))); + itemUnitArray.push_back(MenuItemUnit(IDM_BABYGRID_CLEAR, TEXT("Clear"))); _rightClickMenu.create(_hSelf, itemUnitArray); } @@ -646,10 +766,16 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM { _rightClickMenu.enableItem(IDM_BABYGRID_MODIFY, false); _rightClickMenu.enableItem(IDM_BABYGRID_DELETE, false); + _rightClickMenu.enableItem(IDM_BABYGRID_CLEAR, false); } else { _rightClickMenu.enableItem(IDM_BABYGRID_MODIFY, true); + _rightClickMenu.enableItem(IDM_BABYGRID_DELETE, true); + if (_currentState == STATE_SCINTILLA) + _rightClickMenu.enableItem(IDM_BABYGRID_CLEAR, false); + else + _rightClickMenu.enableItem(IDM_BABYGRID_CLEAR, true); switch(_currentState) { case STATE_MACRO: case STATE_USER: { diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.rc b/PowerEditor/src/WinControls/Grid/ShortcutMapper.rc index 0e7e540e..67a6602e 100644 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper.rc +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.rc @@ -42,7 +42,8 @@ FONT 8, TEXT("MS Shell Dlg"), 400, 0, 0x1 BEGIN CONTROL "",IDC_BABYGRID_TABBAR,"SysTabControl32",WS_TABSTOP,4,6,384,12 DEFPUSHBUTTON "Modify",IDM_BABYGRID_MODIFY,118,319,47,14 - DEFPUSHBUTTON "Delete",IDM_BABYGRID_DELETE,172,319,47,14 - DEFPUSHBUTTON "Close",IDOK,226,319,47,14 + DEFPUSHBUTTON "Clear", IDM_BABYGRID_CLEAR,172,319,47,14 + DEFPUSHBUTTON "Delete", IDM_BABYGRID_DELETE, 226, 319, 47, 14 + DEFPUSHBUTTON "Close",IDOK,280,319,47,14 EDITTEXT IDC_BABYGRID_INFO,4,279,383,29,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | NOT WS_TABSTOP END diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper_rc.h b/PowerEditor/src/WinControls/Grid/ShortcutMapper_rc.h index 8b8c8862..70e418b9 100644 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper_rc.h +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper_rc.h @@ -35,5 +35,6 @@ #define IDM_BABYGRID_DELETE (IDD_SHORTCUTMAPPER_DLG + 3) #define IDC_BABYGRID_TABBAR (IDD_SHORTCUTMAPPER_DLG + 4) #define IDC_BABYGRID_INFO (IDD_SHORTCUTMAPPER_DLG + 5) +#define IDM_BABYGRID_CLEAR (IDD_SHORTCUTMAPPER_DLG + 6) #endif// SHORTCUTMAPPER_RC_H diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.h b/PowerEditor/src/WinControls/shortcut/shortcut.h index c4c77f30..512ab0a7 100644 --- a/PowerEditor/src/WinControls/shortcut/shortcut.h +++ b/PowerEditor/src/WinControls/shortcut/shortcut.h @@ -174,6 +174,14 @@ public: void setName(const TCHAR * name); + void clear(){ + _keyCombo._isCtrl = false; + _keyCombo._isAlt = false; + _keyCombo._isShift = false; + _keyCombo._key = 0; + return; + } + protected : KeyCombo _keyCombo; virtual INT_PTR CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam);