void DocHistory::SetDocument(const doc_id& di) { //wxASSERT(m_catalyst.IsOk(di)); // Check if we are invalidating the view if (!di.IsOk()) { Clear(); return; } if (m_sourceDoc != di) { cxLOCKDOC_WRITE(m_doc) doc.SetDocument(di); // Get the document m_document_id = di.IsDraft() ? doc.GetParent().document_id : di.document_id; cxENDLOCK m_sourceDoc = di; // Check if we need to rebuild the tree ReBuildTree(); } Select(m_selectedNode); MakeItemVisible(m_selectedNode); }
void DiffLineCell::CalcLayout(const doc_id& rev1, const doc_id& rev2) { wxASSERT(rev1.IsOk()); wxASSERT(rev2.IsOk()); wxASSERT(char_width > 0); Clear(); cxLOCKDOC_READ(m_doc) if (rev1 == rev2) { // root has itself as parent int length = doc.GetVersionLength(rev2); if (length > 0) { length = wxMin(length, (int)doc.GetCharPos(rev2, 0, (width/char_width)+1)); wxString text = doc.GetTextPart(rev2, 0, length); CalcSubCells(text, *wxBLACK, m_insertColour); } } else if (!doc.TextChanged(rev1, rev2)) { if (doc.PropertiesChanged(rev1, rev2)) CalcSubCells(_("Properties Changed"), *wxBLACK, bgcolor); } else { bool change = false; const std::vector<match> matchlist = doc.Diff(rev1, rev2); unsigned int pos1 = 0; unsigned int pos2 = 0; unsigned int i = 0; while (i < matchlist.size()) { if (line_width > width) { // No need to parse something that won't be drawn break; } // Calculate how many chars there are room for in // the visible part. Then we can avoid retrieving // long strings (which can be *very* long) int chars_left = ((width-line_width)/char_width)+1; match m = matchlist[i]; if (pos1 < m.iv1_start_pos) { // Deleted unsigned int last_endpos = doc.GetCharPos(rev1, pos1, chars_left); CalcSubCells(doc.GetTextPart(rev1, pos1, wxMin(m.iv1_start_pos, last_endpos)), *wxBLACK, m_deleteColour); // PASTEL RED change = true; } if (pos2 < m.iv2_start_pos) { // Inserted unsigned int last_endpos = doc.GetCharPos(rev2, pos2, chars_left); CalcSubCells(doc.GetTextPart(rev2, pos2, wxMin(m.iv2_start_pos, last_endpos)), *wxBLACK, m_insertColour); // PASTEL GREEN change = true; } if (m.iv2_end_pos > 0 && m.iv2_end_pos > m.iv2_start_pos) { if (change) { unsigned int last_endpos = doc.GetCharPos(rev2, m.iv2_start_pos, chars_left); CalcSubCells(doc.GetTextPart(rev2, m.iv2_start_pos, wxMin(m.iv2_end_pos, last_endpos)), m_hiddenColour, bgcolor); } else { // Get up to 5 chars before first change unsigned int startpos = doc.GetCharPos(rev2, m.iv2_end_pos, -5); wxString initialText = doc.GetTextPart(rev2, wxMax(m.iv2_start_pos, startpos), m.iv2_end_pos); CalcSubCells(initialText, m_hiddenColour, bgcolor); } } pos1 = m.iv1_end_pos; pos2 = m.iv2_end_pos; ++i; } } cxENDLOCK }
void DiffLineCell::CalcLayoutRange(const doc_id& rev1, const doc_id& rev2, const interval& range) { wxASSERT(rev1.IsOk()); wxASSERT(rev2.IsOk()); wxASSERT(char_width > 0); Clear(); cxLOCKDOC_READ(m_doc) if (rev1 == rev2) { // root has itself as parent // Get up to 5 chars before range if (range.start > 0) { const unsigned int startpos = doc.GetCharPos(rev2, range.start, -5); const wxString initialText = doc.GetTextPart(rev2, wxMax(0, startpos), range.start); CalcSubCells(initialText, m_hiddenColour, bgcolor); } // Get the range unsigned int chars_left = ((width - line_width) / char_width)+1; unsigned int end = wxMin(range.end, doc.GetCharPos(rev2, range.start, chars_left)); unsigned int length = end - range.start; if (length == 0) return; const wxString text = doc.GetTextPart(rev2, range.start, length); CalcSubCells(text, *wxBLACK, m_insertColour); // Get text after range chars_left = ((width - line_width) / char_width)+1; length = doc.GetCharPos(rev2, range.end, chars_left); if (length == 0) return; const wxString text2 = doc.GetTextPart(rev2, range.start, length); CalcSubCells(text2, m_hiddenColour, bgcolor); } else { bool change = false; const std::vector<match> matchlist = doc.Diff(rev1, rev2); unsigned int pos1 = 0; unsigned int pos2 = 0; // Advance to range start (ignoring sentinel at end) unsigned int i = 0; while (i+1 < matchlist.size() && matchlist[i].iv2_end_pos < range.start) { pos1 = matchlist[i].iv1_end_pos; pos2 = matchlist[i].iv2_end_pos; ++i; } while (i < matchlist.size()) { if (line_width > width) break; // No need to parse something that won't be drawn // Calculate how many chars there are room for in // the visible part. Then we can avoid retrieving // long strings (which can be *very* long) int chars_left = ((width-line_width)/char_width)+1; const match& m = matchlist[i]; if (pos1 < m.iv1_start_pos && pos2 >= range.start && pos2 <= range.end) { // Deleted (and in range) const unsigned int last_endpos = doc.GetCharPos(rev1, pos1, chars_left); CalcSubCells(doc.GetTextPart(rev1, pos1, wxMin(m.iv1_start_pos, last_endpos)), *wxBLACK, m_deleteColour); // PASTEL RED change = true; } if (pos2 < m.iv2_start_pos && range.start < m.iv2_start_pos) { // Inserted // Get text before range if (pos2 < range.start) { const unsigned int ins_start = wxMax(pos2, doc.GetCharPos(rev2, range.start, -5)); CalcSubCells(doc.GetTextPart(rev2, ins_start, range.start), m_hiddenColour, bgcolor); } // Get text in range (only if overlap) if (pos2 < range.end && m.iv2_start_pos > range.start) { const unsigned int start_pos = wxMax(pos2, range.start); const unsigned int last_endpos = wxMin(wxMin(range.end, m.iv2_start_pos), doc.GetCharPos(rev2, start_pos, chars_left)); CalcSubCells(doc.GetTextPart(rev2, start_pos, last_endpos), *wxBLACK, m_insertColour); // PASTEL GREEN } // Get text after range if (m.iv2_start_pos > range.end) { const unsigned int rest_start = wxMax(pos2, range.end); const unsigned int rest_end = wxMin(m.iv2_start_pos, doc.GetCharPos(rev2, rest_start, chars_left)); CalcSubCells(doc.GetTextPart(rev2, rest_start, rest_end), m_hiddenColour, bgcolor); } change = true; } if (m.iv2_end_pos > 0 && m.iv2_end_pos > m.iv2_start_pos) { if (change) { const unsigned int last_endpos = doc.GetCharPos(rev2, m.iv2_start_pos, chars_left); CalcSubCells(doc.GetTextPart(rev2, m.iv2_start_pos, wxMin(m.iv2_end_pos, last_endpos)), m_hiddenColour, bgcolor); } else { // Get up to 5 chars before first change const unsigned int startpos = doc.GetCharPos(rev2, m.iv2_end_pos, -5); const wxString initialText = doc.GetTextPart(rev2, wxMax(m.iv2_start_pos, startpos), m.iv2_end_pos); CalcSubCells(initialText, m_hiddenColour, bgcolor); } } pos1 = m.iv1_end_pos; pos2 = m.iv2_end_pos; ++i; } } cxENDLOCK }