Add ShortCut functional

Появилась возможность быстрой навигации по дереву объектов.
При нажатии F4 появляется список с 50 последними элементами выбранными в дереве.
This commit is contained in:
lsv 2023-09-07 14:16:10 +05:00 committed by lsv
parent 0d26ad123a
commit 641cbcf282
7 changed files with 393 additions and 8 deletions

196
ctl/ctlShortCut.cpp Normal file
View file

@ -0,0 +1,196 @@
#include "pgAdmin3.h"
#include "ctl/ctlShortCut.h"
#include "frm/frmMain.h"
ctlShortCut::ctlShortCut(frmMain* main,wxWindow* parent, wxWindowID id, const wxPoint& pos , const wxSize& size )
{
wxSize sz(400, -1);
int style = wxCB_SIMPLE| wxTE_PROCESS_ENTER;
frm = main;
imageList = main->GetImageList();
//wxComboCtrl* comboCustom = new wxComboCtrl();
//wxCheckBox* cbox = new wxCheckBox();
txt = new wxTextCtrl();
SetMainControl(txt);
Create(parent, id, wxEmptyString, pos, sz, style);
//comboCustom->Create(panel, wxID_ANY, wxEmptyString);
txt->Create(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, style);
txt->SetFont(settings->GetSystemFont());
//txt->SetBackgroundColour(*wxWHITE);
pop = new wxVListBoxComboPopup();
///UseAltPopupWindow(false);
SetPopupControl(pop);
// wxArrayString ar;
// ar.Add("100000");
// ar.Add("200000");
// ar.Add("300000");
// this->Append(ar);
txt->Bind(wxEVT_TEXT_ENTER, &ctlShortCut::OnTEXT_ENTER, this);
txt->Bind(wxEVT_TEXT, &ctlShortCut::OnTEXT, this);
txt->Bind(wxEVT_CHAR, &ctlShortCut::OnCharT, this);
pop->Bind(wxEVT_CHAR, &ctlShortCut::OnChar, this);
Bind(wxEVT_COMBOBOX, &ctlShortCut::OnCombo, this);
// this->CentreOnParent();
;
}
wxTextCtrl* ctlShortCut::GetTextControl() {
return txt;
}
void ctlShortCut::SetText(wxString &str,bool settext) {
if (settext) {
txt->SetValue(str);
}
this->Clear();
fnd = str;
this->Append(BuildList(str, false));
}
wxString ctlShortCut::viewText(wxString& s) {
wxString src = s;
src = src.AfterFirst('/').AfterFirst('/');
src.Replace(_("Schemas"), "");
src.Replace(_("Tables"), "");
src.Replace(_("Views"), "");
src.Replace(_("Functions"), "");
src.Replace(_("Procedures"), "");
src.Replace(_("Databases"), "");
src.Replace(_("Trigger Functions"), "");
src.Replace(_("Sequences"), "");
src.Replace(_("Foreign Tables"), "");
src.Replace(_("Partitions"), "");
src.Replace(_("Types"), "");
src.Replace(_("Triggers"), "");
src.Replace("//", "/");
return src;
}
wxArrayString ctlShortCut::BuildList(wxString& find, bool full) {
wxArrayString rez;
if (find.Length()==0) return frm->shortcut;
for (int i = 0; i<frm->shortcut.Count(); i++) {
wxString t = viewText(frm->shortcut[i]);
if (t.Find(find) != wxNOT_FOUND) {
if (full)
{
if (find.Length() == t.length()) rez.Add(frm->shortcut[i]);
}
else
rez.Add(frm->shortcut[i]);
}
}
if (rez.Count() > 0|| full) return rez;
return frm->shortcut;
}
ctlShortCut::~ctlShortCut() {
//delete txt;
//delete pop;
}
void ctlShortCut::OnCombo(wxCommandEvent& event) {
// go link
wxString s = GetValue();
if (s.Length() > 0) frm->select_shortcut = s;
GetParent()->Close(true);
}
void ctlShortCut::OnTEXT_ENTER(wxCommandEvent& event ) {
wxString s = txt->GetValue();
//wxMessageBox("Enter press\n Add link "+s, "Ontext_Enter");
wxArrayString a=BuildList(s, true);
if (a.Count() > 0) {
// go link
}
else
{
frm->select_shortcut=s;
}
if (s.Length()>0) frm->select_shortcut = '@'+s;
GetParent()->Close(true);
}
void ctlShortCut::OnTEXT(wxCommandEvent& event) {
if (!IsPopupShown() && ( true) ) {
wxString s = txt->GetValue();
SetText(s,false);
if (pop->GetCount() > 0) {
Popup();
}
//int e = txt->SetSelection(0, 1);
//
}
}
void ctlShortCut::OnCharT(wxKeyEvent& event) {
if (event.GetKeyCode() == WXK_ESCAPE) {
GetParent()->Close(true);
}
event.Skip();
}
void ctlShortCut::OnChar(wxKeyEvent& event) {
if (IsPopupShown()) {
wxString s = txt->GetValue();
wxChar charcode = event.GetUnicodeKey();
if (event.GetKeyCode() == WXK_BACK) {
txt->EmulateKeyPress(event);
//txt->SetValue(s.Left(s.Length()-1));
}
if (wxIsprint(charcode))
{
//txt->EmulateKeyPress(event);
s += charcode;
SetText(s, false);
txt->SetValue(s);
pop->Refresh();
return;
}
else event.Skip();
}
event.Skip();
}
dlgShortCut::dlgShortCut(frmMain* parent, wxWindowID id, wxPoint pos, const wxSize size)
:wxDialog(reinterpret_cast<wxWindow*> (parent), id, wxEmptyString, pos, size, wxSUNKEN_BORDER | wxSTAY_ON_TOP)
{
// SetExtraStyle(GetExtraStyle() & ~wxWS_EX_BLOCK_EVENTS);
//this->SetSize(wxSize(243, 165));
wxBoxSizer* vSizer = new wxBoxSizer(wxVERTICAL);
ctlShortCut *cb=new ctlShortCut(parent,this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
frm = parent;
wxTreeItemId item = frm->GetBrowser()->GetSelection();
wxString curparh=frm->GetNodePath(item);
curparh = "";
cb->SetText(curparh, true);
wxTextCtrl *c=cb->GetTextControl();
cb->Bind(wxEVT_KEY_DOWN, &dlgShortCut::OnKEY_DOWN, this);
// Bind(wxEVT_CHAR_HOOK, &dlgShortCut::OnCharHook, this);
vSizer->Add(cb, 0, wxEXPAND | wxALL, 3);
SetSizerAndFit(vSizer);
//SetSizer(vSizer);
}
dlgShortCut::~dlgShortCut() {
//delete cb;
}
void dlgShortCut::OnCharHook(wxKeyEvent& event) {
event.Skip();
}
void dlgShortCut::OnKEY_DOWN(wxKeyEvent& event) {
if (event.GetKeyCode() == WXK_ESCAPE) {
Close(true);
}
HWND f=GetFocus();
if (!cb->HasFocus()) {
}
event.Skip();
}

View file

@ -38,6 +38,7 @@
#include "schema/pgTable.h"
#include "schema/edbPrivateSynonym.h"
#include "dlg/dlgProperty.h"
#include "ctl/ctlShortCut.h"
// Mutex to protect the "currentObject" from race conditions.
//
@ -59,6 +60,7 @@ BEGIN_EVENT_TABLE(frmMain, pgFrame)
EVT_MENU(MNU_DEFAULTVIEW, frmMain::OnDefaultView)
EVT_MENU(MNU_CHECKALIVE, frmMain::OnCheckAlive)
EVT_MENU(MNU_CONTEXTMENU, frmMain::OnContextMenu)
EVT_MENU(MNU_SHORTCUT, frmMain::OnShortCut)
EVT_AUINOTEBOOK_PAGE_CHANGED(wxID_ANY, frmMain::OnPageChange)
EVT_LIST_ITEM_SELECTED(CTL_PROPVIEW, frmMain::OnPropSelChanged)
@ -470,8 +472,20 @@ void frmMain::OnTreeSelChanged(wxTreeEvent &event)
denyCollapseItem = wxTreeItemId();
// Reset the listviews/SQL pane
if (event.GetItem())
if (event.GetItem()) {
execSelChange(event.GetItem(), true);
wxTreeItemId s=browser->GetSelection();
if (currentObject) {
int imgidx = browser->GetItemImage(s);
wxString path = wxString::Format("%4d", imgidx) + GetCurrentNodePath();
;
int p = shortcut.Index(path);
if (shortcut.GetCount() >= 50) shortcut.RemoveAt(shortcut.GetCount() - 1);
if (p != wxNOT_FOUND) shortcut.RemoveAt(p);
shortcut.Insert(path, 0);
}
}
}
@ -819,7 +833,60 @@ void frmMain::OnContextMenu(wxCommandEvent &event)
}
}
void frmMain::OnShortCut(wxCommandEvent& event)
{
wxPoint point;
if (FindFocus() == browser)
{
wxRect rect;
wxTreeItemId item = browser->GetSelection();
browser->GetBoundingRect(item, rect);
point = rect.GetPosition();
wxPoint origin = GetClientAreaOrigin();
point.y += rect.GetHeight();
// Because this Tree is inside a vertical splitter, we
// must compensate for the size of the other elements
point.x += origin.x;
point.y += origin.y;
wxPoint ps;
ps= browser->ClientToScreen(point);
//ctlShortCut* cb = new ctlShortCut(wxTheApp->GetTopWindow(), wxID_ANY, ps, wxDefaultSize);
//dlgshrcut = new dlgShortCut(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
select_shortcut = wxEmptyString;
dlgShortCut dlg(this, wxID_ANY, ps, wxDefaultSize);
dlg.ShowModal();
wxString path;
bool add = false;
if (select_shortcut.IsEmpty()) return;
if (select_shortcut.StartsWith("@") > 0) {
select_shortcut = select_shortcut.substr(4);
path = select_shortcut.SubString(1, select_shortcut.Length() - 1);
add = true;
}
else path = select_shortcut.substr(4);
if (!SetCurrentNode(GetBrowser()->GetRootItem(), path))
{
wxMessageBox(_("The specified object couldn't be found in the tree."));
return;
}
if (add) {
int p = shortcut.Index(path);
if (p != wxNOT_FOUND) shortcut.RemoveAt(p);
shortcut.Insert(path, 0);
}
//doPopup(this, point, browser->GetObject(item));
}
}
void frmMain::OnBrowserToolTip(wxTreeEvent& event)
{

View file

@ -90,6 +90,9 @@
#include "schema/pgCheck.h"
#include "schema/pgDomain.h"
#include "schema/pgEventTrigger.h"
#include "ctl/ctlShortCut.h"
#ifdef WIN32
#include <wx/msw/ole/automtn.h>
#endif
@ -535,10 +538,9 @@ void frmMain::CreateMenus()
// Add the plugin toolbar button/menu
new pluginButtonMenuFactory(menuFactories, pluginsMenu, toolBar, pluginUtilityCount);
//--------------------------
toolBar->AddSeparator();
actionFactory *helpFact = new contentsFactory(menuFactories, helpMenu, 0);
new hintFactory(menuFactories, helpMenu, toolBar, true);
new faqFactory(menuFactories, helpMenu, 0);
@ -589,6 +591,8 @@ void frmMain::CreateMenus()
}
treeContextMenu = 0;
// Status bar
statusBar = CreateStatusBar(4);
@ -599,15 +603,16 @@ void frmMain::CreateMenus()
statusBar->SetStatusText(_("Ready."), 1);
statusBar->SetStatusText(_("0 Secs"), 3);
wxAcceleratorEntry entries[4];
wxAcceleratorEntry entries[5];
entries[0].Set(wxACCEL_NORMAL, WXK_F5, refFact->GetId());
entries[1].Set(wxACCEL_NORMAL, WXK_DELETE, MNU_DELETE);
entries[2].Set(wxACCEL_NORMAL, WXK_F1, helpFact->GetId());
entries[3].Set(wxACCEL_SHIFT, WXK_F10, MNU_CONTEXTMENU);
wxAcceleratorTable accel(4, entries);
entries[4].Set(wxACCEL_NORMAL, WXK_F4, MNU_SHORTCUT);
wxAcceleratorTable accel(5, entries);
SetAcceleratorTable(accel);
// Display the bar and configure buttons.
toolBar->Realize();
}

