From d0fd184063cfa61398fa89f34c4be738e22cae85 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Fri, 7 Feb 2014 20:49:31 +0200 Subject: [PATCH] Add !SkinCustomMenu bang that displays the user-defined context menu items only --- Library/CommandHandler.cpp | 3 ++- Library/CommandHandler.h | 1 + Library/ContextMenu.cpp | 24 ++++++++++++++++++++---- Library/ContextMenu.h | 4 +++- Library/MeterWindow.cpp | 4 ++++ Library/Rainmeter.h | 1 + 6 files changed, 31 insertions(+), 6 deletions(-) diff --git a/Library/CommandHandler.cpp b/Library/CommandHandler.cpp index f799febb..59789766 100644 --- a/Library/CommandHandler.cpp +++ b/Library/CommandHandler.cpp @@ -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(). diff --git a/Library/CommandHandler.h b/Library/CommandHandler.h index 2f8ce570..92138fbb 100644 --- a/Library/CommandHandler.h +++ b/Library/CommandHandler.h @@ -106,6 +106,7 @@ enum class Bang About, Manage, SkinMenu, + SkinCustomMenu, TrayMenu, ResetStats, Log, diff --git a/Library/ContextMenu.cpp b/Library/ContextMenu.cpp index c7c055df..6c61a98c 100644 --- a/Library/ContextMenu.cpp +++ b/Library/ContextMenu.cpp @@ -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); diff --git a/Library/ContextMenu.h b/Library/ContextMenu.h index 98f5de74..79e1986d 100644 --- a/Library/ContextMenu.h +++ b/Library/ContextMenu.h @@ -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); } diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 34529735..42746f4c 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -980,6 +980,10 @@ void MeterWindow::DoBang(Bang bang, const std::vector& args) case Bang::SetOptionGroup: SetOption(args[0], args[1], args[2], true); break; + + case Bang::SkinCustomMenu: + Rainmeter::GetInstance().ShowSkinCustomContextMenu(System::GetCursorPosition(), this); + break; } } diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index 727f0932..c19caf6f 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -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; }