PowerToys/src/modules/powerrename/lib/Settings.h

147 lines
3 KiB
C
Raw Normal View History

#pragma once
#include <common/utils/json.h>
class CSettings
{
public:
CSettings();
inline bool GetEnabled()
{
Reload();
return settings.enabled;
}
inline void SetEnabled(bool enabled)
{
settings.enabled = enabled;
Save();
}
inline bool GetShowIconOnMenu() const
{
return settings.showIconOnMenu;
}
inline void SetShowIconOnMenu(bool show)
{
settings.showIconOnMenu = show;
}
inline bool GetExtendedContextMenuOnly() const
{
return settings.extendedContextMenuOnly;
}
inline void SetExtendedContextMenuOnly(bool extendedOnly)
{
settings.extendedContextMenuOnly = extendedOnly;
}
inline bool GetPersistState() const
{
return settings.persistState;
}
inline void SetPersistState(bool persistState)
{
settings.persistState = persistState;
}
PowerRename: Add Lookbehind (#7571) * Add boost-regex library * If enabled use boost lib for regex Add property `_useBoostLib` to `CPowerRenameRegEx`. If enabled for replacements with regular expressions the Boost Library is used instead of the Standard Library. * Extend signatures to create RegEx with Boost Extend create and constructor singatures of `CPowerRenameRegEx` with an option to enable (or disabled, which is default) the Boost Library. * Verify Lookbehind fails with STD library To verify that the boost library is disabled as expected, check if a lookbehind fails. * Add Unit tests for RegEx with Boost Add unit tests to verify regex replacement with Boost Library. They are copied and adapted from the Standard Library tests. * Improve verify capturing groups test with Boost It is possible to use a capturing group followed by numbers as replacement if the group number is enclosed in curly braces. Added test cases based on the Standard Library tests. * Add useBoostLib to settings interface * Get library option from settings object * Reduce signatures of RegEx by "useBoost" Remove the parameter added in 19105cf, as it became obsolete. * Settings: Read useBoostLib from JSON file * Add UseBoostLib Option to UI * Boost Lib label states the regex syntax difference * Fix Regex with Boost Lib tests - Do not load settings another time in CPowerRenameRegEx ctor - Set flag correctly in standard library regex tests * Add "lookbehind" to dictionary * change Library to lowercase, and also add a comment As suggested by @enricogior. Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com> * Change Library to lowercase and add a comment As suggested by @enricogior. Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com>
2020-11-09 19:13:43 +01:00
inline bool GetUseBoostLib() const
{
return settings.useBoostLib;
}
inline void SetUseBoostLib(bool useBoostLib)
{
settings.useBoostLib = useBoostLib;
}
inline bool GetMRUEnabled() const
{
return settings.MRUEnabled;
}
inline void SetMRUEnabled(bool MRUEnabled)
{
settings.MRUEnabled = MRUEnabled;
}
inline unsigned int GetMaxMRUSize() const
{
return settings.maxMRUSize;
}
inline void SetMaxMRUSize(unsigned int maxMRUSize)
{
settings.maxMRUSize = maxMRUSize;
}
inline unsigned int GetFlags() const
{
return settings.flags;
}
inline void SetFlags(unsigned int flags)
{
settings.flags = flags;
WriteFlags();
}
inline const std::wstring& GetSearchText() const
{
return settings.searchText;
}
inline void SetSearchText(const std::wstring& text)
{
settings.searchText = text;
Save();
}
inline const std::wstring& GetReplaceText() const
{
return settings.replaceText;
}
inline void SetReplaceText(const std::wstring& text)
{
settings.replaceText = text;
Save();
}
void Save();
void Load();
private:
struct Settings
{
bool enabled{ true };
bool showIconOnMenu{ true };
bool extendedContextMenuOnly{ false }; // Disabled by default.
bool persistState{ true };
PowerRename: Add Lookbehind (#7571) * Add boost-regex library * If enabled use boost lib for regex Add property `_useBoostLib` to `CPowerRenameRegEx`. If enabled for replacements with regular expressions the Boost Library is used instead of the Standard Library. * Extend signatures to create RegEx with Boost Extend create and constructor singatures of `CPowerRenameRegEx` with an option to enable (or disabled, which is default) the Boost Library. * Verify Lookbehind fails with STD library To verify that the boost library is disabled as expected, check if a lookbehind fails. * Add Unit tests for RegEx with Boost Add unit tests to verify regex replacement with Boost Library. They are copied and adapted from the Standard Library tests. * Improve verify capturing groups test with Boost It is possible to use a capturing group followed by numbers as replacement if the group number is enclosed in curly braces. Added test cases based on the Standard Library tests. * Add useBoostLib to settings interface * Get library option from settings object * Reduce signatures of RegEx by "useBoost" Remove the parameter added in 19105cf, as it became obsolete. * Settings: Read useBoostLib from JSON file * Add UseBoostLib Option to UI * Boost Lib label states the regex syntax difference * Fix Regex with Boost Lib tests - Do not load settings another time in CPowerRenameRegEx ctor - Set flag correctly in standard library regex tests * Add "lookbehind" to dictionary * change Library to lowercase, and also add a comment As suggested by @enricogior. Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com> * Change Library to lowercase and add a comment As suggested by @enricogior. Co-authored-by: Enrico Giordani <enricogior@users.noreply.github.com>
2020-11-09 19:13:43 +01:00
bool useBoostLib{ false }; // Disabled by default.
bool MRUEnabled{ true };
unsigned int maxMRUSize{ 10 };
unsigned int flags{ 0 };
std::wstring searchText{};
std::wstring replaceText{};
};
void Reload();
void MigrateFromRegistry();
void ParseJson();
void ReadFlags();
void WriteFlags();
Settings settings;
std::wstring jsonFilePath;
std::wstring UIFlagsFilePath;
FILETIME lastLoadedTime;
};
CSettings& CSettingsInstance();