Add !SkinCustomMenu bang that displays the user-defined context menu items only

This commit is contained in:
Birunthan Mohanathas 2014-02-07 20:49:31 +02:00
parent feb90f35d2
commit d0fd184063
6 changed files with 31 additions and 6 deletions

View File

@ -100,7 +100,8 @@ const BangInfo s_Bangs[] =
{ Bang::PauseMeasureGroup, L"PauseMeasureGroup", 1 },
{ Bang::UnpauseMeasureGroup, L"UnpauseMeasureGroup", 1 },
{ Bang::TogglePauseMeasureGroup, L"TogglePauseMeasureGroup", 1 },
{ Bang::UpdateMeasureGroup, L"UpdateMeasureGroup", 1 }
{ Bang::UpdateMeasureGroup, L"UpdateMeasureGroup", 1 },
{ Bang::SkinCustomMenu, L"SkinCustomMenu", 0 }
};
// Bangs that are to be handled with DoGroupBang().

View File

@ -106,6 +106,7 @@ enum class Bang
About,
Manage,
SkinMenu,
SkinCustomMenu,
TrayMenu,
ResetStats,
Log,

View File

@ -170,6 +170,21 @@ void ContextMenu::ShowMenu(POINT pos, MeterWindow* meterWindow)
m_MenuActive = false;
}
void ContextMenu::ShowSkinCustomMenu(POINT pos, MeterWindow* meterWindow)
{
if (m_MenuActive || meterWindow->IsClosing()) return;
m_MenuActive = true;
HMENU menu = CreatePopupMenu();
AppendSkinCustomMenu(meterWindow, 0, menu, true);
DisplayMenu(pos, menu, meterWindow->GetWindow());
DestroyMenu(menu);
m_MenuActive = false;
}
void ContextMenu::DisplayMenu(POINT pos, HMENU menu, HWND parentWindow)
{
// Set the window to foreground
@ -428,12 +443,13 @@ HMENU ContextMenu::CreateSkinMenu(MeterWindow* meterWindow, int index, HMENU men
}
}
AppendSkinCustomMenu(meterWindow, index, skinMenu);
AppendSkinCustomMenu(meterWindow, index, skinMenu, false);
return skinMenu;
}
void ContextMenu::AppendSkinCustomMenu(MeterWindow* meterWindow, int index, HMENU menu)
void ContextMenu::AppendSkinCustomMenu(
MeterWindow* meterWindow, int index, HMENU menu, bool standaloneMenu)
{
// Add custom actions to the context menu
std::wstring contextTitle = meterWindow->GetParser().ReadString(L"Rainmeter", L"ContextTitle", L"");
@ -477,7 +493,7 @@ void ContextMenu::AppendSkinCustomMenu(MeterWindow* meterWindow, int index, HMEN
// Build a sub-menu if more than three items
const size_t titleSize = cTitles.size();
if (titleSize <= 3)
if (titleSize <= 3 || standaloneMenu)
{
size_t position = 0;
for (size_t i = 0; i < titleSize; ++i)
@ -496,7 +512,7 @@ void ContextMenu::AppendSkinCustomMenu(MeterWindow* meterWindow, int index, HMEN
++position;
}
if (position != 0)
if (position != 0 && !standaloneMenu)
{
InsertMenu(menu, 1, MF_BYPOSITION | MF_STRING | MF_GRAYED, 0, L"Custom skin actions");
InsertMenu(menu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, nullptr);

View File

@ -35,6 +35,7 @@ public:
bool IsMenuActive() { return m_MenuActive; }
void ShowMenu(POINT pos, MeterWindow* meterWindow);
void ShowSkinCustomMenu(POINT pos, MeterWindow* meterWindow);
static void CreateMonitorMenu(HMENU monitorMenu, MeterWindow* meterWindow);
@ -42,7 +43,8 @@ private:
static void DisplayMenu(POINT pos, HMENU menu, HWND parentWindow);
static HMENU CreateSkinMenu(MeterWindow* meterWindow, int index, HMENU menu);
static void AppendSkinCustomMenu(MeterWindow* meterWindow, int index, HMENU menu);
static void AppendSkinCustomMenu(
MeterWindow* meterWindow, int index, HMENU menu, bool standaloneMenu);
static void ChangeSkinIndex(HMENU subMenu, int index);
static void CreateAllSkinsMenu(HMENU skinMenu) { CreateAllSkinsMenuRecursive(skinMenu, 0); }

View File

@ -980,6 +980,10 @@ void MeterWindow::DoBang(Bang bang, const std::vector<std::wstring>& args)
case Bang::SetOptionGroup:
SetOption(args[0], args[1], args[2], true);
break;
case Bang::SkinCustomMenu:
Rainmeter::GetInstance().ShowSkinCustomContextMenu(System::GetCursorPosition(), this);
break;
}
}

View File

@ -166,6 +166,7 @@ public:
bool IsMenuActive() { return m_ContextMenu.IsMenuActive(); }
void ShowContextMenu(POINT pos, MeterWindow* mw) { return m_ContextMenu.ShowMenu(pos, mw); }
void ShowSkinCustomContextMenu(POINT pos, MeterWindow* mw) { return m_ContextMenu.ShowSkinCustomMenu(pos, mw); }
const std::wstring& GetTrayExecuteR() { return m_TrayExecuteR; }
const std::wstring& GetTrayExecuteM() { return m_TrayExecuteM; }