From de9f725b137415b0aacd729bdc2db89d4a0d09eb Mon Sep 17 00:00:00 2001 From: lsv Date: Tue, 23 May 2023 09:15:51 +0500 Subject: [PATCH] Draw DBname in browse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Для улучшения наглядности и понимания в какой БД мы находимся в строке браузера объектов при выделении элемента будет напротив отображаться имя БД. Это поведение можно отключить в настройках. --- ctl/ctlTree.cpp | 52 +++++++++++++++++++++++++++++++++++-- frm/events.cpp | 3 ++- frm/frmOptions.cpp | 4 +++ include/ctl/ctlTree.h | 2 +- include/utils/sysSettings.h | 10 +++++++ ui/frmOptions.xrc | 8 ++++++ 6 files changed, 75 insertions(+), 4 deletions(-) diff --git a/ctl/ctlTree.cpp b/ctl/ctlTree.cpp index 88ecc3d..18b189d 100644 --- a/ctl/ctlTree.cpp +++ b/ctl/ctlTree.cpp @@ -171,6 +171,55 @@ wxTreeItemId ctlTree::GetVerticalItem(wxPoint& pt) { } return NULL; } +void ctlTree::DrawDbName(const wxTreeItemId& item) { + if (item && settings->GetVisibleDbNameTree()) { + wxRect r; + GetBoundingRect(item, r, false); + wxTreeItemId prev; + wxString name = ""; + pgObject* o = GetObject(item); + if (o) { + pgConn* conn = o->GetConnection(); + pgServer* s = o->GetServer(); + if (conn) + name = conn->GetName().BeforeFirst(' '); + if (name.IsEmpty()) { + return ; + } + wxColour c; + wxClientDC dc(this); + if (s) { + if (!(s->GetColour().IsEmpty())) { + c=s->GetColour(); + dc.SetBrush(wxBrush(c, wxSOLID)); + } else + dc.SetBrush(*wxYELLOW_BRUSH); + } +// pgServer* s = wxColour(server->GetColour(); + + wxRect orig; +// dc.SetBrush(*wxYELLOW_BRUSH); + dc.SetPen(*wxTRANSPARENT_PEN); + + wxString str = wxString::Format("%s", name); + wxSize sz = dc.GetTextExtent(str); + sz.SetWidth(sz.GetX() + 3); + r.SetWidth(sz.GetX() + 5); + orig = r; + orig.Deflate(2); + orig.SetLeft(orig.GetLeft() + (orig.GetWidth() - sz.GetWidth())); + orig.SetHeight(sz.GetHeight()); + orig.SetWidth(sz.GetWidth()); + dc.DrawRoundedRectangle(orig, 2); + + dc.DrawText(name, wxPoint(orig.x + 2, orig.y + 1)); + } + + //Update(); + //return; + } + +} void ctlTree::OnMouse(wxMouseEvent& event) { wxPoint pt = event.GetPosition(); @@ -193,7 +242,7 @@ void ctlTree::OnMouse(wxMouseEvent& event) //event.Skip(!GetEventHandler()->ProcessEvent(nevent)); return; } - + } else { if ((flags & wxTREE_HITTEST_ONITEMINDENT) == wxTREE_HITTEST_ONITEMINDENT && (item==GetSelection())) { @@ -234,7 +283,6 @@ void ctlTree::OnMouse(wxMouseEvent& event) return; } - } event.Skip(); diff --git a/frm/events.cpp b/frm/events.cpp index 159b515..44c9905 100644 --- a/frm/events.cpp +++ b/frm/events.cpp @@ -502,7 +502,7 @@ void frmMain::execSelChange(wxTreeItemId item, bool currentNode) ResetLists(); sqlPane->Clear(); } - + // Get the item data, and feed it to the relevant handler, // cast as required. // @@ -596,6 +596,7 @@ void frmMain::execSelChange(wxTreeItemId item, bool currentNode) else setDisplay(currentObject, 0, 0); } + browser->DrawDbName(item); } diff --git a/frm/frmOptions.cpp b/frm/frmOptions.cpp index 833281f..9cb276e 100644 --- a/frm/frmOptions.cpp +++ b/frm/frmOptions.cpp @@ -77,6 +77,7 @@ #define chkAskSaveConfirm CTRL_CHECKBOX("chkAskSaveConfirm") #define chkAskDelete CTRL_CHECKBOX("chkAskDelete") #define chkShowUsersForPrivileges CTRL_CHECKBOX("chkShowUsersForPrivileges") +#define chkShowDBnameTree CTRL_CHECKBOX("chkShowDBnameTree") #define txtAutoRowCount CTRL_TEXT("txtAutoRowCount") #define txtIndent CTRL_TEXT("txtIndent") #define chkSpacesForTabs CTRL_CHECKBOX("chkSpacesForTabs") @@ -293,6 +294,7 @@ frmOptions::frmOptions(frmMain *parent) chkAskDelete->SetValue(settings->GetConfirmDelete()); chkShowUsersForPrivileges->SetValue(settings->GetShowUsersForPrivileges()); txtAutoRowCount->SetValue(NumToStr(settings->GetAutoRowCountThreshold())); + chkShowDBnameTree->SetValue(settings->GetVisibleDbNameTree()); txtIndent->SetValue(NumToStr(settings->GetIndentSpaces())); chkSpacesForTabs->SetValue(settings->GetSpacesForTabs()); cbCopyQuote->SetSelection(settings->GetCopyQuoting()); @@ -662,6 +664,8 @@ void frmOptions::OnOK(wxCommandEvent &ev) settings->SetAskSaveConfirmation(!chkAskSaveConfirm->GetValue()); settings->SetConfirmDelete(chkAskDelete->GetValue()); settings->SetShowUsersForPrivileges(chkShowUsersForPrivileges->GetValue()); + settings->SetVisibleDbNameTree(chkShowDBnameTree->GetValue()); + settings->SetAutoRowCountThreshold(StrToLong(txtAutoRowCount->GetValue())); settings->SetIndentSpaces(StrToLong(txtIndent->GetValue())); settings->SetSpacesForTabs(chkSpacesForTabs->GetValue()); diff --git a/include/ctl/ctlTree.h b/include/ctl/ctlTree.h index cf6ba8c..ba58bc2 100644 --- a/include/ctl/ctlTree.h +++ b/include/ctl/ctlTree.h @@ -43,6 +43,7 @@ public: void NavigateTree(int keyCode); virtual ~ctlTree(); void OnMouse(wxMouseEvent& ev); + void DrawDbName(const wxTreeItemId& item); wxTreeItemId GetVerticalItem(wxPoint& pt); DECLARE_EVENT_TABLE() @@ -51,7 +52,6 @@ private: void OnChar(wxKeyEvent &event); wxString m_findPrefix; ctlTreeFindTimer *m_findTimer; - friend class ctlTreeFindTimer; }; diff --git a/include/utils/sysSettings.h b/include/utils/sysSettings.h index 210007e..9189a79 100644 --- a/include/utils/sysSettings.h +++ b/include/utils/sysSettings.h @@ -814,6 +814,16 @@ public: { WriteBool(wxT("ASUTPstyle"), newval); } + bool GetVisibleDbNameTree() const + { + bool b; + Read(wxT("VisibleDbNameTree"), &b, true); + return b; + } + void SetVisibleDbNameTree(const bool newval) + { + WriteBool(wxT("VisibleDbNameTree"), newval); + } wxString GetOptionsLastTreeItem() const diff --git a/ui/frmOptions.xrc b/ui/frmOptions.xrc index a707b66..8e3a6c2 100644 --- a/ui/frmOptions.xrc +++ b/ui/frmOptions.xrc @@ -363,6 +363,14 @@ wxEXPAND|wxTOP|wxLEFT|wxRIGHT 4 + + + + 0 + + wxEXPAND|wxTOP|wxLEFT|wxRIGHT + 4 + 2