From 904ba63af8d182ea8f5a00a6d45c3604d21eb92b Mon Sep 17 00:00:00 2001 From: olshevskiy87 Date: Sun, 22 Jun 2014 13:53:27 +0400 Subject: [PATCH] save and restore the settings of the search objects dialog --- pgadmin/dlg/dlgSearchObject.cpp | 70 +++++++++++++++++++++++++++++++++-- pgadmin/include/dlg/dlgSearchObject.h | 3 ++ 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/pgadmin/dlg/dlgSearchObject.cpp b/pgadmin/dlg/dlgSearchObject.cpp index 804fc2f..c65e850 100644 --- a/pgadmin/dlg/dlgSearchObject.cpp +++ b/pgadmin/dlg/dlgSearchObject.cpp @@ -144,8 +144,6 @@ dlgSearchObject::dlgSearchObject(frmMain *p, pgDatabase *db, pgObject *obj) cbType->Append(_("Collations")); } - cbType->SetSelection(0); - cbSchema->Clear(); cbSchema->Append(_("All schemas")); cbSchema->Append(_("My schemas")); @@ -188,14 +186,77 @@ dlgSearchObject::dlgSearchObject(frmMain *p, pgDatabase *db, pgObject *obj) delete set; } - cbSchema->SetSelection(0); - + RestoreSettings(); txtPattern->SetFocus(); } dlgSearchObject::~dlgSearchObject() { + SavePosition(); +} + +void dlgSearchObject::SaveSettings() +{ + settings->Write(wxT("SearchObject/Pattern"), txtPattern->GetValue()); + settings->Write(wxT("SearchObject/Type"), aMap[cbType->GetValue()]); + settings->Write(wxT("SearchObject/Schema"), cbSchema->GetValue()); + settings->WriteBool(wxT("SearchObject/Names"), chkNames->GetValue()); + settings->WriteBool(wxT("SearchObject/Definitions"), chkDefinitions->GetValue()); + settings->WriteBool(wxT("SearchObject/Comments"), chkComments->GetValue()); +} + +wxString dlgSearchObject::getMapKeyByValue(wxString search_value) +{ + wxString key = wxEmptyString; + LngMapping::iterator it; + + for (it = aMap.begin(); it != aMap.end(); ++it) + { + if (search_value.IsSameAs(it->second)) + { + key = it->first; + break; + } + } + return key; +} + +void dlgSearchObject::RestoreSettings() +{ + wxString val, mapkey; + bool bVal; + + // Pattern + settings->Read(wxT("SearchObject/Pattern"), &val, wxEmptyString); + txtPattern->SetValue(val); + + // Type + settings->Read(wxT("SearchObject/Type"), &val, wxT("All types")); + mapkey = getMapKeyByValue(val); + if (cbType->FindString(mapkey, true) == wxNOT_FOUND) + cbType->SetValue(getMapKeyByValue(wxT("All types"))); + else + cbType->SetValue(mapkey); + + // Schema + settings->Read(wxT("SearchObject/Schema"), &val, wxT("All schemas")); + if (cbSchema->FindString(val, true) == wxNOT_FOUND) + cbSchema->SetValue(wxT("All schemas")); + else + cbSchema->SetValue(val); + + // names + settings->Read(wxT("SearchObject/Names"), &bVal, true); + chkNames->SetValue(bVal); + + // definitions + settings->Read(wxT("SearchObject/Definitions"), &bVal, false); + chkDefinitions->SetValue(bVal); + + // comments + settings->Read(wxT("SearchObject/Comments"), &bVal, false); + chkComments->SetValue(bVal); } void dlgSearchObject::OnHelp(wxCommandEvent &ev) @@ -840,6 +901,7 @@ wxString dlgSearchObject::TranslatePath(wxString &path) void dlgSearchObject::OnCancel(wxCommandEvent &ev) { + SaveSettings(); if (IsModal()) EndModal(wxID_CANCEL); else diff --git a/pgadmin/include/dlg/dlgSearchObject.h b/pgadmin/include/dlg/dlgSearchObject.h index 19d054a..231a1e2 100644 --- a/pgadmin/include/dlg/dlgSearchObject.h +++ b/pgadmin/include/dlg/dlgSearchObject.h @@ -31,7 +31,10 @@ private: void OnCancel(wxCommandEvent &ev); void OnChange(wxCommandEvent &ev); void OnSelSearchResult(wxListEvent &ev); + void SaveSettings(); + void RestoreSettings(); wxString TranslatePath(wxString &path); + wxString getMapKeyByValue(wxString); void ToggleBtnSearch(bool enable); WX_DECLARE_STRING_HASH_MAP(wxString, LngMapping); LngMapping aMap; -- 1.8.3.msysgit.0