Limitation of the coloring of hints in the query results.

Ограничения добавлены для повышения производительности.
Раскраска отключается при размерах строки более 32000 символа (MAX_TEXT_LEN_COLORIZE)
При более 500000 вызывается диалог подтверждения вывода окна подказки (MAX_TEXT_LEN_WARNING).
Вывод подказки для csv пока не ограничен.
This commit is contained in:
lsv 2025-12-24 16:06:33 +05:00
parent 1156992cc4
commit 409bcc95ce
5 changed files with 107 additions and 51 deletions

View file

@ -30,6 +30,7 @@
#include "utils/FormatterSQL.h"
#include "utils/dlgTransformText.h"
#include "utils/TableColsMap.h"
#include "utils/PreviewHtml.h"
#include "wx/display.h"
wxString ctlSQLBox::sqlKeywords;
@ -662,18 +663,7 @@ void ctlSQLBox::OnFuncHelp(wxCommandEvent& ev) {
for (int i = tmp.Len()-1; i >=0; i--) key+=tmp[i];
}
delete m_PopupHelp;
wxSize rr(450, 370);
m_PopupHelp = new popuphelp(this->GetParent(), key, 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, fh, p, rr);
}
if (m_PopupHelp && m_PopupHelp->IsValid()) {
//m_PopupHelp->UpdateWindowUI(true);
wxSize top_sz=m_PopupHelp->GetSizePopup();
// screen size
wxPoint posScreen;
wxSize sizeScreen;
const int displayNum = wxDisplay::GetFromPoint(p);
@ -689,6 +679,23 @@ void ctlSQLBox::OnFuncHelp(wxCommandEvent& ev) {
posScreen = wxPoint(0, 0);
sizeScreen = wxGetDisplaySize();
}
wxSize rr(450, 370);
bool bigtext=key.Len() > MAX_TEXT_LEN_COLORIZE;
if (bigtext) {
rr.x=(int) sizeScreen.x*0.8;rr.y=sizeScreen.y*0.7;
}
m_PopupHelp = new popuphelp(this->GetParent(), key, fh,p,rr);
if (m_PopupHelp && m_PopupHelp->IsValid() && rr != m_PopupHelp->GetSizePopup() && !bigtext) {
// recreate with new size
rr = m_PopupHelp->GetSizePopup();
delete m_PopupHelp;
m_PopupHelp = new popuphelp(this->GetParent(), key, fh, p, rr);
}
if (m_PopupHelp && m_PopupHelp->IsValid()) {
//m_PopupHelp->UpdateWindowUI(true);
wxSize top_sz=m_PopupHelp->GetSizePopup();
wxSize top_new(top_sz);
wxPoint oldp(p);
if (p.x + top_new.x > sizeScreen.x) p.x = sizeScreen.x - top_new.x - 20;
@ -1809,8 +1816,9 @@ wxString ctlSQLBox::TextToHtml(int start, int end,bool isAddNewLine, const std::
wxString fontName = fntSQLBox.GetFaceName();
wxString sz;
sz.Printf("%d", fntSQLBox.GetPixelSize().GetHeight());
int lenstr = selText.Length();
//str = wxT("<div style=\"font-family: ") + fontName + wxT("; font-size: " + sz + "px\"><font>");
str.Alloc(lenstr*2);
str = wxString::Format("<div style=\"font-family: %s; font-size: %spx\"><font face=\"%s\" >", fontName, sz, fontName);
int k = 0;
int l = 1;
@ -1818,7 +1826,7 @@ wxString ctlSQLBox::TextToHtml(int start, int end,bool isAddNewLine, const std::
if (isAddNewLine) newline = L"\u2936<br>";
//if (isAddNewLine) newline = L"&ldca;<br>";
//if (isAddNewLine) newline = L"<br>\x0b78";
int lenstr = selText.Length();
int IndexObj=0;
int pos=999999999;
wxString obj;
@ -1829,7 +1837,9 @@ wxString ctlSQLBox::TextToHtml(int start, int end,bool isAddNewLine, const std::
int st = GetStyleAt(startp);
if (st < 34) tColor = frColor[st].GetAsString(wxC2S_HTML_SYNTAX);
if (prevColor != tColor) {
str = str + wxT("</font><font color=\"") + tColor + wxT("\">");
str+= wxT("</font><font color=\"");
str+= tColor;
str+= wxT("\">");
prevColor = tColor;
}
//str.append(str[k].GetValue());
@ -1866,7 +1876,7 @@ wxString ctlSQLBox::TextToHtml(int start, int end,bool isAddNewLine, const std::
str += lstr;
lstr="";
}
str = str + wxT("</font></div>");
str+= wxT("</font></div>");
return str;
}
void ctlSQLBox::Copy() {

View file

@ -889,6 +889,13 @@ void ctlSQLGrid::OnShowPopup(wxThreadEvent& event) {
bgColor = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
}
bg = bgColor.GetAsString(wxC2S_HTML_SYNTAX);
long long lenstr=s.Len();
bool bigtext=lenstr >MAX_TEXT_LEN_COLORIZE;
if (lenstr > MAX_TEXT_LEN_WARNING) {
wxString h = NumToStrHuman(wxLongLong(lenstr));
if (wxMessageBox(wxString::Format(_("The line size is [ %s ] characters, do you want to continue?"),h ), _("Confirm"), wxYES_NO, this)!=wxYES) return;
}
// parse context
wxRegEx r(L"(?im)(select|from|where|set|insert|into|delete)\\b", wxRE_NEWLINE);
int cnt = 0;
@ -904,7 +911,7 @@ void ctlSQLGrid::OnShowPopup(wxThreadEvent& event) {
}
cnt = unic.size();
}
if (cnt >= 2) {
if (cnt >= 2 && !bigtext) {
wxString q = s;
wxString html;
ctlSQLBox* box = new ctlSQLBox((wxWindow*) winMain, CTL_SQLQUERY, wxDefaultPosition, wxSize(0, 0), wxTE_MULTILINE | wxTE_RICH2);
@ -924,11 +931,32 @@ void ctlSQLGrid::OnShowPopup(wxThreadEvent& event) {
s = tt;
}
delete m_Popup;
// screen size
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 rr(350, 70);
if (bigtext) {
rr.x=(int) sizeScreen.x*0.8;rr.y=sizeScreen.y*0.7;
}
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()) {
if (m_Popup && m_Popup->IsValid() && rr != m_Popup->GetSizePopup() && !bigtext) {
// recreate with new size
rr = m_Popup->GetSizePopup();
delete m_Popup;
@ -938,21 +966,6 @@ void ctlSQLGrid::OnShowPopup(wxThreadEvent& event) {
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;

View file

@ -1,6 +1,8 @@
#pragma once
#include <wx/wx.h>
#define MAX_TEXT_LEN_COLORIZE 32000
#define MAX_TEXT_LEN_WARNING 500000
#define PREVIEW_SEP 1
#define PREVIEW_DIGITS 2
#define PREVIEW_WORD 4
@ -8,9 +10,9 @@
#define PREVIEW_ENDFIELD 16
#define PREVIEW_ENDROW 32
#define PREVIEW_QUOTE 64
#define CHKFLAG(val,par) ((val & par)>0)
#define CHKFLAG2(val,par) ((val & par)>0)
enum class fmtpreview {
AUTO, AUTOVACCUM,CSV
AUTO, AUTOVACCUM,CSV,SIMPLE_TEXT
};
struct Element {
@ -61,8 +63,8 @@ private:
wxString tmp = savestr;
tmp=escapeHtml(tmp,true);
tmp.Replace(" ", "&nbsp;");
if (CHKFLAG(flag, PREVIEW_ENDROW)) tmp = "<br>";
if (CHKFLAG(flag, PREVIEW_DIGITS)) {
if (CHKFLAG2(flag, PREVIEW_ENDROW)) tmp = "<br>";
if (CHKFLAG2(flag, PREVIEW_DIGITS)) {
int l = savestr.Length();
if (l > 4 && !savestr.Contains('.')) {
int dl = 3;
@ -92,7 +94,7 @@ private:
tmp = t;
}
if (CHKFLAG(flag, PREVIEW_QUOTE)) {
if (CHKFLAG2(flag, PREVIEW_QUOTE)) {
wxString t = wxString::Format("<font color=\"%s\">%s</font>",quotecolor,tmp);
tmp = t;
}
@ -111,7 +113,7 @@ private:
bool f2 = is_what_find & 2;
bool r1 = false;
bool r2 = false;
if (f1 && CHKFLAG(t.flags, flag_find)) {
if (f1 && CHKFLAG2(t.flags, flag_find)) {
r1 = true;
}
if (f2 && t.src==value_find ) {

View file

@ -71,13 +71,10 @@ wxString PreviewHtml::Preview(const wxString& txt, fmtpreview type) {
iscsv = true;
}
else if (fmt == fmtpreview::AUTO) {
//CSVTokenizer tk(txt);
//int nfield = 0;
//while (tk.HasMoreTokens()) {
// wxString field = tk.GetNextToken();
// nfield++;
//}
//if (nfield>1) iscsv = true;
if (txt.Len()>MAX_TEXT_LEN_COLORIZE) {
// simple format
fmt = fmtpreview::SIMPLE_TEXT;
}
}
// prepare csv
std::vector<wxString> strlist;
@ -124,6 +121,15 @@ wxString PreviewHtml::Preview(const wxString& txt, fmtpreview type) {
int startstr = -1;
while (pos < len) {
c = tmpstr[pos++];
if (fmt == fmtpreview::SIMPLE_TEXT) {
if (c=='&') html+="&amp;";
else if (c=='<') html+="&lt;";
else if (c=='>') html+="&gt;";
//else if (c==' ') html+="&nbsp;";
else if (c=='\n') html+="<br>";
html+=c;
continue;
}
bool isquote = c == '"';
if (quote) {
if (prevchar == c && isquote) {
@ -220,7 +226,7 @@ wxString PreviewHtml::Preview(const wxString& txt, fmtpreview type) {
while (pp > 0 && pp > p) {
pp--;
Element t2 = tokens[pp];
if (CHKFLAG(t2.flags, PREVIEW_SEP) && t2.src.StartsWith(":")) {
if (CHKFLAG2(t2.flags, PREVIEW_SEP) && t2.src.StartsWith(":")) {
// Right bound title
if (pp - p > 0) {
tokens[p].html = "<b>" + tokens[p].html;
@ -239,7 +245,7 @@ wxString PreviewHtml::Preview(const wxString& txt, fmtpreview type) {
wxString tit="field"+wxString::Format("%d",nf+1);
if (strlist.size() == 26) tit = titles_log[nf];
tit = "<tr><td valign=\"top\"><b>" + tit + "</b></td>";
html=html+tit+"<td>" + generateHtml() + "</td></tr>";
html+=tit+"<td>" + generateHtml() + "</td></tr>";
} else
html+= generateHtml(); // tokens -> html

View file

@ -196,9 +196,9 @@ wxString NumToStrHuman(wxLongLong value) {
ddiv = ddiv / 1000;
if (ddiv == 0) return wxEmptyString;
}
if (ddiv == 1000000000) s = "Bi";
else if (ddiv == 1000000) s = "Mi";
else if (ddiv == 1000) s = "ths";
if (ddiv == 1000000000) s = _("Bi");
else if (ddiv == 1000000) s = _("Mi");
else if (ddiv == 1000) s = _("ths");
else return wxEmptyString;
wxLongLong m = value % ddiv;
@ -1483,3 +1483,28 @@ bool make_identifier(const wxString &strname, wxString &s, wxString &n, bool isl
} else {if (islower) s=s.MakeLower();}
return true;
}
/*
class DirCopyTraverser: public wxDirTraverser {
public:
DirCopyTraverser(const wxString &destBase): m_destBase(destBase) {}
virtual wxDirTraverseResult OnFile(const wxString &file) wxOVERRIDE {
wxFileName srcFile(file);
//wxString relativePath=srcFile.GetPath(wxPATH_DOS,true);
srcFile.MakeRelativeTo(m_destBase);
wxString destFile=m_destBase+wxFileName::GetPathSeparator()+srcFile.GetFullName();
wxFileName destDir(destFile);
destDir.RemoveLastDir();
if (!destDir.DirExists()) destDir.Mkdir(wxS_DIR_DEFAULT,wxPATH_MKDIR_FULL);
if (!wxCopyFile(file,destFile,true)) {
wxLogError("Error copy file %s",file);
return wxDIR_STOP;
}
return wxDIR_CONTINUE;
}
virtual wxDirTraverseResult OnDir(const wxString &file) wxOVERRIDE {
return 0;
}
private:
wxString m_destBase;
}
*/