3232#include < wx/filefn.h>
3333#include < wx/filename.h>
3434
35- #define ADD_OBJ_IF_NOT_EXISTS (parent, objName ) \
36- if (!parent.hasNamedObject(objName)) { \
37- JSONItem obj = JSONItem::createObject (objName ); \
38- parent. append ( obj); \
35+ #define ADD_OBJ_IF_NOT_EXISTS (parent, objName ) \
36+ if (!( parent) .hasNamedObject(( objName))) { \
37+ JSONItem obj = JSONItem::createObject (); \
38+ ( parent). addProperty ((objName), obj); \
3939 }
4040
41- #define ADD_ARR_IF_NOT_EXISTS (parent, arrName ) \
42- if (!parent.hasNamedObject(arrName)) { \
43- JSONItem arr = JSONItem::createArray (arrName ); \
44- parent. append ( arr); \
41+ #define ADD_ARR_IF_NOT_EXISTS (parent, arrName ) \
42+ if (!( parent) .hasNamedObject(( arrName))) { \
43+ JSONItem arr = JSONItem::createArray (); \
44+ ( parent). addProperty ((arrName), arr); \
4545 }
4646
4747namespace
@@ -115,10 +115,10 @@ void clConfig::SetOutputTabOrder(const wxArrayString& tabs, int selected)
115115 DoDeleteProperty (" outputTabOrder" );
116116
117117 // first time
118- JSONItem e = JSONItem::createObject (" outputTabOrder " );
118+ JSONItem e = JSONItem::createObject ();
119119 e.addProperty (" tabs" , tabs);
120120 e.addProperty (" selected" , selected);
121- m_root->toElement ().append ( e);
121+ m_root->toElement ().addProperty ( " outputTabOrder " , e);
122122 m_root->save (m_filename);
123123}
124124
@@ -138,10 +138,10 @@ void clConfig::SetWorkspaceTabOrder(const wxArrayString& tabs, int selected)
138138 DoDeleteProperty (" workspaceTabOrder" );
139139
140140 // first time
141- JSONItem e = JSONItem::createObject (" workspaceTabOrder " );
141+ JSONItem e = JSONItem::createObject ();
142142 e.addProperty (" tabs" , tabs);
143143 e.addProperty (" selected" , selected);
144- m_root->toElement ().append ( e);
144+ m_root->toElement ().addProperty ( " workspaceTabOrder " , e);
145145
146146 m_root->save (m_filename);
147147}
@@ -173,8 +173,7 @@ bool clConfig::Write(const wxString& name, std::function<JSONItem()> serialiser_
173173 } else {
174174 // add it to the global configuration file
175175 DoDeleteProperty (name);
176- item.SetPropertyName (name);
177- m_root->toElement ().append (item);
176+ m_root->toElement ().addProperty (name, item);
178177 return true ;
179178 }
180179}
@@ -263,10 +262,7 @@ void clConfig::Save(const wxFileName& fn)
263262
264263JSONItem clConfig::GetGeneralSetting ()
265264{
266- if (!m_root->toElement ().hasNamedObject (" General" )) {
267- JSONItem general = JSONItem::createObject (" General" );
268- m_root->toElement ().append (general);
269- }
265+ ADD_OBJ_IF_NOT_EXISTS (m_root->toElement (), " General" )
270266 return m_root->toElement ().namedObject (" General" );
271267}
272268
@@ -342,10 +338,7 @@ int clConfig::GetAnnoyingDlgAnswer(const wxString& name, int defaultValue)
342338
343339void clConfig::SetAnnoyingDlgAnswer (const wxString& name, int value)
344340{
345- if (!m_root->toElement ().hasNamedObject (" AnnoyingDialogsAnswers" )) {
346- JSONItem element = JSONItem::createObject (" AnnoyingDialogsAnswers" );
347- m_root->toElement ().append (element);
348- }
341+ ADD_OBJ_IF_NOT_EXISTS (m_root->toElement (), " AnnoyingDialogsAnswers" )
349342
350343 JSONItem element = m_root->toElement ().namedObject (" AnnoyingDialogsAnswers" );
351344 if (element.hasNamedObject (name)) {
@@ -524,14 +517,13 @@ wxFont clConfig::Read(const wxString& name, const wxFont& defaultValue)
524517
525518void clConfig::Write (const wxString& name, const wxFont& value)
526519{
527- JSONItem font = JSONItem::createObject (name);
528- font.addProperty (" fontDesc" , FontUtils::GetFontInfo (value));
529-
530520 JSONItem general = GetGeneralSetting ();
531521 if (general.hasNamedObject (name)) {
532522 general.removeProperty (name);
533523 }
534- general.append (font);
524+ JSONItem font = JSONItem::createObject ();
525+ font.addProperty (" fontDesc" , FontUtils::GetFontInfo (value));
526+ general.addProperty (name, font);
535527 Save ();
536528}
537529
0 commit comments