From f0cf7723f1dc099ffa9ad4b75fa13f67076c3ffe Mon Sep 17 00:00:00 2001 From: lsv Date: Fri, 1 Jan 2021 14:20:08 +0500 Subject: [PATCH] Add context menu for statistic partition tables (PG12 only). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Для окна статистики секционированной таблицы добавлено контекстное меню. Статистика по секц. таблице работает с 12 версии --- frm/events.cpp | 78 +++++++++++++++++++++++++++++++++++++++++-- include/frm/frmMain.h | 4 ++- schema/pgObject.cpp | 2 +- 3 files changed, 79 insertions(+), 5 deletions(-) diff --git a/frm/events.cpp b/frm/events.cpp index 3c6973a..ef01865 100644 --- a/frm/events.cpp +++ b/frm/events.cpp @@ -64,7 +64,9 @@ BEGIN_EVENT_TABLE(frmMain, pgFrame) EVT_LIST_ITEM_SELECTED(CTL_PROPVIEW, frmMain::OnPropSelChanged) EVT_LIST_ITEM_ACTIVATED(CTL_PROPVIEW, frmMain::OnPropSelActivated) EVT_LIST_ITEM_RIGHT_CLICK(CTL_PROPVIEW, frmMain::OnPropRightClick) - EVT_LIST_ITEM_SELECTED(CTL_STATVIEW, frmMain::OnSelectItem) + EVT_LIST_ITEM_SELECTED(CTL_STATVIEW, frmMain::OnStatSelChanged) + EVT_LIST_ITEM_RIGHT_CLICK(CTL_STATVIEW, frmMain::OnStatRightClick) + // EVT_LIST_ITEM_SELECTED(CTL_STATVIEW, frmMain::OnSelectItem) EVT_LIST_ITEM_SELECTED(CTL_DEPVIEW, frmMain::OnSelectItem) EVT_LIST_ITEM_SELECTED(CTL_REFVIEW, frmMain::OnSelectItem) EVT_TREE_SEL_CHANGED(CTL_BROWSER, frmMain::OnTreeSelChanged) @@ -291,6 +293,76 @@ void frmMain::OnCheckAlive(wxCommandEvent &event) } +void frmMain::OnStatRightClick(wxListEvent& event) +{ + OnStatSelChanged(event); + + if (currentObject) + doPopup(statistics, event.GetPoint(), currentObject); +} +void frmMain::OnStatSelChanged(wxListEvent& event) +{ + if (statistics->GetSelectedItemCount() == 1) + { + int key = event.GetKeyCode(); + wxTreeItemId item = browser->GetSelection(); + if (item) + { + wxString table = statistics->GetItemText(event.GetIndex(), 0); + wxCookieType cookie; + wxTreeItemId idstop= browser->GetNextSibling(item); + if (!idstop.IsOk()) return; + //item = browser->GetFirstChild(item, cookie); + wxTreeItemId id = item; + wxString fn = ""; + while (id.IsOk()) { + pgObject* oo = ((pgObject*)browser->GetItemData(id)); + if (oo) { + pgaFactory* ff = oo->GetFactory(); + wxString typen = ff->GetTypeName(); + fn = oo->GetName(); + bool isChilds = typen == wxT("Tables") || typen == wxT("Partitions"); + if (typen == wxT("Table")|| typen == wxT("TABLE") && ((((pgTable*)oo)->GetIsPartitioned()))) isChilds = true; + if (fn == table) { + break; + } + if (browser->HasChildren(id) && ( isChilds) + ) + { + if (oo) oo->ShowTreeDetail(browser); + id = browser->GetFirstChild(id, cookie); + } + else + { + // Try a sibling of this or ancestor instead + wxTreeItemId p = id; + wxTreeItemId toFind; + do + { + toFind = browser->GetNextSibling(p); + p = browser->GetItemParent(p); + } while (p.IsOk() && !toFind.IsOk()); + id = toFind; + if (id == idstop) break; + } + + } + + } + if (id == idstop || !id.IsOk()) return; + + pgObject* data = browser->GetObject(id); + if (data ) + { + currentObject = data; + setDisplay(currentObject,0,0,false); + sqlPane->SetReadOnly(false); + sqlPane->SetText(currentObject->GetSql(browser)); + sqlPane->SetReadOnly(true); + } + } + } +} void frmMain::OnPropSelChanged(wxListEvent &event) { @@ -516,7 +588,7 @@ void frmMain::execSelChange(wxTreeItemId item, bool currentNode) } -void frmMain::setDisplay(pgObject *data, ctlListView *props, ctlSQLBox *sqlbox) +void frmMain::setDisplay(pgObject *data, ctlListView *props, ctlSQLBox *sqlbox, bool showtree) { pgServer *server = 0; @@ -539,7 +611,7 @@ void frmMain::setDisplay(pgObject *data, ctlListView *props, ctlSQLBox *sqlbox) else showTree = false; - if (showTree) + if (showTree && showtree) data->ShowTree(this, browser, props, sqlbox); if (sqlbox) diff --git a/include/frm/frmMain.h b/include/frm/frmMain.h index 1187370..8e3ade8 100644 --- a/include/frm/frmMain.h +++ b/include/frm/frmMain.h @@ -249,6 +249,8 @@ private: void OnAuiNotebookPageClose(wxAuiNotebookEvent &event); void OnContextMenu(wxCommandEvent &event); + void OnStatSelChanged(wxListEvent& event); + void OnStatRightClick(wxListEvent& event); void OnPageChange(wxAuiNotebookEvent &event); void OnPropSelChanged(wxListEvent &event); void OnPropSelActivated(wxListEvent &event); @@ -272,7 +274,7 @@ private: void ResetLists(); bool dropSingleObject(pgObject *data, bool updateFinal, bool cascaded); void doPopup(wxWindow *win, wxPoint point, pgObject *object); - void setDisplay(pgObject *data, ctlListView *props = 0, ctlSQLBox *sqlbox = 0); + void setDisplay(pgObject *data, ctlListView *props = 0, ctlSQLBox *sqlbox = 0, bool showtree=true); void RetrieveServers(); bool reportError(const wxString &error, const wxString &msgToIdentify, const wxString &hint); wxTreeItemId RestoreEnvironment(pgServer *server); diff --git a/schema/pgObject.cpp b/schema/pgObject.cpp index c4a2fb0..c91ea0e 100644 --- a/schema/pgObject.cpp +++ b/schema/pgObject.cpp @@ -239,7 +239,7 @@ void pgObject::ShowStatisticsTables(frmMain* form, ctlListView* statistics, pgOb ) tabcoll = true; if ( t == ("Partitions")) partcoll = true; } - else onetable = true; + else if (obj->GetConnection()->BackendMinimumVersion(12, 0)) onetable = true; bool hasSize = obj->GetConnection()->HasFeature(FEATURE_SIZE); // Add the statistics view columns