void ScintillaAccelerator::updateKeys() { NppParameters *pNppParam = NppParameters::getInstance(); vector<ScintillaKeyMap> & map = pNppParam->getScintillaKeyList(); size_t mapSize = map.size(); size_t index; for(int i = 0; i < _nrScintillas; ++i) { ::SendMessage(_vScintillas[i], SCI_CLEARALLCMDKEYS, 0, 0); for(int32_t j = static_cast<int32_t>(mapSize) - 1; j >= 0; j--) //reverse order, top of the list has highest priority { ScintillaKeyMap skm = map[j]; if (skm.isEnabled()) { //no validating, scintilla accepts more keys size_t size = skm.getSize(); for(index = 0; index < size; ++index) ::SendMessage(_vScintillas[i], SCI_ASSIGNCMDKEY, skm.toKeyDef(index), skm.getScintillaKeyID()); } if (skm.getMenuCmdID() != 0) { updateMenuItemByID(skm, skm.getMenuCmdID()); } if (j == 0) //j is unsigned, so default method doesnt work break; } } }
void ScintillaAccelerator::updateMenuItemByID(ScintillaKeyMap skm, int id) { const int commandSize = 64; TCHAR cmdName[commandSize]; ::GetMenuString(_hAccelMenu, id, cmdName, commandSize, MF_BYCOMMAND); int i = 0; while(cmdName[i] != 0) { if (cmdName[i] == '\t') { cmdName[i] = 0; break; } ++i; } generic_string menuItem = cmdName; if (skm.isEnabled()) { menuItem += TEXT("\t"); //menuItem += TEXT("Sc:"); //sc: scintilla shortcut menuItem += skm.toString(); } ::ModifyMenu(_hAccelMenu, id, MF_BYCOMMAND, id, menuItem.c_str()); ::DrawMenuBar(_hMenuParent); }
int ShortcutMapper::disable_selected(int disable) { int i,count,sel=0; NppParameters *nppParam = NppParameters::getInstance(); count=ListView_GetItemCount(hlistview); for(i=0;i<count;i++){ if(ListView_GetItemState(hlistview,i,LVIS_SELECTED)==LVIS_SELECTED){ int index=getitemindex(i); switch(_currentState) { case STATE_MENU: { vector<CommandShortcut> & shortcuts = nppParam->getUserShortcuts(); CommandShortcut csc = shortcuts[index]; if(disable){ sel+=csc.Disable(); shortcuts[index]=csc; } else sel+=csc.isEnabled(); } break; case STATE_MACRO: { vector<MacroShortcut> & shortcuts = nppParam->getMacroList(); MacroShortcut msc = shortcuts[index]; if(disable){ sel+=msc.Disable(); shortcuts[index]=msc; } else sel+=msc.isEnabled(); } break; case STATE_USER: { vector<UserCommand> & shortcuts = nppParam->getUserCommandList(); UserCommand ucmd = shortcuts[index]; if(disable){ sel+=ucmd.Disable(); shortcuts[index]=ucmd; } else sel+=ucmd.isEnabled(); } break; case STATE_PLUGIN: { vector<PluginCmdShortcut> & shortcuts = nppParam->getPluginCommandList(); if(shortcuts.empty()) break; PluginCmdShortcut pcsc = shortcuts[index]; if(disable){ sel+=pcsc.Disable(); shortcuts[index]=pcsc; } else sel+=pcsc.isEnabled(); } break; case STATE_SCINTILLA: { vector<ScintillaKeyMap> & shortcuts = nppParam->getScintillaKeyList(); ScintillaKeyMap skm = shortcuts[index]; if(disable){ int j; for(j=skm.getSize()-1;j>=0;j--) skm.removeKeyComboByIndex(j); skm.Disable(); sel++; shortcuts[index]=skm; } else sel+=skm.isEnabled(); } break; } } } return sel; }