private EditScript ConvertMatchPointsToEditScript(int N, int M, ArrayList MatchPoints) { EditScript Script = new EditScript(); int iCurrX = 1; int iCurrY = 1; //Add a fictitious match point at (N+1, M+1) so we're guaranteed to //pick up all edits with a single loop. MatchPoints.Add(new Point(N + 1, M + 1)); //NOTE: When we create new Edit instances, we'll store iCurrX and iCurrY //minus 1 because we want to convert them back to 0-based indexes for //the user. The user shouldn't have to know that internally we use any //1-based types. foreach (Point Pt in MatchPoints) { int iMatchX = Pt.X; int iMatchY = Pt.Y; //A one-to-one grouping of inserts and deletes will be considered a change. if (iCurrX < iMatchX && iCurrY < iMatchY) { int iChangeLength = Math.Min(iMatchX - iCurrX, iMatchY - iCurrY); Script.Add(new Edit(EditType.Change, iCurrX - 1, iCurrY - 1, iChangeLength)); iCurrX += iChangeLength; iCurrY += iChangeLength; } if (iCurrX < iMatchX) { Script.Add(new Edit(EditType.Delete, iCurrX - 1, iCurrY - 1, iMatchX - iCurrX)); } if (iCurrY < iMatchY) { Script.Add(new Edit(EditType.Insert, iCurrX - 1, iCurrY - 1, iMatchY - iCurrY)); } iCurrX = iMatchX + 1; iCurrY = iMatchY + 1; } return Script; }
public void SetData(IList<string> StringListA, IList<string> StringListB, EditScript Script, string strNameA, string strNameB) { ViewA.SetData(StringListA, Script, true); ViewB.SetData(StringListB, Script, false); Overview.DiffView = ViewA; Debug.Assert(ViewA.LineCount == ViewB.LineCount, "Both DiffView's LineCounts must be the same"); bool bShowNames = strNameA.Length > 0 || strNameB.Length > 0; edtLeft.Visible = bShowNames; edtRight.Visible = bShowNames; if (bShowNames) { edtLeft.Text = strNameA; edtRight.Text = strNameB; } UpdateButtons(); m_iCurrentDiffLine = -1; UpdateLineDiff(); ActiveControl = ViewA; }
public DiffViewLines(IList<string> StringList, EditScript Script, bool bUseA) { int iCurrentLine = 0; int iTotalEdits = Script.Count; m_arDiffStartLines = new int[iTotalEdits]; m_arDiffEndLines = new int[iTotalEdits]; for (int e = 0; e < iTotalEdits; e++) { Edit E = Script[e]; //Get the starting line for this Edit int iStartingLine = -1; bool bDummyLine = false; if (bUseA) { bDummyLine = (E.Type == EditType.Insert); iStartingLine = E.StartA; } else { bDummyLine = (E.Type == EditType.Delete); iStartingLine = E.StartB; } //Put in unedited lines up to this point iCurrentLine += AddUneditedLines(StringList, iCurrentLine, iStartingLine); //Record where the next diff starts and ends m_arDiffStartLines[e] = Count; m_arDiffEndLines[e] = Count + E.Length - 1; //Since Inserts occur after the current line //instead of at it, we have to decrement the index. for (int i = 0; i < E.Length; i++) { //A - Shows Deletes and Changes //B - Shows Inserts and Changes string strText = ""; int iNumber = -1; if (!bDummyLine) { iNumber = iStartingLine + i; strText = (string)StringList[iNumber]; iCurrentLine++; } AddLine(strText, iNumber, E.Type, true); } } //Put in any remaining unedited lines AddUneditedLines(StringList, iCurrentLine, StringList.Count); }
public void SetData(IList<string> StringListA, IList<string> StringListB, EditScript Script) { SetData(StringListA, StringListB, Script, "", ""); }
public void SetData(IList<string> StringList, EditScript Script, bool bUseA) { m_StringList = StringList; m_Lines = new DiffViewLines(m_StringList, Script, bUseA); UpdateAfterSetData(); }