From 075347b1c37f29bdd7d5099ef21d16f0a69bf6e1 Mon Sep 17 00:00:00 2001 From: lsv Date: Thu, 11 Jan 2024 10:04:03 +0500 Subject: [PATCH] Add action Compare 2 Cells MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit При помощи команды можно сравнить 2 не пустые ячейки в результах запроса. --- ctl/ctlGitPanel.cpp | 321 +--------------------------- ctl/ctlSQLResult.cpp | 58 ++++- frm/frmQuery.cpp | 9 + include/ctl/SourceViewDialog.h | 378 +++++++++++++++++++++++++++++++++ include/ctl/ctlSQLResult.h | 1 + include/frm/frmQuery.h | 1 + include/frm/menu.h | 1 + 7 files changed, 449 insertions(+), 320 deletions(-) create mode 100644 include/ctl/SourceViewDialog.h diff --git a/ctl/ctlGitPanel.cpp b/ctl/ctlGitPanel.cpp index 6fc9aa4..444b13a 100644 --- a/ctl/ctlGitPanel.cpp +++ b/ctl/ctlGitPanel.cpp @@ -22,327 +22,16 @@ #include "images/gqbAdd.pngc" #include "images/gqbRemove.pngc" #include "images/conversion.pngc" -#include "../utils/diff_match_patch.h" - +#include "ctl/SourceViewDialog.h" enum { MARGIN_LINE_NUMBERS }; + + + #if !defined(NO_WXJSON_GIT) - -class SourceViewDialog : public wxFrame -{ - ctlSQLBox* m_text1; - ctlSQLBox* m_text2; - bool m_changing_values; - wxCheckBox* m_visibleSpace; - wxCheckBox* m_showNumber; - -public: - - void onClose(wxCloseEvent& evt) - { - //EndModal(GetReturnCode()); - evt.Skip(); - - } - void showNumber(ctlSQLBox* text, bool visible) - { - if (visible) { - long int width = text->TextWidth(wxSTC_STYLE_LINENUMBER, - wxT(" ") + NumToStr((long int)text->GetLineCount()) + wxT(" ")); - if (width != text->GetMarginWidth(0)) - { - text->SetMarginWidth(0, width); - text->Update(); - } - } - else { - text->SetMarginWidth(0, 0); - text->Update(); - } - } - ctlSQLBox* createSTC() - { - ctlSQLBox* text = new ctlSQLBox(this, wxID_ANY); - -// text->SetMarginWidth(MARGIN_LINE_NUMBERS, 20); -// text->StyleSetForeground(wxSTC_STYLE_LINENUMBER, wxColour(75, 75, 75)); -// text->StyleSetBackground(wxSTC_STYLE_LINENUMBER, wxColour(220, 220, 220)); -// text->SetMarginType(MARGIN_LINE_NUMBERS, wxSTC_MARGIN_NUMBER); - text->SetEOLMode(2); - - showNumber(text,true); - - //text->StyleSetForeground(wxSTC_H_DOUBLESTRING, wxColour(255, 0, 0)); - //text->StyleSetForeground(wxSTC_H_SINGLESTRING, wxColour(255, 0, 0)); - //text->StyleSetForeground(wxSTC_H_ENTITY, wxColour(255, 0, 0)); - //text->StyleSetForeground(wxSTC_H_TAG, wxColour(0, 150, 0)); - //text->StyleSetForeground(wxSTC_H_TAGUNKNOWN, wxColour(0, 150, 0)); - //text->StyleSetForeground(wxSTC_H_ATTRIBUTE, wxColour(0, 0, 150)); - //text->StyleSetForeground(wxSTC_H_ATTRIBUTEUNKNOWN, wxColour(0, 0, 150)); - //text->StyleSetForeground(wxSTC_H_COMMENT, wxColour(150, 150, 150)); - - return text; - } - void addIndicText(ctlSQLBox* ctl,std::wstring tex,int indic) { - wxString t(tex); - - ctl->AddText(t); - if (indic > 0) { - ctl->IndicatorFillRange(ctl->GetLength()-t.Len(), t.Len()); - } - }; - void difftext(ctlSQLBox* ctlL, ctlSQLBox* ctlR, wxString sL,wxString sR) { - //Diff_EditCost = 4; - //Match_Threshold = 0.5; - //Match_Distance = 1000; - diff_match_patch dmp(4, 0.5, 1000); - std::list diffs; - if (sL == sR) { - return ; - } - diffs = dmp.diff_main(sL.wc_str(), sR.wc_str(), true); - int nstart = 0; - int pos = 0; - std::wstring cur_l; - std::wstring ncur_l;// std::wstring p_ncur_l; std::wstring p_ncur_r; - std::wstring cur_r; - std::wstring ncur_r; - std::wstring tex; - std::wstring t; - std::wstring tableline; - int rline = 1, lline = 1; - std::list::const_iterator it; // ��������� �������� - it = diffs.begin(); // ����������� ��� ������ ������ - Diff aDiff; - bool modify = false; - nstart = 0; - int s_indicHighlight=20; - ctlL->IndicatorSetForeground(s_indicHighlight, wxColour(246, 185, 100)); - ctlL->IndicatorSetAlpha(s_indicHighlight, 50); - ctlL->IndicatorSetStyle(s_indicHighlight, wxSTC_INDIC_ROUNDBOX); - ctlL->SetIndicatorCurrent(s_indicHighlight); - - ctlR->IndicatorSetForeground(s_indicHighlight, wxColour(246, 185, 100)); - ctlR->IndicatorSetAlpha(s_indicHighlight, 50); - ctlR->IndicatorSetStyle(s_indicHighlight, wxSTC_INDIC_ROUNDBOX); - ctlR->SetIndicatorCurrent(s_indicHighlight); - - while (it != diffs.end()) // ���� �������� �� ��������� ����� - { - aDiff = *it; - tex = aDiff.text; - nstart = 0; - while (nstart < tex.length()) { - pos = tex.find('\n', nstart); - if (pos == -1) { t.assign(tex, nstart, tex.length()); nstart = tex.length(); } - else { t.assign(tex, nstart, pos - nstart); nstart = pos; } - if (t.length() > 0) { - // ��� �� ��� ���� ������ - if (aDiff.operation == Operation::INSERT) { - cur_r += L"" + t + L""; addIndicText(ctlR, t, s_indicHighlight); - } - if (aDiff.operation == 0) { - cur_l += L"" + t + L""; addIndicText(ctlL,t, s_indicHighlight); - } - if (aDiff.operation == Operation::EQUAL) { - cur_r += t; - cur_l += t; - addIndicText(ctlL, t, 0); - addIndicText(ctlR, t, 0); - } - else modify = true; - // ���� �� �������� ������� ������ ������� ��� ��� �� ���� ������ - } - else - { - // ����� �� �������� \n - nstart = pos + 1; - ncur_l = std::to_wstring(lline); - ncur_l = L""; ncur_r = L""; - // if (p_ncur_r==ncur_r) { ncur_r=L""; modify=true;} - // if (p_ncur_l==ncur_l) { ncur_l=L""; modify=true;} - - std::wstring t_cur_l = cur_l; - std::wstring t_cur_r = cur_r; - if (aDiff.operation == 0) { - t_cur_r = L""; - addIndicText(ctlL, L"\n", s_indicHighlight); - ncur_l = std::to_wstring(lline); - modify = true; - lline++; - } - else if (aDiff.operation == Operation::INSERT) { - t_cur_l = L""; - addIndicText(ctlR, L"\n", s_indicHighlight); - ncur_r = std::to_wstring(rline); - modify = true; - rline++; - } - else if (aDiff.operation == Operation::EQUAL) { - ncur_r = std::to_wstring(rline); - ncur_l = std::to_wstring(lline); - rline++; lline++; - addIndicText(ctlL, L"\n", 0); - addIndicText(ctlR, L"\n", 0); - } - // if (modify) countdiffline++; - // if (( (ncur_r.empty()&&(!ncur_l.empty())) - // ||(ncur_l.empty()&&(!ncur_r.empty())) - // )&&(!modify)) modify=true; - // create columns - //left - tableline += L""; - tableline += modify ? L"" + ncur_l + "" : L"" + ncur_l + ""; - tableline += L"
" + t_cur_l + "
"; - // right - tableline += L""; - tableline += modify ? L"" + ncur_r + "" : L"" + ncur_r + ""; - tableline += L"
" + t_cur_r + "
"; - tableline += L""; - - if (aDiff.operation == 0) { - cur_l = L""; - } - else if (aDiff.operation == Operation::INSERT) { - cur_r = L""; - } - else if (aDiff.operation == Operation::EQUAL) { - cur_r = L""; cur_l = L""; - } - - // - modify = false; - } - } // ���� �� ������� ������ ������ Diff - ++it; - } - - } - SourceViewDialog(wxWindow* parent, wxString sqlL, wxString sqlR) : - wxFrame(parent, wxID_ANY, L"Compare git to DB", wxDefaultPosition, wxSize(900, 600)) - { - m_changing_values = false; - m_text1 = createSTC(); - //m_text1->SetText(sqlL); - - m_text2 = createSTC(); - //m_text2->SetText(sqlR); - - difftext(m_text1, m_text2, sqlL, sqlR); - - - - wxBoxSizer* bSizer1; - bSizer1 = new wxBoxSizer(wxVERTICAL); - - wxPanel* m_panelSql = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); - wxBoxSizer* bSizer2; - bSizer2 = new wxBoxSizer(wxHORIZONTAL); - - bSizer2->Add(m_text1, 1, wxEXPAND, 5); - - bSizer2->Add(m_text2, 1, wxEXPAND, 5); - - - m_panelSql->SetSizer(bSizer2); - m_panelSql->Layout(); - bSizer2->Fit(m_panelSql); - bSizer1->Add(m_panelSql, 1, wxEXPAND, 2); - - wxPanel* m_panelOpt = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); - wxBoxSizer* bSizer4; - bSizer4 = new wxBoxSizer(wxHORIZONTAL); - - m_visibleSpace = new wxCheckBox(m_panelOpt, wxID_ANY, wxT("Show space simbol"), wxDefaultPosition, wxDefaultSize, 0); - bSizer4->Add(m_visibleSpace, 0, wxALL, 5); - - m_showNumber = new wxCheckBox(m_panelOpt, wxID_ANY, wxT("Show number line"), wxDefaultPosition, wxDefaultSize, 0); - bSizer4->Add(m_showNumber, 0, wxALL, 5); - - - bSizer4->Add(0, 0, 1, wxEXPAND, 5); - - wxButton* m_btn_close = new wxButton(m_panelOpt, wxID_ANY, wxT("Close"), wxDefaultPosition, wxDefaultSize, 0); - bSizer4->Add(m_btn_close, 0, wxALL, 5); - -// wxButton *m_btn_cancel = new wxButton(m_panelOpt, wxID_ANY, wxT("Cancel"), wxDefaultPosition, wxDefaultSize, 0); -// bSizer4->Add(m_btn_cancel, 0, wxALL, 5); - - - m_panelOpt->SetSizer(bSizer4); - m_panelOpt->Layout(); - bSizer4->Fit(m_panelOpt); - bSizer1->Add(m_panelOpt, 0, wxALL | wxEXPAND, 5); - - - this->SetSizer(bSizer1); - this->Layout(); - - this->Centre(wxBOTH); - - m_visibleSpace->Bind(wxEVT_CHECKBOX, &SourceViewDialog::OnShowCheckBoxSpace, this); - m_showNumber->Bind(wxEVT_CHECKBOX, &SourceViewDialog::OnShowCheckShowNumber, this); - m_btn_close->Bind(wxEVT_BUTTON, &SourceViewDialog::onClose2, this); - //Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(SourceViewDialog::onClose), NULL, this); - //m_text1->Connect(wxEVT_STC_PAINTED, wxStyledTextEventHandler(SourceViewDialog::onScrollLeft), NULL, this); - //m_text2->Connect(wxEVT_STC_PAINTED, wxStyledTextEventHandler(SourceViewDialog::onScrollRight), NULL, this); - Bind(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(SourceViewDialog::onClose), this); - m_text1->Bind(wxEVT_STC_PAINTED, wxStyledTextEventHandler(SourceViewDialog::onScrollLeft), this); - m_text2->Bind(wxEVT_STC_PAINTED, wxStyledTextEventHandler(SourceViewDialog::onScrollRight), this); - - } - void onClose2(wxCommandEvent& evt) { - //onClose(wxCloseEvent(NULL)); - Close(); - } - void OnShowCheckBoxSpace(wxCommandEvent& evt) { - bool bVal= m_visibleSpace->IsChecked(); - m_text1->SetViewWhiteSpace(bVal ? wxSTC_WS_VISIBLEALWAYS : wxSTC_WS_INVISIBLE); - m_text1->SetViewEOL(bVal ? 1: 0); - m_text2->SetViewWhiteSpace(bVal ? wxSTC_WS_VISIBLEALWAYS : wxSTC_WS_INVISIBLE); - m_text2->SetViewEOL(bVal ? 1 : 0); - - } - void OnShowCheckShowNumber(wxCommandEvent& evt) { - bool bVal = m_showNumber->IsChecked(); - showNumber(m_text1, bVal); - showNumber(m_text2, bVal); - } - - void onScrollLeft(wxStyledTextEvent& evt) - { - if (m_changing_values) return; - m_changing_values = true; - - int fvl = m_text1->GetFirstVisibleLine(); - if (m_text2->GetFirstVisibleLine() != fvl) - { - m_text2->ScrollToLine(fvl); - // ShowLines - } - - m_changing_values = false; - } - - void onScrollRight(wxStyledTextEvent& evt) - { - if (m_changing_values) return; - m_changing_values = true; - - int fvl = m_text2->GetFirstVisibleLine(); - if (m_text1->GetFirstVisibleLine() != fvl) - { - m_text1->ScrollToLine(fvl); - // ShowLines - } - - m_changing_values = false; - } -}; - ctlGitPanel::ctlGitPanel(wxWindow* parent, frmMain* form, wxJSONValue cf) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize) { @@ -584,7 +273,7 @@ void ctlGitPanel::OnListRClick(wxListEvent& evt) { } wxString sql_git = m_git_content[pat]; wxString sql_db = m_base_content[pat]; - SourceViewDialog* dlg = new SourceViewDialog(NULL, sql_git,sql_db); + SourceViewDialog* dlg = new SourceViewDialog(NULL, sql_git,sql_db, L"Compare git to DB"); dlg->Show(); } diff --git a/ctl/ctlSQLResult.cpp b/ctl/ctlSQLResult.cpp index 18e3bb4..2794b68 100644 --- a/ctl/ctlSQLResult.cpp +++ b/ctl/ctlSQLResult.cpp @@ -22,7 +22,7 @@ #include "frm/frmExport.h" #include "frm/mathplot.h" #include "frm/frmPlot.h" - +#include "ctl/SourceViewDialog.h" ctlSQLResult::ctlSQLResult(wxWindow *parent, pgConn *_conn, wxWindowID id, const wxPoint &pos, const wxSize &size) @@ -341,7 +341,6 @@ wxString ctlSQLResult::OnGetItemText(long item, long col) const } wxString ctlSQLResult::CopySelColumnNameType() { - size_t i; wxString ss = wxEmptyString; if (GetSelectedCols().GetCount()) { wxArrayInt cols = GetSelectedCols(); @@ -479,6 +478,58 @@ wxDateTime parseDT(int &fmttype,const wxString dtStr) { } return dt; } +wxString ctlSQLResult::CompareSelectCells() { + if (IsSelection()) { + unsigned int i; + int row, col; + wxGridCellCoordsArray cells = GetSelectedCells(); + wxString sql_1; + wxString sql_2; + wxString cname; + if (GetSelectionBlockTopLeft().GetCount() > 0 && + GetSelectionBlockBottomRight().GetCount() > 0) + { + unsigned int x1, x2, y1, y2; + int count = GetSelectionBlockTopLeft().GetCount(); + + x1 = GetSelectionBlockTopLeft()[0].GetCol(); + x2 = GetSelectionBlockBottomRight()[0].GetCol(); + y1 = GetSelectionBlockTopLeft()[0].GetRow(); + y2 = GetSelectionBlockBottomRight()[0].GetRow(); + for (size_t n = 0; n < count; n++) + { + x1 = GetSelectionBlockTopLeft()[n].GetCol(); + x2 = GetSelectionBlockBottomRight()[n].GetCol(); + y1 = GetSelectionBlockTopLeft()[n].GetRow(); + y2 = GetSelectionBlockBottomRight()[n].GetRow(); + for (i = y1; i <= y2; i++) + { + //clearCellData(row, col); + row = i; + col = x1; + if (sql_1.IsEmpty()) { sql_1 = GetCellValue(row, col); cname = wxString::Format("Row: %d col:%s", row + 1, ctlSQLGrid::GetColumnName(col)); } + else { + sql_2 = GetCellValue(row, col); cname += wxString::Format(" # Row: %d col:%s", row + 1, ctlSQLGrid::GetColumnName(col)); + } + if (!sql_2.IsEmpty() && sql_1 == sql_2) { + sql_2 = wxEmptyString; + cname = cname.BeforeFirst('#'); + continue; + } + if (!sql_2.IsEmpty()) { + SourceViewDialog* dlg = new SourceViewDialog(NULL, sql_1, sql_2, cname); + dlg->Show(); + return "Diff cells"; + } + } + } + } + else + { + } + } + return "Not diff cells."; +} wxString ctlSQLResult::AutoColsPlot(int flags,frmQuery* parent) { wxArrayInt cols; wxArrayString leg; @@ -486,7 +537,7 @@ wxString ctlSQLResult::AutoColsPlot(int flags,frmQuery* parent) { wxString rez="Draw plot"; if (IsSelection()) { unsigned int i; - int row, col; + int col; wxGridCellCoordsArray cells = GetSelectedCells(); for (i = 0; i < cells.Count(); i++) { //clearCellData(cells[i].GetRow(), cells[i].GetCol()); @@ -789,7 +840,6 @@ void ctlSQLResult::OnKeyChar(wxKeyEvent& event) { int colS = GetGridCursorCol(); int rowS= GetGridCursorRow(); wxString fltval = this->searchStr; - bool eq; size_t numRows = GetNumberRows(); size_t numCols = GetNumberCols(); int all = 0, show = 0, hide = 0; diff --git a/frm/frmQuery.cpp b/frm/frmQuery.cpp index c043789..2790619 100644 --- a/frm/frmQuery.cpp +++ b/frm/frmQuery.cpp @@ -119,6 +119,7 @@ BEGIN_EVENT_TABLE(frmQuery, pgFrame) EVT_MENU(MNU_PASTE, frmQuery::OnPaste) EVT_MENU(MNU_CLEAR, frmQuery::OnClear) EVT_MENU(MNU_SUMMARY_COL, frmQuery::OnSummary_Column) + EVT_MENU(MNU_COMPARE_2CELL, frmQuery::OnCompare_2Cell) EVT_MENU(MNU_COPY_INSERT, frmQuery::OnCopy_Insert) EVT_MENU(MNU_COPY_INLIST, frmQuery::OnCopy_InList) EVT_MENU(MNU_COPY_WHERELIST, frmQuery::OnCopy_WhereList) @@ -2219,6 +2220,7 @@ void frmQuery::OnLabelRightClick(wxGridEvent &event) xmenu->AppendSeparator(); xmenu->Append(MNU_AUTOCOLSPLOT, _("Draw plot LY(bar) or LXY or XYYY..."), _("Draw plot LY(bar) LXY or XYYY...")); xmenu->Append(MNU_SUMMARY_COL, _("Summary"), _("Summary selected cells.")); + xmenu->Append(MNU_COMPARE_2CELL, _("Compare 2 Cells"), _("Compare 2 selected cells.")); xmenu->Append(MNU_CHECK_COLUMN_DATE, _("Check the sequence of dates"), _("Check the sequence of dates")); xmenu->Append(MNU_CLEAR_FILTER, _("Clear filter"), _("Clear filter")); bool selcol = sqlResult->GetSelectedCols().GetCount() > 0; @@ -2227,6 +2229,7 @@ void frmQuery::OnLabelRightClick(wxGridEvent &event) xmenu->Enable(MNU_COPY_TABLEHTML, selcol|| rows.GetCount()>0); xmenu->Enable(MNU_AUTOCOLSPLOT, sqlResult->IsSelection()); xmenu->Enable(MNU_SUMMARY_COL, sqlResult->IsSelection()); + xmenu->Enable(MNU_COMPARE_2CELL, sqlResult->IsSelection()); xmenu->Enable(MNU_COPY_INLIST, sqlResult->IsSelection()); xmenu->Enable(MNU_COPY_WHERELIST, sqlResult->IsSelection()); @@ -2341,6 +2344,12 @@ void frmQuery::OnAutoColsPlot(wxCommandEvent& ev) } } +void frmQuery::OnCompare_2Cell(wxCommandEvent& ev) +{ + wxString s = sqlResult->CompareSelectCells(); + SetStatusText(s, STATUSPOS_MSGS); +} + void frmQuery::OnSummary_Column(wxCommandEvent &ev) { // if (currentControl() == sqlResult) diff --git a/include/ctl/SourceViewDialog.h b/include/ctl/SourceViewDialog.h new file mode 100644 index 0000000..641db70 --- /dev/null +++ b/include/ctl/SourceViewDialog.h @@ -0,0 +1,378 @@ +#pragma once + +class SourceViewDialog : public wxFrame +{ + ctlSQLBox* m_text1; + ctlSQLBox* m_text2; + bool m_changing_values; + wxCheckBox* m_visibleSpace; + wxCheckBox* m_showNumber; + int s_indicHighlight; + int pos = 0; + int prev_line = -1; +public: + SourceViewDialog::~SourceViewDialog() { + //delete m_text1; + //m_btn_close->UnBind(); + } + void onClose(wxCloseEvent& evt) + { + //EndModal(GetReturnCode()); + evt.Skip(); + + } + void showNumber(ctlSQLBox* text, bool visible) + { + if (visible) { + long int width = text->TextWidth(wxSTC_STYLE_LINENUMBER, + wxT(" ") + NumToStr((long int)text->GetLineCount()) + wxT(" ")); + if (width != text->GetMarginWidth(0)) + { + text->SetMarginWidth(0, width); + text->Update(); + } + } + else { + text->SetMarginWidth(0, 0); + text->Update(); + } + } + ctlSQLBox* createSTC() + { + ctlSQLBox* text = new ctlSQLBox(this, wxID_ANY); + + // text->SetMarginWidth(MARGIN_LINE_NUMBERS, 20); + // text->StyleSetForeground(wxSTC_STYLE_LINENUMBER, wxColour(75, 75, 75)); + // text->StyleSetBackground(wxSTC_STYLE_LINENUMBER, wxColour(220, 220, 220)); + // text->SetMarginType(MARGIN_LINE_NUMBERS, wxSTC_MARGIN_NUMBER); + text->SetEOLMode(2); + + showNumber(text, true); + + //text->StyleSetForeground(wxSTC_H_DOUBLESTRING, wxColour(255, 0, 0)); + //text->StyleSetForeground(wxSTC_H_SINGLESTRING, wxColour(255, 0, 0)); + //text->StyleSetForeground(wxSTC_H_ENTITY, wxColour(255, 0, 0)); + //text->StyleSetForeground(wxSTC_H_TAG, wxColour(0, 150, 0)); + //text->StyleSetForeground(wxSTC_H_TAGUNKNOWN, wxColour(0, 150, 0)); + //text->StyleSetForeground(wxSTC_H_ATTRIBUTE, wxColour(0, 0, 150)); + //text->StyleSetForeground(wxSTC_H_ATTRIBUTEUNKNOWN, wxColour(0, 0, 150)); + //text->StyleSetForeground(wxSTC_H_COMMENT, wxColour(150, 150, 150)); + + return text; + } + void addIndicText(ctlSQLBox* ctl, std::wstring tex, int indic) { + wxString t(tex); + + ctl->AddText(t); + if (indic > 0) { + ctl->IndicatorFillRange(ctl->GetLength() - t.Len(), t.Len()); + } + }; + void difftext(ctlSQLBox* ctlL, ctlSQLBox* ctlR, wxString sL, wxString sR) { + //Diff_EditCost = 4; + //Match_Threshold = 0.5; + //Match_Distance = 1000; + diff_match_patch dmp(4, 0.5, 1000); + std::list diffs; + if (sL == sR) { + return; + } + diffs = dmp.diff_main(sL.wc_str(), sR.wc_str(), true); + int nstart = 0; + int pos = 0; + std::wstring cur_l; + std::wstring ncur_l;// std::wstring p_ncur_l; std::wstring p_ncur_r; + std::wstring cur_r; + std::wstring ncur_r; + std::wstring tex; + std::wstring t; + std::wstring tableline; + int rline = 1, lline = 1; + std::list::const_iterator it; // ��������� �������� + it = diffs.begin(); // ����������� ��� ������ ������ + Diff aDiff; + bool modify = false; + nstart = 0; + s_indicHighlight = 20; + ctlL->IndicatorSetForeground(s_indicHighlight, wxColour(246, 85, 100)); + + ctlL->IndicatorSetAlpha(s_indicHighlight, 50); + ctlL->IndicatorSetStyle(s_indicHighlight, wxSTC_INDIC_ROUNDBOX); + ctlL->SetIndicatorCurrent(s_indicHighlight); + + //ctlR->IndicatorSetForeground(s_indicHighlight, wxColour(246, 185, 100)); + ctlR->IndicatorSetForeground(s_indicHighlight, wxColour(246, 85, 100)); + ctlR->IndicatorSetAlpha(s_indicHighlight, 50); + ctlR->IndicatorSetStyle(s_indicHighlight, wxSTC_INDIC_ROUNDBOX); + ctlR->SetIndicatorCurrent(s_indicHighlight); + + while (it != diffs.end()) // ���� �������� �� ��������� ����� + { + aDiff = *it; + tex = aDiff.text; + nstart = 0; + while (nstart < tex.length()) { + pos = tex.find('\n', nstart); + if (pos == -1) { t.assign(tex, nstart, tex.length()); nstart = tex.length(); } + else { t.assign(tex, nstart, pos - nstart); nstart = pos; } + if (t.length() > 0) { + // ��� �� ��� ���� ������ + if (aDiff.operation == Operation::INSERT) { + cur_r += L"" + t + L""; addIndicText(ctlR, t, s_indicHighlight); + } + if (aDiff.operation == 0) { + cur_l += L"" + t + L""; addIndicText(ctlL, t, s_indicHighlight); + } + if (aDiff.operation == Operation::EQUAL) { + cur_r += t; + cur_l += t; + addIndicText(ctlL, t, 0); + addIndicText(ctlR, t, 0); + } + else modify = true; + // ���� �� �������� ������� ������ ������� ��� ��� �� ���� ������ + } + else + { + // ����� �� �������� \n + nstart = pos + 1; + ncur_l = std::to_wstring(lline); + ncur_l = L""; ncur_r = L""; + // if (p_ncur_r==ncur_r) { ncur_r=L""; modify=true;} + // if (p_ncur_l==ncur_l) { ncur_l=L""; modify=true;} + + std::wstring t_cur_l = cur_l; + std::wstring t_cur_r = cur_r; + if (aDiff.operation == 0) { + t_cur_r = L""; + addIndicText(ctlL, L"\n", s_indicHighlight); + ncur_l = std::to_wstring(lline); + modify = true; + lline++; + } + else if (aDiff.operation == Operation::INSERT) { + t_cur_l = L""; + addIndicText(ctlR, L"\n", s_indicHighlight); + ncur_r = std::to_wstring(rline); + modify = true; + rline++; + } + else if (aDiff.operation == Operation::EQUAL) { + ncur_r = std::to_wstring(rline); + ncur_l = std::to_wstring(lline); + rline++; lline++; + addIndicText(ctlL, L"\n", 0); + addIndicText(ctlR, L"\n", 0); + } + // if (modify) countdiffline++; + // if (( (ncur_r.empty()&&(!ncur_l.empty())) + // ||(ncur_l.empty()&&(!ncur_r.empty())) + // )&&(!modify)) modify=true; + // create columns + //left + tableline += L""; + tableline += modify ? L"" + ncur_l + "" : L"" + ncur_l + ""; + tableline += L"
" + t_cur_l + "
"; + // right + tableline += L""; + tableline += modify ? L"" + ncur_r + "" : L"" + ncur_r + ""; + tableline += L"
" + t_cur_r + "
"; + tableline += L""; + + if (aDiff.operation == 0) { + cur_l = L""; + } + else if (aDiff.operation == Operation::INSERT) { + cur_r = L""; + } + else if (aDiff.operation == Operation::EQUAL) { + cur_r = L""; cur_l = L""; + } + + // + modify = false; + } + } // ���� �� ������� ������ ������ Diff + ++it; + } + + } + SourceViewDialog(wxWindow* parent, wxString sqlL, wxString sqlR, wxString title) : + wxFrame(parent, wxID_ANY, title, wxDefaultPosition, wxSize(1200, 700)) + { + m_changing_values = false; + m_text1 = createSTC(); + //m_text1->SetText(sqlL); + + m_text2 = createSTC(); + //m_text2->SetText(sqlR); + + difftext(m_text1, m_text2, sqlL, sqlR); + + + + wxBoxSizer* bSizer1; + bSizer1 = new wxBoxSizer(wxVERTICAL); + + wxPanel* m_panelSql = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + wxBoxSizer* bSizer2; + bSizer2 = new wxBoxSizer(wxHORIZONTAL); + + bSizer2->Add(m_text1, 1, wxEXPAND, 5); + + bSizer2->Add(m_text2, 1, wxEXPAND, 5); + + + m_panelSql->SetSizer(bSizer2); + m_panelSql->Layout(); + bSizer2->Fit(m_panelSql); + bSizer1->Add(m_panelSql, 1, wxEXPAND, 2); + + wxPanel* m_panelOpt = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); + wxBoxSizer* bSizer4; + bSizer4 = new wxBoxSizer(wxHORIZONTAL); + + m_visibleSpace = new wxCheckBox(m_panelOpt, wxID_ANY, wxT("Show space simbol"), wxDefaultPosition, wxDefaultSize, 0); + bSizer4->Add(m_visibleSpace, 0, wxALL, 5); + + m_showNumber = new wxCheckBox(m_panelOpt, wxID_ANY, wxT("Show number line"), wxDefaultPosition, wxDefaultSize, 0); + bSizer4->Add(m_showNumber, 0, wxALL, 5); + wxButton* m_btn_next = new wxButton(m_panelOpt, wxID_ANY, wxT("Next"), wxDefaultPosition, wxDefaultSize, 0); + + bSizer4->Add(m_btn_next, 0, wxALL, 5); + + bSizer4->Add(0, 0, 1, wxEXPAND, 5); + + wxButton* m_btn_close = new wxButton(m_panelOpt, wxID_ANY, wxT("Close"), wxDefaultPosition, wxDefaultSize, 0); + bSizer4->Add(m_btn_close, 0, wxALL, 5); + + // wxButton *m_btn_cancel = new wxButton(m_panelOpt, wxID_ANY, wxT("Cancel"), wxDefaultPosition, wxDefaultSize, 0); + // bSizer4->Add(m_btn_cancel, 0, wxALL, 5); + + + m_panelOpt->SetSizer(bSizer4); + m_panelOpt->Layout(); + bSizer4->Fit(m_panelOpt); + bSizer1->Add(m_panelOpt, 0, wxALL | wxEXPAND, 5); + + + this->SetSizer(bSizer1); + this->Layout(); + + this->Centre(wxBOTH); + + m_visibleSpace->Bind(wxEVT_CHECKBOX, &SourceViewDialog::OnShowCheckBoxSpace, this); + m_showNumber->Bind(wxEVT_CHECKBOX, &SourceViewDialog::OnShowCheckShowNumber, this); + m_btn_close->Bind(wxEVT_BUTTON, &SourceViewDialog::onClose2, this); + m_btn_next->Bind(wxEVT_BUTTON, &SourceViewDialog::onNext, this); + //Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(SourceViewDialog::onClose), NULL, this); + //m_text1->Connect(wxEVT_STC_PAINTED, wxStyledTextEventHandler(SourceViewDialog::onScrollLeft), NULL, this); + //m_text2->Connect(wxEVT_STC_PAINTED, wxStyledTextEventHandler(SourceViewDialog::onScrollRight), NULL, this); + Bind(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(SourceViewDialog::onClose), this); + m_text1->Bind(wxEVT_STC_PAINTED, wxStyledTextEventHandler(SourceViewDialog::onScrollLeft), this); + m_text2->Bind(wxEVT_STC_PAINTED, wxStyledTextEventHandler(SourceViewDialog::onScrollRight), this); + + } + void onClose2(wxCommandEvent& evt) { + //onClose(wxCloseEvent(NULL)); + Close(); + } + void onNext(wxCommandEvent& evt) { + //onClose(wxCloseEvent(NULL)); + + int v = 0; + int l = -1; + ctlSQLBox* t=NULL; + int l1 = m_text1->GetLength(); + int l2 = m_text2->GetLength(); + m_text1->SelectNone(); + m_text2->SelectNone(); + while (v == 0 && pos < wxMax(l1, l2)) { + if (pos < m_text1->GetLength()) v = m_text1->IndicatorAllOnFor(pos); + if (v != 0) { + t=m_text1; + } + else { + if (pos < m_text2->GetLength()) v = m_text2->IndicatorAllOnFor(pos); + if (v != 0) { + t = m_text2; + } + } + if (t == NULL) { + pos++; + continue; + } + l = t->LineFromPosition(pos); + pos++; + if (l > prev_line) { + t->SetCurrentPos(pos - 1); + int start = pos - 1; + prev_line = l; + bool f = false; + // find end fragment + while (posGetLength()) { + if (t->IndicatorAllOnFor(pos++) == 0) { + f = true; + break; + } + } + t->SetSelection(start,pos-1); + t->SetFirstVisibleLine(l); + break; + } + else { + t = NULL; + v = 0; + continue; + } + + } + if (t == NULL) { + pos = 0; + prev_line = -1; + } + } + void OnShowCheckBoxSpace(wxCommandEvent& evt) { + bool bVal = m_visibleSpace->IsChecked(); + m_text1->SetViewWhiteSpace(bVal ? wxSTC_WS_VISIBLEALWAYS : wxSTC_WS_INVISIBLE); + m_text1->SetViewEOL(bVal ? 1 : 0); + m_text2->SetViewWhiteSpace(bVal ? wxSTC_WS_VISIBLEALWAYS : wxSTC_WS_INVISIBLE); + m_text2->SetViewEOL(bVal ? 1 : 0); + + } + void OnShowCheckShowNumber(wxCommandEvent& evt) { + bool bVal = m_showNumber->IsChecked(); + showNumber(m_text1, bVal); + showNumber(m_text2, bVal); + } + + void onScrollLeft(wxStyledTextEvent& evt) + { + if (m_changing_values) return; + m_changing_values = true; + + int fvl = m_text1->GetFirstVisibleLine(); + if (m_text2->GetFirstVisibleLine() != fvl) + { + m_text2->ScrollToLine(fvl); + // ShowLines + } + + m_changing_values = false; + } + + void onScrollRight(wxStyledTextEvent& evt) + { + if (m_changing_values) return; + m_changing_values = true; + + int fvl = m_text2->GetFirstVisibleLine(); + if (m_text1->GetFirstVisibleLine() != fvl) + { + m_text1->ScrollToLine(fvl); + // ShowLines + } + + m_changing_values = false; + } +}; diff --git a/include/ctl/ctlSQLResult.h b/include/ctl/ctlSQLResult.h index 2c9c6d7..e75af10 100644 --- a/include/ctl/ctlSQLResult.h +++ b/include/ctl/ctlSQLResult.h @@ -48,6 +48,7 @@ public: wxString OnGetItemText(long item, long col) const; wxString SummaryColumn(); + wxString CompareSelectCells(); wxString AutoColsPlot(int flags,frmQuery *parent); wxString CheckSelColumnDate(); wxString CopySelColumnNameType(); diff --git a/include/frm/frmQuery.h b/include/frm/frmQuery.h index 87687dc..317c4d2 100644 --- a/include/frm/frmQuery.h +++ b/include/frm/frmQuery.h @@ -215,6 +215,7 @@ private: void OnPaste(wxCommandEvent &event); void OnClear(wxCommandEvent &event); void OnSummary_Column(wxCommandEvent &event); + void OnCompare_2Cell(wxCommandEvent& event); void OnCopy_Insert(wxCommandEvent &event); void OnCopy_InList(wxCommandEvent& event); void OnCopy_WhereList(wxCommandEvent& event); diff --git a/include/frm/menu.h b/include/frm/menu.h index 4923c65..0378a86 100644 --- a/include/frm/menu.h +++ b/include/frm/menu.h @@ -77,6 +77,7 @@ enum MNU_TIMING, MNU_AUTOSELECTQUERY, MNU_SUMMARY_COL, + MNU_COMPARE_2CELL, MNU_COPY_INSERT, MNU_COPY_INLIST, MNU_COPY_LISTCOLTYPE,