Revamp tab context menu

Add sub-menu in tab context menu so it will be less cluttered.

Fix #12147, close #12150
This commit is contained in:
Don Ho 2022-09-12 06:00:43 +02:00
parent aad36afc6b
commit 6322562cf8
7 changed files with 126 additions and 68 deletions

View File

@ -24,7 +24,7 @@ The comments are here for explanation, it's not necessary to translate them.
<!-- Sub Menu Entries -->
<SubEntries>
<Item subMenuId="file-openFolder" name="Open Containing &amp;Folder"/>
<Item subMenuId="file-closeMore" name="Close &amp;More"/>
<Item subMenuId="file-closeMore" name="Close &amp;Multiple Documents"/>
<Item subMenuId="file-recentFiles" name="&amp;Recent Files"/>
<Item subMenuId="edit-insert" name="Insert"/>
<Item subMenuId="edit-copyToClipboard" name="Cop&amp;y to Clipboard"/>
@ -404,6 +404,17 @@ The comments are here for explanation, it's not necessary to translate them.
<Item CMID="21" name="Open in Default Viewer"/>
<Item CMID="22" name="Close All Unchanged"/>
<Item CMID="23" name="Open Containing Folder as Workspace"/>
<Item CMID="24" name="Apply Color 1"/>
<Item CMID="25" name="Apply Color 2"/>
<Item CMID="26" name="Apply Color 3"/>
<Item CMID="27" name="Apply Color 4"/>
<Item CMID="28" name="Apply Color 5"/>
<Item CMID="29" name="Remove Color"/>
<Item CMID="30" name="Close Multiple Tabs"/>
<Item CMID="31" name="Open into"/>
<Item CMID="32" name="Copy to Clipboard"/>
<Item CMID="33" name="Move Document"/>
<Item CMID="34" name="Apply Color to Tab"/>
</TabBar>
</Menu>
@ -651,6 +662,12 @@ The comments are here for explanation, it's not necessary to translate them.
<Item id="44107" name="Switch to Folder as Workspace"/>
<Item id="44109" name="Switch to Document List"/>
<Item id="44108" name="Switch to Function List"/>
<Item id="44110" name="Remove Tab Colour"/>
<Item id="44111" name="Apply Tab Colour 1"/>
<Item id="44112" name="Apply Tab Colour 2"/>
<Item id="44113" name="Apply Tab Colour 3"/>
<Item id="44114" name="Apply Tab Colour 4"/>
<Item id="44115" name="Apply Tab Colour 5"/>
<Item id="11002" name="Sort By Name A to Z"/>
<Item id="11003" name="Sort By Name Z to A"/>
<Item id="11004" name="Sort By Path A to Z"/>

View File

@ -24,7 +24,7 @@ The comments are here for explanation, it's not necessary to translate them.
<!-- Sub Menu Entries -->
<SubEntries>
<Item subMenuId="file-openFolder" name="Ouvrir le répertoire du fichier en cours"/>
<Item subMenuId="file-closeMore" name="Fermer +"/>
<Item subMenuId="file-closeMore" name="Fermer plusieurs documents"/>
<Item subMenuId="file-recentFiles" name="Fichiers récents"/>
<Item subMenuId="edit-insert" name="Insertion"/>
<Item subMenuId="edit-copyToClipboard" name="Copier dans le presse-papiers"/>
@ -402,6 +402,17 @@ The comments are here for explanation, it's not necessary to translate them.
<Item CMID="21" name="Ouvrir dans l'application par défaut"/>
<Item CMID="22" name="Fermer tous les documents non-modifiés"/>
<Item CMID="23" name="Ouvrir le répertoire du fichier en cours en tant qu'espace de travail"/>
<Item CMID="24" name="Appliquer la couleur 1"/>
<Item CMID="25" name="Appliquer la couleur 2"/>
<Item CMID="26" name="Appliquer la couleur 3"/>
<Item CMID="27" name="Appliquer la couleur 4"/>
<Item CMID="28" name="Appliquer la couleur 5"/>
<Item CMID="29" name="Enlever la couleur"/>
<Item CMID="30" name="Fermer plusieurs onglets"/>
<Item CMID="31" name="Ouvrir dans"/>
<Item CMID="32" name="Copier dans le presse-papiers"/>
<Item CMID="33" name="Déplacer le document"/>
<Item CMID="34" name="Appliquer la Couleur à l'onglet"/>
</TabBar>
</Menu>

