Skip to content

Commit

Permalink
[PowerRename][ImageResizer]Fallback for tier 1 menus (#19195)
Browse files Browse the repository at this point in the history
* [PowerRename][ImageResizer]fallback for tier 1 menus

* Simplify logic
  • Loading branch information
jaimecbernardo authored Jul 7, 2022
1 parent d4b62d8 commit e887b3b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ namespace ImageResizerConstants
// Name of the ImageResizer save folder.
inline const std::wstring ModuleOldSaveFolderKey = L"ImageResizer";
inline const std::wstring ModuleSaveFolderKey = L"Image Resizer";
inline const std::wstring ModulePackageDisplayName = L"ImageResizerContextMenu";
}
13 changes: 6 additions & 7 deletions src/modules/imageresizer/dll/ContextMenuHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "pch.h"
#include "ContextMenuHandler.h"
#include <ImageResizerConstants.h>

#include <Settings.h>
#include <trace.h>
Expand Down Expand Up @@ -63,17 +64,15 @@ HRESULT CContextMenuHandler::Initialize(_In_opt_ PCIDLIST_ABSOLUTE pidlFolder, _

HRESULT CContextMenuHandler::QueryContextMenu(_In_ HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
{
if (package::IsWin11OrGreater())
return E_FAIL;

if (uFlags & CMF_DEFAULTONLY)
{
return S_OK;
}

if (!CSettingsInstance().GetEnabled())
{
return E_FAIL;
}

if (package::IsWin11OrGreater() && package::IsPackageRegistered(ImageResizerConstants::ModulePackageDisplayName))
return E_FAIL;

// NB: We just check the first item. We could iterate through more if the first one doesn't meet the criteria
HDropIterator i(m_pdtobj);
i.First();
Expand Down
3 changes: 1 addition & 2 deletions src/modules/imageresizer/dll/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ class ImageResizerModule : public PowertoyModuleIface
std::wstring path = get_module_folderpath(g_hInst_imageResizer);
std::wstring packageUri = path + L"\\ImageResizerContextMenuPackage.msix";

std::wstring packageDisplayName{ L"ImageResizerContextMenu" };
if (!package::IsPackageRegistered(packageDisplayName))
if (!package::IsPackageRegistered(ImageResizerConstants::ModulePackageDisplayName))
{
package::RegisterSparsePackage(path, packageUri);
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/powerrename/dll/PowerRenameConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ namespace PowerRenameConstants
{
// Name of the powertoy module.
inline const std::wstring ModuleKey = L"PowerRename";
inline const std::wstring ModulePackageDisplayName = L"PowerRenameContextMenu";
}
27 changes: 8 additions & 19 deletions src/modules/powerrename/dll/PowerRenameExt.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "pch.h"
#include "PowerRenameExt.h"
#include "PowerRenameConstants.h"
#include <trace.h>
#include <Helpers.h>
#include <common/themes/icon_helpers.h>
Expand Down Expand Up @@ -64,29 +65,17 @@ HRESULT CPowerRenameMenu::QueryContextMenu(HMENU hMenu, UINT index, UINT uIDFirs
if (!CSettingsInstance().GetEnabled())
return E_FAIL;

// Win11 context menu can't distinguish between extended and default menu, so use this one
if (package::IsWin11OrGreater())
{
if (CSettingsInstance().GetExtendedContextMenuOnly() && (uFlags & CMF_EXTENDEDVERBS))
{
// continue
}
else
{
return E_FAIL;
}
}
else
{
// Check if we should only be on the extended context menu
if (CSettingsInstance().GetExtendedContextMenuOnly() && (!(uFlags & CMF_EXTENDEDVERBS)))
return E_FAIL;
}

// Check if at least one of the selected items is actually renamable.
if (!DataObjectContainsRenamableItem(m_spdo))
return E_FAIL;

if (package::IsWin11OrGreater() && package::IsPackageRegistered(PowerRenameConstants::ModulePackageDisplayName))
return E_FAIL;

// Check if we should only be on the extended context menu
if (CSettingsInstance().GetExtendedContextMenuOnly() && (!(uFlags & CMF_EXTENDEDVERBS)))
return E_FAIL;

HRESULT hr = E_UNEXPECTED;
if (m_spdo && !(uFlags & (CMF_DEFAULTONLY | CMF_VERBSONLY | CMF_OPTIMIZEFORINVOKE)))
{
Expand Down
3 changes: 1 addition & 2 deletions src/modules/powerrename/dll/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ class PowerRenameModule : public PowertoyModuleIface
std::wstring path = get_module_folderpath(g_hInst);
std::wstring packageUri = path + L"\\PowerRenameContextMenuPackage.msix";

std::wstring packageDisplayName{ L"PowerRenameContextMenu" };
if (!package::IsPackageRegistered(packageDisplayName))
if (!package::IsPackageRegistered(PowerRenameConstants::ModulePackageDisplayName))
{
package::RegisterSparsePackage(path, packageUri);
}
Expand Down

0 comments on commit e887b3b

Please sign in to comment.