| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include <Common.h>
- #include "CustomWinConfiguration.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- //---------------------------------------------------------------------------
- class THistoryStrings : public TStringList
- {
- public:
- __fastcall THistoryStrings() : TStringList()
- {
- FModified = false;
- };
- __property bool Modified = { read = FModified, write = FModified };
- private:
- bool FModified;
- };
- //---------------------------------------------------------------------------
- __fastcall TCustomWinConfiguration::TCustomWinConfiguration():
- TGUIConfiguration()
- {
- FHistory = new TStringList();
- FEmptyHistory = new TStringList();
- }
- //---------------------------------------------------------------------------
- __fastcall TCustomWinConfiguration::~TCustomWinConfiguration()
- {
- ClearHistory();
- delete FHistory;
- delete FEmptyHistory;
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomWinConfiguration::ClearHistory()
- {
- assert(FHistory != NULL);
- THistoryStrings * HistoryStrings;
- for (int Index = 0; Index < FHistory->Count; Index++)
- {
- HistoryStrings = dynamic_cast<THistoryStrings *>(FHistory->Objects[Index]);
- FHistory->Objects[Index] = NULL;
- delete HistoryStrings;
- }
- FHistory->Clear();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomWinConfiguration::Default()
- {
- TGUIConfiguration::Default();
- FShowAdvancedLoginOptions = false;
- FInterface = ifCommander;
- FLogView = lvNone;
- ClearHistory();
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomWinConfiguration::ModifyAll()
- {
- TGUIConfiguration::ModifyAll();
- THistoryStrings * HistoryStrings;
- for (int Index = 0; Index < FHistory->Count; Index++)
- {
- HistoryStrings = dynamic_cast<THistoryStrings *>(FHistory->Objects[Index]);
- assert(HistoryStrings != NULL);
- HistoryStrings->Modified = false;
- }
- }
- //---------------------------------------------------------------------------
- // duplicated from core\configuration.cpp
- #define LASTELEM(ELEM) \
- ELEM.SubString(ELEM.LastDelimiter(".>")+1, ELEM.Length() - ELEM.LastDelimiter(".>"))
- #define BLOCK(KEY, CANCREATE, BLOCK) \
- if (Storage->OpenSubKey(KEY, CANCREATE)) try { BLOCK } __finally { Storage->CloseSubKey(); }
- #define REGCONFIG(CANCREATE) \
- BLOCK("Interface", CANCREATE, \
- KEY(Integer, Interface); \
- KEY(Bool, ShowAdvancedLoginOptions); \
- ) \
- BLOCK("Logging", CANCREATE, \
- KEY(Integer, LogView); \
- );
- //---------------------------------------------------------------------------
- void __fastcall TCustomWinConfiguration::SaveSpecial(
- THierarchicalStorage * Storage)
- {
- TGUIConfiguration::SaveSpecial(Storage);
- // duplicated from core\configuration.cpp
- #define KEY(TYPE, VAR) Storage->Write ## TYPE(LASTELEM(AnsiString(#VAR)), VAR)
- REGCONFIG(true);
- #undef KEY
- if ((FHistory->Count > 0) && Storage->OpenSubKey("History", true))
- {
- try
- {
- THistoryStrings * HistoryStrings;
- for (int Index = 0; Index < FHistory->Count; Index++)
- {
- HistoryStrings = dynamic_cast<THistoryStrings *>(FHistory->Objects[Index]);
- assert(HistoryStrings != NULL);
- if (HistoryStrings->Modified)
- {
- if (Storage->OpenSubKey(FHistory->Strings[Index], true))
- {
- try
- {
- Storage->WriteValues(HistoryStrings);
- HistoryStrings->Modified = false;
- }
- __finally
- {
- Storage->CloseSubKey();
- }
- }
- }
- }
- }
- __finally
- {
- Storage->CloseSubKey();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomWinConfiguration::LoadSpecial(
- THierarchicalStorage * Storage)
- {
- TGUIConfiguration::LoadSpecial(Storage);
- // duplicated from core\configuration.cpp
- #define KEY(TYPE, VAR) VAR = Storage->Read ## TYPE(LASTELEM(AnsiString(#VAR)), VAR)
- #pragma warn -eas
- REGCONFIG(false);
- #pragma warn +eas
- #undef KEY
- ClearHistory();
- TStrings * Names = NULL;
- if (Storage->OpenSubKey("History", false))
- {
- try
- {
- Names = new TStringList();
- Storage->GetSubKeyNames(Names);
- THistoryStrings * HistoryStrings;
- for (int Index = 0; Index < Names->Count; Index++)
- {
- HistoryStrings = NULL;
- if (Storage->OpenSubKey(Names->Strings[Index], false))
- {
- try
- {
- HistoryStrings = new THistoryStrings();
- Storage->ReadValues(HistoryStrings);
- FHistory->AddObject(Names->Strings[Index], HistoryStrings);
- HistoryStrings = NULL;
- }
- __finally
- {
- Storage->CloseSubKey();
- delete HistoryStrings;
- }
- }
- }
- }
- __finally
- {
- Storage->CloseSubKey();
- delete Names;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomWinConfiguration::SetShowAdvancedLoginOptions(bool value)
- {
- SET_CONFIG_PROPERTY(ShowAdvancedLoginOptions);
- }
- //---------------------------------------------------------------------
- void __fastcall TCustomWinConfiguration::SetLogView(TLogView value)
- {
- SET_CONFIG_PROPERTY(LogView);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomWinConfiguration::SetInterface(TInterface value)
- {
- SET_CONFIG_PROPERTY(Interface);
- }
- //---------------------------------------------------------------------------
- void __fastcall TCustomWinConfiguration::SetHistory(const AnsiString Index,
- TStrings * value)
- {
- int I = FHistory->IndexOf(Index);
- bool NonEmpty = (value != NULL) && (value->Count > 0);
- THistoryStrings * HistoryStrings = NULL;
- if (I >= 0)
- {
- HistoryStrings = dynamic_cast<THistoryStrings *>(FHistory->Objects[I]);
- if (HistoryStrings->Equals(value))
- {
- HistoryStrings = NULL;
- }
- }
- else if (NonEmpty)
- {
- HistoryStrings = new THistoryStrings();
- FHistory->AddObject(Index, HistoryStrings);
- }
- if (HistoryStrings != NULL)
- {
- if (NonEmpty)
- {
- HistoryStrings->Assign(value);
- while (HistoryStrings->Count > MaxHistoryCount)
- {
- HistoryStrings->Delete(HistoryStrings->Count - 1);
- }
- }
- else
- {
- HistoryStrings->Clear();
- }
- HistoryStrings->Modified = true;
- }
- }
- //---------------------------------------------------------------------------
- TStrings * __fastcall TCustomWinConfiguration::GetHistory(const AnsiString Index)
- {
- int I = FHistory->IndexOf(Index);
- return I >= 0 ? dynamic_cast<TStrings *>(FHistory->Objects[I]) : FEmptyHistory;
- }
|