Extended hints

В результатах запроса, нажатием правой кнопки мыши можно вызвать окно
подсказки, с возможностью выделения содержимого и его копирования (Rbutton).
This commit is contained in:
lsv 2025-07-31 16:14:09 +05:00 committed by lsv
parent c2c44c18f1
commit 077de1ad7c
17 changed files with 4789 additions and 3946 deletions

View file

@ -132,7 +132,14 @@ wxString ctlListView::GetText(long row, long col)
item.SetColumn(col);
item.SetMask(wxLIST_MASK_TEXT);
GetItem(item);
return item.GetText();
wxString v = item.GetText();
if (storelongstring) {
int len = v.Length();
if (len==200 && row >= 0 && col==0 && row < longstring.size()) {
return longstring[row];
}
}
return v;
};
@ -151,7 +158,19 @@ void ctlListView::AddColumn(const wxString& text, int size, int format)
long ctlListView::AppendItem(int icon, const wxString& val, const wxString& val2, const wxString& val3, const wxString& val4)
{
long pos = InsertItem(GetItemCount(), val, icon);
long idx = GetItemCount();
long pos;
if (storelongstring) {
if (val.Length() > 200) {
longstring.push_back(val);
pos = InsertItem(idx, val.Mid(0,200), icon);
}
else {
longstring.push_back(wxEmptyString);
pos = InsertItem(idx, val, icon);
}
} else
pos = InsertItem(idx, val, icon);
if (!val2.IsEmpty())
SetItem(pos, 1, val2);
if (!val3.IsEmpty())

View file

@ -261,6 +261,13 @@ wxMenu* ctlNavigatePanel::GetPopupMenu() {
}
return NULL;
}
void ctlNavigatePanel::SetFindString(const wxString& findstr) {
logFindString = findstr;
items_find.clear();
FindText(logFindString, FOCUSNEXT, false);
Refresh();
}
bool ctlNavigatePanel::RunKeyCommand(wxKeyEvent& event,int numCmd) {
//wxAcceleratorEntry::ParseAccel(const wxString & text, int* flagsOut, int* keyOut);
wxJSONValue cmds = opt["commands"];
@ -693,7 +700,7 @@ void ctlNavigatePanel::OnMouse(wxMouseEvent& evt) {
wxString tt;
if (i >= 0 && i < items_mark.size() && items_mark[i] > pos) i--;
if (i >= 0 && i < items_mark.size() ) {
tt = ctrl->GetItemText(items_mark[i]);
tt = ctrl->GetText(items_mark[i]);
this->SetToolTip(tt);
}
else
@ -983,7 +990,7 @@ int ctlNavigatePanel::FindText(wxString findtext, int position, bool directionUp
// this item is selected - do whatever is needed with it
//wxLogMessage("Item %ld is focused.", item);
//long fpos = logList->FindItem(item, logFindString, true);
wxString s = ctrl->GetItemText(item);
wxString s = ctrl->GetText(item);
item++;
if (!(s.Find(logFindString) > -1)) {
continue;

View file

@ -30,6 +30,7 @@
#include "utils/FormatterSQL.h"
#include "utils/dlgTransformText.h"
#include "utils/TableColsMap.h"
#include "wx/display.h"
wxString ctlSQLBox::sqlKeywords;
static const wxString s_leftBrace(_T("([{"));
@ -591,9 +592,40 @@ void ctlSQLBox::OnFuncHelp(wxCommandEvent& ev) {
for (int i = tmp.Len()-1; i >=0; i--) key+=tmp[i];
}
delete m_PopupHelp;
m_PopupHelp = new popuphelp(this->GetParent(), key.Lower(), fh);
wxSize rr(450, 370);
m_PopupHelp = new popuphelp(this->GetParent(), key.Lower(), fh,p,rr);
if (m_PopupHelp && m_PopupHelp->IsValid() && rr != m_PopupHelp->GetSizePopup()) {
// recreate with new size
rr = m_PopupHelp->GetSizePopup();
delete m_PopupHelp;
m_PopupHelp = new popuphelp(this->GetParent(), key.Lower(), fh, p, rr);
}
if (m_PopupHelp && m_PopupHelp->IsValid()) {
m_PopupHelp->Position(p, wxSize(0, 17));
//m_PopupHelp->UpdateWindowUI(true);
wxSize top_sz=m_PopupHelp->GetSizePopup();
wxPoint posScreen;
wxSize sizeScreen;
const int displayNum = wxDisplay::GetFromPoint(p);
if (displayNum != wxNOT_FOUND)
{
const wxRect rectScreen = wxDisplay(displayNum).GetGeometry();
posScreen = rectScreen.GetPosition();
sizeScreen = rectScreen.GetSize();
}
else // outside of any display?
{
// just use the primary one then
posScreen = wxPoint(0, 0);
sizeScreen = wxGetDisplaySize();
}
wxSize top_new(top_sz);
wxPoint oldp(p);
if (p.x + top_new.x > sizeScreen.x) p.x = sizeScreen.x - top_new.x - 20;
if (p.y + top_new.y > sizeScreen.y) p.y = sizeScreen.y - top_new.y - 20;
if (oldp==p) p.x = p.x + 20;
m_PopupHelp->Move(p);
//m_PopupHelp->Position(p, wxSize(0, 17));
m_PopupHelp->Popup();
}
@ -1659,7 +1691,7 @@ void ctlSQLBox::OnMarginClick(wxStyledTextEvent &event)
event.Skip();
}
wxString ctlSQLBox::TextToHtml(int start, int end) {
wxString ctlSQLBox::TextToHtml(int start, int end,bool isAddNewLine) {
wxColor frColor[40];
wxString str;
wxColour frc = settings->GetSQLBoxColourForeground();
@ -1691,10 +1723,16 @@ wxString ctlSQLBox::TextToHtml(int start, int end) {
wxString sz;
sz.Printf("%d", fntSQLBox.GetPixelSize().GetHeight());
str = wxT("<div style=\"font-family: ") + fontName + wxT("; font-size: " + sz + "px\"><font>");
//str = wxT("<div style=\"font-family: ") + fontName + wxT("; font-size: " + sz + "px\"><font>");
str = wxString::Format("<div style=\"font-family: %s; font-size: %spx\"><font face=\"%s\" >", fontName, sz, fontName);
int k = 0;
int l = 1;
while (startp < endp) {
wxString newline = "<br>";
if (isAddNewLine) newline = L"\u2936<br>";
//if (isAddNewLine) newline = L"&ldca;<br>";
//if (isAddNewLine) newline = L"<br>\x0b78";
int lenstr = selText.Length();
while (k<lenstr) {
int st = GetStyleAt(startp);
if (st < 34) tColor = frColor[st].GetAsString(wxC2S_HTML_SYNTAX);
if (prevColor != tColor) {
@ -1703,15 +1741,16 @@ wxString ctlSQLBox::TextToHtml(int start, int end) {
}
//str.append(str[k].GetValue());
l = 1;
if (!selText[k].IsAscii()) l++;
wxUniChar c = selText[k];
if (!c.IsAscii()) l++;
int s = 0;
wxUniChar c = selText[k].GetValue();
//wxUniChar c = selText[k].GetValue();
if (c == '\r') { startp = startp + l; k++; continue; };
if (c == '\n') { str += wxT("<br>"); startp = startp + l; k++; continue; };
if (c == '\n') { str += newline; startp = startp + l; k++; continue; };
if (c == 9) s = 5;
if (c == 32) s = 1;
if (s > 0) for (int tt = 0; tt < s; tt++) str += wxT("&nbsp;");
else str += selText[k];
else str += c;
startp = startp + l; k++;
}
str = str + wxT("</font></div>");

View file

@ -22,12 +22,17 @@
#include <wx/regex.h>
#include "ctl/ctlSQLResult.h"
#include "utils/misc.h"
#include "utils/FunctionPGHelper.h"
#include "utils/PreviewHtml.h"
#define EXTRAEXTENT_HEIGHT 6
#define EXTRAEXTENT_WIDTH 6
//DEFINE_EVENT_TYPE(myEVT_SHOW_POPUP)
BEGIN_EVENT_TABLE(ctlSQLGrid, wxGrid)
EVT_MOUSEWHEEL(ctlSQLGrid::OnMouseWheel)
//EVT_CUSTOM(wxID_ANY, myEVT_SHOW_POPUP,ctlSQLGrid::OnShowPopup)
EVT_GRID_COL_SIZE(ctlSQLGrid::OnGridColSize)
EVT_GRID_LABEL_LEFT_CLICK(ctlSQLGrid::OnLabelClick)
EVT_GRID_CELL_RIGHT_CLICK(ctlSQLGrid::OnCellRightClick)
@ -66,7 +71,7 @@ ctlSQLGrid::ctlSQLGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos, cons
event.Skip();
});
*/
Bind(wxEVT_THREAD, &ctlSQLGrid::OnShowPopup, this);
setresizedpi();
SetDefaultCellOverflow(false);
//SetDefaultRenderer(new wxGridCellAutoWrapStringRenderer);
@ -859,15 +864,132 @@ void ctlSQLGrid::OnLabelDoubleClick(wxGridEvent& event)
}
}
}
void ctlSQLGrid::OnMouseEvent(wxMouseEvent& event)
{
if (event.RightDown()) {
wxGridEvent ev;
OnCellRightClick(ev);
return;
}
event.Skip();
}
void ctlSQLGrid::OnShowPopup(wxThreadEvent& event) {
// wxMessageBox("omshowpopup "+event.GetString(), "msg");
wxString s = event.GetString();
wxPoint p = rpos;
wxPoint p1(rpos);
wxString bg;
wxColour bgColor = settings->GetSQLBoxColourBackground();
if (settings->GetSQLBoxUseSystemBackground())
{
bgColor = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
}
bg = bgColor.GetAsString(wxC2S_HTML_SYNTAX);
// parse context
wxRegEx r(L"(?im)(select|from|where|set|insert|into|delete)\\b", wxRE_NEWLINE);
int cnt = 0;
if (r.IsValid()) {
size_t start=0;
std::unordered_set<wxString> unic;
while (r.Matches(s.Mid(start))) {
size_t start2 = 0, len2 = 0;
r.GetMatch(&start2, &len2, 1);
unic.insert(s.Mid(start + start2,len2));
r.GetMatch(&start2, &len2, 0);
start = start + start2 + len2;
}
cnt = unic.size();
}
if (cnt >= 2) {
wxString q = s;
wxString html;
ctlSQLBox* box = new ctlSQLBox((wxWindow*) winMain, CTL_SQLQUERY, wxDefaultPosition, wxSize(0, 0), wxTE_MULTILINE | wxTE_RICH2);
box->SetText(q);
int l = q.Length();
box->Colourise(0, box->GetLength());
//bg = box->SetSQLBoxColourBackground(false).GetAsString(wxC2S_CSS_SYNTAX);
html = box->TextToHtml(0, box->GetLength(),false);
delete box;
s = html;
s = "<html><body BGCOLOR=\"" + bg + "\">" + s + "</body></html>";
}
else {
//simple text
PreviewHtml v;
wxString tt=v.Preview(s,fmtpreview::AUTO);
s = tt;
}
delete m_Popup;
wxSize rr(350, 70);
FunctionPGHelper fh(s);
wxString key = "content";
m_Popup = new popuphelp(this, key, &fh, p, rr);
if (m_Popup && m_Popup->IsValid() && rr != m_Popup->GetSizePopup()) {
// recreate with new size
rr = m_Popup->GetSizePopup();
delete m_Popup;
m_Popup = new popuphelp((wxWindow*)winMain, key, &fh, p, rr);
}
if (m_Popup && m_Popup->IsValid()) {
//m_PopupHelp->UpdateWindowUI(true);
wxSize top_sz = m_Popup->GetSizePopup();
wxPoint posScreen;
wxSize sizeScreen;
const int displayNum = wxDisplay::GetFromPoint(p);
if (displayNum != wxNOT_FOUND)
{
const wxRect rectScreen = wxDisplay(displayNum).GetGeometry();
posScreen = rectScreen.GetPosition();
sizeScreen = rectScreen.GetSize();
}
else // outside of any display?
{
// just use the primary one then
posScreen = wxPoint(0, 0);
sizeScreen = wxGetDisplaySize();
}
wxSize top_new(top_sz);
wxPoint oldp(p);
if (p.x + top_new.x > sizeScreen.x) p.x = sizeScreen.x - top_new.x - 20;
if (p.y + top_new.y > sizeScreen.y) p.y = sizeScreen.y - top_new.y - 20;
if (oldp == p) p.x = p.x + 20;
m_Popup->Move(p);
wxRect r = m_Popup->GetScreenRect();
if (r.Contains(p1)) {
//wxMouseEvent mv(wxEVT_MOTION,);
//wxGetMousePosition();
}
//m_PopupHelp->Position(p, wxSize(0, 17));
m_Popup->Popup();
//wxPopupTransientWindow
}
}
void ctlSQLGrid::OnCellRightClick(wxGridEvent& event)
{
int row = event.GetRow();
int col = event.GetCol();
//SetRowLabelValue(row-1,);
//HideRow(row);
event.Skip();
wxPoint p;
if (row != -1 && col != -1) {
rrow = row;
rcol = col;
rpos = ClientToScreen(event.GetPosition());
wxThreadEvent e(wxEVT_THREAD);
//e.SetString(s);
e.SetString(GetCellValue(row, col));
//GetEventHandler()->AddPendingEvent(e);
wxPostEvent(this, e);
//event.Skip();
return;
}
else
{
row = rrow;
col = rcol;
p = rpos;
}
wxString s = GetCellValue(row, col);
}
void ctlSQLGrid::OnLabelClick(wxGridEvent& event)
{