Add Pin/Unpin Tab context menu item

Close #15852
This commit is contained in:
Don Ho 2024-11-25 05:12:28 +01:00
parent 2c1212cba5
commit 287c85f8f0
9 changed files with 89 additions and 8 deletions

View File

@ -422,6 +422,7 @@ Translation note:
<Item CMDID="41009" name="Close All to the Left"/>
<Item CMDID="41018" name="Close All to the Right"/>
<Item CMDID="41024" name="Close All Unchanged"/>
<Item CMDID="44048" name="Pin Tab" alternativeName="Unpin Tab"/>
<Item CMDID="41006" name="Save"/>
<Item CMDID="41008" name="Save As..."/>
<Item CMDID="1" name="Open into"/>

View File

@ -422,6 +422,7 @@ Translation note:
<Item CMDID="41009" name="Close All to the Left"/>
<Item CMDID="41018" name="Close All to the Right"/>
<Item CMDID="41024" name="Close All Unchanged"/>
<Item CMDID="44048" name="Pin Tab" alternativeName="Unpin Tab"/>
<Item CMDID="41006" name="Save"/>
<Item CMDID="41008" name="Save As..."/>
<Item CMDID="1" name="Open into"/>

View File

@ -422,6 +422,7 @@ Translation note:
<Item CMDID="41009" name="Fermer les onglets sur la gauche"/>
<Item CMDID="41018" name="Fermer les onglets sur la droite"/>
<Item CMDID="41024" name="Fermer tous les documents non-modifiés"/>
<Item CMDID="44048" name="Epingler longlet" alternativeName="Désépingler longlet"/>
<Item CMDID="41006" name="Enregistrer"/>
<Item CMDID="41008" name="Enregistrer sous..."/>
<Item CMDID="1" name="Ouvrir dans"/>

View File

@ -394,6 +394,7 @@
<Item CMDID="41009" name="關閉左側所有檔案"/>
<Item CMDID="41018" name="關閉右側所有檔案"/>
<Item CMDID="41024" name="關閉所有未更改的檔案"/>
<Item CMDID="44048" name="固定標籤頁" alternativeName="取消固定標籤頁"/>
<Item CMDID="41006" name="儲存"/>
<Item CMDID="41008" name="另存新檔..."/>
<Item CMDID="1" name="開啟至"/>

View File

@ -3978,6 +3978,18 @@ void Notepad_plus::command(int id)
}
break;
case IDM_PINTAB:
{
TBHDR nmhdr{};
nmhdr._hdr.hwndFrom = _pDocTab->getHSelf();
nmhdr._hdr.code = TCN_TABPINNED;
nmhdr._hdr.idFrom = reinterpret_cast<UINT_PTR>(this);
nmhdr._tabOrigin = _pDocTab->getCurrentTabIndex();
::SendMessage(_pPublicInterface->getHSelf(), WM_NOTIFY, 0, reinterpret_cast<LPARAM>(&nmhdr));
::SendMessage(_pPublicInterface->getHSelf(), NPPM_INTERNAL_REFRESHTABAR, 0, 0);
}
break;
default :
if (id > IDM_FILEMENU_LASTONE && id < (IDM_FILEMENU_LASTONE + _lastRecentFileList.getMaxNbLRF() + 1))
{

View File

@ -574,6 +574,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_TOLEFT, L"Close All to the Left", L"Close Multiple Tabs"));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_TORIGHT, L"Close All to the Right", L"Close Multiple Tabs"));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_UNCHANGED, L"Close All Unchanged", L"Close Multiple Tabs"));
itemUnitArray.push_back(MenuItemUnit(IDM_PINTAB, L"Pin Tab"));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_SAVE, L"Save"));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_SAVEAS, L"Save As..."));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_OPEN_FOLDER, L"Open Containing Folder in Explorer", L"Open into"));
@ -623,7 +624,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
bool isEnable = ((::GetMenuState(_mainMenuHandle, IDM_FILE_SAVE, MF_BYCOMMAND)&MF_DISABLED) == 0);
_tabPopupMenu.enableItem(IDM_FILE_SAVE, isEnable);
Buffer * buf = _pEditView->getCurrentBuffer();
Buffer* buf = _pEditView->getCurrentBuffer();
bool isUserReadOnly = buf->getUserReadOnly();
_tabPopupMenu.checkItem(IDM_EDIT_SETREADONLY, isUserReadOnly);
@ -653,6 +654,33 @@ BOOL Notepad_plus::notify(SCNotification *notification)
_tabPopupMenu.enableItem(IDM_FILE_SAVEAS, !isInaccessible);
_tabPopupMenu.enableItem(IDM_FILE_RENAME, !isInaccessible);
bool isTabPinEnabled = TabBarPlus::drawTabPinButton();
wstring newName;
if (isTabPinEnabled)
{
wstring defaultName;
bool isAlternative;
if (buf->isPinned())
{
defaultName = L"Unpin Tab";
isAlternative = true;
}
else
{
defaultName = L"Pin Tab";
isAlternative = false;
}
_nativeLangSpeaker.getAlternativeNameFromTabContextMenu(newName, IDM_PINTAB, isAlternative, defaultName);
::ModifyMenu(_tabPopupMenu.getMenuHandle(), IDM_PINTAB, MF_BYCOMMAND, IDM_PINTAB, newName.c_str());
}
else
{
_nativeLangSpeaker.getAlternativeNameFromTabContextMenu(newName, IDM_PINTAB, false, L"Pin Tab");
::ModifyMenu(_tabPopupMenu.getMenuHandle(), IDM_PINTAB, MF_BYCOMMAND, IDM_PINTAB, newName.c_str());
}
_tabPopupMenu.enableItem(IDM_PINTAB, isTabPinEnabled);
_tabPopupMenu.display(p);
return TRUE;
}

