5#include "Stroika/Foundation/StroikaPreComp.h"
10#include "Stroika/Foundation/Execution/ModuleGetterSetter.h"
21using namespace Stroika::Frameworks::Led;
25using SearchParameters = TextInteractor::SearchParameters;
26#if qSupportSyntaxColoring
27using SyntaxColoringOption = Options::SyntaxColoringOption;
33 SearchParameters fSearchParameters{};
34 bool fSmartCutAndPaste{
true};
35 bool fAutoIndent{
true};
36 bool fTabsAutoShiftsText{
true};
37#if qSupportSyntaxColoring
38 SyntaxColoringOption fSyntaxColoring{SyntaxColoringOption::eSyntaxColoringNone};
40#if qStroika_Foundation_Common_Platform_Windows
41 bool fCheckFileAssocAtStartup{
true};
42 BLOB fDefaultNewDocFont;
46 struct Options_Storage_IMPL_ {
47 Options_Storage_IMPL_ ()
48 : fOptionsFile_{L
"AppSettings"sv,
56 Led_tString* intoObj) ->
void { *intoObj = d.
As<
String> ().As<Led_tString> (); });
57 mapper.AddCommonType<vector<Led_tString>> ();
60#if qSupportSyntaxColoring
61 mapper.AddCommonType<SyntaxColoringOption> ();
64 mapper.AddClass<SearchParameters> ({
65 {L
"Match-String", &SearchParameters::fMatchString},
66 {L
"Wrap-Search", &SearchParameters::fWrapSearch},
67 {L
"Whole-Word-Search", &SearchParameters::fWholeWordSearch},
68 {L
"Case-Sensative-Search", &SearchParameters::fCaseSensativeSearch},
69 {L
"Recent-Match-Strings", &SearchParameters::fRecentFindStrings},
72 mapper.AddClass<Options_> ({
73 {L
"Dock-Bar-State", &Options_::fDockBarState},
74 {L
"Search-Parameters", &Options_::fSearchParameters},
75 {L
"Smart-Cut-And-Paste", &Options_::fSmartCutAndPaste},
76 {L
"Auto-Indent", &Options_::fAutoIndent},
77 {L
"Tabs-Auto-Shifts-Text", &Options_::fTabsAutoShiftsText},
79#if qSupportSyntaxColoring
80 {L
"Syntax-Coloring", &Options_::fSyntaxColoring},
83#if qStroika_Foundation_Common_Platform_Windows
84 {L
"Check-File-Assoc-At-Startup", &Options_::fCheckFileAssocAtStartup},
85 {L
"Default-New-Doc-Font", &Options_::fDefaultNewDocFont},
93 OptionsFile::mkFilenameMapper (L
"LedLineIt"sv)}
94 , fActualCurrentConfigData_{fOptionsFile_.Read<Options_> (Options_{})}
96 Set (fActualCurrentConfigData_);
100 return fActualCurrentConfigData_;
102 void Set (
const Options_& v)
104 fActualCurrentConfigData_ = v;
105 fOptionsFile_.Write (v);
110 Options_ fActualCurrentConfigData_;
121SearchParameters Options::GetSearchParameters ()
const
123 return sOptions_.
Get ().fSearchParameters;
126void Options::SetSearchParameters (
const SearchParameters& searchParameters)
128 sOptions_.Update ([=] (Options_ d) {
129 d.fSearchParameters = searchParameters;
134#if qStroika_Foundation_Common_Platform_Windows
135const CDockState& Options::GetDocBarState ()
const
137 static CDockState dockState;
138 static std::once_flag sOnce_;
139 std::call_once (sOnce_, [] () {
141 BLOB bytes = sOptions_.Get ().fDockBarState;
142 if (not bytes.
empty ()) {
144 file.Write (Traversal::Iterator2Pointer (bytes.begin ()), static_cast<UINT> (bytes.size ()));
146 CArchive ar (&file, CArchive::load);
147 dockState.Serialize (ar);
154void Options::SetDocBarState (
const CDockState& dockState)
157 CArchive ar (&file, CArchive::store);
158 CDockState& ds =
const_cast<CDockState&
> (dockState);
161 ULONG nSize =
static_cast<ULONG
> (file.GetLength ());
162 ASSERT (nSize < 4096);
163 byte* p =
new byte[nSize];
165 file.Read (p, nSize);
166 sOptions_.Update ([=] (Options_ d) {
167 d.fDockBarState =
BLOB{p, p + nSize};
174bool Options::GetSmartCutAndPaste ()
const
176 return sOptions_.Get ().fSmartCutAndPaste;
179void Options::SetSmartCutAndPaste (
bool smartCutAndPaste)
181 sOptions_.Update ([=] (Options_ d) {
182 d.fSmartCutAndPaste = smartCutAndPaste;
187bool Options::GetAutoIndent ()
const
189 return sOptions_.Get ().fAutoIndent;
192void Options::SetAutoIndent (
bool autoIndent)
194 sOptions_.Update ([=] (Options_ d) {
195 d.fAutoIndent = autoIndent;
200bool Options::GetTreatTabAsIndentChar ()
const
202 return sOptions_.Get ().fTabsAutoShiftsText;
205void Options::SetTreatTabAsIndentChar (
bool tabAsIndentChar)
207 sOptions_.Update ([=] (Options_ d) {
208 d.fTabsAutoShiftsText = tabAsIndentChar;
213#if qSupportSyntaxColoring
214Options::SyntaxColoringOption Options::GetSyntaxColoringOption ()
const
216 return sOptions_.Get ().fSyntaxColoring;
219void Options::SetSyntaxColoringOption (SyntaxColoringOption syntaxColoringOption)
221 sOptions_.Update ([=] (Options_ d) {
222 d.fSyntaxColoring = syntaxColoringOption;
228#if qStroika_Foundation_Common_Platform_Windows
229bool Options::GetCheckFileAssocsAtStartup ()
const
231 return sOptions_.Get ().fCheckFileAssocAtStartup;
234void Options::SetCheckFileAssocsAtStartup (
bool checkFileAssocsAtStartup)
236 sOptions_.Update ([=] (Options_ d) {
237 d.fCheckFileAssocAtStartup = checkFileAssocsAtStartup;
245#if qStroika_Foundation_Common_Platform_Windows
246 BLOB bytes = sOptions_.Get ().fDefaultNewDocFont;
247 if (not bytes.
empty ()) {
248 if (bytes.
size () == sizeof (LOGFONT)) {
250 fsp.SetOSRep (bytes.
As<LOGFONT> ());
260 defFont.SetFontName (_T (
"Courier New"));
261 defFont.SetPointSize (10);
265void Options::SetDefaultNewDocFont ([[maybe_unused]]
const FontSpecification& defaultNewDocFont)
267#if qStroika_Foundation_Common_Platform_Windows
268 sOptions_.Update ([&] (Options_ d) {
269 d.fDefaultNewDocFont =
BLOB::FromRaw (defaultNewDocFont.GetOSRep ());
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Set<T> is a container of T, where once an item is added, additionally adds () do nothing.
ObjectVariantMapper can be used to map C++ types to and from variant-union types, which can be transp...
nonvirtual void Add(const TypeMappingDetails &s)
static const ModuleDataUpgraderType kDefaultUpgrader
Simple variant-value (case variant union) object, with (variant) basic types analogous to a value in ...
nonvirtual bool empty() const
static BLOB FromRaw(const T *s, const T *e)
Convert pointed to/referenced data to BLOB (treating the argument as raw bytes).
nonvirtual size_t size() const
Helper to define synchronized, lazy constructed, module initialization (intended to work with DataExc...