| e8555c89 Andy McCall |
1 |
#ifndef SETTINGSCONFIG_HH |
| 2 |
#define SETTINGSCONFIG_HH |
| 3 |
|
| 4 |
#include "Command.hh" |
| 5 |
#include "SettingsManager.hh" |
| 6 |
|
| 7 |
#include "hash_map.hh" |
| 8 |
#include "xxhash.hh" |
| 9 |
|
| 10 |
#include <string> |
| 11 |
#include <string_view> |
| 12 |
|
| 13 |
namespace openmsx { |
| 14 |
|
| 15 |
class FileContext; |
| 16 |
class HotKey; |
| 17 |
class GlobalCommandController; |
| 18 |
class CommandController; |
| 19 |
class Shortcuts; |
| 20 |
|
| 21 |
class SettingsConfig |
| 22 |
{ |
| 23 |
public: |
| 24 |
SettingsConfig(GlobalCommandController& globalCommandController, |
| 25 |
HotKey& hotKey, Shortcuts& shortcuts); |
| 26 |
~SettingsConfig(); |
| 27 |
|
| 28 |
void loadSetting(const FileContext& context, std::string_view filename); |
| 29 |
void saveSetting(std::string filename = {}); |
| 30 |
void setSaveSettings(bool save) { mustSaveSettings = save; } |
| 31 |
void setSaveFilename(const FileContext& context, std::string_view filename); |
| 32 |
|
| 33 |
[[nodiscard]] SettingsManager& getSettingsManager() { return settingsManager; } |
| 34 |
|
| 35 |
|
| 36 |
[[nodiscard]] const std::string* getValueForSetting(std::string_view setting) const; |
| 37 |
void setValueForSetting(std::string_view setting, std::string_view value); |
| 38 |
void removeValueForSetting(std::string_view setting); |
| 39 |
|
| 40 |
private: |
| 41 |
CommandController& commandController; |
| 42 |
|
| 43 |
struct SaveSettingsCommand final : Command { |
| 44 |
explicit SaveSettingsCommand(CommandController& commandController); |
| 45 |
void execute(std::span<const TclObject> tokens, TclObject& result) override; |
| 46 |
[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override; |
| 47 |
void tabCompletion(std::vector<std::string>& tokens) const override; |
| 48 |
} saveSettingsCommand; |
| 49 |
|
| 50 |
struct LoadSettingsCommand final : Command { |
| 51 |
explicit LoadSettingsCommand(CommandController& commandController); |
| 52 |
void execute(std::span<const TclObject> tokens, TclObject& result) override; |
| 53 |
[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override; |
| 54 |
void tabCompletion(std::vector<std::string>& tokens) const override; |
| 55 |
} loadSettingsCommand; |
| 56 |
|
| 57 |
SettingsManager settingsManager; |
| 58 |
hash_map<std::string, std::string, XXHasher> settingValues; |
| 59 |
HotKey& hotKey; |
| 60 |
Shortcuts& shortcuts; |
| 61 |
std::string saveName; |
| 62 |
bool mustSaveSettings = false; |
| 63 |
}; |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
#endif |