コード例 #1
0
        private Hashtable ProcessUnifiedDiff(string oldPath, string newPath, Hashtable commonFiles)
        {
            Hashtable             hashtable  = new Hashtable();
            IDictionaryEnumerator enumerator = commonFiles.GetEnumerator();

            while (enumerator.MoveNext())
            {
                StringBuilder sb         = new StringBuilder();
                StringWriter  writer     = new StringWriter(sb);
                string        key        = enumerator.Key.ToString();
                string        path       = Path.Combine(oldPath, key);
                string        text3      = Path.Combine(newPath + key);
                string[]      leftLines  = new string[0];
                string[]      rightLines = new string[0];
                if (File.Exists(text3))
                {
                    rightLines = File.OpenText(text3).ReadToEnd().Split(new char[] { '\n' });
                }
                if (File.Exists(path))
                {
                    leftLines = File.OpenText(path).ReadToEnd().Split(new char[] { '\n' });
                }
                UnifiedDiff.WriteUnifiedDiff(leftLines, path, rightLines, text3, writer, 1, false, false);
                hashtable.Add(key, sb.ToString());
            }
            return(hashtable);
        }
コード例 #2
0
        public PatchWidget(ComparisonView comparisonView, VersionControlDocumentInfo info)
        {
            this.Build();
            diffEditor = new Mono.TextEditor.TextEditor();
            diffEditor.Document.MimeType        = "text/x-diff";
            diffEditor.Options.FontName         = info.Document.TextEditorData.Options.FontName;
            diffEditor.Options.ColorScheme      = info.Document.TextEditorData.Options.ColorScheme;
            diffEditor.Options.ShowFoldMargin   = false;
            diffEditor.Options.ShowIconMargin   = false;
            diffEditor.Options.ShowTabs         = true;
            diffEditor.Options.ShowSpaces       = true;
            diffEditor.Options.ShowInvalidLines = info.Document.TextEditorData.Options.ShowInvalidLines;
            diffEditor.Document.ReadOnly        = true;
            scrolledwindow1.Child = diffEditor;
            diffEditor.ShowAll();
            using (var writer = new StringWriter()) {
                UnifiedDiff.WriteUnifiedDiff(comparisonView.Diff, writer,
                                             System.IO.Path.GetFileName(info.Item.Path) + "    (repository)",
                                             System.IO.Path.GetFileName(info.Item.Path) + "    (working copy)",
                                             3);
                diffEditor.Document.Text = writer.ToString();
            }
            buttonSave.Clicked += delegate {
                var dlg = new OpenFileDialog(GettextCatalog.GetString("Save as..."), FileChooserAction.Save)
                {
                    TransientFor = IdeApp.Workbench.RootWindow
                };

                if (!dlg.Run())
                {
                    return;
                }
                File.WriteAllText(dlg.SelectedFile, diffEditor.Document.Text);
            };
        }
コード例 #3
0
        protected override void SaveAs(string fileName)
        {
            if (!(left is string))
            {
                return;
            }

            using (StreamWriter writer = new StreamWriter(fileName)) {
                UnifiedDiff.WriteUnifiedDiff(
                    diff,
                    writer,
                    Path.GetFileName((string)right) + "    (repository)",
                    Path.GetFileName((string)right) + "    (working copy)",
                    3);
            }
        }
コード例 #4
0
        public static FileCompareResults ProcessUnifiedDiff(FileCompareResults fileData)
        {
            StringBuilder sb        = new StringBuilder();
            StringWriter  sw        = new StringWriter(sb);
            string        leftFile  = fileData.LeftScriptPath;
            string        rightFile = fileData.RightScriptPath;

            string[] leftContents  = new string[0];
            string[] rightContents = new string[0];
            if (File.Exists(rightFile))
            {
                rightContents = File.OpenText(rightFile).ReadToEnd().Split('\n');
                for (int i = 0; i < rightContents.Length; i++)
                {
                    rightContents[i] = rightContents[i].TrimEnd(); // trim the end because the diff blocks a a WriteLine, don't want extra \r\n's
                }
            }

            if (File.Exists(leftFile))
            {
                leftContents = File.OpenText(leftFile).ReadToEnd().Split('\n');
                for (int i = 0; i < leftContents.Length; i++)
                {
                    leftContents[i] = leftContents[i].TrimEnd(); // trim the end because the diff blocks a a WriteLine, don't want extra \r\n's
                }
            }

            //Get the diff
            UnifiedDiff.WriteUnifiedDiff(leftContents, leftFile, rightContents, rightFile, sw, 500, false, false);

            //If there is not a real diff, just add the file contents, otherwise, add the unified diff text
            if (sb.ToString().Trim().Split('\r').Length < 3)
            {
                fileData.LeftScriptText = String.Join("\r\n", leftContents);
            }
            else
            {
                fileData.UnifiedDiffText = sb.ToString();
                fileData.LeftScriptText  = String.Join("\r\n", leftContents);
                fileData.RightSciptText  = String.Join("\r\n", rightContents);
            }

            return(fileData);
        }
コード例 #5
0
        void SetDiffCellData(Gtk.TreeViewColumn tree_column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
        {
            try {
                CellRendererDiff cellRendererDiff = (CellRendererDiff)cell;
                Change           change           = store.GetValue(iter, objColumn) as Change;
                cellRendererDiff.Visible = !(bool)store.GetValue(iter, statusVisibleColumn);
                if (change == null || !cellRendererDiff.Visible)
                {
                    cellRendererDiff.InitCell(treeviewPreview, false, "", "");
                    return;
                }
                TextReplaceChange replaceChange = change as TextReplaceChange;
                if (replaceChange == null)
                {
                    return;
                }

                Mono.TextEditor.Document doc = new Mono.TextEditor.Document();
                doc.Text = System.IO.File.ReadAllText(replaceChange.FileName);
                List <string> before = new List <string> ();
                foreach (var line in doc.Lines)
                {
                    before.Add(doc.GetTextAt(line.Offset, line.EditableLength));
                }

                ((Mono.TextEditor.IBuffer)doc).Replace(replaceChange.Offset, replaceChange.RemovedChars, replaceChange.InsertedText);

                List <string> after = new List <string> ();
                foreach (var line in doc.Lines)
                {
                    after.Add(doc.GetTextAt(line.Offset, line.EditableLength));
                }

                Diff diff = new Diff(before.ToArray(), after.ToArray(), true, true);

                System.IO.StringWriter w = new System.IO.StringWriter();
                UnifiedDiff.WriteUnifiedDiff(diff, w, replaceChange.FileName, replaceChange.FileName, 2);
                cellRendererDiff.InitCell(treeviewPreview, true, w.ToString().Trim(), replaceChange.FileName);
            } catch (Exception e) {
                Console.WriteLine(e);
            }
        }