mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Tweaks
This commit is contained in:
parent
aecef0b5f9
commit
27fe4a1e1c
@ -3283,82 +3283,85 @@ HMENU CRainmeter::CreateSkinMenu(CMeterWindow* meterWindow, int index, HMENU men
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add custom actions to the context menu
|
// Add custom actions to the context menu
|
||||||
auto isTitleSeparator = [](const std::wstring& title)
|
|
||||||
{
|
|
||||||
return title.find_first_not_of(L'-') == std::wstring::npos;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::wstring contextTitle = meterWindow->GetParser().ReadString(L"Rainmeter", L"ContextTitle", L"");
|
std::wstring contextTitle = meterWindow->GetParser().ReadString(L"Rainmeter", L"ContextTitle", L"");
|
||||||
std::wstring contextAction = meterWindow->GetParser().ReadString(L"Rainmeter", L"ContextAction", L"");
|
if (!contextTitle.empty())
|
||||||
if (!contextTitle.empty() && (!contextAction.empty() || isTitleSeparator(contextTitle)))
|
|
||||||
{
|
{
|
||||||
std::vector<std::wstring> cTitles;
|
auto isTitleSeparator = [](const std::wstring& title)
|
||||||
WCHAR buffer[128];
|
|
||||||
int i = 1;
|
|
||||||
|
|
||||||
while (!contextTitle.empty() &&
|
|
||||||
(!contextAction.empty() || isTitleSeparator(contextTitle)) &&
|
|
||||||
(IDM_SKIN_CUSTOMCONTEXTMENU_FIRST + i - 1) <= IDM_SKIN_CUSTOMCONTEXTMENU_LAST) // Set maximum context items in resource.h
|
|
||||||
{
|
{
|
||||||
// Trim long titles
|
return title.find_first_not_of(L'-') == std::wstring::npos;
|
||||||
if (contextTitle.size() > 30)
|
};
|
||||||
{
|
|
||||||
contextTitle.replace(27, contextTitle.size() - 27, L"...");
|
|
||||||
}
|
|
||||||
|
|
||||||
cTitles.push_back(contextTitle);
|
std::wstring contextAction = meterWindow->GetParser().ReadString(L"Rainmeter", L"ContextAction", L"");
|
||||||
|
if (!contextAction.empty() || isTitleSeparator(contextTitle))
|
||||||
_snwprintf_s(buffer, _TRUNCATE, L"ContextTitle%i", ++i);
|
|
||||||
contextTitle = meterWindow->GetParser().ReadString(L"Rainmeter", buffer, L"");
|
|
||||||
_snwprintf_s(buffer, _TRUNCATE, L"ContextAction%i", i);
|
|
||||||
contextAction = meterWindow->GetParser().ReadString(L"Rainmeter", buffer, L"");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build a sub-menu if more than three items
|
|
||||||
size_t titleSize = cTitles.size();
|
|
||||||
if (titleSize <= 3)
|
|
||||||
{
|
{
|
||||||
size_t position = 0;
|
std::vector<std::wstring> cTitles;
|
||||||
for (size_t i = 0; i < titleSize; ++i)
|
WCHAR buffer[128];
|
||||||
|
int i = 1;
|
||||||
|
|
||||||
|
while (!contextTitle.empty() &&
|
||||||
|
(!contextAction.empty() || isTitleSeparator(contextTitle)) &&
|
||||||
|
(IDM_SKIN_CUSTOMCONTEXTMENU_FIRST + i - 1) <= IDM_SKIN_CUSTOMCONTEXTMENU_LAST) // Set maximum context items in resource.h
|
||||||
{
|
{
|
||||||
if (isTitleSeparator(cTitles[i]))
|
// Trim long titles
|
||||||
|
if (contextTitle.size() > 30)
|
||||||
{
|
{
|
||||||
// Separators not allowed in main top-level menu
|
contextTitle.replace(27, contextTitle.size() - 27, L"...");
|
||||||
--position;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
InsertMenu(skinMenu, position + 1, MF_BYPOSITION | MF_STRING, (index << 16) | (IDM_SKIN_CUSTOMCONTEXTMENU_FIRST + i), cTitles[i].c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
++position;
|
cTitles.push_back(contextTitle);
|
||||||
|
|
||||||
|
_snwprintf_s(buffer, _TRUNCATE, L"ContextTitle%i", ++i);
|
||||||
|
contextTitle = meterWindow->GetParser().ReadString(L"Rainmeter", buffer, L"");
|
||||||
|
_snwprintf_s(buffer, _TRUNCATE, L"ContextAction%i", i);
|
||||||
|
contextAction = meterWindow->GetParser().ReadString(L"Rainmeter", buffer, L"");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (position != 0)
|
// Build a sub-menu if more than three items
|
||||||
|
size_t titleSize = cTitles.size();
|
||||||
|
if (titleSize <= 3)
|
||||||
{
|
{
|
||||||
InsertMenu(skinMenu, 1, MF_BYPOSITION | MF_STRING | MF_GRAYED, NULL, L"Custom skin actions");
|
size_t position = 0;
|
||||||
|
for (size_t i = 0; i < titleSize; ++i)
|
||||||
|
{
|
||||||
|
if (isTitleSeparator(cTitles[i]))
|
||||||
|
{
|
||||||
|
// Separators not allowed in main top-level menu
|
||||||
|
--position;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
InsertMenu(skinMenu, position + 1, MF_BYPOSITION | MF_STRING, (index << 16) | (IDM_SKIN_CUSTOMCONTEXTMENU_FIRST + i), cTitles[i].c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
++position;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (position != 0)
|
||||||
|
{
|
||||||
|
InsertMenu(skinMenu, 1, MF_BYPOSITION | MF_STRING | MF_GRAYED, NULL, L"Custom skin actions");
|
||||||
|
InsertMenu(skinMenu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
HMENU customMenu = CreatePopupMenu();
|
||||||
|
InsertMenu(skinMenu, 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)customMenu, L"Custom skin actions");
|
||||||
|
|
||||||
|
for (size_t i = 0; i < titleSize; ++i)
|
||||||
|
{
|
||||||
|
if (isTitleSeparator(cTitles[i]))
|
||||||
|
{
|
||||||
|
AppendMenu(customMenu, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AppendMenu(customMenu, MF_BYPOSITION | MF_STRING, (index << 16) | (IDM_SKIN_CUSTOMCONTEXTMENU_FIRST + i), cTitles[i].c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
InsertMenu(skinMenu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
|
InsertMenu(skinMenu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
HMENU customMenu = CreatePopupMenu();
|
|
||||||
InsertMenu(skinMenu, 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)customMenu, L"Custom skin actions");
|
|
||||||
|
|
||||||
for (size_t i = 0; i < titleSize; ++i)
|
|
||||||
{
|
|
||||||
if (isTitleSeparator(cTitles[i]))
|
|
||||||
{
|
|
||||||
AppendMenu(customMenu, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
AppendMenu(customMenu, MF_BYPOSITION | MF_STRING, (index << 16) | (IDM_SKIN_CUSTOMCONTEXTMENU_FIRST + i), cTitles[i].c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
InsertMenu(skinMenu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user