111
include/ctl/ctlShortCut.h Normal file
View file

@ -0,0 +1,111 @@
#ifndef CTLSHORTCUT_H
#define CTLSHORTCUT_H
#include "pgAdmin3.h"
#include <wx/odcombo.h>
class ctlShortCut : public wxOwnerDrawnComboBox
{
public:
ctlShortCut(frmMain* main,wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize);
~ctlShortCut();
void OnTEXT_ENTER(wxCommandEvent& event);
void OnCombo(wxCommandEvent& event);
void OnTEXT(wxCommandEvent& event);
void OnChar(wxKeyEvent& event);
void OnCharT(wxKeyEvent& event);
void SetText(wxString& str, bool settext);
wxTextCtrl* GetTextControl();
static wxString viewText(wxString& src);
wxArrayString BuildList(wxString& find,bool full);
wxTextCtrl* txt;
wxString fnd;
wxVListBoxComboPopup* pop;
frmMain* frm;
wxImageList* imageList;
virtual void OnDrawItem(wxDC& dc, const wxRect& rect, int item, int flags) const
{
if (item == wxNOT_FOUND) return;
wxCoord w1, h1, w2, h2;
wxString ss = GetString(item);
wxString src = viewText(ss);
int pp = src.Find(fnd);
wxRect r;
int idx=0;
wxString si = ss.substr(0, 4).Trim();
if (si.ToInt(&idx)) {
dc.DrawBitmap(imageList->GetBitmap(idx),wxPoint(rect.x,rect.y));
}
;
r.x = rect.x+24;
r.y = rect.y + (rect.height / 2) - (dc.GetCharHeight() / 2);
if (pp >= 0) {
dc.SetBrush(*wxYELLOW_BRUSH);
const wxString& line = src;
pp = line.Find(fnd);
int lineWidth, lineWidthP, lineHeight, start = 0;
wxString pref;
pref = line.substr(start, pp);
dc.GetTextExtent(pref, &lineWidthP, &lineHeight);
r.x = r.x + lineWidthP+3;
pref = line.substr(pp, fnd.Len());
dc.GetTextExtent(pref, &lineWidth, &lineHeight);
r.width = lineWidth;
r.height = lineHeight;
dc.DrawRoundedRectangle(r, 3);
}
dc.GetTextExtent(src, &w1, &h1);
dc.DrawText(src,
rect.x + 3+24,
(rect.y + 0) + (rect.height / 2) - (dc.GetCharHeight() / 2)
);
//dc.SetFont(m_fontList[item]);
}
virtual void OnDrawBackground(wxDC& dc, const wxRect& rect, int item, int flags) const
{
// If item is selected or even, or we are painting the
// combo control itself, use the default rendering.
if ((flags & (wxODCB_PAINTING_CONTROL | wxODCB_PAINTING_SELECTED)) ||
(item & 1) == 0)
{
wxOwnerDrawnComboBox::OnDrawBackground(dc, rect, item, flags);
return;
}
// Otherwise, draw every other background with different colour.
wxColour bgCol(245, 245, 255);
dc.SetBrush(wxBrush(bgCol));
dc.SetPen(wxPen(bgCol));
dc.DrawRectangle(rect);
}
virtual wxCoord OnMeasureItem(size_t item) const
{
return 20;
}
virtual wxCoord OnMeasureItemWidth(size_t item) const
{
return 400;
}
};
class dlgShortCut : public wxDialog
{
public:
dlgShortCut(frmMain* parent, wxWindowID id, wxPoint pos, const wxSize size);
~dlgShortCut();
void OnKEY_DOWN(wxKeyEvent& event);
void OnCharHook(wxKeyEvent& event);
//void OnPopUpOKClick(wxCommandEvent& event);
//void focus();
private:
ctlShortCut *cb;
frmMain* frm;
};
#endif