View File

@ -491,14 +491,14 @@ static const int tabCmSubMenuEntryPos[] =
// | |
// | |
1, // 0 Close Multiple Tabs
4, // 1 Open into
13, // 2 Copy to Clipboard
14, // 3 Move Document
15, // 4 Apply Color to Tab
5, // 1 Open into
14, // 2 Copy to Clipboard
15, // 3 Move Document
16, // 4 Apply Color to Tab
};
void NativeLangSpeaker::changeLangTabContextMenu(HMENU hCM)
void NativeLangSpeaker::changeLangTabContextMenu(HMENU hCM) const
{
if (_nativeLangA != nullptr)
{
@ -548,6 +548,42 @@ void NativeLangSpeaker::changeLangTabContextMenu(HMENU hCM)
}
}
void NativeLangSpeaker::getAlternativeNameFromTabContextMenu(wstring& output, int cmdID, bool isAlternative, const wstring& defaultValue) const
{
if (_nativeLangA != nullptr)
{
TiXmlNodeA* tabBarMenu = _nativeLangA->FirstChild("Menu");
if (tabBarMenu)
{
tabBarMenu = tabBarMenu->FirstChild("TabBar");
if (tabBarMenu)
{
WcharMbcsConvertor& wmc = WcharMbcsConvertor::getInstance();
for (TiXmlNodeA* childNode = tabBarMenu->FirstChildElement("Item");
childNode;
childNode = childNode->NextSibling("Item"))
{
TiXmlElementA* element = childNode->ToElement();
int cmd;
element->Attribute("CMDID", &cmd);
if (cmd == cmdID) // menu item CMD
{
const char* pName = element->Attribute(isAlternative ? "alternativeName" : "name");
if (pName)
{
output = wmc.char2wchar(pName, _nativeLangEncoding);
return;
}
}
}
}
}
}
output = defaultValue;
}
void NativeLangSpeaker::changeLangTabDropContextMenu(HMENU hCM)
{
const int POS_GO2VIEW = 0;

View File

@ -41,7 +41,8 @@ class NativeLangSpeaker {
public:
void init(TiXmlDocumentA *nativeLangDocRootA, bool loadIfEnglish = false);
void changeConfigLang(HWND hDlg);
void changeLangTabContextMenu(HMENU hCM);
void changeLangTabContextMenu(HMENU hCM) const;
void getAlternativeNameFromTabContextMenu(std::wstring& output, int cmdID, bool isAlternative, const std::wstring& defaultValue) const;
TiXmlNodeA * searchDlgNode(TiXmlNodeA *node, const char *dlgTagName);
bool changeDlgLang(HWND hDlg, const char *dlgTagName, char *title = NULL, size_t titleMaxSize = 0);
void changeLangTabDropContextMenu(HMENU hCM);

View File

@ -320,7 +320,7 @@
//#define IDM_VIEW_DOCCHANGEMARGIN (IDM_VIEW + 45)
//#define IDM_VIEW_LWDEF (IDM_VIEW + 46)
//#define IDM_VIEW_LWALIGN (IDM_VIEW + 47)
//#define IDM_VIEW_LWINDENT (IDM_VIEW + 48)
#define IDM_PINTAB (IDM_VIEW + 48)
#define IDM_VIEW_SUMMARY (IDM_VIEW + 49)
#define IDM_VIEW_FOLD (IDM_VIEW + 50)