View File

@ -393,6 +393,17 @@
<Item CMID="21" name="在預設檢視中開啟"/>
<Item CMID="22" name="關閉所有未更改的檔案"/>
<Item CMID="23" name="在工作區開啟此檔資料夾"/>
<Item CMID="24" name="顏色一"/>
<Item CMID="25" name="顏色二"/>
<Item CMID="26" name="顏色三"/>
<Item CMID="27" name="顏色四"/>
<Item CMID="28" name="顏色五"/>
<Item CMID="29" name="移除顏色"/>
<Item CMID="30" name="關閉多個檔案"/>
<Item CMID="31" name="開啟至"/>
<Item CMID="32" name="複製到剪貼簿"/>
<Item CMID="33" name="文件移至"/>
<Item CMID="34" name="頁籤使用顏色"/>
</TabBar>
</Menu>
<Dialog>

View File

@ -406,7 +406,7 @@ BEGIN
MENUITEM "&Rename...", IDM_FILE_RENAME
MENUITEM "&Close", IDM_FILE_CLOSE
MENUITEM "Clos&e All", IDM_FILE_CLOSEALL
POPUP "Close &More"
POPUP "Close &Multiple Documents"
BEGIN
MENUITEM "Close All but Active Document", IDM_FILE_CLOSEALL_BUT_CURRENT
MENUITEM "Close All to the Left", IDM_FILE_CLOSEALL_TOLEFT

View File

