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.SetColumn(col);
item.SetMask(wxLIST_MASK_TEXT); item.SetMask(wxLIST_MASK_TEXT);
GetItem(item); 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 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()) if (!val2.IsEmpty())
SetItem(pos, 1, val2); SetItem(pos, 1, val2);
if (!val3.IsEmpty()) if (!val3.IsEmpty())

View file

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

View file

@ -30,6 +30,7 @@
#include "utils/FormatterSQL.h" #include "utils/FormatterSQL.h"
#include "utils/dlgTransformText.h" #include "utils/dlgTransformText.h"
#include "utils/TableColsMap.h" #include "utils/TableColsMap.h"
#include "wx/display.h"
wxString ctlSQLBox::sqlKeywords; wxString ctlSQLBox::sqlKeywords;
static const wxString s_leftBrace(_T("([{")); 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]; for (int i = tmp.Len()-1; i >=0; i--) key+=tmp[i];
} }
delete m_PopupHelp; 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()) { 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(); m_PopupHelp->Popup();
} }
@ -1659,7 +1691,7 @@ void ctlSQLBox::OnMarginClick(wxStyledTextEvent &event)
event.Skip(); event.Skip();
} }
wxString ctlSQLBox::TextToHtml(int start, int end) { wxString ctlSQLBox::TextToHtml(int start, int end,bool isAddNewLine) {
wxColor frColor[40]; wxColor frColor[40];
wxString str; wxString str;
wxColour frc = settings->GetSQLBoxColourForeground(); wxColour frc = settings->GetSQLBoxColourForeground();
@ -1691,10 +1723,16 @@ wxString ctlSQLBox::TextToHtml(int start, int end) {
wxString sz; wxString sz;
sz.Printf("%d", fntSQLBox.GetPixelSize().GetHeight()); 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 k = 0;
int l = 1; 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); int st = GetStyleAt(startp);
if (st < 34) tColor = frColor[st].GetAsString(wxC2S_HTML_SYNTAX); if (st < 34) tColor = frColor[st].GetAsString(wxC2S_HTML_SYNTAX);
if (prevColor != tColor) { if (prevColor != tColor) {
@ -1703,15 +1741,16 @@ wxString ctlSQLBox::TextToHtml(int start, int end) {
} }
//str.append(str[k].GetValue()); //str.append(str[k].GetValue());
l = 1; l = 1;
if (!selText[k].IsAscii()) l++; wxUniChar c = selText[k];
if (!c.IsAscii()) l++;
int s = 0; int s = 0;
wxUniChar c = selText[k].GetValue(); //wxUniChar c = selText[k].GetValue();
if (c == '\r') { startp = startp + l; k++; continue; }; 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 == 9) s = 5;
if (c == 32) s = 1; if (c == 32) s = 1;
if (s > 0) for (int tt = 0; tt < s; tt++) str += wxT("&nbsp;"); if (s > 0) for (int tt = 0; tt < s; tt++) str += wxT("&nbsp;");
else str += selText[k]; else str += c;
startp = startp + l; k++; startp = startp + l; k++;
} }
str = str + wxT("</font></div>"); str = str + wxT("</font></div>");

View file

