-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPresets.h
157 lines (119 loc) · 4 KB
/
Presets.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#ifndef __PRESETS_H
#define __PRESETS_H
#pragma warning(disable:327)
typedef OperationResult (*PresetExecutor)();
// Mapping of parameter names to existing variables
class CParameterSet {
public:
CParameterSet(PresetExecutor Executor, ...);
map<string, tstring *> m_mapStrings;
map<string, int *> m_mapInts;
map<string, bool *> m_mapBools;
PresetExecutor m_Executor;
};
class CParameterBackup {
public:
CParameterBackup(CParameterSet &Set, bool bAutoRestore = true);
void Restore();
~CParameterBackup();
map<string, tstring> m_mapStrings;
map<string, int> m_mapInts;
CParameterSet &m_Set;
bool m_bAutoRestore;
};
// Saveable mapping of parameter names to values
class CPreset {
public:
CPreset(CParameterSet &ParamSet);
CPreset(CParameterSet &ParamSet, const tstring &strName, CFarSettingsKey &hKey); // hKey is root key
void FillDefaults();
void CopyFrom(const CPreset &Preset);
OperationResult ExecutePreset();
virtual void Apply();
void FillMenuItem(CFarMenuItemEx &Item);
void Save(CFarSettingsKey &hKey, int nIndex);
tstring &Name() {return m_mapStrings[""];}
public:
int m_nID;
bool m_bAddToMenu;
map<string, tstring> m_mapStrings;
map<string, int> m_mapInts;
CParameterSet &m_ParamSet;
};
class CPresetCollection : public vector<CPreset *> {
public:
CPresetCollection(CParameterSet &ParamSet, const TCHAR *strKey, int nTitle);
void Load();
virtual ~CPresetCollection();
void Save();
int ShowMenu(bool bExecute, int nDefaultID = 0);
virtual CPreset *LoadPreset(const tstring &strName, CFarSettingsKey &hKey) = 0;
virtual CPreset *NewPreset() = 0;
virtual bool EditPreset(CPreset *pPreset) = 0;
virtual int ID() = 0; // For batches
CPreset *operator()(int nID);
void FillMenuItems(vector<CFarMenuItemEx> &MenuItems);
CPreset *FindMenuPreset(int &nIndex);
CPreset *FindMenuPreset(LPCTSTR szName);
const TCHAR *Name() {return m_strKey.c_str();}
const TCHAR *Title() {return GetMsg(m_nTitle);}
CParameterSet &m_ParamSet;
tstring m_strKey;
int m_nTitle;
protected:
int FindUnusedID();
void ValidateIDs();
size_t m_nCurrent;
};
template<class _Preset>
class CPresetCollectionT : public CPresetCollection
{
public:
CPresetCollectionT(CParameterSet &ParamSet, const TCHAR *strKey, int nTitle)
: CPresetCollection(ParamSet, strKey, nTitle) { Load(); }
virtual CPreset *LoadPreset(const tstring &strName, CFarSettingsKey &hKey) { return new _Preset(m_ParamSet, strName, hKey); }
virtual CPreset *NewPreset() { return new _Preset(m_ParamSet); }
};
typedef CPresetCollectionT<CPreset> CStdPresetCollection;
//////////////////////////////////////////////////////////////////////////
typedef pair<int, int> BatchActionIndex; // Collection and Preset IDs
extern const BatchActionIndex NO_BATCH_INDEX;
class CBatchType : public vector<CPresetCollection *> {
public:
CBatchType(int nTitle, ...);
CPresetCollection *operator()(int nCollID);
CPreset *operator[](const BatchActionIndex &Pair);
BatchActionIndex SelectPreset();
public:
int m_nTitle;
};
class CBatchAction : public vector<BatchActionIndex> { // Collection index and ID
public:
CBatchAction(CBatchType &Type);
CBatchAction(CBatchType &Type, tstring strName, CFarSettingsKey &hKey);
void Save(CFarSettingsKey &hKey, int nIndex);
bool EditProperties();
bool EditItems();
void Execute();
CFarMenuItemEx GetMenuItem();
bool m_bAddToMenu;
tstring m_strName;
protected:
CBatchType &m_Type;
class CBatchActionCollection *Collection();
size_t m_nCurrent;
};
class CBatchActionCollection : public vector<CBatchAction *> {
public:
CBatchActionCollection(CBatchType &Type, CFarSettingsKey &hKey); // CPresetCollection *
void Save(CFarSettingsKey &hKey);
void ShowMenu();
void FillMenuItems(vector<CFarMenuItemEx> &MenuItems);
CBatchAction *FindMenuAction(int &nIndex);
CBatchAction *FindMenuAction(LPCTSTR szName);
public:
CBatchType &m_Type;
protected:
size_t m_nCurrent;
};
#endif