mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-11 05:52:19 +02:00
Migrate power rename MRU lists from registry to JSON (#2090)
* Handle most recently used search/replace strings within settings. * Check for last modified time of json file and reload it if needed. * Handle changes in MRU search / replace lists size. * Improve handling of changes in MRU list size. * Don't check for last modified time in every getter method. Load only when starting application. * Add const identifier to getter methods. * Address PR comments: Add const to reg and json file paths and set them in constructor initializer. Check pushIdx validity. Move implementation to cpp of PowerRenameUI constructor. * Add error checking when getting values from registry.
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
|
||||
#include "json.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class CSettings
|
||||
{
|
||||
public:
|
||||
@@ -11,9 +9,17 @@ public:
|
||||
|
||||
CSettings();
|
||||
|
||||
bool GetEnabled();
|
||||
inline bool GetEnabled()
|
||||
{
|
||||
Reload();
|
||||
return settings.enabled;
|
||||
}
|
||||
|
||||
void SetEnabled(bool enabled);
|
||||
inline void SetEnabled(bool enabled)
|
||||
{
|
||||
settings.enabled = enabled;
|
||||
Save();
|
||||
}
|
||||
|
||||
inline bool GetShowIconOnMenu() const
|
||||
{
|
||||
@@ -73,6 +79,7 @@ public:
|
||||
inline void SetFlags(long flags)
|
||||
{
|
||||
settings.flags = flags;
|
||||
Save();
|
||||
}
|
||||
|
||||
inline const std::wstring& GetSearchText() const
|
||||
@@ -83,6 +90,7 @@ public:
|
||||
inline void SetSearchText(const std::wstring& text)
|
||||
{
|
||||
settings.searchText = text;
|
||||
Save();
|
||||
}
|
||||
|
||||
inline const std::wstring& GetReplaceText() const
|
||||
@@ -93,14 +101,16 @@ public:
|
||||
inline void SetReplaceText(const std::wstring& text)
|
||||
{
|
||||
settings.replaceText = text;
|
||||
Save();
|
||||
}
|
||||
|
||||
void LoadPowerRenameData();
|
||||
void SavePowerRenameData() const;
|
||||
void Save();
|
||||
void Load();
|
||||
|
||||
private:
|
||||
struct Settings
|
||||
{
|
||||
bool enabled{ true };
|
||||
bool showIconOnMenu{ true };
|
||||
bool extendedContextMenuOnly{ false }; // Disabled by default.
|
||||
bool persistState{ true };
|
||||
@@ -111,11 +121,13 @@ private:
|
||||
std::wstring replaceText{};
|
||||
};
|
||||
|
||||
void MigrateSettingsFromRegistry();
|
||||
void ParseJsonSettings();
|
||||
void Reload();
|
||||
void MigrateFromRegistry();
|
||||
void ParseJson();
|
||||
|
||||
Settings settings;
|
||||
std::wstring jsonFilePath;
|
||||
FILETIME lastLoadedTime;
|
||||
};
|
||||
|
||||
CSettings& CSettingsInstance();
|
||||
|
||||
Reference in New Issue
Block a user