@ -22,12 +22,17 @@
#include <wx/regex.h> #include <wx/regex.h>
#include "ctl/ctlSQLResult.h" #include "ctl/ctlSQLResult.h"
#include "utils/misc.h" #include "utils/misc.h"
#include "utils/FunctionPGHelper.h"
#include "utils/PreviewHtml.h"
#define EXTRAEXTENT_HEIGHT 6 #define EXTRAEXTENT_HEIGHT 6
#define EXTRAEXTENT_WIDTH 6 #define EXTRAEXTENT_WIDTH 6
//DEFINE_EVENT_TYPE(myEVT_SHOW_POPUP)
BEGIN_EVENT_TABLE(ctlSQLGrid, wxGrid) BEGIN_EVENT_TABLE(ctlSQLGrid, wxGrid)
EVT_MOUSEWHEEL(ctlSQLGrid::OnMouseWheel) EVT_MOUSEWHEEL(ctlSQLGrid::OnMouseWheel)
//EVT_CUSTOM(wxID_ANY, myEVT_SHOW_POPUP,ctlSQLGrid::OnShowPopup)
EVT_GRID_COL_SIZE(ctlSQLGrid::OnGridColSize) EVT_GRID_COL_SIZE(ctlSQLGrid::OnGridColSize)
EVT_GRID_LABEL_LEFT_CLICK(ctlSQLGrid::OnLabelClick) EVT_GRID_LABEL_LEFT_CLICK(ctlSQLGrid::OnLabelClick)
EVT_GRID_CELL_RIGHT_CLICK(ctlSQLGrid::OnCellRightClick) EVT_GRID_CELL_RIGHT_CLICK(ctlSQLGrid::OnCellRightClick)
@ -66,7 +71,7 @@ ctlSQLGrid::ctlSQLGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos, cons
event.Skip(); event.Skip();
}); });
*/ */
Bind(wxEVT_THREAD, &ctlSQLGrid::OnShowPopup, this);
setresizedpi(); setresizedpi();
SetDefaultCellOverflow(false); SetDefaultCellOverflow(false);
//SetDefaultRenderer(new wxGridCellAutoWrapStringRenderer); //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) void ctlSQLGrid::OnCellRightClick(wxGridEvent& event)
{ {
int row = event.GetRow(); int row = event.GetRow();
int col = event.GetCol(); int col = event.GetCol();
wxPoint p;
//SetRowLabelValue(row-1,); if (row != -1 && col != -1) {
//HideRow(row); rrow = row;
event.Skip(); 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) void ctlSQLGrid::OnLabelClick(wxGridEvent& event)
{ {

File diff suppressed because it is too large Load diff

View file

@ -25,11 +25,19 @@ private:
void OnSortGrid(wxListEvent& event); void OnSortGrid(wxListEvent& event);
bool nosort; // если кто то пользуется SetItemData то не будем сортировать такие ctlListView bool nosort; // если кто то пользуется SetItemData то не будем сортировать такие ctlListView
int order, prev_col; int order, prev_col;
// будем сохранять длинные строки 0 колонки в этом массиве
bool storelongstring = false;
std::vector<wxString> longstring;
public: public:
bool SetItemData(long item, long data) { bool SetItemData(long item, long data) {
nosort = true; nosort = true;
return wxListView::SetItemData(item, data); return wxListView::SetItemData(item, data);
} }
void SetModeStoreLongString() { storelongstring = true; }
bool DeleteAllItems() {
longstring.clear();
return wxListView::DeleteAllItems();
}
ctlListView(wxWindow* p, int id, wxPoint pos, wxSize siz, long attr = 0); ctlListView(wxWindow* p, int id, wxPoint pos, wxSize siz, long attr = 0);
long GetSelection(); long GetSelection();
wxString GetText(long row, long col = 0); wxString GetText(long row, long col = 0);

View file

@ -68,6 +68,7 @@ public:
int GetIndexColor(const wxColour &color) const; int GetIndexColor(const wxColour &color) const;
void ClearMark(); void ClearMark();
void RowVisibleCenter(long row); void RowVisibleCenter(long row);
void SetFindString(const wxString &findstr);
int GetCountMark(); int GetCountMark();
wxMenu* GetPopupMenu(); wxMenu* GetPopupMenu();
bool RunKeyCommand(wxKeyEvent& event,int numCmd=-1); bool RunKeyCommand(wxKeyEvent& event,int numCmd=-1);

View file

@ -53,7 +53,7 @@ public:
void Create(wxWindow *parent, wxWindowID id = -1, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = 0); void Create(wxWindow *parent, wxWindowID id = -1, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = 0);
void HighlightBrace(int lb, int rb); void HighlightBrace(int lb, int rb);
void SetDatabase(pgConn *db); void SetDatabase(pgConn *db);
wxString TextToHtml(int start, int end); wxString TextToHtml(int start, int end, bool isAddNewLine=false);
void Copy(); void Copy();
void OnKeyDown(wxKeyEvent &event); void OnKeyDown(wxKeyEvent &event);
void OnAutoComplete(wxCommandEvent &event); void OnAutoComplete(wxCommandEvent &event);

View file

@ -15,6 +15,8 @@
// wxWindows headers // wxWindows headers
#include <wx/grid.h> #include <wx/grid.h>
#include <wx/brush.h> #include <wx/brush.h>
#include "utils/popuphelp.h"
class GroupRows; class GroupRows;
class ctlSQLGrid : public wxGrid class ctlSQLGrid : public wxGrid
@ -52,6 +54,8 @@ public:
void OnGridSelectCell(wxGridEvent& evt); void OnGridSelectCell(wxGridEvent& evt);
void OnLabelClick(wxGridEvent& event); void OnLabelClick(wxGridEvent& event);
void OnCellRightClick(wxGridEvent& event); void OnCellRightClick(wxGridEvent& event);
void OnMouseEvent(wxMouseEvent& event);
void OnShowPopup(wxThreadEvent& event);
bool FullArrayCollapseRowsPlan(bool clear); bool FullArrayCollapseRowsPlan(bool clear);
void AutoSizeColumn(int col, bool setAsMin = false, bool doLimit = true); void AutoSizeColumn(int col, bool setAsMin = false, bool doLimit = true);
void AutoSizeColumns(bool setAsMin); void AutoSizeColumns(bool setAsMin);
@ -83,7 +87,11 @@ private:
// Max size for each column // Max size for each column
wxArrayInt colMaxSizes; wxArrayInt colMaxSizes;
bool isSort; bool isSort;
// viewr
popuphelp* m_Popup = NULL;
int rcol, rrow;
wxPoint rpos;
//FunctionPGHelper fh;
}; };
class GroupRows class GroupRows

View file

@ -63,12 +63,14 @@ enum
MNU_QUERYSTATETRIGGER, MNU_QUERYSTATETRIGGER,
MNU_WAITENABLE, MNU_WAITENABLE,
MNU_WAITSAVE, MNU_WAITSAVE,
CMD_EVENT_FIND_STR,
TIMER_REFRESHUI_ID, TIMER_REFRESHUI_ID,
TIMER_STATUS_ID, TIMER_STATUS_ID,
TIMER_LOCKS_ID, TIMER_LOCKS_ID,
TIMER_XACT_ID, TIMER_XACT_ID,
TIMER_LOG_ID, TIMER_LOG_ID,
TIMER_QUERYSTATE_ID TIMER_QUERYSTATE_ID,
TIMER_LOGHINT_ID
}; };
@ -80,9 +82,6 @@ enum
PANE_LOG, PANE_LOG,
PANE_QUERYSTATE PANE_QUERYSTATE
}; };
//
// This number MUST be incremented if changing any of the default perspectives // This number MUST be incremented if changing any of the default perspectives
// //
#define FRMSTATUS_PERSPECTIVE_VER wxT("8275") #define FRMSTATUS_PERSPECTIVE_VER wxT("8275")
@ -241,6 +240,7 @@ private:
wxTimer *refreshUITimer; wxTimer *refreshUITimer;
wxTimer *statusTimer, *locksTimer, *xactTimer, *logTimer, *querystateTimer; wxTimer *statusTimer, *locksTimer, *xactTimer, *logTimer, *querystateTimer;
wxTimer *delayHitLog;
int statusRate, locksRate, xactRate, logRate, querystateRate; int statusRate, locksRate, xactRate, logRate, querystateRate;
ctlListView *statusList; ctlListView *statusList;
@ -261,6 +261,9 @@ private:
wxArrayString filterValue; wxArrayString filterValue;
int statusColWidth[12], lockColWidth[10], xactColWidth[5], querystateColWidth[5]; int statusColWidth[12], lockColWidth[10], xactColWidth[5], querystateColWidth[5];
popuphelp* m_Popup = NULL;
long lastlogitem = -1, lastlogitemShow=-1;
wxPoint lastmouse;
int cboToRate(); int cboToRate();
wxString rateToCboString(int rate); wxString rateToCboString(int rate);
@ -288,6 +291,8 @@ private:
void OnToggleWaitEnable(wxCommandEvent& event); void OnToggleWaitEnable(wxCommandEvent& event);
void OnEmptyAction(wxCommandEvent &event); void OnEmptyAction(wxCommandEvent &event);
void OnLogContextMenu(wxCommandEvent& event); void OnLogContextMenu(wxCommandEvent& event);
void OnMoveMouseLog(wxMouseEvent& event);
void OnTimerHintLog(wxTimerEvent& event);
void OnToggleToolBar(wxCommandEvent &event); void OnToggleToolBar(wxCommandEvent &event);
void OnDefaultView(wxCommandEvent &event); void OnDefaultView(wxCommandEvent &event);
@ -348,6 +353,7 @@ private:
void OnLogKeyUp(wxKeyEvent& event); void OnLogKeyUp(wxKeyEvent& event);
void OnAddLabelTextThread(wxThreadEvent& event); void OnAddLabelTextThread(wxThreadEvent& event);
void ActivatePane(wxString name); void ActivatePane(wxString name);
void OnCmdFindStrLog(wxCommandEvent& event);
void OnChangeDatabase(wxCommandEvent &ev); void OnChangeDatabase(wxCommandEvent &ev);

