Index: src/chext/TContextMenuHandler.cpp =================================================================== diff -u -r250c9a4d3a066af0d40def01e15df5753748aefe -rd3371a00eafb40afa4251953591ff1004343e1be --- src/chext/TContextMenuHandler.cpp (.../TContextMenuHandler.cpp) (revision 250c9a4d3a066af0d40def01e15df5753748aefe) +++ src/chext/TContextMenuHandler.cpp (.../TContextMenuHandler.cpp) (revision d3371a00eafb40afa4251953591ff1004343e1be) @@ -25,6 +25,24 @@ #include "../common/TShellExtMenuConfig.h" #include "Logger.h" +namespace +{ + void CutAmpersands(LPTSTR lpszString) + { + int iOffset = 0; + size_t iLength = _tcslen(lpszString); + for (size_t j = 0; j < iLength; j++) + { + if (lpszString[j] == _T('&')) + iOffset++; + else + if (iOffset != 0) + lpszString[j - iOffset] = lpszString[j]; + } + lpszString[iLength - iOffset] = _T('\0'); + } +} + TContextMenuHandler::TContextMenuHandler() : m_uiFirstMenuID(0), m_uiNextMenuID(0), @@ -75,6 +93,52 @@ return false; } +int TContextMenuHandler::FindMenuInsertLocation(HMENU hMenu) +{ + // current commands count in menu + TCHAR szText[_MAX_PATH]; + int iCount = ::GetMenuItemCount(hMenu); + + // find a place where the commands should be inserted + for (int iMenuIndex = 0; iMenuIndex < iCount; iMenuIndex++) + { + MENUITEMINFO mii = { 0 }; + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_STRING; + mii.dwTypeData = szText; + mii.cch = _MAX_PATH; + + if (!::GetMenuItemInfo(hMenu, iMenuIndex, TRUE, &mii)) + continue; + + // get rid of & + CutAmpersands(szText); + _tcslwr(szText); + + // check for texts Wytnij/Wklej/Kopiuj/Cut/Paste/Copy + if (_tcscmp(szText, _T("wytnij")) == 0 || _tcscmp(szText, _T("wklej")) == 0 || + _tcscmp(szText, _T("kopiuj")) == 0 || _tcscmp(szText, _T("cut")) == 0 || + _tcscmp(szText, _T("paste")) == 0 || _tcscmp(szText, _T("copy")) == 0) + { + // found - find the nearest bar and insert above + for (int j = iMenuIndex + 1; j < iCount; j++) + { + MENUITEMINFO miiInner = { 0 }; + miiInner.cbSize = sizeof(miiInner); + miiInner.fMask = MIIM_FTYPE; + + // find bar + if (::GetMenuItemInfo(hMenu, j, TRUE, &miiInner) && miiInner.fType == MFT_SEPARATOR) + return j; + } + + break; + } + } + + return -1; +} + void TContextMenuHandler::UpdateMenuRecursive(const TShellMenuItemPtr& spRootMenuItem, HMENU hMenu, UINT uiFirstItemPosition, const TShellExtData& rShellExtData, const chengine::TSizeFormatterPtr& spFormatter, bool bShowFreeSpace, bool bOverrideDefaultItem) {