예제 #1
0
void cbUnifiedCtrl::ShowDiff(wxDiff diff)
{
    m_txtctrl->SetReadOnly(false);
    m_txtctrl->ClearAll();
    m_txtctrl->AppendText(diff.GetDiff());
    m_txtctrl->SetReadOnly(true);
}
예제 #2
0
void cbSideBySideCtrl::ShowDiff(wxDiff diff)
{
    wxArrayInt right_added = diff.GetAddedLines();
    wxArrayInt right_empty = diff.GetRightEmptyLines();
    wxArrayInt left_empty = diff.GetLeftEmptyLines();
    wxArrayInt left_removed = diff.GetRemovedLines();

    /* Left Textctrl (m_fromfile) */
    TCLeft->SetReadOnly(false);
    TCLeft->ClearAll();
    wxTextFile tff(diff.GetFromFilename());
    tff.Open();
    bool refill = false;
    wxString str = tff.GetFirstLine();
    int linecount = tff.GetLineCount() + left_empty.GetCount();
    int linenumber = 1;
    for (int i = 0; i < linecount; i++)
    {
        if(refill && !tff.Eof())
            str = tff.GetNextLine();
        if(left_removed.Index(i+1) != wxNOT_FOUND)
        {
            TCLeft->AppendText(str + _T("\n"));
            refill = true;
            TCLeft->MarginSetStyle(i, wxSCI_STYLE_LINENUMBER);
            TCLeft->MarginSetText(i,wxString::Format(_T("%d"),linenumber));
            TCLeft->MarkerAdd(i, MINUS_MARKER);
            TCLeft->MarkerAdd(i, RED_BKG_MARKER);
            linenumber++;
            continue;
        }
        if(left_empty.Index(i+1) != wxNOT_FOUND)
        {
            TCLeft->AppendText(_T("\n"));
            TCLeft->MarkerAdd(i, GREY_BKG_MARKER);
            refill = false;
            continue;
        }
        TCLeft->AppendText(str + _T("\n"));
        refill = true;
        TCLeft->MarginSetStyle(i, wxSCI_STYLE_LINENUMBER);
        TCLeft->MarginSetText(i,wxString::Format(_T("%d"),linenumber));
        TCLeft->MarkerAdd(i, EQUAL_MARKER);
        linenumber++;
    }
    TCLeft->SetReadOnly(true);

    /* Right Textctrl (m_tofile) */
    TCRight->SetReadOnly(false);
    TCRight->ClearAll();
    wxTextFile tft(diff.GetToFilename());
    tft.Open();
    refill = false;
    str = tft.GetFirstLine();
    linecount = tft.GetLineCount() + right_empty.GetCount();
    linenumber = 1;
    for (int i = 0; i < linecount; i++)
    {
        if(refill && !tft.Eof())
            str = tft.GetNextLine();
        if(right_added.Index(i+1) != wxNOT_FOUND)
        {
            TCRight->AppendText(str + _T("\n"));
            refill = true;
            TCRight->MarginSetStyle(i, wxSCI_STYLE_LINENUMBER);
            TCRight->MarginSetText(i, wxString::Format(_T("%d"),linenumber));
            linenumber++;
            TCRight->MarkerAdd(i, PLUS_MARKER);
            TCRight->MarkerAdd(i, GREEN_BKG_MARKER);
            continue;
        }
        if(right_empty.Index(i+1) != wxNOT_FOUND)
        {
            TCRight->AppendText(_T("\n"));
            TCRight->MarkerAdd(i, GREY_BKG_MARKER);
            refill = false;
            continue;
        }
        TCRight->AppendText(str + _T("\n"));
        refill = true;
        TCRight->MarginSetStyle(i, wxSCI_STYLE_LINENUMBER);
        TCRight->MarginSetText(i, wxString::Format(_T("%d"),linenumber));
        TCRight->MarkerAdd(i, EQUAL_MARKER);
        linenumber++;
    }
    TCRight->SetReadOnly(true);
}
예제 #3
0
void cbTableCtrl::ShowDiff(wxDiff diff)
{
    std::map<long, int> right_added  = diff.GetAddedLines();
    std::map<long, int> left_removed = diff.GetRemovedLines();
    std::map<long, int> left_empty   = diff.GetLeftEmptyLines();

    rightFilename_ = diff.GetRightFilename();
    leftFilename_ = diff.GetLeftFilename();
    leftReadOnly_ = true;
    rightReadOnly_ = diff.RightReadOnly();

    txtctrl_->SetReadOnly(false);
    int cursorPos = txtctrl_->GetCurrentPos();
    txtctrl_->ClearAll();
    wxTextFile left_text_file(diff.GetLeftFilename());
    wxTextFile right_text_file(diff.GetRightFilename());
    left_text_file.Open();
    right_text_file.Open();
    bool refillleft = false;
    bool refillright = false;
    int left_empty_lines=0;
    for(auto itr = left_empty.begin() ; itr != left_empty.end() ; ++itr)
        left_empty_lines += itr->second;
    wxString strleft = left_text_file.GetFirstLine();
    wxString strright = right_text_file.GetFirstLine();
    int linecount = left_text_file.GetLineCount() + left_empty_lines;
    int linenumberleft = 0;
    int linenumberright = 0;
    int removed = 0;
    int added = 0;

    for (int i = 0; i < linecount; ++i)
    {
        if(refillleft && !left_text_file.Eof())
            strleft = left_text_file.GetNextLine();
        if(refillright && !right_text_file.Eof())
            strright = right_text_file.GetNextLine();
        auto litr = left_removed.find(linenumberleft);
        if(litr != left_removed.end() || removed)
        {
            if(!removed)
            {
                linesWithDifferences_.push_back(i);
                removed = litr->second;
            }
            --removed;
            txtctrl_->AppendText(strleft + _T("\n"));
            refillleft = true;
            refillright = false;
            ++linenumberleft;
            txtctrl_->MarginSetStyle(i, wxSCI_STYLE_LINENUMBER);
            txtctrl_->MarginSetText(i, wxString::Format(_T("%9d%9c"), linenumberleft, ' '));
            txtctrl_->MarkerAdd(i, RED_BKG_MARKER);
            continue;
        }
        auto ritr = right_added.find(linenumberright);
        if(ritr != right_added.end() || added)
        {
            if(!added)
            {
                linesWithDifferences_.push_back(i);
                added = ritr->second;
            }
            --added;
            txtctrl_->AppendText(strright + _T("\n"));
            refillleft = false;
            refillright = true;
            ++linenumberright;
            txtctrl_->MarginSetStyle(i, wxSCI_STYLE_LINENUMBER);
            txtctrl_->MarginSetText(i, wxString::Format(_T("%9d"), linenumberright));
            txtctrl_->MarkerAdd(i, GREEN_BKG_MARKER);
            continue;
        }
        txtctrl_->AppendText(strleft + _T("\n"));
        refillleft = true;
        refillright = true;
        ++linenumberleft;
        ++linenumberright;
        txtctrl_->MarginSetStyle(i, wxSCI_STYLE_LINENUMBER);
        txtctrl_->MarginSetText(i, wxString::Format(_T("%9d%9d"), linenumberleft, linenumberright));
    }
    txtctrl_->SetReadOnly(true);
    txtctrl_->GotoPos(cursorPos);
}