?? shortcut.cpp
字號:
{
if (LOWORD(wParam) == IDC_NAME_EDIT)
{
::EnableWindow(::GetDlgItem(_hSelf, IDOK), isValid() && (textlen > 0 || !_canModifyName));
return TRUE;
}
}
else if (HIWORD(wParam) == CBN_SELCHANGE)
{
if (LOWORD(wParam) == IDC_KEY_COMBO)
{
int i = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETCURSEL, 0, 0);
_keyCombo._key = namedKeyArray[i].id;
::EnableWindow(::GetDlgItem(_hSelf, IDOK), isValid() && (textlen > 0 || !_canModifyName));
::ShowWindow(::GetDlgItem(_hSelf, IDC_WARNING_STATIC), isEnabled()?SW_HIDE:SW_SHOW);
return TRUE;
}
}
return FALSE;
}
}
default :
return FALSE;
}
return FALSE;
}
// return true if one of CommandShortcuts is deleted. Otherwise false.
void Accelerator::updateShortcuts()
{
NppParameters *pNppParam = NppParameters::getInstance();
vector<CommandShortcut> & shortcuts = pNppParam->getUserShortcuts();
vector<MacroShortcut> & macros = pNppParam->getMacroList();
vector<UserCommand> & userCommands = pNppParam->getUserCommandList();
vector<PluginCmdShortcut> & pluginCommands = pNppParam->getPluginCommandList();
size_t nbMenu = shortcuts.size();
size_t nbMacro = macros.size();
size_t nbUserCmd = userCommands.size();
size_t nbPluginCmd = pluginCommands.size();
if (_pAccelArray)
delete [] _pAccelArray;
_pAccelArray = new ACCEL[nbMenu+nbMacro+nbUserCmd+nbPluginCmd];
int offset = 0;
size_t i = 0;
//no validation performed, it might be that invalid shortcuts are being used by default. Allows user to 'hack', might be a good thing
for(i = 0; i < nbMenu; i++) {
if (shortcuts[i].isEnabled()) {// && shortcuts[i].isValid()) {
_pAccelArray[offset].cmd = (WORD)(shortcuts[i].getID());
_pAccelArray[offset].fVirt = shortcuts[i].getAcceleratorModifiers();
_pAccelArray[offset].key = shortcuts[i].getKeyCombo()._key;
offset++;
}
}
for(i = 0; i < nbMacro; i++) {
if (macros[i].isEnabled()) {// && macros[i].isValid()) {
_pAccelArray[offset].cmd = (WORD)(macros[i].getID());
_pAccelArray[offset].fVirt = macros[i].getAcceleratorModifiers();
_pAccelArray[offset].key = macros[i].getKeyCombo()._key;
offset++;
}
}
for(i = 0; i < nbUserCmd; i++) {
if (userCommands[i].isEnabled()) {// && userCommands[i].isValid()) {
_pAccelArray[offset].cmd = (WORD)(userCommands[i].getID());
_pAccelArray[offset].fVirt = userCommands[i].getAcceleratorModifiers();
_pAccelArray[offset].key = userCommands[i].getKeyCombo()._key;
offset++;
}
}
for(i = 0; i < nbPluginCmd; i++) {
if (pluginCommands[i].isEnabled()) {// && pluginCommands[i].isValid()) {
_pAccelArray[offset].cmd = (WORD)(pluginCommands[i].getID());
_pAccelArray[offset].fVirt = pluginCommands[i].getAcceleratorModifiers();
_pAccelArray[offset].key = pluginCommands[i].getKeyCombo()._key;
offset++;
}
}
_nbAccelItems = offset;
updateFullMenu();
reNew(); //update the table
return;
}
void Accelerator::updateFullMenu() {
NppParameters * pNppParam = NppParameters::getInstance();
vector<CommandShortcut> commands = pNppParam->getUserShortcuts();
for(size_t i = 0; i < commands.size(); i++) {
updateMenuItemByCommand(commands[i]);
}
vector<MacroShortcut> mcommands = pNppParam->getMacroList();
for(size_t i = 0; i < mcommands.size(); i++) {
updateMenuItemByCommand(mcommands[i]);
}
vector<UserCommand> ucommands = pNppParam->getUserCommandList();
for(size_t i = 0; i < ucommands.size(); i++) {
updateMenuItemByCommand(ucommands[i]);
}
vector<PluginCmdShortcut> pcommands = pNppParam->getPluginCommandList();
for(size_t i = 0; i < pcommands.size(); i++) {
updateMenuItemByCommand(pcommands[i]);
}
::DrawMenuBar(_hMenuParent);
}
void Accelerator::updateMenuItemByCommand(CommandShortcut csc) {
int cmdID = (int)csc.getID();
::ModifyMenu(_hAccelMenu, cmdID, MF_BYCOMMAND, cmdID, csc.toMenuItemString().c_str());
}
recordedMacroStep::recordedMacroStep(int iMessage, long wParam, long lParam)
: message(iMessage), wParameter(wParam), lParameter(lParam), MacroType(mtUseLParameter)
{
if (lParameter) {
switch (message) {
case SCI_SETTEXT :
case SCI_REPLACESEL :
case SCI_REPLACETARGET :
case SCI_REPLACETARGETRE :
case SCI_SEARCHINTARGET :
case SCI_ADDTEXT :
case SCI_ADDSTYLEDTEXT :
case SCI_INSERTTEXT :
case SCI_APPENDTEXT :
case SCI_SETWORDCHARS :
case SCI_SETWHITESPACECHARS :
case SCI_SETSTYLINGEX :
case SCI_TEXTWIDTH :
case SCI_STYLESETFONT :
case SCI_SEARCHNEXT :
case SCI_SEARCHPREV :
sParameter = *reinterpret_cast<char *>(lParameter);
MacroType = mtUseSParameter;
lParameter = 0;
break;
default : // for all other messages, use lParameter "as is"
break;
}
}
}
void recordedMacroStep::PlayBack(Window* pNotepad, ScintillaEditView *pEditView)
{
if (MacroType == mtMenuCommand)
::SendMessage(pNotepad->getHSelf(), WM_COMMAND, wParameter, 0);
else
{
long lParam = lParameter;
if (MacroType == mtUseSParameter)
lParam = reinterpret_cast<long>(sParameter.c_str());
pEditView->execute(message, wParameter, lParam);
if ( (message == SCI_SETTEXT)
|| (message == SCI_REPLACESEL)
|| (message == SCI_ADDTEXT)
|| (message == SCI_ADDSTYLEDTEXT)
|| (message == SCI_INSERTTEXT)
|| (message == SCI_APPENDTEXT) ) {
SCNotification scnN;
scnN.nmhdr.code = SCN_CHARADDED;
scnN.nmhdr.hwndFrom = pEditView->getHSelf();
scnN.nmhdr.idFrom = 0;
scnN.ch = sParameter.at(0);
::SendMessage(pNotepad->getHSelf(), WM_NOTIFY, 0, reinterpret_cast<LPARAM>(&scnN));
}
}
}
void ScintillaAccelerator::init(vector<HWND> * vScintillas, HMENU hMenu, HWND menuParent) {
_hAccelMenu = hMenu;
_hMenuParent = menuParent;
size_t nr = vScintillas->size();
for(size_t i = 0; i < nr; i++) {
_vScintillas.push_back(vScintillas->at(i));
}
_nrScintillas = (int)nr;
}
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(size_t j = 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::updateKey(ScintillaKeyMap skmOld, ScintillaKeyMap skmNew) {
updateKeys(); //do a full update, double mappings can make this work badly
return;
//for(int i = 0; i < _nrScintillas; i++) {
// ::SendMessage(_vScintillas[i], SCI_CLEARCMDKEY, skmOld.toKeyDef(0), 0);
// ::SendMessage(_vScintillas[i], SCI_ASSIGNCMDKEY, skmNew.toKeyDef(0), skmNew.getScintillaKeyID());
//}
}
void ScintillaAccelerator::updateMenuItemByID(ScintillaKeyMap skm, int id) {
NppParameters *pNppParam = NppParameters::getInstance();
char cmdName[64];
::GetMenuString(_hAccelMenu, id, cmdName, sizeof(cmdName), MF_BYCOMMAND);
int i = 0;
while(cmdName[i] != 0) {
if (cmdName[i] == '\t') {
cmdName[i] = 0;
break;
}
i++;
}
string menuItem = cmdName;
if (skm.isEnabled()) {
menuItem += "\t";
//menuItem += "Sc:"; //sc: scintilla shortcut
menuItem += skm.toString();
}
::ModifyMenu(_hAccelMenu, id, MF_BYCOMMAND, id, menuItem.c_str());
::DrawMenuBar(_hMenuParent);
}
//This procedure uses _keyCombo as a temp. variable to store current settings which can then later be applied (by pressing OK)
void ScintillaKeyMap::applyToCurrentIndex() {
int index = (int)::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_GETCURSEL, 0, 0);
if(index == LB_ERR)
return;
setKeyComboByIndex(index, _keyCombo);
updateListItem(index);
::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_SETCURSEL, index, 0);
}
void ScintillaKeyMap::validateDialog() {
bool valid = isValid(); //current combo valid?
bool isDisabling = _keyCombo._key == 0; //true if this keycombo were to disable the shortcut
bool isDisabled = !isEnabled(); //true if this shortcut already is
::EnableWindow(::GetDlgItem(_hSelf, IDC_BUTTON_ADD), valid && !isDisabling);
::EnableWindow(::GetDlgItem(_hSelf, IDC_BUTTON_APPLY), valid && (!isDisabling || size == 1));
::EnableWindow(::GetDlgItem(_hSelf, IDC_BUTTON_RMVE), (size > 1)?TRUE:FALSE);
::ShowWindow(::GetDlgItem(_hSelf, IDC_WARNING_STATIC), isDisabled?SW_SHOW:SW_HIDE);
}
void ScintillaKeyMap::showCurrentSettings() {
int i = ::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_GETCURSEL, 0, 0);
_keyCombo = _keyCombos[i];
::SendDlgItemMessage(_hSelf, IDC_CTRL_CHECK, BM_SETCHECK, _keyCombo._isCtrl?BST_CHECKED:BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDC_ALT_CHECK, BM_SETCHECK, _keyCombo._isAlt?BST_CHECKED:BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDC_SHIFT_CHECK, BM_SETCHECK, _keyCombo._isShift?BST_CHECKED:BST_UNCHECKED, 0);
for (size_t i = 0 ; i < nrKeys ; i++)
{
if (_keyCombo._key == namedKeyArray[i].id)
{
::SendDlgItemMessage(_hSelf, IDC_KEY_COMBO, CB_SETCURSEL, i, 0);
break;
}
}
}
void ScintillaKeyMap::updateListItem(int index) {
::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_INSERTSTRING, index, (LPARAM)toString(index).c_str());
::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_DELETESTRING, index+1, 0);
}
BOOL CALLBACK ScintillaKeyMap::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam)
{
switch (Message)
{
case WM_INITDIALOG :
{
::SetDlgItemText(_hSelf, IDC_NAME_EDIT, _name);
int textlen = (int)::SendDlgItemMessage(_hSelf, IDC_NAME_EDIT, WM_GETTEXTLENGTH, 0, 0);
_keyCombo = _keyCombos[0];
for (size_t i = 0 ; i < nrKeys ; i++)
{
::SendDlgItemMessage(_hSelf, IDC_KEY_COMBO, CB_ADDSTRING, 0, (LPARAM)namedKeyArray[i].name);
}
for(size_t i = 0; i < size; i++) {
::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_ADDSTRING, 0, (LPARAM)toString(i).c_str());
}
::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_SETCURSEL, 0, 0);
showCurrentSettings();
validateDialog();
goToCenter();
return TRUE;
}
case WM_COMMAND :
{
switch (wParam)
{
case IDC_CTRL_CHECK :
_keyCombo._isCtrl = BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0);
//applyToCurrentIndex();
validateDialog();
return TRUE;
case IDC_ALT_CHECK :
_keyCombo._isAlt = BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0);
//applyToCurrentIndex();
validateDialog();
return TRUE;
case IDC_SHIFT_CHECK :
_keyCombo._isShift = BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0);
//applyToCurrentIndex();
return TRUE;
case IDOK :
//Cleanup
_keyCombo._key = 0;
_keyCombo._isCtrl = _keyCombo._isAlt = _keyCombo._isShift = false;
::EndDialog(_hSelf, 0);
return TRUE;
case IDCANCEL :
::EndDialog(_hSelf, -1);
return TRUE;
case IDC_BUTTON_ADD: {
int oldsize = size;
int res = addKeyCombo(_keyCombo);
if (res > -1) {
if (res == oldsize) {
::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_INSERTSTRING, -1, (LPARAM)toString(res).c_str());
}else { //update current string, can happen if it was disabled
updateListItem(res);
}
::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_SETCURSEL, res, 0);
}
showCurrentSettings();
validateDialog();
return TRUE; }
case IDC_BUTTON_RMVE: {
if (size == 1) //cannot delete last shortcut
return TRUE;
int i = ::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_GETCURSEL, 0, 0);
removeKeyComboByIndex(i);
::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_DELETESTRING, i, 0);
if (i == size)
i = size - 1;
::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_SETCURSEL, i, 0);
showCurrentSettings();
validateDialog();
return TRUE; }
case IDC_BUTTON_APPLY: {
applyToCurrentIndex();
validateDialog();
return TRUE; }
default:
if (HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == LBN_SELCHANGE)
{
switch(LOWORD(wParam)) {
case IDC_KEY_COMBO:
{
int i = ::SendDlgItemMessage(_hSelf, IDC_KEY_COMBO, CB_GETCURSEL, 0, 0);
_keyCombo._key = namedKeyArray[i].id;
//applyToCurrentIndex();
validateDialog();
return TRUE;
}
case IDC_LIST_KEYS:
{
showCurrentSettings();
return TRUE;
}
}
}
return FALSE;
}
}
default :
return FALSE;
}
return FALSE;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -