Example #1
0
        /// <summary>
        /// Removes highlighting of special regions.
        /// </summary>
        private void DeselectLines(bool restoreOriginalColor, int startLine, int endLine)
        {
            Color color = restoreOriginalColor ? OrigianlLineSpan.OriginalColor : Color.White;

            for (int i = startLine; i <= endLine; i++)
            {
                syntaxEditor1.Document.Lines[i].BackColor = color;
            }
            OrigianlLineSpan = null;
        }
Example #2
0
        private void syntaxEditor1_DocumentTextChanged(object sender, ActiproSoftware.SyntaxEditor.DocumentModificationEventArgs e)
        {
            // Colour lines correctly when new lines inserted or existing lines deleted
            if (e.Modification.LinesInserted + e.Modification.LinesDeleted > 0)
            {
                int lineNum = e.Modification.StartLineIndex;// -1;

                if (e.Modification.LinesInserted > 0 && syntaxEditor1.Document.Lines[lineNum].BackColor == Color.Red &&
                    syntaxEditor1.Document.Lines[lineNum + 1].BackColor != Color.Red)
                {
                    DeselectLines();
                }
                if (e.Modification.LinesDeleted > 0 && OrigianlLineSpan != null)
                {
                    if (OrigianlLineSpan.EndLine - OrigianlLineSpan.StartLine > 0)
                    {
                        OrigianlLineSpan.EndLine -= 1;
                    }
                    if (OrigianlLineSpan.EndLine == OrigianlLineSpan.StartLine)
                    {
                        DeselectLines(true, OrigianlLineSpan.StartLine, OrigianlLineSpan.EndLine);
                        OrigianlLineSpan = null;
                    }
                    if (lineNum + 1 < syntaxEditor1.Document.Lines.Count &&
                        (syntaxEditor1.Document.Lines[lineNum].BackColor == Color.White &&
                            syntaxEditor1.Document.Lines[lineNum + 1].BackColor == Color.Red))
                    {
                        DeselectLines();
                    }
                }
            }
        }
Example #3
0
        public TypeOfDiff DisplayNodeFiles(TreeListNode node, DiffFile currentDiffFile, AutoMergeTypes autoMergeType, string userText, string templateText, string parentText, string mergedText, TypeOfDiff currentDiffType, OriginTypes originType)
        {
            OriginType = originType;
            CurrentDiffFile = currentDiffFile;
            CurrentDiffType = currentDiffType;
            BusyPopulatingEditor = true;

            if (node.Tag.GetType() == typeof(DiffFile) &&
                !((DiffFile)node.Tag).IsText)
            {
                ucBinaryFileViewer1.RootParent = SlyceMergeWorker.PreviousGenerationFolder;
                ucBinaryFileViewer1.RootTemplate = Controller.Instance.GetTempFilePathForComponent(ComponentKey.WorkbenchFileGenerator);
                ucBinaryFileViewer1.RootUser = Controller.Instance.ProjectSettings.ProjectPath;
                ucBinaryFileViewer1.DiffFile = (DiffFile)node.Tag;
                // Binary file
                ucBinaryFileViewer1.Visible = true;
                ucBinaryFileViewer1.Left = this.Left;
                ucBinaryFileViewer1.Width = this.ClientSize.Width;
                ucBinaryFileViewer1.Top = this.Top;
                ucBinaryFileViewer1.Height = this.ClientSize.Height;
                SetNavigationButtons();
                ShowBinaryFiles(node);
                return GetCurrentDiffStatus();
            }
            else
            {
                ucBinaryFileViewer1.Visible = false;
            }
            OrigianlLineSpan = null;
            bool filesTheSame = true;
            syntaxEditor1.ResetText();

            // Perform a 3-way diff on the file
            string parentFile = "";
            string userFile = "";
            string templateFile = "";
            string mergedFile = "";
            string fileBodyParent = null;
            string fileBodyUser = null;
            string fileBodyGenerated = null;

            if (OriginType == OriginTypes.DiffFile)
            {
                parentFile = Path.Combine(SlyceMergeWorker.PreviousGenerationFolder, ((DiffFile)node.Tag).RelativePath);
                userFile = Path.Combine(Controller.Instance.ProjectSettings.ProjectPath, ((DiffFile)node.Tag).RelativePath);
                templateFile = Path.Combine(Controller.Instance.GetTempFilePathForComponent(ComponentKey.WorkbenchFileGenerator), ((DiffFile)node.Tag).RelativePath);
                mergedFile = Path.Combine(SlyceMergeWorker.StagingFolder, ((DiffFile)node.Tag).RelativePath + ".merged");

                fileBodyParent = File.Exists(parentFile) ? IOUtility.GetTextFileBody(parentFile) : "";
                fileBodyUser = File.Exists(userFile) ? IOUtility.GetTextFileBody(userFile) : "";
                fileBodyGenerated = File.Exists(templateFile) ? IOUtility.GetTextFileBody(templateFile) : "";
            }
            else
            {
                fileBodyParent = parentText;
                fileBodyUser = userText;
                fileBodyGenerated = templateText;
            }
            fileBodyParent = Slyce.Common.Utility.StandardizeLineBreaks(fileBodyParent, Slyce.Common.Utility.LineBreaks.Unix);
            fileBodyUser = Slyce.Common.Utility.StandardizeLineBreaks(fileBodyUser, Slyce.Common.Utility.LineBreaks.Unix);
            fileBodyGenerated = Slyce.Common.Utility.StandardizeLineBreaks(fileBodyGenerated, Slyce.Common.Utility.LineBreaks.Unix);
            DetermineFileType(node);

            if (CurrentDiffType == TypeOfDiff.UserChangeOnly)
            {
                MarginTextUser = "******";
                Slyce.IntelliMerge.UI.Utility.Perform2WayDiffInSingleEditor(syntaxEditor1, ref fileBodyUser, ref fileBodyParent, true);
                syntaxEditor1.Document.ReadOnly = true;
                toolStripButtonAcceptTemplateChanges.Enabled = false;
                toolStripButtonAcceptUserChanges.Enabled = false;
                this.Text = "View only - No conflicts";
                buttonClose.Text = "&Close";
                buttonSave.Visible = false;
                SetNavigationButtons();
                this.ShowDialog(Controller.Instance.MainForm);
                return CurrentDiffType;
            }
            else if (CurrentDiffType == TypeOfDiff.TemplateChangeOnly)
            {
                MarginTextUser = "******";

                if (fileBodyGenerated == null)
                {
                    // This is marked as a TemplateChange because the template DELETED the corresponding entity
                    DisplayingTextMessage = true;
                    toolStripComboBoxFileType.Text = Slyce.Common.SyntaxEditorHelper.LanguageNameFromEnum(Slyce.Common.SyntaxEditorHelper.Languages.PlainText);
                    syntaxEditor1.WordWrap = ActiproSoftware.SyntaxEditor.WordWrapType.Word;
                    syntaxEditor1.Text = "This is a TemplateChange because it looks like the Template has not created the corresponding entity. In effect, the template has DELETED the corresponding entity. Alternatively, the corresponding entity has been RENAMED, or it's namespace has been renamed. If this is the case, click 'Select Match' on the popup menu to locate a renamed version of this entity if the template has renamed it (or its namespace).";
                }
                else
                {
                    Slyce.IntelliMerge.UI.Utility.Perform2WayDiffInSingleEditor(syntaxEditor1, ref fileBodyGenerated, ref fileBodyParent, true);
                }
                syntaxEditor1.Document.ReadOnly = true;
                toolStripButtonAcceptTemplateChanges.Enabled = false;
                toolStripButtonAcceptUserChanges.Enabled = false;
                this.Text = "View only - No conflicts";
                buttonClose.Text = "&Close";
                buttonSave.Visible = false;
                SetNavigationButtons();
                this.ShowDialog(Controller.Instance.MainForm);
                return CurrentDiffType;
            }
            else if (CurrentDiffType == TypeOfDiff.UserAndTemplateChange)
            {
                if (OriginType == OriginTypes.DiffFile)
                {
                    string mergedFileName = mergedFile.Replace(".merged", ".copy");

                    if (!File.Exists(mergedFileName))
                    {
                        throw new Exception("Merged file with user and template changes not found.");
                    }
                    mergedText = IOUtility.GetTextFileBody(mergedFileName);
                    mergedText = Slyce.Common.Utility.StandardizeLineBreaks(mergedText, Slyce.Common.Utility.LineBreaks.Unix);
                }
                SlyceMerge.LineSpan[] userLines;
                SlyceMerge.LineSpan[] templateLines;
                SlyceMerge.LineSpan[] rightLinesUser;
                SlyceMerge.LineSpan[] rightLinesTemplate;
                string combinedText;
                SlyceMerge.PerformTwoWayDiff(false, mergedText, fileBodyUser, out userLines, out rightLinesUser, out combinedText);
                SlyceMerge.PerformTwoWayDiff(false, mergedText, fileBodyGenerated, out templateLines, out rightLinesTemplate, out combinedText);
                syntaxEditor1.Text = mergedText;

                for (int i = 0; i < userLines.Length; i++)
                {
                    #region Get offset
                    int offsetUser = 0;

                    for (int counterRightLineUser = 0; counterRightLineUser < rightLinesUser.Length; counterRightLineUser++)
                    {
                        if (rightLinesUser[counterRightLineUser].StartLine < userLines[i].StartLine)
                        {
                            offsetUser += (rightLinesUser[counterRightLineUser].EndLine - rightLinesUser[counterRightLineUser].StartLine + 1);
                        }
                        else
                        {
                            break;
                        }

                    }
                    #endregion

                    for (int lineCounter = userLines[i].StartLine; lineCounter <= userLines[i].EndLine; lineCounter++)
                    {
                        syntaxEditor1.Document.Lines[lineCounter - offsetUser].BackColor = Slyce.IntelliMerge.UI.Utility.ColourNewGen;
                    }
                }
                for (int i = 0; i < templateLines.Length; i++)
                {
                    #region Get offset
                    int offsetTemplate = 0;

                    for (int counterRightLineTemplate = 0; counterRightLineTemplate < rightLinesTemplate.Length; counterRightLineTemplate++)
                    {
                        if (rightLinesTemplate[counterRightLineTemplate].StartLine < templateLines[i].StartLine)
                        {
                            offsetTemplate += (rightLinesTemplate[counterRightLineTemplate].EndLine - rightLinesTemplate[counterRightLineTemplate].StartLine + 1);
                        }
                        else
                        {
                            break;
                        }
                    }
                    #endregion

                    for (int lineCounter = templateLines[i].StartLine; lineCounter <= templateLines[i].EndLine; lineCounter++)
                    {
                        syntaxEditor1.Document.Lines[lineCounter - offsetTemplate].BackColor = Slyce.IntelliMerge.UI.Utility.ColourUser;
                    }
                }
                syntaxEditor1.Document.ReadOnly = true;
                toolStripButtonAcceptTemplateChanges.Enabled = false;
                toolStripButtonAcceptUserChanges.Enabled = false;
                this.Text = "View only - No conflicts";
                buttonClose.Text = "&Close";
                buttonSave.Visible = false;
                SetNavigationButtons();
                this.ShowDialog(Controller.Instance.MainForm);
                return currentDiffFile.DiffType;
            }
            syntaxEditor1.SuspendPainting();

            if (File.Exists(mergedFile))
            {
                using (TextReader tr = new StreamReader(mergedFile))
                {
                    string line = "";
                    int lineCounter = 0;
                    int pipeIndex = 0;
                    int backColor = 0;

                    while ((line = tr.ReadLine()) != null)
                    {
                        pipeIndex = line.IndexOf("|");
                        backColor = int.Parse(line.Substring(0, pipeIndex));
                        syntaxEditor1.Document.AppendText(line.Substring(pipeIndex + 1) + Environment.NewLine);
                        syntaxEditor1.Document.Lines[lineCounter].BackColor = Color.FromArgb(backColor);
                        lineCounter++;
                    }
                }
            }
            else // A merged file hasn't been created yet, so conflicts still exist
            {
                if (fileBodyParent != null &&
                          fileBodyUser != null &&
                          fileBodyGenerated != null)
                {
                    // Perform 3-way diff
                    string output;
                    SlyceMerge slyceMerge = SlyceMerge.Perform3wayDiff(fileBodyUser, fileBodyParent, fileBodyGenerated, out output);
                    int lineCounter = 0;
                    StringBuilder sb = new StringBuilder(Math.Max(fileBodyUser.Length, Math.Max(fileBodyParent.Length, fileBodyGenerated.Length)) + 1000);
                    System.Collections.ArrayList colouredLines = new System.Collections.ArrayList();

                    foreach (SlyceMerge.LineText line in slyceMerge.Lines)
                    {
                        int charPos = 0;
                        int numLineBreaks = 0;
                        charPos = line.Text.IndexOf("\r", 0);

                        if (charPos < 0) { numLineBreaks++; }

                        while (charPos >= 0)
                        {
                            numLineBreaks++;
                            charPos = line.Text.IndexOf("\r", charPos + 1);
                        }
                        sb.AppendLine(line.Text.Replace("\r", ""));
                        colouredLines.Add(new SlyceMerge.LineSpan(lineCounter, lineCounter + numLineBreaks, line.Colour));
                        lineCounter += numLineBreaks;
                    }
                    int linesToRemove = 0;
                    string text = sb.ToString();
                    string lastChar = text.Substring(text.Length - linesToRemove - 1);

                    while (lastChar.Length == 0 ||
                        lastChar == "\n" ||
                        lastChar == "\r" &&
                        text.Length >= linesToRemove + 1)
                    {
                        linesToRemove++;
                        lastChar = text.Substring(text.Length - linesToRemove - 1, 1);
                    }
                    syntaxEditor1.Document.Text = text.Substring(0, text.Length - linesToRemove);

                    for (int i = 0; i < colouredLines.Count; i++)
                    {
                        SlyceMerge.LineSpan ls = (SlyceMerge.LineSpan)colouredLines[i];

                        if (ls.OriginalColor != Color.White) { filesTheSame = false; }

                        for (int x = ls.StartLine; x <= ls.EndLine; x++)
                        {
                            if (x >= syntaxEditor1.Document.Lines.Count)
                            {
                                break;
                            }
                            syntaxEditor1.Document.Lines[x].BackColor = ls.OriginalColor;
                        }
                    }
                    if (filesTheSame)
                    {
                        this.Text = "No Changes";
                    }
                }
                else if (fileBodyParent != null &&
                          fileBodyUser != null &&
                          fileBodyGenerated == null)
                {
                    // No template file, just use the user file
                    syntaxEditor1.Text = fileBodyUser;
                    this.Text = "No Conflicts";
                }
                else if (fileBodyParent != null &&
             fileBodyUser == null &&
            fileBodyGenerated != null)
                {
                    // No user file, just use the template file
                    Slyce.IntelliMerge.UI.Utility.Perform2WayDiffInSingleEditor(syntaxEditor1, ref fileBodyGenerated, ref fileBodyParent, true);
                }
                else if (fileBodyParent == null &&
                       fileBodyUser != null &&
                  fileBodyGenerated != null)
                {
                    // No parent file, make sure the user merges the template and user files
                    string combinedText;
                    Slyce.IntelliMerge.SlyceMerge.LineSpan[] userLines;
                    Slyce.IntelliMerge.SlyceMerge.LineSpan[] templateLines;
                    SlyceMerge.PerformTwoWayDiff(false, fileBodyUser, fileBodyGenerated, out userLines, out templateLines, out combinedText);
                    Slyce.IntelliMerge.UI.Utility.PopulateSyntaxEditor(syntaxEditor1, combinedText, userLines, templateLines);
                    this.Text = "User changes vs generated";
                }
                else
                {
                    if (fileBodyParent != null)
                    {
                        if (File.Exists(userFile) || File.Exists(templateFile))
                        {
                            throw new Exception("More than one file exists. Shouldn't be here.");
                        }
                        syntaxEditor1.Text = fileBodyParent;
                        this.Text = "Unchanged file";
                    }
                    else if (fileBodyUser != null)
                    {
                        if (File.Exists(parentFile) || File.Exists(templateFile))
                        {
                            throw new Exception("More than one file exists. Shouldn't be here.");
                        }
                        syntaxEditor1.Text = fileBodyUser;
                        this.Text = "User-only file";
                    }
                    else if (fileBodyGenerated != null)
                    {
                        if (File.Exists(parentFile) || File.Exists(userFile))
                        {
                            throw new Exception("More than one file exists. Shouldn't be here.");
                        }
                        syntaxEditor1.Text = fileBodyGenerated;
                        this.Text = "Newly Generated file";
                    }
                }
            }
            syntaxEditor1.Refresh();

            if (syntaxEditor1.Document.Text.Length > 0)
            {
                syntaxEditor1.SelectedView.Selection.StartOffset = 0;
                syntaxEditor1.SelectedView.Selection.EndOffset = 0;
            }
            syntaxEditor1.Document.Modified = false;
            syntaxEditor1.ResumePainting();
            BusyPopulatingEditor = false;

            switch (autoMergeType)
            {
                case AutoMergeTypes.None:
                    GotoNextConflictLine(0);
                    this.ShowDialog(Controller.Instance.MainForm);
                    break;
                case AutoMergeTypes.KeepUserChanges:
                    AcceptAllUserChanges();

                    if (!SaveCurrentFile(false))
                    {
                        MessageBox.Show("There was a problem processing this file automatically. Please resolve these changes manually.", "Auto Processing Problem", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        GotoNextConflictLine(0);
                        this.ShowDialog(Controller.Instance.MainForm);
                    }
                    break;
                case AutoMergeTypes.KeepTemplateChanges:
                    AcceptAllTemplateChanges();

                    if (!SaveCurrentFile(false))
                    {
                        MessageBox.Show("There was a problem processing this file automatically. Please resolve these changes manually.", "Auto Processing Problem", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        GotoNextConflictLine(0);
                        this.ShowDialog(Controller.Instance.MainForm);
                    }
                    break;
            }
            SetNavigationButtons();
            if (CancelClicked) { return TypeOfDiff.Conflict; }
            else { return GetCurrentDiffStatus(); }
        }
Example #4
0
        /// <summary>
        /// Determines whether the location is part of a special region, and highlights the special region
        /// if it is.
        /// </summary>
        /// <param name="location"></param>
        private void SelectLines(int lineNumber)
        {
            DeselectLines();
            int spanStartLine = lineNumber;
            int spanEndLine = lineNumber;
            Color selectedColor = syntaxEditor1.Document.Lines[lineNumber].BackColor;
            bool newColourFound = false;

            for (int i = lineNumber; i > 0; i--)
            {
                if (syntaxEditor1.Document.Lines[i].BackColor != selectedColor &&
                    syntaxEditor1.Document.Lines[i].BackColor.ToArgb() != 0)
                {
                    newColourFound = true;
                    break;
                }
                spanStartLine = i;
            }
            if (!newColourFound)
            {
                spanStartLine = lineNumber;
            }
            newColourFound = false;
            for (int i = lineNumber; i < syntaxEditor1.Document.Lines.Count; i++)
            {
                if (syntaxEditor1.Document.Lines[i].BackColor != selectedColor &&
                    syntaxEditor1.Document.Lines[i].BackColor.ToArgb() != 0)
                {
                    newColourFound = true;
                    break;
                }
                spanEndLine = i;
            }
            if (!newColourFound)
            {
                spanEndLine = lineNumber;
            }
            if (newColourFound)
            {
                for (int i = spanStartLine; i <= spanEndLine; i++)
                {
                    syntaxEditor1.Document.Lines[i].BackColor = Color.Red;
                }
            }
            OrigianlLineSpan = new SlyceMerge.LineSpan(spanStartLine, spanEndLine, selectedColor);
        }