View file

@ -26,7 +26,7 @@
#include "utils/factory.h"
#include "frm/frmLog.h"
#include "ctl/ctlGitPanel.h"
#include "ctl/ctlShortCut.h"
//
// This number MUST be incremented if changing any of the default perspectives
//
@ -201,6 +201,8 @@ public:
public:
frmLog* Logfrm;
wxArrayString shortcut;
wxString select_shortcut;
private:
wxAuiManager manager;
ctlTree *browser;
@ -215,7 +217,7 @@ private:
wxMenu *newMenu, *debuggingMenu, *reportMenu, *toolsMenu, *pluginsMenu, *viewMenu,
*treeContextMenu, *newContextMenu, *slonyMenu, *scriptingMenu, *viewDataMenu;
pgServerCollection *serversObj;
dlgShortCut *dlgshrcut;
pluginUtilityFactory *lastPluginUtility;
int pluginUtilityCount;
@ -255,6 +257,7 @@ private:
void OnAuiUpdate(wxAuiManagerEvent &event);
void OnAuiNotebookPageClose(wxAuiNotebookEvent &event);
void OnContextMenu(wxCommandEvent &event);
void OnShortCut(wxCommandEvent& event);
void OnStatSelChanged(wxListEvent& event);
void OnStatRightClick(wxListEvent& event);

View file

@ -22,6 +22,7 @@ enum
MNU_SAVEAS_IMAGE_GQB,
MNU_SAVEAS_IMAGE_EXPLAIN,
MNU_CONTEXTMENU,
MNU_SHORTCUT,
MNU_SQLPANE,
MNU_OBJECTBROWSER,
MNU_TOOLBAR,

View file

@ -758,6 +758,7 @@
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="ctl\calbox.cpp" />
<ClCompile Include="ctl\ctlShortCut.cpp" />
<ClCompile Include="ctl\ctlAuiNotebook.cpp" />
<ClCompile Include="ctl\ctlCheckTreeView.cpp" />
<ClCompile Include="ctl\ctlColourPicker.cpp" />
@ -1573,6 +1574,7 @@
<ItemGroup>
<ClInclude Include="include\copyright.h" />
<ClInclude Include="include\ctl\ctlGitPanel.h" />
<ClInclude Include="include\ctl\ctlShortCut.h" />
<ClInclude Include="include\dlg\dlgProJob.h" />
<ClInclude Include="include\dlg\dlgResourceGroup.h" />
<ClInclude Include="include\frm\frmLog.h" />