@ -528,41 +528,39 @@ BOOL Notepad_plus::notify(SCNotification *notification)
// IMPORTANT: If list below is modified, you have to change the value of tabContextMenuItemPos[] in localization.cpp file
std::vector<MenuItemUnit> itemUnitArray;
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSE, TEXT("Close")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_BUT_CURRENT, TEXT("Close All BUT This")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_TOLEFT, TEXT("Close All to the Left")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_TORIGHT, TEXT("Close All to the Right")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_UNCHANGED, TEXT("Close All Unchanged")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_BUT_CURRENT, TEXT("Close All BUT This"), TEXT("Close Multiple Tabs")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_TOLEFT, TEXT("Close All to the Left"), TEXT("Close Multiple Tabs")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_TORIGHT, TEXT("Close All to the Right"), TEXT("Close Multiple Tabs")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_UNCHANGED, TEXT("Close All Unchanged"), TEXT("Close Multiple Tabs")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_SAVE, TEXT("Save")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_SAVEAS, TEXT("Save As...")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_OPEN_FOLDER, TEXT("Open Containing Folder in Explorer"), TEXT("Open into")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_OPEN_CMD, TEXT("Open Containing Folder in cmd"), TEXT("Open into")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CONTAININGFOLDERASWORKSPACE, TEXT("Open Containing Folder as Workspace"), TEXT("Open into")));
itemUnitArray.push_back(MenuItemUnit(0, NULL, TEXT("Open into")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_OPEN_DEFAULT_VIEWER, TEXT("Open in Default Viewer"), TEXT("Open into")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_RENAME, TEXT("Rename")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_DELETE, TEXT("Move to Recycle Bin")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_RELOAD, TEXT("Reload")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_PRINT, TEXT("Print")));
itemUnitArray.push_back(MenuItemUnit(0, NULL));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_TAB_COLOUR_1, TEXT("Apply Color 1")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_TAB_COLOUR_2, TEXT("Apply Color 2")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_TAB_COLOUR_3, TEXT("Apply Color 3")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_TAB_COLOUR_4, TEXT("Apply Color 4")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_TAB_COLOUR_5, TEXT("Apply Color 5")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_TAB_COLOUR_NONE, TEXT("Remove Color")));
itemUnitArray.push_back(MenuItemUnit(0, NULL));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_OPEN_FOLDER, TEXT("Open Containing Folder in Explorer")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_OPEN_CMD, TEXT("Open Containing Folder in cmd")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CONTAININGFOLDERASWORKSPACE, TEXT("Open Containing Folder as Workspace")));
itemUnitArray.push_back(MenuItemUnit(0, NULL));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_OPEN_DEFAULT_VIEWER, TEXT("Open in Default Viewer")));
itemUnitArray.push_back(MenuItemUnit(0, NULL));
itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_SETREADONLY, TEXT("Read-Only")));
itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_CLEARREADONLY, TEXT("Clear Read-Only Flag")));
itemUnitArray.push_back(MenuItemUnit(0, NULL));
itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_FULLPATHTOCLIP, TEXT("Copy Full File Path")));
itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_FILENAMETOCLIP, TEXT("Copy Filename")));
itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_CURRENTDIRTOCLIP, TEXT("Copy Current Dir. Path")));
itemUnitArray.push_back(MenuItemUnit(0, NULL));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_GOTO_ANOTHER_VIEW, TEXT("Move to Other View")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_CLONE_TO_ANOTHER_VIEW, TEXT("Clone to Other View")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_GOTO_NEW_INSTANCE, TEXT("Move to New Instance")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_LOAD_IN_NEW_INSTANCE, TEXT("Open in New Instance")));
itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_FULLPATHTOCLIP, TEXT("Copy Full File Path"), TEXT("Copy to Clipboard")));
itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_FILENAMETOCLIP, TEXT("Copy Filename"), TEXT("Copy to Clipboard")));
itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_CURRENTDIRTOCLIP, TEXT("Copy Current Dir. Path"), TEXT("Copy to Clipboard")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_GOTO_ANOTHER_VIEW, TEXT("Move to Other View"), TEXT("Move Document")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_CLONE_TO_ANOTHER_VIEW, TEXT("Clone to Other View"), TEXT("Move Document")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_GOTO_NEW_INSTANCE, TEXT("Move to New Instance"), TEXT("Move Document")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_LOAD_IN_NEW_INSTANCE, TEXT("Open in New Instance"), TEXT("Move Document")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_TAB_COLOUR_1, TEXT("Apply Color 1"), TEXT("Apply Color to Tab")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_TAB_COLOUR_2, TEXT("Apply Color 2"), TEXT("Apply Color to Tab")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_TAB_COLOUR_3, TEXT("Apply Color 3"), TEXT("Apply Color to Tab")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_TAB_COLOUR_4, TEXT("Apply Color 4"), TEXT("Apply Color to Tab")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_TAB_COLOUR_5, TEXT("Apply Color 5"), TEXT("Apply Color to Tab")));
itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_TAB_COLOUR_NONE, TEXT("Remove Color"), TEXT("Apply Color to Tab")));
// IMPORTANT: If list above is modified, you have to change the value of tabContextMenuItemPos[] in localization.cpp file
_tabPopupMenu.create(_pPublicInterface->getHSelf(), itemUnitArray);

View File