View file

@ -155,10 +155,11 @@ public:
int getCountGroup(int row); int getCountGroup(int row);
int GetTotalCountGroup(int rowfilter); int GetTotalCountGroup(int rowfilter);
wxArrayString GetAllFields(int row, bool isfilter); wxArrayString GetAllFields(int row, bool isfilter);
// use for parse csv log file
static Line getLineParse(const wxString& str, bool csv = false, const wxString& host=wxEmptyString);
static wxString get_field(Line& l, MyConst::colField col);
private: private:
bool checkFilter(Line& l); bool checkFilter(Line& l);
Line getLineParse(const wxString& str, bool csv = false);
wxString get_field(Line& l, MyConst::colField col);
LineFilter getLineFilter(wxString strflt,wxString fn); LineFilter getLineFilter(wxString strflt,wxString fn);
void getLineToCache(int row, bool filter = true); void getLineToCache(int row, bool filter = true);
bool CompareFilterLine(int row, bool filter); bool CompareFilterLine(int row, bool filter);

View file

@ -9,12 +9,27 @@
#include <wx/textfile.h> #include <wx/textfile.h>
#include <wx/filename.h> #include <wx/filename.h>
extern sysSettings *settings; extern sysSettings* settings;
class FunctionPGHelper class FunctionPGHelper
{ {
public: public:
FunctionPGHelper() {}; FunctionPGHelper() {};
/// <summary>
/// Создать только переданный в конструкторе html текст с именем "content"
/// </summary>
/// <param name="content"></param>
FunctionPGHelper(const wxString& content) {
body.clear();
Add("content", content);
isload = true;
};
int Size() {
return body.size();
}
void SetTimerClose(int ms) { m_interval = ms; }
int GetTimerClose() { return m_interval; }
void Add(const wxString& key, const wxString& v) { body.emplace(key, v); }
wxString getHelpString(wxString fnd, bool isPart = true) { wxString getHelpString(wxString fnd, bool isPart = true) {
if (!isValid()) return wxEmptyString; if (!isValid()) return wxEmptyString;
auto search = body.find(fnd); auto search = body.find(fnd);
@ -46,9 +61,9 @@ public:
wxString getSqlCommandHelp(wxString fnd) { wxString getSqlCommandHelp(wxString fnd) {
wxUniChar sep = wxFileName::GetPathSeparator(); wxUniChar sep = wxFileName::GetPathSeparator();
fnd.Replace(" ", ""); fnd.Replace(" ", "");
wxString f = wxFindFirstFile(path + sep+"sql-"+fnd+"*.html"); wxString f = wxFindFirstFile(path + sep + "sql-" + fnd + "*.html");
wxString last,txt; wxString last, txt;
int c = 0; int c = 0;
while (!f.empty()) while (!f.empty())
{ {
@ -61,7 +76,7 @@ public:
if (last.empty()) { if (last.empty()) {
return wxEmptyString; return wxEmptyString;
} }
else if (c==1) { else if (c == 1) {
return getHelpFile(last); return getHelpFile(last);
} }
else { else {
@ -100,6 +115,7 @@ public:
} }
private: private:
bool isload = false; bool isload = false;
int m_interval = -1;
wxString path; wxString path;
std::map<wxString, wxString> body; std::map<wxString, wxString> body;
void loadfile() { void loadfile() {

149
include/utils/PreviewHtml.h Normal file
View file

@ -0,0 +1,149 @@
#pragma once
#include <wx/wx.h>
#define PREVIEW_SEP 1
#define PREVIEW_DIGITS 2
#define PREVIEW_WORD 4
#define PREVIEW_SPACE 8
#define PREVIEW_ENDFIELD 16
#define PREVIEW_ENDROW 32
#define PREVIEW_QUOTE 64
#define CHKFLAG(val,par) ((val & par)>0)
enum class fmtpreview {
AUTO, AUTOVACCUM,CSV
};
struct Element {
wxString src;
wxString html;
int flags = 0;
} ;
static wxString titles_log[] = {
L"log_time",
L"user_name",
L"database_name",
L"process_id",
L"connection_from",
L"session_id",
L"session_line_num",
L"command_tag",
L"session_start_time",
L"virtual_transaction_id",
L"transaction_id",
L"error_severity",
L"sql_state_code",
L"message",
L"detail",
L"hint",
L"internal_query",
L"internal_query_pos",
L"context",
L"query",
L"query_pos",
L"location",
L"application_name",
L"backend_type",
L"leader_pid",
L"query_id"
};
class PreviewHtml
{
public:
//void SetColors();
PreviewHtml() { InitColor(); };
wxString Preview(const wxString& txt, fmtpreview type);
private:
void InitColor();
bool saveTokenIfNotEmpty(wxString& savestr, int flag) {
if (savestr.Length() > 0) {
wxString tmp = savestr;
tmp=escapeHtml(tmp,true);
tmp.Replace(" ", "&nbsp;");
if (CHKFLAG(flag, PREVIEW_ENDROW)) tmp = "<br>";
if (CHKFLAG(flag, PREVIEW_DIGITS)) {
int l = savestr.Length();
if (l > 4 && !savestr.Contains('.')) {
int dl = 3;
wxString fmt;
std::vector<wxString> dd;
bool smalll = true;
while (l > 0) {
l = l - dl;
if (l < 0) {
dl = dl + l;
l = 0;
}
wxString d3 = savestr.Mid(l, dl);
if (smalll)
dd.push_back("<font size=+1>" + d3 + "</font>");
else
dd.push_back(d3);
smalll = !smalll;
}
for (auto i = dd.rbegin(); i != dd.rend(); i++)
{
fmt += *i;
}
tmp = fmt;
}
wxString t = wxString::Format("<font color=\"%s\">%s</font>", numcolor, tmp);
tmp = t;
}
if (CHKFLAG(flag, PREVIEW_QUOTE)) {
wxString t = wxString::Format("<font color=\"%s\">%s</font>",quotecolor,tmp);
tmp = t;
}
tokens.push_back({savestr,tmp,flag});
savestr = "";
return true;
}
return false;
}
int FindElement(int start_pos, int flag_find, wxString& value_find, int is_what_find) {
int p = start_pos;
int rez = -1;
while (p < tokens.size()) {
Element t = tokens[p];
bool f1 = is_what_find & 1;
bool f2 = is_what_find & 2;
bool r1 = false;
bool r2 = false;
if (f1 && CHKFLAG(t.flags, flag_find)) {
r1 = true;
}
if (f2 && t.src==value_find ) {
r2 = true;
}
if ((is_what_find == 3 && r1 && r2)
|| (is_what_find == 2 && r2)
|| (is_what_find == 1 && r1)
) {
rez = p;
break;
}
p++;
}
return rez;
}
wxString generateHtml() {
wxString s;
for (size_t i = 0; i < tokens.size(); i++) {
Element t = tokens[i];
s += t.html;
}
// s = "<html><body BGCOLOR=\"" + bgcolor + "\">" + s + "</body></html>";
// s=wxString::Format("<html><body BGCOLOR=\"%s\" FGCOLOR=\"%s\"><font face=\"%s\" size=\"%d\">%s</font></body></html>", bgcolor,fgcolor,fname,fsize, s);
return s;
}
std::vector<Element> tokens;
// colors
wxString bgcolor, numcolor, fgcolor, quotecolor;
wxString fname;
int fsize;
};

View file

@ -8,27 +8,58 @@
#include <wx/regex.h> #include <wx/regex.h>
#include <map> #include <map>
#include <vector> #include <vector>
#include "wx/display.h"
class popuphelp : class popuphelp :
public wxPopupTransientWindow public wxPopupTransientWindow
{ {
public: public:
//popuphelp(wxWindow* parent); ~popuphelp() {
bool ProcessLeftDown(wxMouseEvent& event) delete closeTimer;
{ }
return false; //popuphelp(wxWindow* parent);
} bool ProcessLeftDown(wxMouseEvent& event)
bool IsValid() { {
return isvalid; return false;
} }
popuphelp(wxWindow* parent,wxString keyword, FunctionPGHelper *hhelper) : wxPopupTransientWindow(parent) { bool IsValid() {
SetSize(450,370); return isvalid;
this->hhelper = hhelper; }
SetBackgroundColour(*wxBLACK); void SetSizePopup(const wxSize& sz) {
htmlWindow = new wxHtmlWindow(this, -1, wxDefaultPosition,GetSize()); SetSize(sz);
htmlWindow->SetRelatedStatusBar(0); Layout();
//htmlWindow->SetPage("<html><body><h1>TEST</h1><span fgcolor=\"#332233\">Set Page Works</span></body></hmtl>"); Fit();
wxString txt = hhelper->getHelpString(keyword); sizew = sz;
}
wxSize GetSizePopup() { return sizew; }
popuphelp(wxWindow* parent,wxString keyword, FunctionPGHelper *hhelper,wxPoint &posit,wxSize &newSz) : wxPopupTransientWindow(parent) {
wxSize top_sz(newSz);
sizew = top_sz;
//SetSize(top_sz);
this->hhelper = hhelper;
SetBackgroundColour(*wxBLACK);
extern sysSettings* settings;
wxFont fnt = settings->GetSQLFont();
int size = fnt.GetPointSize();
SetFont(fnt);
htmlWindow = new wxHtmlWindow(this, -1, wxDefaultPosition, sizew);
wxFont font(size, wxFontFamily::wxFONTFAMILY_MODERN, wxFontStyle::wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
wxString fixf = font.GetFaceName();
wxString scalf = fnt.GetFaceName();
int f_sizes[7];
f_sizes[0] = int(size -4);
f_sizes[1] = int(size -2);
f_sizes[2] = size;
f_sizes[3] = int(size +1);
f_sizes[4] = int(size +3);
f_sizes[5] = int(size +5);
f_sizes[6] = int(size +7);
htmlWindow->SetFonts(scalf, fixf, f_sizes);
htmlWindow->SetRelatedStatusBar(0);
//htmlWindow->SetPage("<html><body><h1>TEST</h1><span fgcolor=\"#332233\">Set Page Works</span></body></hmtl>");
wxString txt = hhelper->getHelpString(keyword);
if (txt.IsEmpty()) { if (txt.IsEmpty()) {
txt = hhelper->getSqlCommandHelp(keyword); txt = hhelper->getSqlCommandHelp(keyword);
@ -38,47 +69,80 @@ public:
} }
} }
SetPage(txt); SetPage(txt);
//wxSize sz= htmlWindow->GetSize(); //htmlWindow->SetSize(htmlWindow->GetInternalRepresentation()->GetWidth(), htmlWindow->GetInternalRepresentation()->GetHeight());
//sz = htmlWindow->GetBestSize(); //wxSize sz= htmlWindow->GetSize();
//htmlWindow->SetHTMLBackgroundImage(wxBitmapBundle::FromSVGFile("data/bg.svg", wxSize(65, 45))); //sz = htmlWindow->GetBestSize();
wxBoxSizer* topsizer; //htmlWindow->SetHTMLBackgroundImage(wxBitmapBundle::FromSVGFile("data/bg.svg", wxSize(65, 45)));
topsizer = new wxBoxSizer(wxVERTICAL); wxBoxSizer* topsizer;
topsizer = new wxBoxSizer(wxVERTICAL);
//htmlWindow->SetInitialSize(wxSize(htmlWindow->GetInternalRepresentation()->GetWidth(), htmlWindow->GetInternalRepresentation()->GetHeight())); //htmlWindow->SetInitialSize(wxSize(htmlWindow->GetInternalRepresentation()->GetWidth(), htmlWindow->GetInternalRepresentation()->GetHeight()));
//SetSize(wxSize(300,150)); //SetSize(wxSize(300,150));
topsizer->Add(htmlWindow, 1, wxALL, 1); topsizer->Add(htmlWindow, 1, wxALL, 1);
//wxButton* bu1 = new wxButton(this, wxID_OK, _("OK")); //wxButton* bu1 = new wxButton(this, wxID_OK, _("OK"));
//bu1->SetDefault(); //bu1->SetDefault();
//topsizer->Add(bu1, 0, wxALL | wxALIGN_RIGHT, 15); //topsizer->Add(bu1, 0, wxALL | wxALIGN_RIGHT, 15);
SetSizer(topsizer); SetSizer(topsizer);
topsizer->Fit(this); topsizer->Fit(this);
int xx, yy;
htmlWindow->GetVirtualSize(&xx, &yy);
//wxSize sz = GetSize();
wxPoint posScreen;
wxSize sizeScreen;
const int displayNum = wxDisplay::GetFromPoint(posit);
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);
//this->Bind(wxEVT_HTML_CELL_CLICKED, [&](wxHtmlCellEvent& event) { if (xx > sizeScreen.x) xx = sizeScreen.x - 120;
// wxHtmlCell* c = event.GetCell(); if (yy > sizeScreen.y) yy = sizeScreen.y - 120;
//
// wxString ctext=c->ConvertToText(NULL);
// ctext=htmlWindow->SelectionToText();
// wxString s = wxString::Format("cell = %s",ctext.c_str());
// wxMessageBox(s, "cell", wxOK | wxICON_INFORMATION);
// });
this->Bind(wxEVT_HTML_LINK_CLICKED, [&](wxHtmlLinkEvent& event) { if (xx > top_sz.x || yy > top_sz.y) {
wxHtmlLinkInfo i = event.GetLinkInfo(); int dx = 0;
wxString name = i.GetHref(); if (htmlWindow->IsScrollbarShown(wxHORIZONTAL)) dx=htmlWindow->GetScrollThumb(wxHORIZONTAL);
wxString body=this->hhelper->getHelpString(name); SetSizePopup(wxSize(xx+dx, yy+5));
}
//this->Bind(wxEVT_HTML_CELL_CLICKED, [&](wxHtmlCellEvent& event) {
// wxHtmlCell* c = event.GetCell();
//
// wxString ctext=c->ConvertToText(NULL);
// ctext=htmlWindow->SelectionToText();
// wxString s = wxString::Format("cell = %s",ctext.c_str());
// wxMessageBox(s, "cell", wxOK | wxICON_INFORMATION);
// });
this->Bind(wxEVT_HTML_LINK_CLICKED, [&](wxHtmlLinkEvent& event) {
wxHtmlLinkInfo i = event.GetLinkInfo();
wxString name = i.GetHref();
wxString body=this->hhelper->getHelpString(name);
if (body.IsEmpty()) { if (body.IsEmpty()) {
body = this->hhelper->getHelpFile(name); body = this->hhelper->getHelpFile(name);
} }
SetPage(body); SetPage(body);
//ctext=htmlWindow->SelectionToText(); //ctext=htmlWindow->SelectionToText();
//wxString s = wxString::Format("cell = %s",ctext.c_str()); //wxString s = wxString::Format("cell = %s",ctext.c_str());
}); });
htmlWindow->Bind(wxEVT_RIGHT_UP, [&](wxMouseEvent& event) { htmlWindow->Bind(wxEVT_RIGHT_UP, [&](wxMouseEvent& event) {
wxString name; wxString name;
wxLongLong e = wxGetLocalTimeMillis();
if (e - startTimeWin < 150)
return;
//wxString body = this->hhelper->getHelpString(name); //wxString body = this->hhelper->getHelpString(name);
wxString ctext = htmlWindow->SelectionToText(); wxString ctext = htmlWindow->SelectionToText();
if (!ctext.IsEmpty()) { if (!ctext.IsEmpty()) {
@ -88,6 +152,17 @@ public:
{ {
} }
wxString wname = GetParent()->GetName();
if (wname == "frmStatus") {
//CMD_EVENT_FIND_STR
wxCommandEvent event(wxEVT_MENU, 281);
event.SetEventObject(this);
// Give it some contents
event.SetString(ctext);
// Do send it
GetParent()->ProcessWindowEvent(event);
}
//statusBar->SetStatusText(wxString::Format(" TIMER COUNT %d x:%d,y:%d", count, m.x, m.y));
Hide(); Hide();
return; return;
} }
@ -95,21 +170,43 @@ public:
//ctext=htmlWindow->SelectionToText(); //ctext=htmlWindow->SelectionToText();
//wxString s = wxString::Format("cell = %s",ctext.c_str()); //wxString s = wxString::Format("cell = %s",ctext.c_str());
}); });
startTimeWin = wxGetLocalTimeMillis();
} int inter = hhelper->GetTimerClose();
if (inter != -1) {
closeTimer = new wxTimer(this);
Bind(wxEVT_TIMER, [&](wxTimerEvent& event) {
closeTimer->Stop();
wxPoint pm = this->GetScreenPosition();
wxRect rc = this->GetSize();
wxPoint m = wxGetMousePosition();
rc.x = pm.x;
rc.y = pm.y;
if (!rc.Contains(m)) {
Hide();
return;
}
});
closeTimer->StartOnce(inter);
}
}
private: private:
bool isvalid = true; bool isvalid = true;
wxHtmlWindow* htmlWindow; wxHtmlWindow* htmlWindow;
FunctionPGHelper* hhelper; wxLongLong startTimeWin;
wxSize sizew;
FunctionPGHelper* hhelper;
std::vector<wxString> hist; std::vector<wxString> hist;
void SetPage(wxString innerbody,bool gethistory=false) { void SetPage(wxString innerbody,bool gethistory=false) {
wxString h; wxString h;
int p = innerbody.Find("<body>"); int p = innerbody.Find("<body>");
if (p > -1) { if (innerbody.Find("<html>")>=0) h = innerbody;
innerbody.Replace("<body>", "<html><body TEXT=\"#000000\" BGCOLOR=\"#FFFFA0\" LINK=\"#0000FF\" VLINK=\"#FF0000\" ALINK=\"#000088\">", false); else
h = "" + innerbody + ""; if (p > -1) {
} else innerbody.Replace("<body>", "<html><body TEXT=\"#000000\" BGCOLOR=\"#FFFFE0\" LINK=\"#0000FF\" VLINK=\"#FF0000\" ALINK=\"#000088\">", false);
h = "<html><body TEXT=\"#000000\" BGCOLOR=\"#FFFFA0\" LINK=\"#0000FF\" VLINK=\"#FF0000\" ALINK=\"#000088\">" + innerbody + "</body></hmtl>"; h = "" + innerbody + "";
}
else
h = "<html><body TEXT=\"#000000\" BGCOLOR=\"#FFFFE0\" LINK=\"#0000FF\" VLINK=\"#FF0000\" ALINK=\"#000088\">" + innerbody + "</body></hmtl>";
if (gethistory) { if (gethistory) {
if (hist.size() < 2) { if (hist.size() < 2) {
@ -122,7 +219,9 @@ private:
else { else {
hist.push_back(h); hist.push_back(h);
} }
htmlWindow->SetPage(h); htmlWindow->SetPage(h);
} }
private:
wxTimer *closeTimer=NULL;
}; };
#endif #endif

View file

@ -1062,6 +1062,7 @@
<ClCompile Include="utils\pgconfig.cpp" /> <ClCompile Include="utils\pgconfig.cpp" />
<ClCompile Include="utils\registry.cpp" /> <ClCompile Include="utils\registry.cpp" />
<ClCompile Include="utils\sshTunnel.cpp" /> <ClCompile Include="utils\sshTunnel.cpp" />
<ClCompile Include="utils\PreviewHtml.cpp" />
<ClCompile Include="utils\sysLogger.cpp" /> <ClCompile Include="utils\sysLogger.cpp" />
<ClCompile Include="utils\sysProcess.cpp" /> <ClCompile Include="utils\sysProcess.cpp" />
<ClCompile Include="utils\sysSettings.cpp" /> <ClCompile Include="utils\sysSettings.cpp" />
@ -1613,6 +1614,7 @@
<ClInclude Include="include\utils\json\json_defs.h" /> <ClInclude Include="include\utils\json\json_defs.h" />
<ClInclude Include="include\utils\TableColsMap.h" /> <ClInclude Include="include\utils\TableColsMap.h" />
<ClInclude Include="include\utils\sshTunnel.h" /> <ClInclude Include="include\utils\sshTunnel.h" />
<ClInclude Include="include\utils\PreviewHtml.h" />
<ClInclude Include="include\version.h" /> <ClInclude Include="include\version.h" />
<ClInclude Include="include\utils\csvfiles.h" /> <ClInclude Include="include\utils\csvfiles.h" />
<ClInclude Include="include\utils\factory.h" /> <ClInclude Include="include\utils\factory.h" />

250
utils/PreviewHtml.cpp Normal file
View file

@ -0,0 +1,250 @@
#include "pgAdmin3.h"
#include "utils/PreviewHtml.h"
#include "utils/json/jsonval.h"
#include "utils/csvfiles.h"
#include "log/Storage.h"
void PreviewHtml::InitColor() {
wxJSONValue def(wxJSONType::wxJSONTYPE_OBJECT);
def.SetType(wxJSONType::wxJSONTYPE_NULL);
wxJSONValue opt(wxJSONType::wxJSONTYPE_OBJECT);
opt.SetType(wxJSONType::wxJSONTYPE_NULL);
extern sysSettings* settings;
settings->ReadJsonObect("PreviewOptions", opt, def);
// settings->WriteJsonFile();
if (!opt.IsNull()) {
bgcolor = opt["bgcolor"].AsString();
fgcolor = opt["fgcolor"].AsString();
numcolor = opt["numcolor"].AsString();
quotecolor = opt["quotecolor"].AsString();
//fname = opt["fontname"].AsString();
//fsize=opt["fontsize"].AsInt();
}
else {
wxColour frColor = settings->GetSQLBoxColourForeground();
if (settings->GetSQLBoxUseSystemForeground())
{
frColor = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
}
fgcolor=frColor.GetAsString(wxC2S_HTML_SYNTAX);
opt["fgcolor"] = fgcolor;
bgcolor = "#FFFFE0";
//4
numcolor = settings->GetSQLBoxColour(4);
wxColour cc(numcolor);
if (cc.IsOk()) numcolor = cc.GetAsString(wxC2S_HTML_SYNTAX);
//6
quotecolor = settings->GetSQLBoxColour(6);
wxColour ccc(quotecolor);
if (ccc.IsOk()) quotecolor = ccc.GetAsString(wxC2S_HTML_SYNTAX);
// wxFont fnt = settings->GetSQLFont();
// fname = fnt.GetFaceName();
// fsize = fnt.GetPointSize();
//fnt.SetPointSize(fsize);
opt["fgcolor"] = fgcolor;
opt["bgcolor"] = bgcolor;
opt["numcolor"] = numcolor;
opt["quotecolor"] = quotecolor;
// opt["fontname"] = fname;
// opt["fontsize"]=fsize;
settings->WriteJsonObect("PreviewOptions", opt);
}
}
wxString PreviewHtml::Preview(const wxString& txt, fmtpreview type) {
fmtpreview fmt = type;
wxString fieldSep=",";
wxString rowSep = "\n";
bool iscsv = false;
if (txt.StartsWith("automatic vacuum")&& fmt == fmtpreview::AUTO) fmt = fmtpreview::AUTOVACCUM;
if (txt.StartsWith("automatic analyze") && fmt == fmtpreview::AUTO) fmt = fmtpreview::AUTOVACCUM;
//
if (fmt == fmtpreview::AUTOVACCUM) {
fieldSep = ",";
rowSep = "\n";
}
else if (fmt == fmtpreview::CSV) {
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;
}
// prepare csv
std::vector<wxString> strlist;
wxString tmpstr = txt;
if (iscsv) {
CSVTokenizer tk(txt);
tmpstr = "";
int nfield = 0;
while (tk.HasMoreTokens()) {
wxString field = tk.GetNextToken();
if (!field.IsEmpty()) {
if (!tmpstr.IsEmpty()) tmpstr += '\n'; // All not empty field as list rows
tmpstr += field;
}
strlist.push_back(field);
nfield++;
}
if (nfield == 26) {
// log db csv format 14,15,16,17 version
Line l=Storage::getLineParse(txt, true, "");
strlist[15] = Storage::get_field(l, MyConst::colField::logHint); // bind value
strlist[13] = Storage::get_field(l, MyConst::colField::logMessage); // bind value
}
}
if (strlist.size() == 0) strlist.push_back(tmpstr);
wxString html;
int nf = 0;
for (int nf = 0; nf < strlist.size();nf++) {
tmpstr = strlist[nf];
int pos = 0;
int len = tmpstr.Length();
if (len == 0) continue;
wxUniChar c;
wxString currWord;
wxString currDigits;
wxString currSep;
int flag = 0;
tokens.clear();
bool quote = false;
wxUniChar prevchar;
int startstr = -1;
while (pos < len) {
c = tmpstr[pos++];
bool isquote = c == '"';
if (quote) {
if (prevchar == c && isquote) {
// repeat quote
prevchar = '\0';
continue;
}
if (prevchar == '"' && !isquote) {
// end quote string
wxString tmp = tmpstr.Mid(startstr, pos - startstr - 1);
saveTokenIfNotEmpty(tmp, PREVIEW_QUOTE);
quote = false;
}
else {
prevchar = c;
continue;
}
}
if (quote == false && isquote) {
saveTokenIfNotEmpty(currWord, PREVIEW_WORD);
saveTokenIfNotEmpty(currDigits, PREVIEW_DIGITS);
saveTokenIfNotEmpty(currSep, PREVIEW_SEP);
quote = true;
prevchar = '\0';
startstr = pos - 1;
continue;
}
if (fieldSep.Length() > 0 && fieldSep[0] == c) {
//flag |= PREVIEW_ENDFIELD;
saveTokenIfNotEmpty(currWord, PREVIEW_WORD);
saveTokenIfNotEmpty(currDigits, PREVIEW_DIGITS);
saveTokenIfNotEmpty(currSep, PREVIEW_SEP);
currSep = c;
saveTokenIfNotEmpty(currSep, PREVIEW_ENDFIELD);
continue;
}
else if (rowSep.Length() > 0 && rowSep[0] == c) {
//flag |= PREVIEW_ENDROW;
saveTokenIfNotEmpty(currWord, PREVIEW_WORD);
saveTokenIfNotEmpty(currDigits, PREVIEW_DIGITS);
saveTokenIfNotEmpty(currSep, PREVIEW_SEP);
currSep = c;
saveTokenIfNotEmpty(currSep, PREVIEW_ENDROW);
continue;
}
if ((c >= '0' && c <= '9') || (currDigits.Length() > 0 && c == '.')) {
if (currWord.Length() == 0) { // diget not after word
saveTokenIfNotEmpty(currSep, PREVIEW_SEP);
currDigits += c;
continue;
}
}
if (c == '-' || c == '+' || c == '.' || c == ',' ||
c == ':' || c == '~' ||
c == '@' || c == '*' || c == '/' ||
c == '=' || c == '!' || c == '#' ||
c == '&' || c == '%' || c == '^' ||
c == '|' || c == '`' || c == '?' ||
c == '>' || c == '<'
|| c == ';' || c == '_' || c == '(' || c == ')' || c == '[' || c == ']' || c == '{' || c == '}'
|| c == ' '
)
{
saveTokenIfNotEmpty(currWord, PREVIEW_WORD);
saveTokenIfNotEmpty(currDigits, PREVIEW_DIGITS);
currSep += c;
continue;
}
saveTokenIfNotEmpty(currSep, PREVIEW_SEP);
if (currDigits.Length() > 0) {
currWord = currDigits + currWord;
currDigits = "";
}
currWord += c;
}
// last element
if (quote) {
wxString tmp = tmpstr.Mid(startstr);
saveTokenIfNotEmpty(tmp, PREVIEW_QUOTE);
}
saveTokenIfNotEmpty(currWord, PREVIEW_WORD);
saveTokenIfNotEmpty(currDigits, PREVIEW_DIGITS);
saveTokenIfNotEmpty(currSep, PREVIEW_SEP);
// Additonal styled
wxString findstr = "";
int p = 0;
while (p >= 0) {
int fp = FindElement(p, PREVIEW_ENDFIELD | PREVIEW_ENDROW, findstr, 1);
if (fp > 0) {
int pp = fp;
while (pp > 0 && pp > p) {
pp--;
Element t2 = tokens[pp];
if (CHKFLAG(t2.flags, PREVIEW_SEP) && t2.src.StartsWith(":")) {
// Right bound title
if (pp - p > 0) {
tokens[p].html = "<b>" + tokens[p].html;
tokens[pp - 1].html = tokens[pp - 1].html + "</b>";
}
}
}
fp++; // next field
p = fp;
}
else break;
}
if (strlist.size() > 1) {
// csv log
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>";
} else
html+= generateHtml(); // tokens -> html
}
if (strlist.size() > 1) html = "<table CELLPADDING=\"1\">" + html + "</table>";
wxString ttt = wxString::Format("<html><body BGCOLOR=\"%s\" FGCOLOR=\"%s\">%s</body></html>", bgcolor, fgcolor, html);
return ttt;
}

View file

@ -560,7 +560,7 @@ wxString replace_bind_parameters(const wxString& values_param, const wxString& t
replacecount = c; replacecount = c;
return str; return str;
} }
Line Storage::getLineParse(const wxString& str, bool csv) { Line Storage::getLineParse(const wxString& str, bool csv,const wxString &host) {
Line st; Line st;
if (csv) { if (csv) {
CSVTokenizer tk(str); CSVTokenizer tk(str);
@ -575,7 +575,7 @@ Line Storage::getLineParse(const wxString& str, bool csv) {
st.loguser = { static_cast<unsigned short int>(t.Len()),static_cast<unsigned short int>(logUser.Len()) }; st.loguser = { static_cast<unsigned short int>(t.Len()),static_cast<unsigned short int>(logUser.Len()) };
t += logUser; t += logUser;
wxString logDatabase = tk.GetNextToken(); wxString logDatabase = tk.GetNextToken();
if (logDatabase.IsEmpty()) logDatabase = GetHost(); if (logDatabase.IsEmpty()) logDatabase = host;
st.logdb = { static_cast<unsigned short int>(t.Len()),static_cast<unsigned short int>(logDatabase.Len()) }; st.logdb = { static_cast<unsigned short int>(t.Len()),static_cast<unsigned short int>(logDatabase.Len()) };
t += logDatabase; t += logDatabase;
@ -659,7 +659,7 @@ Line Storage::getLineParse(const wxString& str, bool csv) {
wxString logType = tk.GetNextToken(); wxString logType = tk.GetNextToken();
st.logbtype = { static_cast<unsigned short int>(t.Len()),static_cast<unsigned short int>(logType.Len()) }; st.logbtype = { static_cast<unsigned short int>(t.Len()),static_cast<unsigned short int>(logType.Len()) };
t += logType; t += logType;
logCursorpos = GetHost(); logCursorpos = host;
st.logSERVER = { static_cast<unsigned short int>(t.Len()),static_cast<unsigned short int>(logCursorpos.Len()) }; st.logSERVER = { static_cast<unsigned short int>(t.Len()),static_cast<unsigned short int>(logCursorpos.Len()) };
t += logCursorpos; t += logCursorpos;
//fields.Add(logType); //fields.Add(logType);
@ -785,7 +785,7 @@ bool Storage::checkFilter(Line& l) {
return false; return false;
} }
bool Storage::AddLineTextCSV(const wxString& strcsv) { bool Storage::AddLineTextCSV(const wxString& strcsv) {
Line st = getLineParse(strcsv, true); Line st = getLineParse(strcsv, true,GetHost());
if (checkFilter(st)) { if (checkFilter(st)) {
rowsignore++; rowsignore++;