Skip to content

Commit

Permalink
Add shortcut mapper clear command
Browse files Browse the repository at this point in the history
In the shortcut mapper, shortcuts can be cleared easily

Close #2800
  • Loading branch information
cmeriaux authored and donho committed Feb 19, 2017
1 parent 6388d48 commit 7ab6458
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 2 deletions.
126 changes: 126 additions & 0 deletions PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp
Expand Up @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand All @@ -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: {
Expand Down Expand Up @@ -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; }
}
Expand Down Expand Up @@ -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<CommandShortcut> & 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<MacroShortcut> & 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<UserCommand> & 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<PluginCmdShortcut> & 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<LPARAM>(&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)
Expand Down Expand Up @@ -639,17 +758,24 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM
vector<MenuItemUnit> 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);
}

if (_babygrid.getNumberRows() < 1)
{
_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: {
Expand Down
5 changes: 3 additions & 2 deletions PowerEditor/src/WinControls/Grid/ShortcutMapper.rc
Expand Up @@ -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
1 change: 1 addition & 0 deletions PowerEditor/src/WinControls/Grid/ShortcutMapper_rc.h
Expand Up @@ -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
8 changes: 8 additions & 0 deletions PowerEditor/src/WinControls/shortcut/shortcut.h
Expand Up @@ -174,6 +174,14 @@ class Shortcut : public StaticDialog {

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);
Expand Down

0 comments on commit 7ab6458

Please sign in to comment.