mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 10:16:24 +02:00
[File locksmith]Add setting to show only in extended context menu (#26711)
* [File Locksmith] Move File Locksmith "What's using this file?" into the extended context menu * [File Locksmith] Add FileLocksmithExt to directory background context menu * [File Locksmith] * Directory background right click crash fixed. *Settings added. * [File Locksmith] Remove uncessary things. * [File Locksmith] Spell check correction
This commit is contained in:
@@ -20,6 +20,9 @@ namespace constants::nonlocalizable
|
||||
// JSON key used to store whether the module is enabled
|
||||
constexpr WCHAR JsonKeyEnabled[] = L"Enabled";
|
||||
|
||||
// JSON key used to store extended menu enabled
|
||||
constexpr WCHAR JsonKeyShowInExtendedContextMenu[] = L"showInExtendedContextMenu";
|
||||
|
||||
// Path of the JSON file used to store settings
|
||||
constexpr WCHAR DataFilePath[] = L"\\file-locksmith-settings.json";
|
||||
|
||||
|
||||
@@ -69,14 +69,25 @@ IFACEMETHODIMP ExplorerCommand::GetCanonicalName(GUID* pguidCommandName)
|
||||
|
||||
IFACEMETHODIMP ExplorerCommand::GetState(IShellItemArray* psiItemArray, BOOL fOkToBeSlow, EXPCMDSTATE* pCmdState)
|
||||
{
|
||||
if (globals::enabled)
|
||||
{
|
||||
*pCmdState = ECS_ENABLED;
|
||||
}
|
||||
else
|
||||
if (!globals::enabled)
|
||||
{
|
||||
*pCmdState = ECS_HIDDEN;
|
||||
}
|
||||
|
||||
if (FileLocksmithSettingsInstance().GetShowInExtendedContextMenu())
|
||||
{
|
||||
*pCmdState = ECS_HIDDEN;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// When right clicking directory background, selection is empty.
|
||||
if (nullptr == psiItemArray)
|
||||
{
|
||||
*pCmdState = ECS_HIDDEN;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
*pCmdState = ECS_ENABLED;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -101,8 +112,16 @@ IFACEMETHODIMP ExplorerCommand::EnumSubCommands(IEnumExplorerCommand** ppEnum)
|
||||
|
||||
IFACEMETHODIMP ExplorerCommand::Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject* pdtobj, HKEY hkeyProgID)
|
||||
{
|
||||
m_data_obj = pdtobj;
|
||||
m_data_obj->AddRef();
|
||||
if (!FileLocksmithSettingsInstance().GetEnabled())
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
if (pdtobj)
|
||||
{
|
||||
m_data_obj = pdtobj;
|
||||
m_data_obj->AddRef();
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -116,6 +135,11 @@ IFACEMETHODIMP ExplorerCommand::QueryContextMenu(HMENU hmenu, UINT indexMenu, UI
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
if (FileLocksmithSettingsInstance().GetShowInExtendedContextMenu() && !(uFlags & CMF_EXTENDEDVERBS))
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT hr = E_UNEXPECTED;
|
||||
if (m_data_obj && !(uFlags & (CMF_DEFAULTONLY | CMF_VERBSONLY | CMF_OPTIMIZEFORINVOKE)))
|
||||
{
|
||||
|
||||
@@ -62,7 +62,8 @@ public:
|
||||
PowerToysSettings::PowerToyValues values =
|
||||
PowerToysSettings::PowerToyValues::from_json_string(config, get_key());
|
||||
|
||||
// Currently, there are no settings, so we don't do anything.
|
||||
toggle_extended_only(values.get_bool_value(L"bool_show_extended_menu").value());
|
||||
save_settings();
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
@@ -89,6 +90,18 @@ public:
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
virtual void toggle_extended_only(bool extended_only)
|
||||
{
|
||||
Logger::info(L"File Locksmith toggle extended only");
|
||||
m_extended_only = extended_only;
|
||||
save_settings();
|
||||
}
|
||||
|
||||
virtual bool is_extended_only()
|
||||
{
|
||||
return m_extended_only;
|
||||
}
|
||||
|
||||
virtual void destroy() override
|
||||
{
|
||||
delete this;
|
||||
@@ -96,10 +109,12 @@ public:
|
||||
|
||||
private:
|
||||
bool m_enabled;
|
||||
bool m_extended_only;
|
||||
|
||||
void init_settings()
|
||||
{
|
||||
m_enabled = FileLocksmithSettingsInstance().GetEnabled();
|
||||
m_extended_only = FileLocksmithSettingsInstance().GetShowInExtendedContextMenu();
|
||||
Trace::EnableFileLocksmith(m_enabled);
|
||||
}
|
||||
|
||||
@@ -107,6 +122,8 @@ private:
|
||||
{
|
||||
auto& settings = FileLocksmithSettingsInstance();
|
||||
settings.SetEnabled(m_enabled);
|
||||
settings.SetExtendedContextMenuOnly(m_extended_only);
|
||||
|
||||
settings.Save();
|
||||
Trace::EnableFileLocksmith(m_enabled);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ void FileLocksmithSettings::Save()
|
||||
json::JsonObject jsonData;
|
||||
|
||||
jsonData.SetNamedValue(constants::nonlocalizable::JsonKeyEnabled, json::value(settings.enabled));
|
||||
jsonData.SetNamedValue(constants::nonlocalizable::JsonKeyShowInExtendedContextMenu, json::value(settings.showInExtendedContextMenu));
|
||||
|
||||
json::to_file(jsonFilePath, jsonData);
|
||||
GetSystemTimeAsFileTime(&lastLoadedTime);
|
||||
@@ -70,6 +71,11 @@ void FileLocksmithSettings::ParseJson()
|
||||
{
|
||||
settings.enabled = jsonSettings.GetNamedBoolean(constants::nonlocalizable::JsonKeyEnabled);
|
||||
}
|
||||
|
||||
if (json::has(jsonSettings, constants::nonlocalizable::JsonKeyShowInExtendedContextMenu, json::JsonValueType::Boolean))
|
||||
{
|
||||
settings.showInExtendedContextMenu = jsonSettings.GetNamedBoolean(constants::nonlocalizable::JsonKeyShowInExtendedContextMenu);
|
||||
}
|
||||
}
|
||||
catch (const winrt::hresult_error&)
|
||||
{
|
||||
|
||||
@@ -25,6 +25,16 @@ public:
|
||||
Save();
|
||||
}
|
||||
|
||||
inline bool GetShowInExtendedContextMenu() const
|
||||
{
|
||||
return settings.showInExtendedContextMenu;
|
||||
}
|
||||
|
||||
inline void SetExtendedContextMenuOnly(bool extendedOnly)
|
||||
{
|
||||
settings.showInExtendedContextMenu = extendedOnly;
|
||||
}
|
||||
|
||||
void Save();
|
||||
void Load();
|
||||
|
||||
@@ -32,6 +42,7 @@ private:
|
||||
struct Settings
|
||||
{
|
||||
bool enabled{ true };
|
||||
bool showInExtendedContextMenu{ false };
|
||||
};
|
||||
|
||||
void Reload();
|
||||
|
||||
Reference in New Issue
Block a user