Fix Wrong Categories in Shortcuts Mapper
and make localization more accurate. Fix #13285, close #14156
This commit is contained in:
parent
cb1f2d1479
commit
39001d7a02
|
@ -641,17 +641,7 @@ Translation note:
|
|||
<ScintillaCommandsTab name="Scintilla commands"/>
|
||||
<ConflictInfoOk name="No shortcut conflicts for this item."/>
|
||||
<ConflictInfoEditing name="No conflicts . . ."/>
|
||||
<WindowCategory name="Window"/>
|
||||
<FileCategory name="File"/>
|
||||
<EditCategory name="Edit"/>
|
||||
<SearchCategory name="Search"/>
|
||||
<ViewCategory name="View"/>
|
||||
<FormatCategory name="Format"/>
|
||||
<LangCategory name="Lang"/>
|
||||
<AboutCategory name="About"/>
|
||||
<SettingCategory name="Setting"/>
|
||||
<ToolCategory name="Tool"/>
|
||||
<ExecuteCategory name="Execute"/>
|
||||
<ModifyContextMenu name="Modify"/>
|
||||
<DeleteContextMenu name="Delete"/>
|
||||
<ClearContextMenu name="Clear"/>
|
||||
|
|
|
@ -641,17 +641,7 @@ Translation note:
|
|||
<ScintillaCommandsTab name="Commandes de Scintilla "/>
|
||||
<ConflictInfoOk name="Pas de conflit pour cet élément."/>
|
||||
<ConflictInfoEditing name="Pas de conflit . . ."/>
|
||||
<WindowCategory name="Fenêtre"/>
|
||||
<FileCategory name="Fichier"/>
|
||||
<EditCategory name="Édition"/>
|
||||
<SearchCategory name="Recherche"/>
|
||||
<ViewCategory name="Affichage"/>
|
||||
<FormatCategory name="Encodage"/>
|
||||
<LangCategory name="Langage"/>
|
||||
<AboutCategory name="À propos"/>
|
||||
<SettingCategory name="Paramètres"/>
|
||||
<ToolCategory name="Outils"/>
|
||||
<ExecuteCategory name="Exécution"/>
|
||||
<ModifyContextMenu name="Modifier"/>
|
||||
<DeleteContextMenu name="Supprimer"/>
|
||||
<ClearContextMenu name="Effacer"/>
|
||||
|
|
|
@ -614,7 +614,7 @@
|
|||
<ScintillaCommandsTab name="Scintilla 指令"/>
|
||||
<ConflictInfoOk name="沒有與此項目衝突的快捷鍵。"/>
|
||||
<ConflictInfoEditing name="沒有與此項目衝突的快捷鍵..."/>
|
||||
|
||||
<AboutCategory name="關於"/>
|
||||
<MainCommandNames>
|
||||
<Item id="41019" name="在檔案總管內開啟檔案位置"/>
|
||||
<Item id="41020" name="在 CMD 內開啟檔案位置"/>
|
||||
|
|
|
@ -6997,6 +6997,7 @@ bool Notepad_plus::reloadLang()
|
|||
}
|
||||
}
|
||||
|
||||
_nativeLangSpeaker.resetShortcutMenuNameMap();
|
||||
updateCommandShortcuts();
|
||||
|
||||
_accelerator.updateFullMenu();
|
||||
|
@ -8711,12 +8712,9 @@ void Notepad_plus::createMonitoringThread(Buffer* pBuf)
|
|||
void Notepad_plus::updateCommandShortcuts()
|
||||
{
|
||||
NppParameters& nppParam = NppParameters::getInstance();
|
||||
vector<CommandShortcut> & shortcuts = nppParam.getUserShortcuts();
|
||||
size_t len = shortcuts.size();
|
||||
|
||||
for (size_t i = 0; i < len; ++i)
|
||||
for (CommandShortcut& csc : nppParam.getUserShortcuts())
|
||||
{
|
||||
CommandShortcut & csc = shortcuts[i];
|
||||
unsigned long id = csc.getID();
|
||||
generic_string localizedMenuName = _nativeLangSpeaker.getNativeLangMenuString(id);
|
||||
generic_string menuName = localizedMenuName;
|
||||
|
@ -8742,6 +8740,8 @@ void Notepad_plus::updateCommandShortcuts()
|
|||
}
|
||||
|
||||
csc.setName(wstring2string(menuName, CP_UTF8).c_str(), wstring2string(shortcutName, CP_UTF8).c_str());
|
||||
|
||||
csc.setCategoryFromMenu(_mainMenuHandle);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -300,9 +300,7 @@ void ShortcutMapper::fillOutBabyGrid()
|
|||
if (cshortcuts[i].isEnabled()) //avoid empty strings for better performance
|
||||
_babygrid.setText(cs_index, 2, string2wstring(cshortcuts[i].toString(), CP_UTF8).c_str());
|
||||
|
||||
const TCHAR* category = cshortcuts[i].getCategory();
|
||||
generic_string categoryStr = nativeLangSpeaker->getShortcutMapperLangStr((std::string(wstring2string(category, CP_UTF8)) + "Category").c_str(), category);
|
||||
_babygrid.setText(cs_index, 3, categoryStr.c_str());
|
||||
_babygrid.setText(cs_index, 3, cshortcuts[i].getCategory());
|
||||
|
||||
if (isMarker)
|
||||
isMarker = _babygrid.setMarker(false);
|
||||
|
|
|
@ -1224,34 +1224,48 @@ intptr_t CALLBACK ScintillaKeyMap::run_dlgProc(UINT Message, WPARAM wParam, LPAR
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
CommandShortcut::CommandShortcut(const Shortcut& sc, long id) : Shortcut(sc), _id(id)
|
||||
void CommandShortcut::setCategoryFromMenu(HMENU hMenu)
|
||||
{
|
||||
_shortcutName = string2wstring(sc.getName(), CP_UTF8);
|
||||
NativeLangSpeaker* pNativeSpeaker = NppParameters::getInstance().getNativeLangSpeaker();
|
||||
|
||||
if ( _id >= IDM_WINDOW_SORT_FN_ASC and _id <= IDM_WINDOW_SORT_FS_DSC)
|
||||
_category = TEXT("Window");
|
||||
else if ( _id < IDM_EDIT)
|
||||
_category = TEXT("File");
|
||||
else if ( _id < IDM_SEARCH)
|
||||
_category = TEXT("Edit");
|
||||
else if (((_id >= IDM_EDIT_AUTOCOMPLETE) && (_id <= IDM_EDIT_AUTOCOMPLETE_PATH)) ||
|
||||
((_id >= IDM_EDIT_FUNCCALLTIP_PREVIOUS) && (_id <= IDM_EDIT_FUNCCALLTIP_NEXT)))
|
||||
_category = TEXT("Edit");
|
||||
else if ( _id < IDM_VIEW)
|
||||
_category = TEXT("Search");
|
||||
else if ( _id < IDM_FORMAT)
|
||||
_category = TEXT("View");
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "Window", L"Window");
|
||||
else if ( _id >= IDM_VIEW_GOTO_ANOTHER_VIEW and _id <= IDM_VIEW_LOAD_IN_NEW_INSTANCE)
|
||||
_category = TEXT("View");
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "view", L"View");
|
||||
else if (_id == IDM_EDIT_LTR || _id == IDM_EDIT_RTL)
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "view", L"View");
|
||||
else if (_id == IDC_PREV_DOC || _id == IDC_NEXT_DOC)
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "view", L"View");
|
||||
else if (_id == IDM_FORMAT_TODOS || _id == IDM_FORMAT_TOUNIX || _id == IDM_FORMAT_TOMAC)
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "edit", L"Edit");
|
||||
else if (_id == IDM_EDIT_AUTOCOMPLETE || _id == IDM_EDIT_AUTOCOMPLETE_CURRENTFILE || _id == IDM_EDIT_FUNCCALLTIP ||
|
||||
_id == IDM_EDIT_AUTOCOMPLETE_PATH || _id == IDM_EDIT_FUNCCALLTIP_PREVIOUS || _id == IDM_EDIT_FUNCCALLTIP_NEXT)
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "edit", L"Edit");
|
||||
else if (_id == IDM_LANGSTYLE_CONFIG_DLG)
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "settings", L"Settings");
|
||||
else if (_id == IDM_MACRO_STARTRECORDINGMACRO ||_id == IDM_MACRO_STOPRECORDINGMACRO || _id == IDM_MACRO_RUNMULTIMACRODLG ||
|
||||
_id == IDM_MACRO_PLAYBACKRECORDEDMACRO ||_id == IDM_MACRO_SAVECURRENTMACRO || _id == IDC_EDIT_TOGGLEMACRORECORDING)
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "macro", L"Macro");
|
||||
|
||||
|
||||
else if ( _id < IDM_EDIT)
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "file", L"File");
|
||||
else if ( _id < IDM_SEARCH)
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "edit",L"Edit");
|
||||
else if ( _id < IDM_VIEW)
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "search", L"Search");
|
||||
else if ( _id < IDM_FORMAT)
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "view", L"View");
|
||||
else if ( _id < IDM_LANG)
|
||||
_category = TEXT("Format");
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "encoding", L"Encoding");
|
||||
else if ( _id < IDM_ABOUT)
|
||||
_category = TEXT("Lang");
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "language", L"Language");
|
||||
else if ( _id < IDM_SETTING)
|
||||
_category = TEXT("About");
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "about", L"About");
|
||||
else if ( _id < IDM_TOOL)
|
||||
_category = TEXT("Setting");
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "settings", L"Settings");
|
||||
else if ( _id < IDM_EXECUTE)
|
||||
_category = TEXT("Tool");
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "tools", L"Tools");
|
||||
else
|
||||
_category = TEXT("Execute");
|
||||
pNativeSpeaker->getMainMenuEntryName(_category, hMenu, "run", L"Run");
|
||||
}
|
||||
|
|
|
@ -184,7 +184,10 @@ protected :
|
|||
|
||||
class CommandShortcut : public Shortcut {
|
||||
public:
|
||||
CommandShortcut(const Shortcut& sc, long id);
|
||||
CommandShortcut(const Shortcut& sc, long id) : Shortcut(sc), _id(id){
|
||||
_shortcutName = string2wstring(getName(), CP_UTF8);
|
||||
};
|
||||
void setCategoryFromMenu(HMENU hMenu);
|
||||
unsigned long getID() const {return _id;};
|
||||
void setID(unsigned long id) { _id = id;};
|
||||
const TCHAR * getCategory() const { return _category.c_str(); };
|
||||
|
|
|
@ -284,6 +284,43 @@ MenuPosition & getMenuPosition(const char *id)
|
|||
return menuPos[nbSubMenuPos-1];
|
||||
}
|
||||
|
||||
// Get string from map.
|
||||
// If string not found, get string from menu, then put it into map for the next use.
|
||||
void NativeLangSpeaker::getMainMenuEntryName(std::wstring& dest, HMENU hMenu, const char* menuId, const wchar_t* defaultDest)
|
||||
{
|
||||
const auto iter = _shortcutMenuEntryNameMap.find(menuId);
|
||||
if (iter == _shortcutMenuEntryNameMap.end())
|
||||
{
|
||||
MenuPosition& menuPos = getMenuPosition(menuId);
|
||||
if (menuPos._x != -1 && menuPos._y == -1 && menuPos._z == -1)
|
||||
{
|
||||
wchar_t str[MAX_PATH];
|
||||
GetMenuString(hMenu, menuPos._x, str, MAX_PATH, MF_BYPOSITION);
|
||||
dest = str;
|
||||
dest.erase(std::remove(dest.begin(), dest.end(), '&'), dest.end());
|
||||
_shortcutMenuEntryNameMap[menuId] = dest;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strcmp(menuId, "about") == 0)
|
||||
{
|
||||
dest = getShortcutMapperLangStr("AboutCategory", defaultDest);
|
||||
}
|
||||
else
|
||||
{
|
||||
_shortcutMenuEntryNameMap[menuId] = defaultDest;
|
||||
dest = defaultDest;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dest = iter->second;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NativeLangSpeaker::changeMenuLang(HMENU menuHandle)
|
||||
{
|
||||
if (nullptr == _nativeLangA)
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include "Common.h"
|
||||
#include "tinyxmlA.h"
|
||||
|
||||
|
@ -83,6 +84,11 @@ public:
|
|||
generic_string getAttrNameStr(const TCHAR *defaultStr, const char *nodeL1Name, const char *nodeL2Name, const char *nodeL3Name = "name") const;
|
||||
generic_string getAttrNameByIdStr(const TCHAR *defaultStr, TiXmlNodeA *targetNode, const char *nodeL1Value, const char *nodeL1Name = "id", const char *nodeL2Name = "name") const;
|
||||
generic_string getLocalizedStrFromID(const char *strID, const generic_string& defaultString) const;
|
||||
void getMainMenuEntryName(std::wstring& dest, HMENU hMenu, const char* menuIdStr, const wchar_t* defaultDest);
|
||||
|
||||
void resetShortcutMenuNameMap() {
|
||||
_shortcutMenuEntryNameMap.clear();
|
||||
};
|
||||
|
||||
int messageBox(const char *msgBoxTagName, HWND hWnd, const TCHAR *message, const TCHAR *title, int msgBoxType, int intInfo = 0, const TCHAR *strInfo = NULL);
|
||||
private:
|
||||
|
@ -90,6 +96,7 @@ private:
|
|||
int _nativeLangEncoding;
|
||||
bool _isRTL;
|
||||
const char *_fileName;
|
||||
std::map<std::string, std::wstring> _shortcutMenuEntryNameMap;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue