Skip to content

Commit

Permalink
fix #38. Add options "Quick jump to the root node" and "Auto save que…
Browse files Browse the repository at this point in the history
…ry text".

Первая предназначена для отключения/включения быстрого перемещения к корневым узлам.
Вторая для отключения/включения автоматического сохранения закладок в Query Tool.
После отключения авто сохранения возможно понадобиться вручную очистить каталог
с сохранёнными закладками %APPDATA%\postgresql\recovery
  • Loading branch information
levinsv committed Oct 25, 2023
1 parent 4d7ed84 commit bce303c
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 84 deletions.
79 changes: 41 additions & 38 deletions ctl/ctlTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,13 @@ void ctlTree::OnMouse(wxMouseEvent& event)
wxPoint pt = event.GetPosition();
int flags = 0;
wxTreeItemId item = DoTreeHitTest(pt, flags);
if (event.LeftDown())
if (isJumpRoot) {
if (event.LeftDown())
{
if ((flags & wxTREE_HITTEST_ONITEMINDENT) == wxTREE_HITTEST_ONITEMINDENT) {
if (item) {
wxRect r;
wxTreeItemId itemParent=item;
wxTreeItemId itemParent = item;
GetBoundingRect(itemParent, r, false);
wxTreeItemId prev;
prev = GetVerticalItem(pt);
Expand All @@ -245,46 +246,47 @@ void ctlTree::OnMouse(wxMouseEvent& event)

}
else {
if ((flags & wxTREE_HITTEST_ONITEMINDENT) == wxTREE_HITTEST_ONITEMINDENT && (item==GetSelection())) {
wxRect r;
GetBoundingRect(item, r, true);
r.width = r.x-19;
r.x = r.x - 19;
if (r.x < 10) return;
wxTreeItemId prev;
wxTreeItemId itemParent = item;
wxImageList *list=this->GetImageList();
wxClientDC dc(this);
bool ex = false;
while (!ex) {
//ex = true;
prev = itemParent;
itemParent = GetItemParent(itemParent);
//this->ScrollTo(itemParent);
if (!itemParent.IsOk()) break;
if ((flags & wxTREE_HITTEST_ONITEMINDENT) == wxTREE_HITTEST_ONITEMINDENT && (item == GetSelection())) {
wxRect r;
GetBoundingRect(item, r, true);
r.width = r.x - 19;
r.x = r.x - 19;
//if (r.x >= pt.x) ex = false;
int image = this->GetItemImage(itemParent);
if (image >= 0) {
dc.SetClippingRegion(r.x + 1 - 19, r.y + 1,
16, 16);
list->Draw(image, dc,
r.x + 1 - 19,
r.y + 1,
wxIMAGELIST_DRAW_TRANSPARENT
);
dc.DestroyClippingRegion();
if (r.x < 10) return;
wxTreeItemId prev;
wxTreeItemId itemParent = item;
wxImageList* list = this->GetImageList();
wxClientDC dc(this);
bool ex = false;
while (!ex) {
//ex = true;
prev = itemParent;
itemParent = GetItemParent(itemParent);
//this->ScrollTo(itemParent);
if (!itemParent.IsOk()) break;
r.x = r.x - 19;
//if (r.x >= pt.x) ex = false;
int image = this->GetItemImage(itemParent);
if (image >= 0) {
dc.SetClippingRegion(r.x + 1 - 19, r.y + 1,
16, 16);
list->Draw(image, dc,
r.x + 1 - 19,
r.y + 1,
wxIMAGELIST_DRAW_TRANSPARENT
);
dc.DestroyClippingRegion();
}
}
}
// dc.SetBrush(*wxRED);
// dc.SetPen(*wxTRANSPARENT_PEN);
// dc.DrawRectangle(r);
Update();
return;
// dc.SetBrush(*wxRED);
// dc.SetPen(*wxTRANSPARENT_PEN);
// dc.DrawRectangle(r);
Update();
return;

}
}
}
event.Skip();
}
event.Skip();

}
void ctlTree::OnChar(wxKeyEvent &event)
Expand Down Expand Up @@ -352,6 +354,7 @@ void ctlTree::OnChar(wxKeyEvent &event)
ctlTree::ctlTree(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style)
: wxTreeCtrl(parent, id, pos, size, style), m_findTimer(NULL)
{
isJumpRoot = settings->GetJumpRoot();
}

ctlTree::~ctlTree()
Expand Down
14 changes: 14 additions & 0 deletions frm/frmOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@
#define chkKeywordsInUppercase CTRL_CHECKBOX("chkKeywordsInUppercase")
#define chkASUTPstyle CTRL_CHECKBOX("chkASUTPstyle")
#define chkHideQueryHistory CTRL_CHECKBOX("chkHideQueryHistory")
#define chkAutosaveQuery CTRL_CHECKBOX("chkAutosaveQuery")
#define chkJumpRoot CTRL_CHECKBOX("chkJumpRoot")
#define menus CTRL_TREE("menus")
#define pnlBrowserDisplay CTRL_PANEL("pnlBrowserDisplay")
#define pnlBrowserProperties CTRL_PANEL("pnlBrowserProperties")
Expand Down Expand Up @@ -366,6 +368,8 @@ frmOptions::frmOptions(frmMain *parent)
chkKeywordsInUppercase->SetValue(settings->GetSQLKeywordsInUppercase());
chkASUTPstyle->SetValue(settings->GetASUTPstyle());
chkHideQueryHistory->SetValue(settings->GetHideQueryHistory());
chkAutosaveQuery->SetValue(settings->GetAutosaveQuery());
chkJumpRoot->SetValue(settings->GetJumpRoot());
chkNumberPretty->SetValue(settings->GetNumberPretty());
cbLanguage->Append(_("Default"));
int sel = 0;
Expand Down Expand Up @@ -884,6 +888,16 @@ void frmOptions::OnOK(wxCommandEvent &ev)
changed = true;
settings->SetHideQueryHistory(chkHideQueryHistory->GetValue());
}
if (settings->GetAutosaveQuery() != chkAutosaveQuery->GetValue())
{
changed = true;
settings->SetAutosaveQuery(chkAutosaveQuery->GetValue());
}
if (settings->GetJumpRoot() != chkJumpRoot->GetValue())
{
changed = true;
settings->SetJumpRoot(chkJumpRoot->GetValue());
}
if (settings->GetNumberPretty() != chkNumberPretty->GetValue())
{
changed = true;
Expand Down
39 changes: 20 additions & 19 deletions frm/frmQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ frmQuery::frmQuery(frmMain *form, const wxString &_title, pgConn *_conn, const w

mainForm = form;
conn = _conn;

autoSave = settings->GetAutosaveQuery();
loading = true;
closing = false;

Expand Down Expand Up @@ -2455,25 +2455,26 @@ void frmQuery::SaveTempFile()
//if (filename.StartsWith(pref))
filename+=wxT(".a");
wxString tempDir = wxStandardPaths::Get().GetUserConfigDir() +wxFileName::GetPathSeparator()+"postgresql"+wxFileName::GetPathSeparator()+"recovery"+wxFileName::GetPathSeparator();
wxUtfFile file(tempDir+filename, wxFile::write, modeUnicode ? wxFONTENCODING_UTF8 : wxFONTENCODING_DEFAULT);
if (file.IsOpened())
{
int nl=sqlQuery->GetCurrentPos();
wxString strnl;
strnl=wxString::Format(_("%i@"), nl);
file.Write(strnl);
if ((file.Write(sqlQuery->GetText()) == 0) && (!modeUnicode))
wxMessageBox(_("Query text incomplete.\nQuery contained characters that could not be converted to the local charset.\nPlease correct the data or try using UTF8 instead."));
file.Close();
sqlQuery->SetChanged(false);
SqlBookUpdatePageTitle();
}
else
{
wxLogError(__("Could not write the file %s: Errcode=%d."), filename.c_str(), wxSysErrorCode());
if (autoSave) {
wxUtfFile file(tempDir + filename, wxFile::write, modeUnicode ? wxFONTENCODING_UTF8 : wxFONTENCODING_DEFAULT);
if (file.IsOpened())
{
int nl = sqlQuery->GetCurrentPos();
wxString strnl;
strnl = wxString::Format(_("%i@"), nl);
file.Write(strnl);
if ((file.Write(sqlQuery->GetText()) == 0) && (!modeUnicode))
wxMessageBox(_("Query text incomplete.\nQuery contained characters that could not be converted to the local charset.\nPlease correct the data or try using UTF8 instead."));
file.Close();
sqlQuery->SetChanged(false);
SqlBookUpdatePageTitle();
}
else
{
wxLogError(__("Could not write the file %s: Errcode=%d."), filename.c_str(), wxSysErrorCode());
}
}


}

void frmQuery::OnSave(wxCommandEvent &event)
Expand Down Expand Up @@ -4370,7 +4371,7 @@ void frmQuery::fileMarkerActive(bool addOrRemove, const wxString &sqlTabName) {

wxString fn = tempDir + wxT("_active.") + tabname + ".a";
//if (sqlTabName.Right(1)=='*' ) tabname=
if (addOrRemove)
if (addOrRemove && autoSave)
{
//wxUtfFile file(fn, wxFile::write, wxFONTENCODING_UTF8);
wxFile file(fn, wxFile::write);
Expand Down
1 change: 1 addition & 0 deletions include/ctl/ctlTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class ctlTree : public wxTreeCtrl
wxString m_findPrefix;
ctlTreeFindTimer *m_findTimer;
friend class ctlTreeFindTimer;
bool isJumpRoot;
};


Expand Down
1 change: 1 addition & 0 deletions include/frm/frmQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class frmQuery : public pgFrame
gqbModel *model;
gqbController *controller;
bool firstTime;
bool autoSave;
bool gqbUpdateRunning;
wxTimer *adjustSizesTimer;

Expand Down
20 changes: 20 additions & 0 deletions include/utils/sysSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,26 @@ class sysSettings : private wxConfig
{
WriteBool(wxT("HideQueryHistory"), newval);
}
bool GetAutosaveQuery() const
{
bool b;
Read(wxT("AutosaveQuery"), &b, true);
return b;
}
void SetAutosaveQuery(const bool newval)
{
WriteBool(wxT("AutosaveQuery"), newval);
}
bool GetJumpRoot() const
{
bool b;
Read(wxT("JumpRoot"), &b, true);
return b;
}
void SetJumpRoot(const bool newval)
{
WriteBool(wxT("JumpRoot"), newval);
}
bool GetNumberPretty() const
{
bool b;
Expand Down
23 changes: 23 additions & 0 deletions ui/frmOptions.xrc
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,14 @@
<flag>wxEXPAND|wxTOP|wxLEFT|wxRIGHT</flag>
<border>4</border>
</object>
<object class="sizeritem">
<object class="wxCheckBox" name="chkJumpRoot">
<label>Quick jump to the root node</label>
<checked>0</checked>
</object>
<flag>wxEXPAND|wxTOP|wxLEFT|wxRIGHT</flag>
<border>4</border>
</object>
<object class="sizeritem">
<object class="wxFlexGridSizer">
<cols>2</cols>
Expand Down Expand Up @@ -598,6 +606,21 @@
<flag>wxEXPAND|wxTOP|wxLEFT|wxRIGHT</flag>
<border>4</border>
</object>
<object class="sizeritem">
<object class="wxStaticText" name="stAutosaveQuery">
<label>Auto save query text</label>
</object>
<flag>wxALIGN_CENTER_VERTICAL|wxTOP|wxLEFT|wxRIGHT</flag>
<border>4</border>
</object>
<object class="sizeritem">
<object class="wxCheckBox" name="chkAutosaveQuery">
<label></label>
<checked>1</checked>
</object>
<flag>wxEXPAND|wxTOP|wxLEFT|wxRIGHT</flag>
<border>4</border>
</object>
</object>
</object>
<flag>wxEXPAND|wxTOP|wxLEFT|wxRIGHT</flag>
Expand Down

0 comments on commit bce303c

Please sign in to comment.