diff --git a/ctl/ctlGitPanel.cpp b/ctl/ctlGitPanel.cpp index 444b13a..1730eab 100644 --- a/ctl/ctlGitPanel.cpp +++ b/ctl/ctlGitPanel.cpp @@ -31,7 +31,7 @@ enum #if !defined(NO_WXJSON_GIT) - +#if wxUSE_WEBREQUEST ctlGitPanel::ctlGitPanel(wxWindow* parent, frmMain* form, wxJSONValue cf) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize) { @@ -1113,3 +1113,4 @@ void ctlGitPanel::OnNotebookPageChanged(wxBookCtrlEvent& event) } #endif +#endif \ No newline at end of file diff --git a/frm/frmMain.cpp b/frm/frmMain.cpp index 532b091..5fd93e2 100644 --- a/frm/frmMain.cpp +++ b/frm/frmMain.cpp @@ -176,11 +176,13 @@ frmMain::frmMain(const wxString &title) dependencies = new ctlListView(listViews, CTL_DEPVIEW, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER); dependents = new ctlListView(listViews, CTL_REFVIEW, wxDefaultPosition, wxDefaultSize, wxSIMPLE_BORDER); #if !defined(NO_WXJSON_GIT) +#if wxUSE_WEBREQUEST git = NULL; wxJSONValue cfg=ctlGitPanel::GetConfig(); if (!cfg.IsNull()) git = new ctlGitPanel(listViews, this,cfg); #endif +#endif // Switch back to the native list control. @@ -193,10 +195,11 @@ frmMain::frmMain(const wxString &title) listViews->AddPage(dependencies, _("Dependencies")); // NBP_DEPENDENCIES listViews->AddPage(dependents, _("Dependents")); // NBP_DEPENDENTS #if !defined(NO_WXJSON_GIT) - +#if wxUSE_WEBREQUEST if (git) { listViews->AddPage(git, _("Git")); // } +#endif #endif properties->SetImageList(imageList, wxIMAGE_LIST_SMALL); statistics->SetImageList(imageList, wxIMAGE_LIST_SMALL); @@ -879,14 +882,15 @@ void frmMain::ShowObjStatistics(pgObject *data, wxWindow *ctrl) dependents->Thaw(); } #if !defined(NO_WXJSON_GIT) - +#if wxUSE_WEBREQUEST if ((!ctrl && git && git->IsShownOnScreen()) || ctrl == git) { //data->ShowDependents(this, dependents); if (git && data) git->ShowPage(data); } -#endif +#endif +#endif } diff --git a/include/frm/frmMain.h b/include/frm/frmMain.h index 1a94ad5..685e375 100644 --- a/include/frm/frmMain.h +++ b/include/frm/frmMain.h @@ -215,7 +215,9 @@ private: ctlListView *statistics; ctlListView *dependents, *dependencies; #if !defined(NO_WXJSON_GIT) +#if wxUSE_WEBREQUEST ctlGitPanel* git; +#endif #endif FunctionPGHelper hhelp; ctlAuiNotebook *listViews; diff --git a/include/utils/json/json_defs.h b/include/utils/json/json_defs.h index 9b2585d..648d9ff 100644 --- a/include/utils/json/json_defs.h +++ b/include/utils/json/json_defs.h @@ -7,8 +7,6 @@ // Copyright: (c) 2007 Luciano Cattani // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// -#if !defined(NO_WXJSON_GIT) - #ifndef _WX_JSON_DEFS_H_ #define _WX_JSON_DEFS_H_ @@ -205,6 +203,3 @@ #endif // _WX_JSON_DEFS_H_ - - -#endif \ No newline at end of file diff --git a/include/utils/json/jsonreader.h b/include/utils/json/jsonreader.h index 4e2371d..faf8296 100644 --- a/include/utils/json/jsonreader.h +++ b/include/utils/json/jsonreader.h @@ -7,15 +7,13 @@ // Copyright: (c) 2007 Luciano Cattani // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// -#if !defined(NO_WXJSON_GIT) - #include "pgAdmin3.h" #if !defined( _WX_JSONREADER_H ) #define _WX_JSONREADER_H #ifdef __GNUG__ -#pragma interface "jsonreader.h" +//#pragma interface "jsonreader.h" #endif // For compilers that support precompilation, includes "wx/wx.h". @@ -145,5 +143,4 @@ protected: #endif // not defined _WX_JSONREADER_H -#endif diff --git a/include/utils/json/jsonval.h b/include/utils/json/jsonval.h index 4eca663..f5f170d 100644 --- a/include/utils/json/jsonval.h +++ b/include/utils/json/jsonval.h @@ -7,13 +7,12 @@ // Copyright: (c) 2007 Luciano Cattani // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// -#if !defined(NO_WXJSON_GIT) #if !defined( _WX_JSONVAL_H ) #define _WX_JSONVAL_H #ifdef __GNUG__ -#pragma interface "jsonval.h" +//#pragma interface "jsonval.h" #endif // For compilers that support precompilation, includes "wx/wx.h". @@ -437,5 +436,4 @@ public: #endif // not defined _WX_JSONVAL_H -#endif diff --git a/include/utils/json/jsonwriter.h b/include/utils/json/jsonwriter.h index 35cfc1a..c50e7cf 100644 --- a/include/utils/json/jsonwriter.h +++ b/include/utils/json/jsonwriter.h @@ -7,7 +7,6 @@ // Copyright: (c) 2007 Luciano Cattani // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// -#if !defined(NO_WXJSON_GIT) #include "pgAdmin3.h" @@ -16,7 +15,7 @@ #define _WX_JSONWRITER_H #ifdef __GNUG__ -#pragma interface "jsonwriter.h" +//#pragma interface "jsonwriter.h" #endif // For compilers that support precompilation, includes "wx/wx.h". @@ -117,7 +116,6 @@ private: #endif // not defined _WX_JSONWRITER_H -#endif diff --git a/include/utils/sysSettings.h b/include/utils/sysSettings.h index 91f5d95..f5f570e 100644 --- a/include/utils/sysSettings.h +++ b/include/utils/sysSettings.h @@ -13,7 +13,7 @@ #define SYSSETTINGS_H #include "utils/sysLogger.h" - +#include "utils/json/jsonval.h" // wxWindows headers #include #include @@ -894,6 +894,10 @@ public: bool WriteBool(const wxString &key, bool value); bool WritePoint(const wxString &key, const wxPoint &value); bool WriteSize(const wxString &key, const wxSize &value); + bool WriteJsonObect(const wxString& key, wxJSONValue& value); + bool WriteJsonFile(); + bool ReloadJsonFileIfNeed(); + bool ReadJsonObect(const wxString& key, wxJSONValue& value, wxJSONValue& defvalue); bool WriteSizePoint(const wxString &key, const wxSize &size, const wxPoint &point) { WritePoint(key, point); @@ -934,6 +938,9 @@ private: wxFileConfig *defaultSettings; wxString appName; + wxJSONValue jsoncfg; + bool jsonchange = false; + wxDateTime jsonfilemod; }; #endif diff --git a/utils/json/jsonreader.cpp b/utils/json/jsonreader.cpp index d1f1e1c..dfca7d8 100644 --- a/utils/json/jsonreader.cpp +++ b/utils/json/jsonreader.cpp @@ -9,11 +9,11 @@ ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation "jsonreader.cpp" +//#pragma implementation "jsonreader.cpp" #endif #include "pgAdmin3.h" -#if !defined(NO_WXJSON_GIT) + #include #include @@ -2127,6 +2127,3 @@ wxJSONReader::DoStrto_ll(const wxString& str, wxUint64* ui64, wxChar* sign) } */ - - -#endif diff --git a/utils/json/jsonval.cpp b/utils/json/jsonval.cpp index c580d2e..744532e 100644 --- a/utils/json/jsonval.cpp +++ b/utils/json/jsonval.cpp @@ -8,11 +8,11 @@ // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation "jsonval.cpp" +//#pragma implementation "jsonval.cpp" #endif #include "pgAdmin3.h" -#if !defined(NO_WXJSON_GIT) + // For compilers that support precompilation, includes "wx.h". @@ -3554,4 +3554,4 @@ wxJSONValue::operator = (wxUint64 ui) } */ -#endif + diff --git a/utils/json/jsonwriter.cpp b/utils/json/jsonwriter.cpp index 766c0b2..737f084 100644 --- a/utils/json/jsonwriter.cpp +++ b/utils/json/jsonwriter.cpp @@ -8,12 +8,11 @@ // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation "jsonwriter.cpp" +//#pragma implementation "jsonwriter.cpp" #endif #include "pgAdmin3.h" -#if !defined(NO_WXJSON_GIT) #include #include @@ -1271,7 +1270,3 @@ wxJSONWriter::IsPunctuation(wxChar ch) } */ - - - -#endif diff --git a/utils/sysSettings.cpp b/utils/sysSettings.cpp index ab59629..11774b2 100644 --- a/utils/sysSettings.cpp +++ b/utils/sysSettings.cpp @@ -29,7 +29,10 @@ #include "utils/sysSettings.h" #include "utils/sysLogger.h" #include "utils/misc.h" -sysSettings::sysSettings(const wxString &name) : wxConfig(name) +#include "utils/json/jsonval.h" +#include "utils/json/jsonreader.h" +#include "utils/json/jsonwriter.h" +sysSettings::sysSettings(const wxString& name) : wxConfig(name) { appName = name; // Open the default settings file @@ -39,7 +42,6 @@ sysSettings::sysSettings(const wxString &name) : wxConfig(name) wxFileInputStream fst(settingsIni); defaultSettings = new wxFileConfig(fst); } - // Convert settings from pre-1.5 long i, serverCount; Read(wxT("Servers/Count"), &serverCount, 0L); @@ -75,6 +77,7 @@ sysSettings::~sysSettings() delete defaultSettings; defaultSettings = NULL; } + if (!jsoncfg.IsNull()) WriteJsonFile(); } bool sysSettings::GetDisplayOption(const wxString &objtype, bool GetDefault) @@ -453,6 +456,73 @@ bool sysSettings::WriteSize(const wxString &key, const wxSize &value) return rc; } +// Write a json object +bool sysSettings::WriteJsonObect(const wxString& key, wxJSONValue& value) +{ + //wxJSONValue d(wxJSONTYPE_OBJECT); + if (jsoncfg.IsNull()) jsoncfg.SetType(wxJSONTYPE_OBJECT); + jsoncfg[key] = value; + //value =jsoncfg.Get(key,d); + jsonchange = true; + return true; +} +bool sysSettings::ReloadJsonFileIfNeed() { + wxString path = wxStandardPaths::Get().GetUserConfigDir() + sepPath + "postgresql" + sepPath + "pgadmin3opt.json"; + if (wxFileExists(path)) { + wxDateTime fmod = wxFileName(path).GetModificationTime(); + if (!jsonfilemod.IsValid() || fmod != jsonfilemod) { + // load json file + wxFileInputStream input(path); + if (input.IsOk()) { + jsonchange = false; + wxJSONReader reader; + int errnum = reader.Parse(input, &jsoncfg); + if (errnum > 0) { + wxLogError("Parse json file %s errors. Number errors %d", path, errnum); + } + else { + jsonfilemod = fmod; + return true; + } + + } + + } + } + return false; +} +bool sysSettings::WriteJsonFile() +{ + if (!jsoncfg.IsNull() && jsonchange) { + //wxString s = jsoncfg.Dump(true, 0); + { + wxString p = wxStandardPaths::Get().GetUserConfigDir() + sepPath + "postgresql" + sepPath + "pgadmin3opt.json"; + { + wxFileOutputStream out(p); + if (out.IsOk()) { + wxJSONWriter writer(wxJSONWRITER_STYLED | wxJSONWRITER_WRITE_COMMENTS); + writer.Write(jsoncfg, out); + //writer.Write(jsoncfg, s); + out.Close(); + jsonchange = false; + return true; + } + } + } + } + return false; +} + +bool sysSettings::ReadJsonObect(const wxString& key, wxJSONValue& value, wxJSONValue& defvalue) +{ + if (jsoncfg.IsNull()|| (!jsoncfg.HasMember(key))) { + value = defvalue; + WriteJsonObect(key, defvalue); + return true; + } + value=jsoncfg.Get(key,defvalue); + return true; +} ////////////////////////////////////////////////////////////////////////// // Log