5
// Mike Krüger <mkrueger@novell.com>
7
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using MonoDevelop.Core;
30
namespace MonoDevelop.VersionControl.Views
32
[System.ComponentModel.ToolboxItem(false)]
33
public partial class DiffWidget : Gtk.Bin
35
VersionControlDocumentInfo info;
36
Mono.TextEditor.TextEditor diffTextEditor;
37
MonoDevelop.VersionControl.Views.ComparisonWidget comparisonWidget;
39
internal ComparisonWidget ComparisonWidget {
41
return comparisonWidget;
47
if (comparisonWidget.Diff.Count == 0)
48
return GettextCatalog.GetString ("Both files are equal");
49
int added=0, removed=0;
50
foreach (var h in comparisonWidget.Diff) {
54
string changes = string.Format (GettextCatalog.GetPluralString ("{0} change", "{0} changes", comparisonWidget.Diff.Count), comparisonWidget.Diff.Count);
55
string additions = string.Format (GettextCatalog.GetPluralString ("{0} line added", "{0} lines added", added), added);
56
string removals = string.Format (GettextCatalog.GetPluralString ("{0} line removed", "{0} lines removed", removed), removed);
58
return changes + " (" + additions + ", " + removals + ")";
62
public Mono.TextEditor.TextEditor FocusedEditor {
64
return comparisonWidget.FocusedEditor;
68
public DiffWidget (VersionControlDocumentInfo info) : this (info, false)
72
public DiffWidget (VersionControlDocumentInfo info, bool viewOnly)
76
comparisonWidget = new MonoDevelop.VersionControl.Views.ComparisonWidget (viewOnly);
78
fixed1.SetSizeRequest (16, 16);
79
this.buttonNext.Clicked += (sender, args) => ComparisonWidget.GotoNext ();
80
this.buttonPrev.Clicked += (sender, args) => ComparisonWidget.GotoPrev ();
82
vboxComparisonView.PackStart (comparisonWidget, true, true, 0);
83
comparisonWidget.Show ();
85
comparisonWidget.DiffChanged += delegate {
86
labelOverview.Markup = LabelText;
87
SetButtonSensitivity ();
89
comparisonWidget.SetVersionControlInfo (info);
90
this.buttonDiff.Clicked += HandleButtonDiffhandleClicked;
91
diffTextEditor = new global::Mono.TextEditor.TextEditor ();
92
diffTextEditor.Document.MimeType = "text/x-diff";
93
if (info.Document != null) {
94
diffTextEditor.Options.FontName = info.Document.Editor.Options.FontName;
95
diffTextEditor.Options.ColorScheme = info.Document.Editor.Options.ColorScheme;
96
diffTextEditor.Options.ShowTabs = info.Document.Editor.Options.ShowTabs;
97
diffTextEditor.Options.ShowSpaces = info.Document.Editor.Options.ShowSpaces;
98
diffTextEditor.Options.ShowInvalidLines = info.Document.Editor.Options.ShowInvalidLines;
99
diffTextEditor.Options.ShowInvalidLines = info.Document.Editor.Options.ShowInvalidLines;
101
var options = MonoDevelop.SourceEditor.DefaultSourceEditorOptions.Instance;
102
diffTextEditor.Options.FontName = options.FontName;
103
diffTextEditor.Options.ColorScheme = options.ColorScheme;
104
diffTextEditor.Options.ShowTabs = options.ShowTabs;
105
diffTextEditor.Options.ShowSpaces = options.ShowSpaces;
106
diffTextEditor.Options.ShowInvalidLines = options.ShowInvalidLines;
107
diffTextEditor.Options.ShowInvalidLines = options.ShowInvalidLines;
110
diffTextEditor.Options.ShowFoldMargin = false;
111
diffTextEditor.Options.ShowIconMargin = false;
112
diffTextEditor.Document.ReadOnly = true;
113
scrolledwindow1.Child = diffTextEditor;
114
diffTextEditor.Show ();
115
SetButtonSensitivity ();
118
void SetButtonSensitivity ()
120
this.buttonNext.Sensitive = this.buttonPrev.Sensitive = notebook1.Page == 0 && comparisonWidget.Diff != null && comparisonWidget.Diff.Count > 0;
123
void HandleButtonDiffhandleClicked (object sender, EventArgs e)
125
if (notebook1.Page == 0) {
126
buttonDiff.Label = GettextCatalog.GetString ("_Compare");
127
diffTextEditor.Document.Text = Mono.TextEditor.Utils.Diff.GetDiffString (comparisonWidget.Diff,
128
comparisonWidget.DiffEditor.Document,
129
comparisonWidget.OriginalEditor.Document,
130
(info.Item.Path) + "\t\t"+ GetRevisionText (comparisonWidget.DiffEditor, comparisonWidget.diffRevision),
131
(info.Item.Path) + "\t\t"+ GetRevisionText (comparisonWidget.OriginalEditor, comparisonWidget.originalRevision)
136
buttonDiff.Label = GettextCatalog.GetString ("_Patch");
140
SetButtonSensitivity ();
143
string GetRevisionText (Mono.TextEditor.TextEditor editor, Revision rev)
145
if (!editor.Document.ReadOnly)
146
return GettextCatalog.GetString ("(working copy)");
148
return GettextCatalog.GetString ("(base)");
149
return string.Format (GettextCatalog.GetString ("(revision {0})"), rev.ToString ());