From fb17638de706a18a6f1413cf79aa2a2512b00aff Mon Sep 17 00:00:00 2001 From: Don HO Date: Sat, 10 Feb 2018 18:52:59 +0100 Subject: [PATCH] Enhance Shortcut Mapper and make it translatable --- PowerEditor/installer/nativeLang/chinese.xml | 25 ++ PowerEditor/installer/nativeLang/english.xml | 27 +- PowerEditor/src/NppCommands.cpp | 1 - .../src/WinControls/Grid/ShortcutMapper.cpp | 334 +++++++++++------- .../src/WinControls/Grid/ShortcutMapper.h | 14 +- .../src/WinControls/shortcut/shortcut.cpp | 20 +- .../src/WinControls/shortcut/shortcut.rc | 46 +-- PowerEditor/src/localization.cpp | 37 +- PowerEditor/src/localization.h | 2 +- 9 files changed, 316 insertions(+), 190 deletions(-) diff --git a/PowerEditor/installer/nativeLang/chinese.xml b/PowerEditor/installer/nativeLang/chinese.xml index 16389d8cc..b711a1c12 100644 --- a/PowerEditor/installer/nativeLang/chinese.xml +++ b/PowerEditor/installer/nativeLang/chinese.xml @@ -447,6 +447,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PowerEditor/installer/nativeLang/english.xml b/PowerEditor/installer/nativeLang/english.xml index 8e4d139d4..b29e7222d 100644 --- a/PowerEditor/installer/nativeLang/english.xml +++ b/PowerEditor/installer/nativeLang/english.xml @@ -446,9 +446,33 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -987,6 +1011,7 @@ Do you want to continue?"/> + diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 49055ed65..3e93a2268 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -2458,7 +2458,6 @@ void Notepad_plus::command(int id) GridState st = id==IDM_SETTING_SHORTCUT_MAPPER_MACRO?STATE_MACRO:id==IDM_SETTING_SHORTCUT_MAPPER_RUN?STATE_USER:STATE_MENU; ShortcutMapper shortcutMapper; shortcutMapper.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), st); - _nativeLangSpeaker.changeShortcutmapperLang(&shortcutMapper); shortcutMapper.doDialog(_nativeLangSpeaker.isRTL()); shortcutMapper.destroy(); break; diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp index 32ff404a5..daaec0369 100644 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp @@ -29,28 +29,22 @@ #include "ShortcutMapper.h" #include "Notepad_plus.h" -#ifdef UNICODE -#define numToStr std::to_wstring -#else -#define numToStr std::to_string -#endif //UNICODE using namespace std; -void ShortcutMapper::initTabs() { +void ShortcutMapper::initTabs() +{ HWND hTab = _hTabCtrl = ::GetDlgItem(_hSelf, IDC_BABYGRID_TABBAR); TCITEM tie; tie.mask = TCIF_TEXT; - tie.pszText = tabNames[0]; - ::SendMessage(hTab, TCM_INSERTITEM, 0, reinterpret_cast(&tie)); - tie.pszText = tabNames[1]; - ::SendMessage(hTab, TCM_INSERTITEM, 1, reinterpret_cast(&tie)); - tie.pszText = tabNames[2]; - ::SendMessage(hTab, TCM_INSERTITEM, 2, reinterpret_cast(&tie)); - tie.pszText = tabNames[3]; - ::SendMessage(hTab, TCM_INSERTITEM, 3, reinterpret_cast(&tie)); - tie.pszText = tabNames[4]; - ::SendMessage(hTab, TCM_INSERTITEM, 4, reinterpret_cast(&tie)); + + for (size_t i = 0; i < _nbTab; ++i) + { + _tabNames[i] = getTabString(i); + + tie.pszText = const_cast(_tabNames[i].c_str()); + ::SendMessage(hTab, TCM_INSERTITEM, i, reinterpret_cast(&tie)); + } TabCtrl_SetCurSel(_hTabCtrl, int(_currentState)); @@ -78,10 +72,29 @@ void ShortcutMapper::getClientRect(RECT & rc) const rc.right -= NppParameters::getInstance()->_dpiManager.scaleX(5); } -void ShortcutMapper::translateTab(int index, const TCHAR * newname) { - if (index < 0 || index > 4) - return; - generic_strncpy(tabNames[index], newname, maxTabName); +generic_string ShortcutMapper::getTabString(size_t i) const +{ + if (i >= _nbTab) + return TEXT(""); + + NativeLangSpeaker* nativeLangSpeaker = NppParameters::getInstance()->getNativeLangSpeaker(); + switch (i) + { + case 1: + return nativeLangSpeaker->getShortcutMapperLangStr("MacrosTab", TEXT("Macros")); + + case 2: + return nativeLangSpeaker->getShortcutMapperLangStr("RunCommandsTab", TEXT("Run commands")); + + case 3: + return nativeLangSpeaker->getShortcutMapperLangStr("PluginCommandsTab", TEXT("Plugin commands")); + + case 4: + return nativeLangSpeaker->getShortcutMapperLangStr("ScintillaCommandsTab", TEXT("Scintilla commands")); + + default: //0 + return nativeLangSpeaker->getShortcutMapperLangStr("MainMenuTab", TEXT("Main menu")); + } } void ShortcutMapper::initBabyGrid() { @@ -122,6 +135,8 @@ void ShortcutMapper::initBabyGrid() { _babygrid.setProtectColor(RGB(255,130,120)); _babygrid.setHighlightColorProtect(RGB(244,10,20)); _babygrid.setHighlightColorProtectNoFocus(RGB(230,194,190)); + + NppParameters::getInstance()->getNativeLangSpeaker()->changeDlgLang(_hSelf, "ShortcutMapper"); } void ShortcutMapper::fillOutBabyGrid() @@ -131,57 +146,82 @@ void ShortcutMapper::fillOutBabyGrid() _babygrid.setInitialContent(true); size_t nbItems = 0; + NativeLangSpeaker* nativeLangSpeaker = nppParam->getNativeLangSpeaker(); + generic_string nameStr = nativeLangSpeaker->getShortcutMapperLangStr("ColumnName", TEXT("Name")); + generic_string shortcutStr = nativeLangSpeaker->getShortcutMapperLangStr("ColumnShortcut", TEXT("Shortcut")); - _babygrid.setText(0, 1, TEXT("Name")); - _babygrid.setText(0, 2, TEXT("Shortcut")); + _babygrid.setText(0, 1, nameStr.c_str()); + _babygrid.setText(0, 2, shortcutStr.c_str()); - switch(_currentState) { - case STATE_MENU: { + switch(_currentState) + { + case STATE_MENU: + { nbItems = nppParam->getUserShortcuts().size(); _babygrid.setLineColNumber(nbItems, 3); - _babygrid.setText(0, 3, TEXT("Category")); - break; } - case STATE_MACRO: { + generic_string categoryStr = nativeLangSpeaker->getShortcutMapperLangStr("ColumnCategory", TEXT("Category")); + _babygrid.setText(0, 3, categoryStr.c_str()); + } + break; + + case STATE_MACRO: + { nbItems = nppParam->getMacroList().size(); _babygrid.setLineColNumber(nbItems, 2); - break; } - case STATE_USER: { + } + break; + + case STATE_USER: + { nbItems = nppParam->getUserCommandList().size(); _babygrid.setLineColNumber(nbItems, 2); - break; } - case STATE_PLUGIN: { + } + break; + + case STATE_PLUGIN: + { nbItems = nppParam->getPluginCommandList().size(); _babygrid.setLineColNumber(nbItems, 3); - _babygrid.setText(0, 3, TEXT("Plugin")); - break; } - case STATE_SCINTILLA: { + generic_string pluginStr = nativeLangSpeaker->getShortcutMapperLangStr("ColumnPlugin", TEXT("Plugin")); + _babygrid.setText(0, 3, pluginStr.c_str()); + } + break; + + case STATE_SCINTILLA: + { nbItems = nppParam->getScintillaKeyList().size(); _babygrid.setLineColNumber(nbItems, 2); - break; } + } + break; } bool isMarker = false; - switch(_currentState) { - case STATE_MENU: { + switch(_currentState) + { + case STATE_MENU: + { vector & cshortcuts = nppParam->getUserShortcuts(); - for(size_t i = 0; i < nbItems; ++i) + for (size_t i = 0; i < nbItems; ++i) { if (findKeyConflicts(nullptr, cshortcuts[i].getKeyCombo(), i)) isMarker = _babygrid.setMarker(true); - _babygrid.setText(i+1, 1, cshortcuts[i].getName()); + _babygrid.setText(i + 1, 1, cshortcuts[i].getName()); if (cshortcuts[i].isEnabled()) //avoid empty strings for better performance - _babygrid.setText(i+1, 2, cshortcuts[i].toString().c_str()); - _babygrid.setText(i+1, 3, cshortcuts[i].getCategory()); + _babygrid.setText(i + 1, 2, cshortcuts[i].toString().c_str()); + _babygrid.setText(i + 1, 3, cshortcuts[i].getCategory()); if (isMarker) 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: { + ::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: + { vector & cshortcuts = nppParam->getMacroList(); for(size_t i = 0; i < nbItems; ++i) { @@ -199,8 +239,11 @@ void ShortcutMapper::fillOutBabyGrid() ::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: { + } + break; + + case STATE_USER: + { vector & cshortcuts = nppParam->getUserCommandList(); for(size_t i = 0; i < nbItems; ++i) { @@ -218,8 +261,11 @@ void ShortcutMapper::fillOutBabyGrid() ::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: { + } + break; + + case STATE_PLUGIN: + { vector & cshortcuts = nppParam->getPluginCommandList(); for(size_t i = 0; i < nbItems; ++i) { @@ -238,8 +284,11 @@ void ShortcutMapper::fillOutBabyGrid() ::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: { + } + break; + + case STATE_SCINTILLA: + { vector & cshortcuts = nppParam->getScintillaKeyList(); for(size_t i = 0; i < nbItems; ++i) { @@ -266,14 +315,15 @@ void ShortcutMapper::fillOutBabyGrid() ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_MODIFY), true); ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_CLEAR), false); ::EnableWindow(::GetDlgItem(_hSelf, IDM_BABYGRID_DELETE), false); - break; } + } + break; } - if (nbItems > 0) - //restore the last view + + if (nbItems > 0) //restore the last view _babygrid.setLastView(_lastHomeRow[_currentState], _lastCursorRow[_currentState]); - else - //clear the info area + else //clear the info area ::SendDlgItemMessage(_hSelf, IDC_BABYGRID_INFO, WM_SETTEXT, 0, 0); + _babygrid.setInitialContent(false); } @@ -295,32 +345,42 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM { for (const HFONT & hFont : _hGridFonts) ::DeleteObject(hFont); + _hGridFonts.clear(); _hGridFonts.shrink_to_fit(); - break; } + break; - case WM_NOTIFY: { + case WM_NOTIFY: + { NMHDR nmh = *((NMHDR*)lParam); - if (nmh.hwndFrom == _hTabCtrl) { - if (nmh.code == TCN_SELCHANGE) { + if (nmh.hwndFrom == _hTabCtrl) + { + if (nmh.code == TCN_SELCHANGE) + { //save the current view _lastHomeRow[_currentState] = _babygrid.getHomeRow(); _lastCursorRow[_currentState] = _babygrid.getSelectedRow(); int index = TabCtrl_GetCurSel(_hTabCtrl); - switch (index) { + + switch (index) + { case 0: _currentState = STATE_MENU; break; + case 1: _currentState = STATE_MACRO; break; + case 2: _currentState = STATE_USER; break; + case 3: _currentState = STATE_PLUGIN; break; + case 4: _currentState = STATE_SCINTILLA; break; @@ -328,7 +388,8 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM fillOutBabyGrid(); } } - break; } + } + break; case NPPM_INTERNAL_FINDKEYCONFLICTS: { @@ -339,6 +400,7 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM const bool isConflict = findKeyConflicts(&conflictInfo, *reinterpret_cast(wParam), _babygrid.getSelectedRow() - 1); *reinterpret_cast(lParam) = isConflict; + if (isConflict) ::SendDlgItemMessage(_hSelf, IDC_BABYGRID_INFO, WM_SETTEXT, 0, reinterpret_cast(conflictInfo.c_str())); else @@ -381,8 +443,8 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM csc.clear(); shortcuts[row - 1] = csc; //shortcut was altered - nppParam->addUserModifiedIndex(row-1); - + nppParam->addUserModifiedIndex(row - 1); + //save the current view _lastHomeRow[_currentState] = _babygrid.getHomeRow(); _lastCursorRow[_currentState] = _babygrid.getSelectedRow(); @@ -393,8 +455,9 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM //Notify current Accelerator class to update everything nppParam->getAccelerator()->updateShortcuts(); nppParam->setShortcutDirty(); - break; } + break; + case STATE_MACRO: { //Get MacroShortcut corresponding to row @@ -412,15 +475,16 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM //Notify current Accelerator class to update everything nppParam->getAccelerator()->updateShortcuts(); nppParam->setShortcutDirty(); - break; } + 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; @@ -434,8 +498,9 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM //Notify current Accelerator class to update everything nppParam->getAccelerator()->updateShortcuts(); nppParam->setShortcutDirty(); - break; } + break; + case STATE_PLUGIN: { //Get PluginCmdShortcut corresponding to row @@ -443,9 +508,9 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM PluginCmdShortcut pcsc = shortcuts[row - 1]; pcsc.clear(); //shortcut was altered - nppParam->addPluginModifiedIndex(row-1); + nppParam->addPluginModifiedIndex(row - 1); shortcuts[row - 1] = pcsc; - + //save the current view _lastHomeRow[_currentState] = _babygrid.getHomeRow(); _lastCursorRow[_currentState] = _babygrid.getSelectedRow(); @@ -464,18 +529,23 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM ::SendMessage(_hParent, NPPM_INTERNAL_PLUGINSHORTCUTMOTIFIED, cmdID, reinterpret_cast(&shortcut)); nppParam->setShortcutDirty(); - break; } + break; + case STATE_SCINTILLA: { // Do nothing - break; } + 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) @@ -496,7 +566,7 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM if (csc.doDialog() != -1 && prevcsc != csc) { //shortcut was altered - nppParam->addUserModifiedIndex(row-1); + nppParam->addUserModifiedIndex(row - 1); shortcuts[row - 1] = csc; //save the current view @@ -510,8 +580,8 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM nppParam->getAccelerator()->updateShortcuts(); nppParam->setShortcutDirty(); } - break; } + break; case STATE_MACRO: { @@ -535,8 +605,8 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM nppParam->getAccelerator()->updateShortcuts(); nppParam->setShortcutDirty(); } - break; } + break; case STATE_USER: { @@ -546,7 +616,7 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM ucmd.init(_hInst, _hSelf); UserCommand prevucmd = ucmd; if (ucmd.doDialog() != -1 && prevucmd != ucmd) - { + { //shortcut was altered shortcuts[row - 1] = ucmd; @@ -561,8 +631,8 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM nppParam->getAccelerator()->updateShortcuts(); nppParam->setShortcutDirty(); } - break; } + break; case STATE_PLUGIN: { @@ -574,7 +644,7 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM if (pcsc.doDialog() != -1 && prevpcsc != pcsc) { //shortcut was altered - nppParam->addPluginModifiedIndex(row-1); + nppParam->addPluginModifiedIndex(row - 1); shortcuts[row - 1] = pcsc; //save the current view @@ -596,20 +666,20 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM ::SendMessage(_hParent, NPPM_INTERNAL_PLUGINSHORTCUTMOTIFIED, cmdID, reinterpret_cast(&shortcut)); nppParam->setShortcutDirty(); } - break; } + break; case STATE_SCINTILLA: { //Get ScintillaKeyMap corresponding to row vector & shortcuts = nppParam->getScintillaKeyList(); - ScintillaKeyMap skm = shortcuts[row - 1], prevskm = shortcuts[row-1]; + ScintillaKeyMap skm = shortcuts[row - 1], prevskm = shortcuts[row - 1]; skm.init(_hInst, _hSelf); - if (skm.doDialog() != -1 && prevskm != skm) + if (skm.doDialog() != -1 && prevskm != skm) { //shortcut was altered - nppParam->addScintillaModifiedIndex(row-1); - shortcuts[row-1] = skm; + nppParam->addScintillaModifiedIndex(row - 1); + shortcuts[row - 1] = skm; //save the current view _lastHomeRow[_currentState] = _babygrid.getHomeRow(); @@ -623,11 +693,13 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM nppParam->getScintillaAccelerator()->updateKeys(); nppParam->setShortcutDirty(); } - break; } + break; } + if (not isModified) ::SendMessage(_hSelf, WM_COMMAND, MAKEWPARAM(IDD_BABYGRID_ID1, BGN_ROWCHANGED), row); + return TRUE; } @@ -636,9 +708,15 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM if (_babygrid.getNumberRows() < 1) return TRUE; - if (::MessageBox(_hSelf, TEXT("Are you sure you want to delete this shortcut?"), TEXT("Are you sure?"), MB_OKCANCEL) == IDOK) + NppParameters *nppParam = NppParameters::getInstance(); + int res = nppParam->getNativeLangSpeaker()->messageBox("SCMapperDoDeleteOrNot", + _hSelf, + TEXT("Are you sure you want to delete this shortcut?"), + TEXT("Are you sure?"), + MB_OKCANCEL); + + if (res == IDOK) { - NppParameters *nppParam = NppParameters::getInstance(); const int row = _babygrid.getSelectedRow(); int shortcutIndex = row-1; DWORD cmdID = 0; @@ -675,21 +753,21 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM --_lastCursorRow[_currentState]; fillOutBabyGrid(); - + // preparing to remove from menu posBase = 6; nbElem = theMacros.size(); HMENU m = reinterpret_cast(::SendMessage(_hParent, NPPM_INTERNAL_GETMENU, 0, 0)); hMenu = ::GetSubMenu(m, MENUINDEX_MACRO); - modifCmd = IDM_SETTING_SHORTCUT_MAPPER_MACRO; - for (size_t i = shortcutIndex ; i < nbElem ; ++i) //lower the IDs of the remaining items so there are no gaps + modifCmd = IDM_SETTING_SHORTCUT_MAPPER_MACRO; + for (size_t i = shortcutIndex; i < nbElem; ++i) //lower the IDs of the remaining items so there are no gaps { MacroShortcut ms = theMacros[i]; ms.setID(ms.getID() - 1); //shift all IDs theMacros[i] = ms; } - break; } + break; case STATE_USER: { @@ -709,21 +787,21 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM --_lastCursorRow[_currentState]; fillOutBabyGrid(); - + // preparing to remove from menu posBase = 2; nbElem = theUserCmds.size(); HMENU m = reinterpret_cast(::SendMessage(_hParent, NPPM_INTERNAL_GETMENU, 0, 0)); hMenu = ::GetSubMenu(m, MENUINDEX_RUN); - modifCmd = IDM_SETTING_SHORTCUT_MAPPER_RUN; - for (size_t i = shortcutIndex ; i < nbElem ; ++i) //lower the IDs of the remaining items so there are no gaps + modifCmd = IDM_SETTING_SHORTCUT_MAPPER_RUN; + for (size_t i = shortcutIndex; i < nbElem; ++i) //lower the IDs of the remaining items so there are no gaps { UserCommand uc = theUserCmds[i]; uc.setID(uc.getID() - 1); //shift all IDs theUserCmds[i] = uc; } - break; } + break; } // updateShortcuts() will update all menu item - the menu items will be shifted @@ -781,16 +859,23 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM _rightClickMenu.enableItem(IDM_BABYGRID_CLEAR, false); else _rightClickMenu.enableItem(IDM_BABYGRID_CLEAR, true); - switch(_currentState) { + + switch(_currentState) + { case STATE_MACRO: - case STATE_USER: { + case STATE_USER: + { _rightClickMenu.enableItem(IDM_BABYGRID_DELETE, true); - break; } + } + break; + case STATE_MENU: case STATE_PLUGIN: - case STATE_SCINTILLA: { + case STATE_SCINTILLA: + { _rightClickMenu.enableItem(IDM_BABYGRID_DELETE, false); - break; } + } + break; } } @@ -824,34 +909,38 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM { vector & vShortcuts = nppParam->getUserShortcuts(); findKeyConflicts(&conflictInfo, vShortcuts[currentIndex].getKeyCombo(), currentIndex); - break; } + break; + case STATE_MACRO: { vector & vShortcuts = nppParam->getMacroList(); findKeyConflicts(&conflictInfo, vShortcuts[currentIndex].getKeyCombo(), currentIndex); - break; } + break; + case STATE_USER: { vector & vShortcuts = nppParam->getUserCommandList(); findKeyConflicts(&conflictInfo, vShortcuts[currentIndex].getKeyCombo(), currentIndex); - break; } + break; + case STATE_PLUGIN: { vector & vShortcuts = nppParam->getPluginCommandList(); findKeyConflicts(&conflictInfo, vShortcuts[currentIndex].getKeyCombo(), currentIndex); - break; } + break; + case STATE_SCINTILLA: { vector & vShortcuts = nppParam->getScintillaKeyList(); size_t sciCombos = vShortcuts[currentIndex].getSize(); for (size_t sciIndex = 0; sciIndex < sciCombos; ++sciIndex) findKeyConflicts(&conflictInfo, vShortcuts[currentIndex].getKeyComboByIndex(sciIndex), currentIndex); - break; } + break; } if (conflictInfo.empty()) @@ -861,13 +950,16 @@ INT_PTR CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM return TRUE; } - } //switch (HIWORD(wParam)) + } } - } //switch (LOWORD(wParam)) + } } + default: return FALSE; - } //switch (message) + + } + return FALSE; } @@ -905,9 +997,9 @@ bool ShortcutMapper::findKeyConflicts(__inout_opt generic_string * const keyConf { if (not keyConflictLocation->empty()) *keyConflictLocation += TEXT("\r\n"); - *keyConflictLocation += tabNames[gridState]; + *keyConflictLocation += _tabNames[gridState]; *keyConflictLocation += TEXT(" | "); - *keyConflictLocation += numToStr(itemIndex + 1); + *keyConflictLocation += std::to_wstring(itemIndex + 1); *keyConflictLocation += TEXT(" "); *keyConflictLocation += vShortcuts[itemIndex].getName(); *keyConflictLocation += TEXT(" ( "); @@ -939,9 +1031,9 @@ bool ShortcutMapper::findKeyConflicts(__inout_opt generic_string * const keyConf { if (not keyConflictLocation->empty()) *keyConflictLocation += TEXT("\r\n"); - *keyConflictLocation += tabNames[gridState]; + *keyConflictLocation += _tabNames[gridState]; *keyConflictLocation += TEXT(" | "); - *keyConflictLocation += numToStr(itemIndex + 1); + *keyConflictLocation += std::to_wstring(itemIndex + 1); *keyConflictLocation += TEXT(" "); *keyConflictLocation += vShortcuts[itemIndex].getName(); *keyConflictLocation += TEXT(" ( "); @@ -973,9 +1065,9 @@ bool ShortcutMapper::findKeyConflicts(__inout_opt generic_string * const keyConf { if (not keyConflictLocation->empty()) *keyConflictLocation += TEXT("\r\n"); - *keyConflictLocation += tabNames[gridState]; + *keyConflictLocation += _tabNames[gridState]; *keyConflictLocation += TEXT(" | "); - *keyConflictLocation += numToStr(itemIndex + 1); + *keyConflictLocation += std::to_wstring(itemIndex + 1); *keyConflictLocation += TEXT(" "); *keyConflictLocation += vShortcuts[itemIndex].getName(); *keyConflictLocation += TEXT(" ( "); @@ -1007,9 +1099,9 @@ bool ShortcutMapper::findKeyConflicts(__inout_opt generic_string * const keyConf { if (not keyConflictLocation->empty()) *keyConflictLocation += TEXT("\r\n"); - *keyConflictLocation += tabNames[gridState]; + *keyConflictLocation += _tabNames[gridState]; *keyConflictLocation += TEXT(" | "); - *keyConflictLocation += numToStr(itemIndex + 1); + *keyConflictLocation += std::to_wstring(itemIndex + 1); *keyConflictLocation += TEXT(" "); *keyConflictLocation += vShortcuts[itemIndex].getName(); *keyConflictLocation += TEXT(" ( "); @@ -1044,9 +1136,9 @@ bool ShortcutMapper::findKeyConflicts(__inout_opt generic_string * const keyConf { if (not keyConflictLocation->empty()) *keyConflictLocation += TEXT("\r\n"); - *keyConflictLocation += tabNames[gridState]; + *keyConflictLocation += _tabNames[gridState]; *keyConflictLocation += TEXT(" | "); - *keyConflictLocation += numToStr(itemIndex + 1); + *keyConflictLocation += std::to_wstring(itemIndex + 1); if (sciIndex > 0) *keyConflictLocation += TEXT("* "); else @@ -1060,8 +1152,8 @@ bool ShortcutMapper::findKeyConflicts(__inout_opt generic_string * const keyConf } } break; - } //case STATE_SCINTILLA - } //switch (gridState) - } //for (...) + } + } + } return retIsConflict; } diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.h b/PowerEditor/src/WinControls/Grid/ShortcutMapper.h index 3c194acd7..40cbe6988 100644 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper.h +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.h @@ -37,13 +37,7 @@ enum GridState {STATE_MENU, STATE_MACRO, STATE_USER, STATE_PLUGIN, STATE_SCINTIL class ShortcutMapper : public StaticDialog { public: - ShortcutMapper() : _currentState(STATE_MENU), StaticDialog() { - generic_strncpy(tabNames[0], TEXT("Main menu"), maxTabName); - generic_strncpy(tabNames[1], TEXT("Macros"), maxTabName); - generic_strncpy(tabNames[2], TEXT("Run commands"), maxTabName); - generic_strncpy(tabNames[3], TEXT("Plugin commands"), maxTabName); - generic_strncpy(tabNames[4], TEXT("Scintilla commands"), maxTabName); - }; + ShortcutMapper() : _currentState(STATE_MENU), StaticDialog() {}; ~ShortcutMapper() {}; void init(HINSTANCE hInst, HWND parent, GridState initState = STATE_MENU) { @@ -64,7 +58,6 @@ public: ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_SHORTCUTMAPPER_DLG), _hParent, dlgProc, reinterpret_cast(this)); }; void getClientRect(RECT & rc) const; - void translateTab(int index, const TCHAR * newname); bool findKeyConflicts(__inout_opt generic_string * const keyConflictLocation, const KeyCombo & itemKeyCombo, const size_t & itemIndex) const; @@ -73,14 +66,14 @@ protected : INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); private: - static const int maxTabName = 64; BabyGridWrapper _babygrid; ContextMenu _rightClickMenu; GridState _currentState; HWND _hTabCtrl = nullptr; - TCHAR tabNames[5][maxTabName]; + const static int _nbTab = 5; + generic_string _tabNames[_nbTab]; //save/restore the last view std::vector _lastHomeRow; @@ -101,6 +94,7 @@ private: void initTabs(); void initBabyGrid(); void fillOutBabyGrid(); + generic_string getTabString(size_t i) const; bool isConflict(const KeyCombo & lhs, const KeyCombo & rhs) const { diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.cpp b/PowerEditor/src/WinControls/shortcut/shortcut.cpp index f6eef7e80..fa4946e79 100644 --- a/PowerEditor/src/WinControls/shortcut/shortcut.cpp +++ b/PowerEditor/src/WinControls/shortcut/shortcut.cpp @@ -389,8 +389,13 @@ INT_PTR CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM) if (iFound != -1) ::SendDlgItemMessage(_hSelf, IDC_KEY_COMBO, CB_SETCURSEL, iFound, 0); - ::ShowWindow(::GetDlgItem(_hSelf, IDC_WARNING_STATIC), isEnabled()?SW_HIDE:SW_SHOW); + + // Hide this warning on startup + ::ShowWindow(::GetDlgItem(_hSelf, IDC_WARNING_STATIC), SW_HIDE); + updateConflictState(); + NativeLangSpeaker* nativeLangSpeaker = NppParameters::getInstance()->getNativeLangSpeaker(); + nativeLangSpeaker->changeDlgLang(_hSelf, "ShortcutMapperSubDialg"); goToCenter(); return TRUE; } @@ -778,7 +783,8 @@ void ScintillaKeyMap::applyToCurrentIndex() } -void ScintillaKeyMap::validateDialog() { +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 @@ -846,6 +852,11 @@ INT_PTR CALLBACK ScintillaKeyMap::run_dlgProc(UINT Message, WPARAM wParam, LPARA showCurrentSettings(); validateDialog(); + // Hide this warning on startup + ::ShowWindow(::GetDlgItem(_hSelf, IDC_WARNING_STATIC), SW_HIDE); + + NativeLangSpeaker* nativeLangSpeaker = NppParameters::getInstance()->getNativeLangSpeaker(); + nativeLangSpeaker->changeDlgLang(_hSelf, "ShortcutMapperSubDialg"); goToCenter(); return TRUE; } @@ -856,19 +867,16 @@ INT_PTR CALLBACK ScintillaKeyMap::run_dlgProc(UINT Message, WPARAM wParam, LPARA { case IDC_CTRL_CHECK : _keyCombo._isCtrl = BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast(wParam), BM_GETCHECK, 0, 0); - //applyToCurrentIndex(); validateDialog(); return TRUE; case IDC_ALT_CHECK : _keyCombo._isAlt = BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast(wParam), BM_GETCHECK, 0, 0); - //applyToCurrentIndex(); validateDialog(); return TRUE; case IDC_SHIFT_CHECK : _keyCombo._isShift = BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast(wParam), BM_GETCHECK, 0, 0); - //applyToCurrentIndex(); validateDialog(); return TRUE; @@ -935,7 +943,7 @@ INT_PTR CALLBACK ScintillaKeyMap::run_dlgProc(UINT Message, WPARAM wParam, LPARA { auto i = ::SendDlgItemMessage(_hSelf, IDC_KEY_COMBO, CB_GETCURSEL, 0, 0); _keyCombo._key = namedKeyArray[i].id; - //applyToCurrentIndex(); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_WARNING_STATIC), isEnabled() ? SW_HIDE : SW_SHOW); validateDialog(); return TRUE; } diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.rc b/PowerEditor/src/WinControls/shortcut/shortcut.rc index 8549e889a..c5f11b075 100644 --- a/PowerEditor/src/WinControls/shortcut/shortcut.rc +++ b/PowerEditor/src/WinControls/shortcut/shortcut.rc @@ -33,29 +33,24 @@ #define IDC_STATIC -1 #endif -IDD_SHORTCUT_DLG DIALOGEX 0, 0, 180, 102 -STYLE DS_SETFONT | /*DS_MODALFRAME |*/ DS_FIXEDSYS | WS_POPUP | WS_CAPTION | - WS_SYSMENU +IDD_SHORTCUT_DLG DIALOGEX 0, 0, 180, 105 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_TOOLWINDOW CAPTION "Shortcut" FONT 8, TEXT("MS Shell Dlg"), 400, 0, 0x1 BEGIN - CONTROL "CTRL",IDC_CTRL_CHECK,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,12,30,33,10 - CONTROL "ALT",IDC_ALT_CHECK,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,12,51,28,10 - CONTROL "SHIFT",IDC_SHIFT_CHECK,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,57,42,35,10 - COMBOBOX IDC_KEY_COMBO,110,40,64,270,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP + CONTROL "CTRL",IDC_CTRL_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,30,33,10 + CONTROL "ALT",IDC_ALT_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,51,28,10 + CONTROL "SHIFT",IDC_SHIFT_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,57,42,35,10 + COMBOBOX IDC_KEY_COMBO,110,40,64,270,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP PUSHBUTTON "OK",IDOK,32,74,50,14 PUSHBUTTON "Cancel",IDCANCEL,103,73,50,14 LTEXT "+",IDC_STATIC,45,42,8,8 LTEXT "+",IDC_STATIC,96,42,8,8 EDITTEXT IDC_NAME_EDIT,56,9,118,14,ES_AUTOHSCROLL LTEXT "Name :",IDC_NAME_STATIC,15,12,34,8,0,WS_EX_RIGHT - LTEXT "This will disable the accelerator!",IDC_WARNING_STATIC,6,91,170,8 - LTEXT "CONFLICT FOUND!",IDC_CONFLICT_STATIC,6,91,170,8 + LTEXT "This will disable the accelerator",IDC_WARNING_STATIC,6,93,170,8 + LTEXT "CONFLICT FOUND!",IDC_CONFLICT_STATIC,6,93,170,8 END IDD_SHORTCUTSCINT_DLG DIALOGEX 0, 0, 286, 114 @@ -64,25 +59,20 @@ EXSTYLE WS_EX_TOOLWINDOW CAPTION "Shortcut" FONT 8, TEXT("MS Shell Dlg"), 400, 0, 0x1 BEGIN - CONTROL "CTRL",IDC_CTRL_CHECK,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,114,27,33,10 - CONTROL "ALT",IDC_ALT_CHECK,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,114,48,28,10 - CONTROL "SHIFT",IDC_SHIFT_CHECK,"Button",BS_AUTOCHECKBOX | - WS_TABSTOP,159,39,35,10 - COMBOBOX IDC_KEY_COMBO,212,37,64,270,CBS_DROPDOWNLIST | - WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "OK",IDOK,144,78,48,14 - PUSHBUTTON "Cancel",IDCANCEL,210,78,48,14 + CONTROL "CTRL",IDC_CTRL_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,114,27,33,10 + CONTROL "ALT",IDC_ALT_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,114,48,28,10 + CONTROL "SHIFT",IDC_SHIFT_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,159,39,35,10 + COMBOBOX IDC_KEY_COMBO,212,37,64,270,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "Apply", IDC_BUTTON_APPLY, 210, 66, 48, 14 + PUSHBUTTON "OK",IDOK,144,84,48,14 + PUSHBUTTON "Cancel",IDCANCEL,210,84,48,14 LTEXT "+",IDC_STATIC,147,39,8,8 LTEXT "+",IDC_STATIC,198,39,8,8 EDITTEXT IDC_NAME_EDIT,158,6,118,14,ES_AUTOHSCROLL | ES_READONLY LTEXT "Name :",IDC_NAME_STATIC,117,9,34,8,0,WS_EX_RIGHT - LTEXT "This will remove the accelerator!",IDC_WARNING_STATIC,114,99,162,8 - LTEXT "CONFLICT FOUND!",IDC_CONFLICT_STATIC,114,99,162,8 - LISTBOX IDC_LIST_KEYS,6,6,90,72,LBS_NOINTEGRALHEIGHT | - WS_VSCROLL | WS_TABSTOP + LTEXT "This will remove the accelerator",IDC_WARNING_STATIC,6,101,162,8 + LTEXT "CONFLICT FOUND!",IDC_CONFLICT_STATIC,6,101,162,8 + LISTBOX IDC_LIST_KEYS,6,6,90,72,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP PUSHBUTTON "Add",IDC_BUTTON_ADD,6,84,42,14 PUSHBUTTON "Remove",IDC_BUTTON_RMVE,56,84,40,14 - PUSHBUTTON "Apply",IDC_BUTTON_APPLY,210,60,48,14 END diff --git a/PowerEditor/src/localization.cpp b/PowerEditor/src/localization.cpp index 512b4bb05..620cf8e8b 100644 --- a/PowerEditor/src/localization.cpp +++ b/PowerEditor/src/localization.cpp @@ -944,34 +944,27 @@ void NativeLangSpeaker::changeShortcutLang() } -void NativeLangSpeaker::changeShortcutmapperLang(ShortcutMapper * sm) +generic_string NativeLangSpeaker::getShortcutMapperLangStr(const char *nodeName, const TCHAR *defaultStr) const { - if (!_nativeLangA) return; + if (!_nativeLangA) return defaultStr; - TiXmlNodeA *shortcuts = _nativeLangA->FirstChild("Dialog"); - if (!shortcuts) return; + TiXmlNodeA *targetNode = _nativeLangA->FirstChild("Dialog"); + if (!targetNode) return defaultStr; - shortcuts = shortcuts->FirstChild("ShortcutMapper"); - if (!shortcuts) return; + targetNode = targetNode->FirstChild("ShortcutMapper"); + if (!targetNode) return defaultStr; - for (TiXmlNodeA *childNode = shortcuts->FirstChildElement("Item"); - childNode ; - childNode = childNode->NextSibling("Item") ) + targetNode = targetNode->FirstChild(nodeName); + if (!targetNode) return defaultStr; + + const char *name = (targetNode->ToElement())->Attribute("name"); + if (name && name[0]) { - TiXmlElementA *element = childNode->ToElement(); - int index; - if (element->Attribute("index", &index)) - { - if (index > -1 && index < 5) //valid index only - { - const char *name = element->Attribute("name"); - - WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); - const wchar_t * nameW = wmc->char2wchar(name, _nativeLangEncoding); - sm->translateTab(index, nameW); - } - } + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + return wmc->char2wchar(name, _nativeLangEncoding); } + + return defaultStr; } diff --git a/PowerEditor/src/localization.h b/PowerEditor/src/localization.h index f70bc5535..6bd9d90bb 100644 --- a/PowerEditor/src/localization.h +++ b/PowerEditor/src/localization.h @@ -60,7 +60,6 @@ public: generic_string getNativeLangMenuString(int itemID) const; void changeMenuLang(HMENU menuHandle, generic_string & pluginsTrans, generic_string & windowTrans); void changeShortcutLang(); - void changeShortcutmapperLang(ShortcutMapper * sm); void changeStyleCtrlsLang(HWND hDlg, int *idArray, const char **translatedText); void changeUserDefineLang(UserDefineDialog *userDefineDlg); void changeUserDefineLangPopupDlg(HWND hDlg); @@ -82,6 +81,7 @@ public: return _nativeLangEncoding; }; bool getMsgBoxLang(const char *msgBoxTagName, generic_string & title, generic_string & message); + generic_string getShortcutMapperLangStr(const char *nodeName, const TCHAR *defaultStr) const; generic_string getProjectPanelLangMenuStr(const char * nodeName, int cmdID, const TCHAR *defaultStr) const; generic_string getFileBrowserLangMenuStr(int cmdID, const TCHAR *defaultStr) const; generic_string getAttrNameStr(const TCHAR *defaultStr, const char *nodeL1Name, const char *nodeL2Name = NULL) const;