@ -377,43 +377,51 @@ void NativeLangSpeaker::changeMenuLang(HMENU menuHandle)
}
static const int tabContextMenuItemPos[] =
static const std::pair<int, int> tabContextMenuItemPos[] =
{
// +-------------- The item position in tab context menu
// |
// | +------ Index order (CMDID) in <TabBar> of english.xml
// | |
0, // 0: Close
1, // 1: Close ALL BUT This
5, // 2: Save
6, // 3: Save As
10, // 4: Print
32, // 5: Move to Other View
33, // 6: Clone to Other View
28, // 7: Copy Full File Path
29, // 8: Copy Filename
30, // 9: Copy Current Dir. Path
7, // 10: Rename
8, // 11: Move to Recycle Bin
25, // 12: Read-Only
24, // 13: Clear Read-Only Flag
34, // 14: Move to New Instance
35, // 15: Open to New Instance
9, // 16: Reload
2, // 17: Close ALL to the Left
3, // 18: Close ALL to the Right
19, // 19: Open Containing Folder in Explorer
20, // 20: Open Containing Folder in cmd
23, // 21: Open in Default Viewer
4, // 22: Close ALL Unchanged
21, // 23: Open Containing Folder as Workspace
12, // 24: Apply Color
13, // 25: Apply Color
14, // 26: Apply Color
15, // 27: Apply Color
16, // 28: Apply Color
17, // 29: Remove Color
-1 //-------End
// +-------------- The item position on the top level of tab context menu
// |
// | +-------------- The item position in sub-menu of tab context menu. The item is on top level if -1, otherwise it's in the sub-menu
// | |
// | | +--------- Index order (CMID: Context Menu ID) in <TabBar> of english.xml - the number and the order of this array should be synchronized with <TabBar>
// | | |
{0, -1}, // 0: Close
{1, 0}, // 1: Close ALL BUT This
{2, -1}, // 2: Save
{3, -1}, // 3: Save As
{8, -1}, // 4: Print
{14, 0}, // 5: Move to Other View
{14, 1}, // 6: Clone to Other View
{13, 0}, // 7: Copy Full File Path
{13, 1}, // 8: Copy Filename
{13, 2}, // 9: Copy Current Dir. Path
{5, -1}, // 10: Rename
{6, -1}, // 11: Move to Recycle Bin
{10, -1}, // 12: Read-Only
{11, -1}, // 13: Clear Read-Only Flag
{14, 2}, // 14: Move to New Instance
{14, 3}, // 15: Open to New Instance
{7, -1}, // 16: Reload
{1, 1}, // 17: Close ALL to the Left
{1, 2}, // 18: Close ALL to the Right
{4, 0}, // 19: Open Containing Folder in Explorer
{4, 1}, // 20: Open Containing Folder in cmd
{4, 4}, // 21: Open in Default Viewer
{1, 3}, // 22: Close ALL Unchanged
{4, 2}, // 23: Open Containing Folder as Workspace
{15, 0}, // 24: Apply Color
{15, 1}, // 25: Apply Color
{15, 2}, // 26: Apply Color
{15, 3}, // 27: Apply Color
{15, 4}, // 28: Apply Color
{15, 5}, // 29: Remove Color
{1, -1}, // 30: Close Multiple Tabs
{4, -1}, // 31: Open into
{13, -1}, // 32: Copy to Clipboard
{14, -1}, // 33: Move Document
{15, -1}, // Apply Color to Tab
{-1, -1}, //-------End
};
@ -428,7 +436,7 @@ void NativeLangSpeaker::changeLangTabContextMenu(HMENU hCM)
if (tabBarMenu)
{
WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance();
int nbCMItems = sizeof(tabContextMenuItemPos)/sizeof(int);
int nbCMItems = sizeof(tabContextMenuItemPos)/sizeof(std::pair<int, int>);
for (TiXmlNodeA *childNode = tabBarMenu->FirstChildElement("Item");
childNode ;
@ -440,13 +448,26 @@ void NativeLangSpeaker::changeLangTabContextMenu(HMENU hCM)
if (!indexStr || (index < 0 || index >= nbCMItems-1))
continue;
int pos = tabContextMenuItemPos[index];
std::pair<int, int> pos = tabContextMenuItemPos[index];
const char *pName = element->Attribute("name");
if (pName)
{
const wchar_t *pNameW = wmc.char2wchar(pName, _nativeLangEncoding);
int cmdID = ::GetMenuItemID(hCM, pos);
::ModifyMenu(hCM, pos, MF_BYPOSITION, cmdID, pNameW);
if (pos.second == -1) // the 1st level
{
int cmdID = ::GetMenuItemID(hCM, pos.first);
::ModifyMenu(hCM, pos.first, MF_BYPOSITION, cmdID, pNameW);
}
else // it's the sub-menu item
{
HMENU hSubMenu = ::GetSubMenu(hCM, pos.first);
if (!hSubMenu)
continue;
int cmdID = ::GetMenuItemID(hSubMenu, pos.second);
::ModifyMenu(hSubMenu, pos.second, MF_BYPOSITION, cmdID, pNameW);
}
}
}
}

View File

@ -68,7 +68,7 @@
//10 Rename...
//11 Close
//12 Close All
//13 Close More
//13 Close Multiple Documents
//14 Move to Recycle Bin
//15 --------
//16 Load Session...