diff options
author | Alan McGovern <alan.mcgovern@gmail.com> | 2011-10-10 19:29:04 +0400 |
---|---|---|
committer | Alan McGovern <alan.mcgovern@gmail.com> | 2011-10-12 18:40:37 +0400 |
commit | 542b468b135dd869df8dc32316b7438f54b9be29 (patch) | |
tree | 01d9c27bd902a6e14aa50e3ef9a7ec2c700766fd /main/src/addins/VersionControl | |
parent | 5f851d3eda566ac299b8c1f450ac5f6ffb4b747c (diff) |
[VersionControl] Turn DiffView/LogView/BlameView etc into extension points
There are places where we need customised diff/log/blame handling for specific
file types. For example plist files can always be viewed in text format but the
on-disk file may be binary. To implement diff support for this requires special
handling. This is supported by turning the various version control views into
extension points so that custom handlers can be created.
The default views for Diff, Blame, Log etc have also been refactored to not
depend directly on SourceEditorView. These views now all check to see if the
PrimaryView they're wrapping supports ITextFile, ITextBuffer etc before
using features defined by those interfaces. DiffView works with an ITextFile
at the most basic level by displaying a readonly view. If the view is an
IEditableTextFile/ITextBuffer or SourceEditorView we enable further features
automatically.
Similary for the other views.
Diffstat (limited to 'main/src/addins/VersionControl')
25 files changed, 794 insertions, 287 deletions
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/Makefile.am b/main/src/addins/VersionControl/MonoDevelop.VersionControl/Makefile.am index 69a540e493..2942763c2c 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/Makefile.am +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/Makefile.am @@ -31,9 +31,11 @@ FILES = \ MonoDevelop.VersionControl.Views/MergeWidget.cs \ MonoDevelop.VersionControl.Views/StatusView.cs \ MonoDevelop.VersionControl.Views/SubviewAttachmentHandler.cs \ + MonoDevelop.VersionControl.Views/VersionControlDocumentInfo.cs \ MonoDevelop.VersionControl/AddRemoveMoveCommand.cs \ MonoDevelop.VersionControl/AnnotateCommand.cs \ MonoDevelop.VersionControl/BaseView.cs \ + MonoDevelop.VersionControl/BlameCommand.cs \ MonoDevelop.VersionControl/ChangeLogWriter.cs \ MonoDevelop.VersionControl/ChangeSet.cs \ MonoDevelop.VersionControl/CheckoutCommand.cs \ @@ -44,9 +46,17 @@ FILES = \ MonoDevelop.VersionControl/CommitMessageFormat.cs \ MonoDevelop.VersionControl/CommitMessageStyle.cs \ MonoDevelop.VersionControl/CreatePatchCommand.cs \ + MonoDevelop.VersionControl/DefaultBlameViewHandler.cs \ + MonoDevelop.VersionControl/DefaultDiffViewHandler.cs \ + MonoDevelop.VersionControl/DefaultLogViewHandler.cs \ + MonoDevelop.VersionControl/DefaultMergeViewHandler.cs \ + MonoDevelop.VersionControl/DiffCommand.cs \ MonoDevelop.VersionControl/FileUpdateEventHandler.cs \ MonoDevelop.VersionControl/IRepositoryEditor.cs \ + MonoDevelop.VersionControl/IVersionControlViewHandler.cs \ MonoDevelop.VersionControl/LockCommand.cs \ + MonoDevelop.VersionControl/LogCommand.cs \ + MonoDevelop.VersionControl/MergeCommand.cs \ MonoDevelop.VersionControl/PublishCommand.cs \ MonoDevelop.VersionControl/Repository.cs \ MonoDevelop.VersionControl/RevertCommand.cs \ diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/BlameView.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/BlameView.cs index 7b9b8482e4..d39f273e51 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/BlameView.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/BlameView.cs @@ -32,7 +32,11 @@ using Mono.TextEditor; using System.Linq; namespace MonoDevelop.VersionControl.Views { - internal class BlameView : BaseView, IAttachableViewContent, IUndoHandler, IClipboardHandler + public interface IBlameView : IAttachableViewContent + { + } + + internal class BlameView : BaseView, IBlameView, IUndoHandler, IClipboardHandler { BlameWidget widget; VersionControlDocumentInfo info; @@ -45,43 +49,29 @@ namespace MonoDevelop.VersionControl.Views } } - public static bool Show (VersionControlItemList items, bool test) - { - if (!test) { - Show (items); - return true; - } - else - return items.All (i => i.VersionInfo.CanAnnotate); - } - - public static void Show (VersionControlItemList items) - { - foreach (VersionControlItem item in items) { - var document = IdeApp.Workbench.OpenDocument (item.Path, OpenDocumentOptions.Default | OpenDocumentOptions.OnlyInternalViewer); - DiffView.AttachViewContents (document, item); - document.Window.SwitchView (document.Window.FindView (typeof(BlameView))); - } - } - public BlameView (VersionControlDocumentInfo info) : base (GettextCatalog.GetString ("Blame")) { this.info = info; - } #region IAttachableViewContent implementation public void Selected () { info.Start (); - widget.Editor.Caret.Location = info.Document.Editor.Caret.Location; - widget.Editor.VAdjustment.Value = info.Document.Editor.VAdjustment.Value; + var sourceEditor = info.Document.GetContent <MonoDevelop.SourceEditor.SourceEditorView> (); + if (sourceEditor != null) { + widget.Editor.Caret.Location = sourceEditor.TextEditor.Caret.Location; + widget.Editor.VAdjustment.Value = sourceEditor.TextEditor.VAdjustment.Value; + } } public void Deselected () { - info.Document.Editor.Caret.Location = widget.Editor.Caret.Location; - info.Document.Editor.VAdjustment.Value = widget.Editor.VAdjustment.Value; + var sourceEditor = info.Document.GetContent <MonoDevelop.SourceEditor.SourceEditorView> (); + if (sourceEditor != null) { + sourceEditor.TextEditor.Caret.Location = widget.Editor.Caret.Location; + sourceEditor.TextEditor.VAdjustment.Value = widget.Editor.VAdjustment.Value; + } } public void BeforeSave () diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/BlameWidget.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/BlameWidget.cs index 26c19c63b1..f51021eca4 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/BlameWidget.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/BlameWidget.cs @@ -85,7 +85,7 @@ namespace MonoDevelop.VersionControl.Views public Ide.Gui.Document Document { get { - return info.Document; + return info.Document.WorkbenchWindow.Document; } } public VersionControlItem VersionControlItem { @@ -101,6 +101,7 @@ namespace MonoDevelop.VersionControl.Views public BlameWidget (VersionControlDocumentInfo info) { this.info = info; + var sourceEditor = info.Document.GetContent<MonoDevelop.SourceEditor.SourceEditorView> (); vAdjustment = new Adjustment (0, 0, 0, 0, 0, 0); vAdjustment.Changed += HandleAdjustmentChanged; @@ -114,7 +115,7 @@ namespace MonoDevelop.VersionControl.Views hScrollBar = new HScrollbar (hAdjustment); AddChild (hScrollBar); - editor = new TextEditor (info.Document.Editor.Document, info.Document.Editor.Options); + editor = new TextEditor (sourceEditor.TextEditor.Document, sourceEditor.TextEditor.Options); AddChild (editor); editor.SetScrollAdjustments (hAdjustment, vAdjustment); @@ -502,10 +503,10 @@ namespace MonoDevelop.VersionControl.Views if (highlightAnnotation == null) return; int i = 1; - foreach (var content in widget.info.Document.Window.SubViewContents) { + foreach (var content in widget.info.Document.WorkbenchWindow.SubViewContents) { DiffView diffView = content as DiffView; if (diffView != null) { - widget.info.Document.Window.SwitchView (i); + widget.info.Document.WorkbenchWindow.SwitchView (i); var rev = widget.info.History.FirstOrDefault (h => h.ToString () == highlightAnnotation.Revision); if (rev == null) return; @@ -523,10 +524,10 @@ namespace MonoDevelop.VersionControl.Views if (highlightAnnotation == null) return; int i = 1; - foreach (var content in widget.info.Document.Window.SubViewContents) { + foreach (var content in widget.info.Document.WorkbenchWindow.SubViewContents) { LogView logView = content as LogView; if (logView != null) { - widget.info.Document.Window.SwitchView (i); + widget.info.Document.WorkbenchWindow.SwitchView (i); var rev = widget.info.History.FirstOrDefault (h => h.ToString () == highlightAnnotation.Revision); if (rev == null) return; diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/ComparisonWidget.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/ComparisonWidget.cs index 9611267d7b..5112875a88 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/ComparisonWidget.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/ComparisonWidget.cs @@ -35,11 +35,12 @@ using MonoDevelop.Ide; using MonoDevelop.Components; using System.ComponentModel; using MonoDevelop.Core; +using MonoDevelop.Ide.Gui; namespace MonoDevelop.VersionControl.Views { [ToolboxItem (true)] - class ComparisonWidget : EditorCompareWidgetBase + public class ComparisonWidget : EditorCompareWidgetBase { internal DropDownBox originalComboBox, diffComboBox; @@ -72,11 +73,12 @@ namespace MonoDevelop.VersionControl.Views protected override void CreateComponents () { - this.editors = new [] { new TextEditor (), new TextEditor ()}; - DiffEditor.Document.ReadOnly = true; - if (viewOnly) { - OriginalEditor.Document.ReadOnly = true; - } else { + this.editors = new [] { + new TextEditor (new Mono.TextEditor.Document (), new CommonTextEditorOptions ()), + new TextEditor (new Mono.TextEditor.Document (), new CommonTextEditorOptions ()), + }; + + if (!viewOnly) { originalComboBox = new DropDownBox (); originalComboBox.WindowRequestFunc = CreateComboBoxSelector; originalComboBox.Text = "Local"; diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/DiffView.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/DiffView.cs index c13fbe8ee3..ca36faf2e7 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/DiffView.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/DiffView.cs @@ -32,97 +32,16 @@ using System.Collections.Generic; using System.Threading; using MonoDevelop.Core; using MonoDevelop.Ide.Gui.Content; +using Mono.Addins; +using MonoDevelop.Projects.Text; namespace MonoDevelop.VersionControl.Views { - public class VersionControlDocumentInfo + public interface IDiffView : IAttachableViewContent { - bool alreadyStarted = false; - - public Document Document { - get; - set; - } - - public VersionControlItem Item { - get; - set; - } - - public Revision[] History { - get; - set; - } - - public VersionInfo VersionInfo { - get; - set; - } - - public Repository Repository { - get; - set; - } - - public bool Started { - get { return alreadyStarted; } - } - - public VersionControlDocumentInfo (Document document, VersionControlItem item, Repository repository) - { - this.Document = document; - this.Item = item; - this.Repository = repository; - } - - public void Start () - { - if (alreadyStarted) - return; - alreadyStarted = true; - ThreadPool.QueueUserWorkItem (delegate { - lock (updateLock) { - try { - History = Item.Repository.GetHistory (Item.Path, null); - VersionInfo = Item.Repository.GetVersionInfo (Item.Path, false); - } catch (Exception ex) { - LoggingService.LogError ("Error retrieving history", ex); - } - - DispatchService.GuiDispatch (delegate { - OnUpdated (EventArgs.Empty); - }); - isUpdated = true; - } - }); - } - - object updateLock = new object (); - bool isUpdated = false; - - public void RunAfterUpdate (Action act) - { - if (isUpdated) { - act (); - return; - } - while (!isUpdated) - Thread.Sleep (10); - act (); - } - - protected virtual void OnUpdated (EventArgs e) - { - EventHandler handler = this.Updated; - if (handler != null) - handler (this, e); - } - - public event EventHandler Updated; - } - class DiffView : BaseView, IAttachableViewContent, IUndoHandler, IClipboardHandler + public class DiffView : BaseView, IDiffView, IUndoHandler, IClipboardHandler { DiffWidget widget; @@ -150,39 +69,7 @@ namespace MonoDevelop.VersionControl.Views return ComparisonWidget.Diff; } } - - public static void AttachViewContents (Document document, VersionControlItem item) - { - IWorkbenchWindow window = document.Window; - if (window.SubViewContents.Any (sub => sub is DiffView)) - return; - - VersionControlDocumentInfo info = new VersionControlDocumentInfo (document, item, item.Repository); - - DiffView comparisonView = new DiffView (info); - window.AttachViewContent (comparisonView); -// window.AttachViewContent (new PatchView (comparisonView, info)); - window.AttachViewContent (new BlameView (info)); - window.AttachViewContent (new LogView (info)); - - if (info.VersionInfo != null && info.VersionInfo.Status == VersionStatus.Conflicted) - window.AttachViewContent (new MergeView (info)); - } - public static void Show (VersionControlItemList items) - { - foreach (VersionControlItem item in items) { - var document = IdeApp.Workbench.OpenDocument (item.Path, OpenDocumentOptions.Default | OpenDocumentOptions.OnlyInternalViewer); - DiffView.AttachViewContents (document, item); - document.Window.SwitchView (document.Window.FindView (typeof(DiffView))); - } - } - - public static bool CanShow (VersionControlItemList items) - { - return items.Any (i => i.VersionInfo.HasLocalChanges); - } - VersionControlDocumentInfo info; public DiffView (VersionControlDocumentInfo info) : base (GettextCatalog.GetString ("Changes")) { @@ -193,24 +80,12 @@ namespace MonoDevelop.VersionControl.Views { this.info = info; widget = new DiffWidget (info); - - ComparisonWidget.OriginalEditor.Document.MimeType = ComparisonWidget.DiffEditor.Document.MimeType = info.Document.Editor.Document.MimeType; - ComparisonWidget.OriginalEditor.Options.FontName = ComparisonWidget.DiffEditor.Options.FontName = info.Document.Editor.Options.FontName; - ComparisonWidget.OriginalEditor.Options.ColorScheme = ComparisonWidget.DiffEditor.Options.ColorScheme = info.Document.Editor.Options.ColorScheme; - ComparisonWidget.OriginalEditor.Options.ShowFoldMargin = ComparisonWidget.DiffEditor.Options.ShowFoldMargin = false; - ComparisonWidget.OriginalEditor.Options.ShowIconMargin = ComparisonWidget.DiffEditor.Options.ShowIconMargin = false; - ComparisonWidget.SetRevision (ComparisonWidget.DiffEditor, baseRev); ComparisonWidget.SetRevision (ComparisonWidget.OriginalEditor, toRev); widget.ShowAll (); } - public override void Dispose () - { - base.Dispose (); - } - #region IAttachableViewContent implementation public int GetLineInCenter (Mono.TextEditor.TextEditor editor) @@ -223,8 +98,13 @@ namespace MonoDevelop.VersionControl.Views { info.Start (); ComparisonWidget.UpdateLocalText (); - ComparisonWidget.OriginalEditor.Document.IgnoreFoldings = true; - ComparisonWidget.OriginalEditor.Caret.Location = info.Document.Editor.Caret.Location; + var buffer = info.Document.GetContent<ITextBuffer> (); + if (buffer != null) { + int line, col; + buffer.GetLineColumnFromPosition (buffer.CursorPosition, out line, out col); + ComparisonWidget.OriginalEditor.SetCaretTo (line, col); + } + if (ComparisonWidget.Allocation.Height == 1 && ComparisonWidget.Allocation.Width == 1) { ComparisonWidget.SizeAllocated += HandleComparisonWidgetSizeAllocated; } else { @@ -235,20 +115,24 @@ namespace MonoDevelop.VersionControl.Views void HandleComparisonWidgetSizeAllocated (object o, Gtk.SizeAllocatedArgs args) { ComparisonWidget.SizeAllocated -= HandleComparisonWidgetSizeAllocated; - int line = GetLineInCenter (info.Document.Editor.Parent); - ComparisonWidget.OriginalEditor.CenterTo (line, 1); - ComparisonWidget.OriginalEditor.GrabFocus (); + var sourceEditorView = info.Document.GetContent<MonoDevelop.SourceEditor.SourceEditorView> (); + if (sourceEditorView != null) { + int line = GetLineInCenter (sourceEditorView.TextEditor); + ComparisonWidget.OriginalEditor.CenterTo (line, 1); + ComparisonWidget.OriginalEditor.GrabFocus (); + } } public void Deselected () { - info.Document.Editor.Caret.Location = ComparisonWidget.OriginalEditor.Caret.Location; - - int line = GetLineInCenter (ComparisonWidget.OriginalEditor); - if (Math.Abs (GetLineInCenter (info.Document.Editor.Parent) - line) > 2) - info.Document.Editor.CenterTo (line, 1); - - ComparisonWidget.OriginalEditor.Document.IgnoreFoldings = false; + var sourceEditor = info.Document.GetContent <MonoDevelop.SourceEditor.SourceEditorView> (); + if (sourceEditor != null) { + sourceEditor.TextEditor.Caret.Location = ComparisonWidget.OriginalEditor.Caret.Location; + + int line = GetLineInCenter (ComparisonWidget.OriginalEditor); + if (Math.Abs (GetLineInCenter (sourceEditor.TextEditor) - line) > 2) + sourceEditor.TextEditor.CenterTo (line, 1); + } } public void BeforeSave () diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/DiffWidget.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/DiffWidget.cs index a58fe6e046..24f3f1c094 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/DiffWidget.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/DiffWidget.cs @@ -26,6 +26,7 @@ using System; using System.Linq; using MonoDevelop.Core; +using MonoDevelop.Ide.Gui; namespace MonoDevelop.VersionControl.Views { @@ -88,24 +89,8 @@ namespace MonoDevelop.VersionControl.Views }; comparisonWidget.SetVersionControlInfo (info); this.buttonDiff.Clicked += HandleButtonDiffhandleClicked; - diffTextEditor = new global::Mono.TextEditor.TextEditor (); + diffTextEditor = new global::Mono.TextEditor.TextEditor (new Mono.TextEditor.Document (), new CommonTextEditorOptions ()); diffTextEditor.Document.MimeType = "text/x-diff"; - if (info.Document != null) { - diffTextEditor.Options.FontName = info.Document.Editor.Options.FontName; - diffTextEditor.Options.ColorScheme = info.Document.Editor.Options.ColorScheme; - diffTextEditor.Options.ShowTabs = info.Document.Editor.Options.ShowTabs; - diffTextEditor.Options.ShowSpaces = info.Document.Editor.Options.ShowSpaces; - diffTextEditor.Options.ShowInvalidLines = info.Document.Editor.Options.ShowInvalidLines; - diffTextEditor.Options.ShowInvalidLines = info.Document.Editor.Options.ShowInvalidLines; - } else { - var options = MonoDevelop.SourceEditor.DefaultSourceEditorOptions.Instance; - diffTextEditor.Options.FontName = options.FontName; - diffTextEditor.Options.ColorScheme = options.ColorScheme; - diffTextEditor.Options.ShowTabs = options.ShowTabs; - diffTextEditor.Options.ShowSpaces = options.ShowSpaces; - diffTextEditor.Options.ShowInvalidLines = options.ShowInvalidLines; - diffTextEditor.Options.ShowInvalidLines = options.ShowInvalidLines; - } diffTextEditor.Options.ShowFoldMargin = false; diffTextEditor.Options.ShowIconMargin = false; diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/EditorCompareWidgetBase.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/EditorCompareWidgetBase.cs index 0bdb75428f..9fa2a55fcc 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/EditorCompareWidgetBase.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/EditorCompareWidgetBase.cs @@ -38,6 +38,8 @@ using System.ComponentModel; using MonoDevelop.Core; using System.Globalization; using MonoDevelop.Components.Commands; +using MonoDevelop.Ide.Gui.Content; +using MonoDevelop.Projects.Text; namespace MonoDevelop.VersionControl.Views { @@ -267,33 +269,15 @@ namespace MonoDevelop.VersionControl.Views public void SetVersionControlInfo (VersionControlDocumentInfo info) { this.info = info; - - if (info.Document != null) { - foreach (var editor in editors) { - editor.Document.MimeType = info.Document.Editor.Document.MimeType; - editor.Options.FontName = info.Document.Editor.Options.FontName; - editor.Options.ColorScheme = info.Document.Editor.Options.ColorScheme; - editor.Options.ShowSpaces = info.Document.Editor.Options.ShowSpaces; - editor.Options.ShowTabs = info.Document.Editor.Options.ShowTabs; - editor.Options.ShowEolMarkers = info.Document.Editor.Options.ShowEolMarkers; - editor.Options.ShowInvalidLines = info.Document.Editor.Options.ShowInvalidLines; - editor.Options.TabSize = info.Document.Editor.Options.TabSize; - editor.Options.ShowFoldMargin = false; - editor.Options.ShowIconMargin = false; - } - } else { - var options = MonoDevelop.SourceEditor.DefaultSourceEditorOptions.Instance; - foreach (var editor in editors) { - editor.Options.FontName = options.FontName; - editor.Options.ColorScheme = options.ColorScheme; - editor.Options.ShowSpaces = options.ShowSpaces; - editor.Options.ShowTabs = options.ShowTabs; - editor.Options.ShowEolMarkers = options.ShowEolMarkers; - editor.Options.ShowInvalidLines = options.ShowInvalidLines; - editor.Options.TabSize = options.TabSize; - editor.Options.ShowFoldMargin = false; - editor.Options.ShowIconMargin = false; - } + + var mimeType = DesktopService.GetMimeTypeForUri (info.Item.Path); + foreach (var editor in editors) { + editor.Document.IgnoreFoldings = true; + editor.Document.MimeType = mimeType; + editor.Document.ReadOnly = true; + + editor.Options.ShowFoldMargin = false; + editor.Options.ShowIconMargin = false; } } @@ -620,9 +604,10 @@ namespace MonoDevelop.VersionControl.Views public void UpdateLocalText () { + var text = info.Document.GetContent<ITextFile> (); foreach (var data in dict.Values) { data.Document.TextReplaced -= HandleDataDocumentTextReplaced; - data.Document.Text = info.Document.Editor.Document.Text; + data.Document.Text = text.Text; data.Document.TextReplaced += HandleDataDocumentTextReplaced; } CreateDiff (); @@ -633,8 +618,12 @@ namespace MonoDevelop.VersionControl.Views if (info == null) throw new InvalidOperationException ("Version control info must be set before attaching the merge view to an editor."); dict[data.Document] = data; - data.Document.Text = info.Document.Editor.Document.Text; - data.Document.ReadOnly = false; + + var editor = info.Document.GetContent <ITextFile> (); + if (editor != null) + data.Document.Text = editor.Text; + data.Document.ReadOnly = info.Document.GetContent<IEditableTextFile> () == null; + CreateDiff (); data.Document.TextReplaced += HandleDataDocumentTextReplaced; } @@ -643,7 +632,9 @@ namespace MonoDevelop.VersionControl.Views { var data = dict[(Document)sender]; localUpdate.Remove (data); - info.Document.Editor.Replace (e.Offset, e.Count, e.Value); + var editor = info.Document.GetContent<IEditableTextFile> (); + editor.DeleteText (e.Offset, e.Count); + editor.InsertText (e.Offset, e.Value); localUpdate.Add (data); UpdateDiff (); } @@ -651,7 +642,6 @@ namespace MonoDevelop.VersionControl.Views public void RemoveLocal (TextEditorData data) { localUpdate.Remove (data); - data.Document.ReadOnly = true; data.Document.TextReplaced -= HandleDataDocumentTextReplaced; } diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/LogView.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/LogView.cs index 9d20d63449..4db0bddbef 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/LogView.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/LogView.cs @@ -9,7 +9,11 @@ using System.Linq; namespace MonoDevelop.VersionControl.Views { - public class LogView : BaseView, IAttachableViewContent + public interface ILogView : IAttachableViewContent + { + } + + public class LogView : BaseView, ILogView { string filepath; LogWidget widget; @@ -24,26 +28,6 @@ namespace MonoDevelop.VersionControl.Views } } - public static void Show (VersionControlItemList items, Revision since) - { - foreach (VersionControlItem item in items) { - if (!item.IsDirectory) { - var document = IdeApp.Workbench.OpenDocument (item.Path, OpenDocumentOptions.Default | OpenDocumentOptions.OnlyInternalViewer); - if (document != null) { - DiffView.AttachViewContents (document, item); - document.Window.SwitchView (document.Window.FindView (typeof(LogView))); - } else { - VersionControlDocumentInfo info = new VersionControlDocumentInfo (null, item, item.Repository); - LogView logView = new LogView (info); - info.Document = IdeApp.Workbench.OpenDocument (logView, true); - logView.Selected (); - } - } else if (item.VersionInfo.CanLog) { - new Worker (item.Repository, item.Path, item.IsDirectory, since).Start (); - } - } - } - class Worker : Task { Repository vc; string filepath; diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/LogWidget.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/LogWidget.cs index bb055798e7..06931373e3 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/LogWidget.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/LogWidget.cs @@ -119,7 +119,7 @@ namespace MonoDevelop.VersionControl.Views this.Build (); this.info = info; if (info.Document != null) - this.preselectFile = info.Document.FileName; + this.preselectFile = info.Item.Path; revertButton = new Gtk.ToolButton (new Gtk.Image ("vc-revert-command", Gtk.IconSize.Menu), GettextCatalog.GetString ("Revert changes from this revision")); revertButton.IsImportant = true; diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/MergeView.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/MergeView.cs index 6b7d858e44..724d062293 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/MergeView.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/MergeView.cs @@ -30,7 +30,11 @@ using MonoDevelop.Core; namespace MonoDevelop.VersionControl.Views { - class MergeView : BaseView, IAttachableViewContent + public interface IMergeView : IAttachableViewContent + { + } + + class MergeView : BaseView, IMergeView { MergeWidget widget; @@ -40,15 +44,6 @@ namespace MonoDevelop.VersionControl.Views } } - public static void Show (VersionControlItemList items) - { - foreach (VersionControlItem item in items) { - var document = IdeApp.Workbench.OpenDocument (item.Path, OpenDocumentOptions.Default | OpenDocumentOptions.OnlyInternalViewer); - DiffView.AttachViewContents (document, item); - document.Window.SwitchView (document.Window.FindView (typeof (MergeView))); - } - } - public MergeView (VersionControlDocumentInfo info) : base (GettextCatalog.GetString ("Merge")) { widget = new MergeWidget (); diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/SubviewAttachmentHandler.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/SubviewAttachmentHandler.cs index 768dbd31a5..42f9856bf2 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/SubviewAttachmentHandler.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/SubviewAttachmentHandler.cs @@ -24,7 +24,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; +using System.Linq; using MonoDevelop.Components.Commands; +using Mono.Addins; +using MonoDevelop.VersionControl; +using MonoDevelop.Ide.Gui; namespace MonoDevelop.VersionControl.Views { @@ -37,18 +41,27 @@ namespace MonoDevelop.VersionControl.Views void HandleDocumentOpened (object sender, Ide.Gui.DocumentEventArgs e) { - if (e.Document.Project == null) + if (!e.Document.IsFile || e.Document.Project == null) return; + var repo = VersionControlService.GetRepository (e.Document.Project); - if (repo == null) - return; - if (!e.Document.IsFile || !repo.GetVersionInfo (e.Document.FileName).IsVersioned) + if (repo == null || !repo.GetVersionInfo (e.Document.FileName).IsVersioned) return; - if (e.Document.Editor == null) - return; - var item = new VersionControlItem (repo, e.Document.Project, e.Document.FileName, false, null); - DiffView.AttachViewContents (e.Document, item); + var item = new VersionControlItem (repo, e.Document.Project, e.Document.FileName, false, null); + TryAttachView <IDiffView> (e.Document, item, DiffCommand.DiffViewHandlers); + TryAttachView <IBlameView> (e.Document, item, BlameCommand.BlameViewHandlers); + TryAttachView <ILogView> (e.Document, item, LogCommand.LogViewHandlers); + TryAttachView <IMergeView> (e.Document, item, MergeCommand.MergeViewHandlers); + } + + void TryAttachView <T>(Document document, VersionControlItem item, string type) + where T : IAttachableViewContent + { + var handler = AddinManager.GetExtensionObjects<IVersionControlViewHandler<T>> (type).FirstOrDefault (h => h.CanHandle (item)); + if (handler != null) { + document.Window.AttachViewContent (handler.CreateView (item, document.PrimaryView)); + } } } } diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/VersionControlDocumentInfo.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/VersionControlDocumentInfo.cs new file mode 100644 index 0000000000..369e59a276 --- /dev/null +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/VersionControlDocumentInfo.cs @@ -0,0 +1,126 @@ +// +// VersionControlView.cs +// +// Author: +// Mike Krüger <mkrueger@novell.com> +// +// Copyright (c) 2010 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Linq; +using System.IO; +using MonoDevelop.Ide; +using MonoDevelop.Ide.Gui; +using System.Collections.Generic; +using System.Threading; +using MonoDevelop.Core; +using MonoDevelop.Ide.Gui.Content; +using Mono.Addins; + +namespace MonoDevelop.VersionControl.Views +{ + public class VersionControlDocumentInfo + { + bool alreadyStarted = false; + + public IViewContent Document { + get; + set; + } + + public VersionControlItem Item { + get; + set; + } + + public Revision[] History { + get; + set; + } + + public VersionInfo VersionInfo { + get; + set; + } + + public Repository Repository { + get; + set; + } + + public bool Started { + get { return alreadyStarted; } + } + + public VersionControlDocumentInfo (IViewContent document, VersionControlItem item, Repository repository) + { + this.Document = document; + this.Item = item; + this.Repository = repository; + } + + public void Start () + { + if (alreadyStarted) + return; + alreadyStarted = true; + ThreadPool.QueueUserWorkItem (delegate { + lock (updateLock) { + try { + History = Item.Repository.GetHistory (Item.Path, null); + VersionInfo = Item.Repository.GetVersionInfo (Item.Path, false); + } catch (Exception ex) { + LoggingService.LogError ("Error retrieving history", ex); + } + + DispatchService.GuiDispatch (delegate { + OnUpdated (EventArgs.Empty); + }); + isUpdated = true; + } + }); + } + + object updateLock = new object (); + bool isUpdated = false; + + public void RunAfterUpdate (Action act) + { + if (isUpdated) { + act (); + return; + } + while (!isUpdated) + Thread.Sleep (10); + act (); + } + + protected virtual void OnUpdated (EventArgs e) + { + EventHandler handler = this.Updated; + if (handler != null) + handler (this, e); + } + + public event EventHandler Updated; + + } +} diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.csproj b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.csproj index 9bacd1d0b9..f21c2d4a2d 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.csproj +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.csproj @@ -214,6 +214,16 @@ <Compile Include="gtk-gui\MonoDevelop.VersionControl.Views.LogWidget.cs" /> <Compile Include="MonoDevelop.VersionControl\IRepositoryEditor.cs" /> <Compile Include="MonoDevelop.VersionControl\VersionControlOperation.cs" /> + <Compile Include="MonoDevelop.VersionControl.Views\VersionControlDocumentInfo.cs" /> + <Compile Include="MonoDevelop.VersionControl\IVersionControlViewHandler.cs" /> + <Compile Include="MonoDevelop.VersionControl\DefaultDiffViewHandler.cs" /> + <Compile Include="MonoDevelop.VersionControl\DefaultBlameViewHandler.cs" /> + <Compile Include="MonoDevelop.VersionControl\DefaultLogViewHandler.cs" /> + <Compile Include="MonoDevelop.VersionControl\DefaultMergeViewHandler.cs" /> + <Compile Include="MonoDevelop.VersionControl\LogCommand.cs" /> + <Compile Include="MonoDevelop.VersionControl\DiffCommand.cs" /> + <Compile Include="MonoDevelop.VersionControl\MergeCommand.cs" /> + <Compile Include="MonoDevelop.VersionControl\BlameCommand.cs" /> </ItemGroup> <ItemGroup> <None Include="Makefile.am" /> diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/BlameCommand.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/BlameCommand.cs new file mode 100644 index 0000000000..a6d4e04636 --- /dev/null +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/BlameCommand.cs @@ -0,0 +1,60 @@ +// +// BlameCommand.cs +// +// Author: +// Alan McGovern <alan@xamarin.com> +// +// Copyright 2011, Xamarin Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Linq; +using Mono.Addins; +using MonoDevelop.Ide; +using MonoDevelop.Ide.Gui; +using MonoDevelop.VersionControl.Views; + +namespace MonoDevelop.VersionControl +{ + public class BlameCommand + { + internal static readonly string BlameViewHandlers = "/MonoDevelop/VersionControl/BlameViewHandler"; + + static bool CanShow (VersionControlItem item) + { + return !item.IsDirectory && AddinManager.GetExtensionObjects<IBlameViewHandler> (BlameViewHandlers).Any (h => h.CanHandle (item)); + } + + public static bool Show (VersionControlItemList items, bool test) + { + if (test) + return items.All (CanShow); + + foreach (var item in items) { + var document = IdeApp.Workbench.OpenDocument (item.Path, OpenDocumentOptions.Default | OpenDocumentOptions.OnlyInternalViewer); + if (document != null) + document.Window.SwitchView (document.Window.FindView<IBlameView> ()); + } + + return true; + } + } +} + diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/Commands.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/Commands.cs index cc5eaf566d..e3e0348feb 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/Commands.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/Commands.cs @@ -214,9 +214,8 @@ namespace MonoDevelop.VersionControl { protected override void Run () { - var doc = IdeApp.Workbench.ActiveDocument; - DiffView.AttachViewContents (doc, GetItem ()); - doc.Window.SwitchView (doc.Window.FindView (typeof (DiffView))); + var window = IdeApp.Workbench.ActiveDocument.Window; + window.SwitchView (window.FindView<IDiffView> ()); } } @@ -224,9 +223,8 @@ namespace MonoDevelop.VersionControl { protected override void Run () { - var doc = IdeApp.Workbench.ActiveDocument; - DiffView.AttachViewContents (doc, GetItem ()); - doc.Window.SwitchView (doc.Window.FindView (typeof (BlameView))); + var window = IdeApp.Workbench.ActiveDocument.Window; + window.SwitchView (window.FindView<IBlameView> ()); } } @@ -234,9 +232,8 @@ namespace MonoDevelop.VersionControl { protected override void Run () { - var doc = IdeApp.Workbench.ActiveDocument; - DiffView.AttachViewContents (doc, GetItem ()); - doc.Window.SwitchView (doc.Window.FindView (typeof (LogView))); + var window = IdeApp.Workbench.ActiveDocument.Window; + window.SwitchView (window.FindView<ILogView> ()); } } } diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/DefaultBlameViewHandler.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/DefaultBlameViewHandler.cs new file mode 100644 index 0000000000..24a3d8c9bc --- /dev/null +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/DefaultBlameViewHandler.cs @@ -0,0 +1,46 @@ +// +// DefaultBlameViewHandler.cs +// +// Author: +// Alan McGovern <alan@xamarin.com> +// +// Copyright 2011, Xamarin Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using MonoDevelop.Ide; +using MonoDevelop.Ide.Gui; +using MonoDevelop.VersionControl.Views; + +namespace MonoDevelop.VersionControl +{ + public class DefaultBlameViewHandler : IBlameViewHandler + { + public bool CanHandle (VersionControlItem item) + { + return DesktopService.GetMimeTypeIsText (DesktopService.GetMimeTypeForUri (item.Path)); + } + + public IBlameView CreateView (VersionControlItem item, IViewContent primaryView) + { + return new BlameView (new VersionControlDocumentInfo (primaryView, item, item.Repository)); + } + } +} diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/DefaultDiffViewHandler.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/DefaultDiffViewHandler.cs new file mode 100644 index 0000000000..65a3d9cdde --- /dev/null +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/DefaultDiffViewHandler.cs @@ -0,0 +1,47 @@ +// +// DefaultDiffViewHandler.cs +// +// Author: +// Alan McGovern <alan@xamarin.com> +// +// Copyright 2011, Xamarin Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using MonoDevelop.Ide; +using MonoDevelop.Ide.Gui; +using MonoDevelop.VersionControl.Views; + +namespace MonoDevelop.VersionControl +{ + public class DefaultDiffViewHandler : IDiffViewHandler + { + + public bool CanHandle (VersionControlItem item) + { + return DesktopService.GetMimeTypeIsText (DesktopService.GetMimeTypeForUri (item.Path)); + } + + public IDiffView CreateView (VersionControlItem item, IViewContent primaryView) + { + return new DiffView (new VersionControlDocumentInfo (primaryView, item, item.Repository)); + } + } +} diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/DefaultLogViewHandler.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/DefaultLogViewHandler.cs new file mode 100644 index 0000000000..0e94e54ed6 --- /dev/null +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/DefaultLogViewHandler.cs @@ -0,0 +1,46 @@ +// +// DefaultLogViewHandler.cs +// +// Author: +// Alan McGovern <alan@xamarin.com> +// +// Copyright 2011, Xamarin Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using MonoDevelop.Ide; +using MonoDevelop.Ide.Gui; +using MonoDevelop.VersionControl.Views; + +namespace MonoDevelop.VersionControl +{ + public class DefaultLogViewHandler : ILogViewHandler + { + public bool CanHandle (VersionControlItem item) + { + return true; + } + + public ILogView CreateView (VersionControlItem item, IViewContent primaryView) + { + return new LogView (new VersionControlDocumentInfo (primaryView, item, item.Repository)); + } + } +} diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/DefaultMergeViewHandler.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/DefaultMergeViewHandler.cs new file mode 100644 index 0000000000..d2cd2a6317 --- /dev/null +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/DefaultMergeViewHandler.cs @@ -0,0 +1,46 @@ +// +// DefaultMergeViewHandler.cs +// +// Author: +// Alan McGovern <alan@xamarin.com> +// +// Copyright 2011, Xamarin Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using MonoDevelop.Ide; +using MonoDevelop.Ide.Gui; +using MonoDevelop.VersionControl.Views; + +namespace MonoDevelop.VersionControl +{ + public class DefaultMergeViewHandler : IMergeViewHandler + { + public bool CanHandle (VersionControlItem item) + { + return DesktopService.GetMimeTypeIsText (DesktopService.GetMimeTypeForUri (item.Path)); + } + + public IMergeView CreateView (VersionControlItem item, IViewContent primaryView) + { + return new MergeView (new VersionControlDocumentInfo (primaryView, item, item.Repository)); + } + } +} diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/DiffCommand.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/DiffCommand.cs new file mode 100644 index 0000000000..3155da86a8 --- /dev/null +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/DiffCommand.cs @@ -0,0 +1,60 @@ +// +// LogCommand.cs +// +// Author: +// Alan McGovern <alan@xamarin.com> +// +// Copyright 2011, Xamarin Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Linq; +using Mono.Addins; +using MonoDevelop.Ide; +using MonoDevelop.Ide.Gui; +using MonoDevelop.VersionControl.Views; + +namespace MonoDevelop.VersionControl +{ + public class DiffCommand + { + internal static readonly string DiffViewHandlers = "/MonoDevelop/VersionControl/DiffViewHandler"; + + static bool CanShow (VersionControlItem item) + { + return !item.IsDirectory && AddinManager.GetExtensionObjects<IDiffViewHandler> (DiffViewHandlers).Any (h => h.CanHandle (item)); + } + + public static bool Show (VersionControlItemList items, bool test) + { + if (test) + return items.All (CanShow); + + foreach (var item in items) { + var document = IdeApp.Workbench.OpenDocument (item.Path, OpenDocumentOptions.Default | OpenDocumentOptions.OnlyInternalViewer); + if (document != null) + document.Window.SwitchView (document.Window.FindView<IDiffView> ()); + } + + return true; + } + } +} + diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/IVersionControlViewHandler.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/IVersionControlViewHandler.cs new file mode 100644 index 0000000000..65ea04ede3 --- /dev/null +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/IVersionControlViewHandler.cs @@ -0,0 +1,61 @@ +// +// IVersionControlViewHandler.cs +// +// Author: +// Alan McGovern <alan@xamarin.com> +// +// Copyright 2011, Xamarin Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using MonoDevelop.Core; +using MonoDevelop.VersionControl.Views; +using MonoDevelop.Ide.Gui; + +namespace MonoDevelop.VersionControl { + + public interface IVersionControlViewHandler<T> + where T : IAttachableViewContent + { + bool CanHandle (VersionControlItem item); + T CreateView (VersionControlItem item, IViewContent primaryView); + } + + public interface IDiffViewHandler : IVersionControlViewHandler<IDiffView> + { + + } + + public interface IBlameViewHandler : IVersionControlViewHandler<IBlameView> + { + + } + + public interface ILogViewHandler : IVersionControlViewHandler<ILogView> + { + + } + + public interface IMergeViewHandler : IVersionControlViewHandler<IMergeView> + { + + } +} + diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/LogCommand.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/LogCommand.cs new file mode 100644 index 0000000000..0d002c8af3 --- /dev/null +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/LogCommand.cs @@ -0,0 +1,66 @@ +// +// LogCommand.cs +// +// Author: +// Alan McGovern <alan@xamarin.com> +// +// Copyright 2011, Xamarin Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Linq; +using Mono.Addins; +using MonoDevelop.Ide; +using MonoDevelop.Ide.Gui; +using MonoDevelop.VersionControl.Views; + +namespace MonoDevelop.VersionControl +{ + public class LogCommand + { + internal static readonly string LogViewHandlers = "/MonoDevelop/VersionControl/LogViewHandler"; + + static bool CanShow (VersionControlItem item) + { + return !item.IsDirectory && AddinManager.GetExtensionObjects<ILogViewHandler> (LogViewHandlers).Any (h => h.CanHandle (item)); + } + + public static bool Show (VersionControlItemList items, bool test) + { + if (test) + return items.All (CanShow); + + foreach (var item in items) { + var document = IdeApp.Workbench.OpenDocument (item.Path, OpenDocumentOptions.Default | OpenDocumentOptions.OnlyInternalViewer); + if (document != null) { + document.Window.SwitchView (document.Window.FindView<ILogView> ()); + } else { + VersionControlDocumentInfo info = new VersionControlDocumentInfo (null, item, item.Repository); + LogView logView = new LogView (info); + info.Document = IdeApp.Workbench.OpenDocument (logView, true).PrimaryView; + logView.Selected (); + } + } + + return true; + } + } +} + diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/MergeCommand.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/MergeCommand.cs new file mode 100644 index 0000000000..06eff36b6b --- /dev/null +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/MergeCommand.cs @@ -0,0 +1,60 @@ +// +// MergeCommand.cs +// +// Author: +// Alan McGovern <alan@xamarin.com> +// +// Copyright 2011, Xamarin Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Linq; +using Mono.Addins; +using MonoDevelop.Ide; +using MonoDevelop.Ide.Gui; +using MonoDevelop.VersionControl.Views; + +namespace MonoDevelop.VersionControl +{ + public class MergeCommand + { + internal static readonly string MergeViewHandlers = "/MonoDevelop/VersionControl/MergeViewHandler"; + + static bool CanShow (VersionControlItem item) + { + return !item.IsDirectory && AddinManager.GetExtensionObjects<IMergeViewHandler> (MergeViewHandlers).Any (h => h.CanHandle (item)); + } + + public static bool Show (VersionControlItemList items, bool test) + { + if (test) + return items.All (CanShow); + + foreach (var item in items) { + var document = IdeApp.Workbench.OpenDocument (item.Path, OpenDocumentOptions.Default | OpenDocumentOptions.OnlyInternalViewer); + if (document != null) + document.Window.SwitchView (document.Window.FindView<IMergeView> ()); + } + + return true; + } + } +} + diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/VersionControlNodeExtension.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/VersionControlNodeExtension.cs index eafa8f2846..1250bad1b6 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/VersionControlNodeExtension.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl/VersionControlNodeExtension.cs @@ -422,18 +422,10 @@ namespace MonoDevelop.VersionControl res = UpdateCommand.Update (items, test); break;
case Commands.Diff:
- if (!test) {
- DiffView.Show (items);
- } else {
- res = DiffView.CanShow (items);
- }
+ res = DiffCommand.Show (items, test);
break;
case Commands.Log:
- if (!test) {
- MonoDevelop.VersionControl.Views.LogView.Show (items, null);
- } else {
- res = MonoDevelop.VersionControl.Views.LogView.CanShow (items, null);
- }
+ res = LogCommand.Show (items, test);
break;
case Commands.Status:
res = StatusView.Show (items, test);
@@ -462,7 +454,7 @@ namespace MonoDevelop.VersionControl res = PublishCommand.Publish (it.WorkspaceObject, it.Path, test);
break;
case Commands.Annotate:
- res = BlameView.Show (items, test);
+ res = BlameCommand.Show (items, test);
break;
case Commands.CreatePatch:
res = CreatePatchCommand.CreatePatch (items, test);
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/VersionControl.addin.xml b/main/src/addins/VersionControl/MonoDevelop.VersionControl/VersionControl.addin.xml index fa764eec65..c467105df5 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/VersionControl.addin.xml +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/VersionControl.addin.xml @@ -54,6 +54,42 @@ <ExtensionNodeSet id="MonoDevelop.Components.Commands.ItemSet" /> </ExtensionPoint> + <ExtensionPoint path = "/MonoDevelop/VersionControl/DiffViewHandler" name = "Diff view handler"> + <Description>Handler used to create the a diff view which can display the current file.</Description> + <ExtensionNode name="Handler" objectType="MonoDevelop.VersionControl.IDiffViewHandler" /> + </ExtensionPoint> + + <Extension path = "/MonoDevelop/VersionControl/DiffViewHandler"> + <Handler class = "MonoDevelop.VersionControl.DefaultDiffViewHandler" /> + </Extension> + + <ExtensionPoint path = "/MonoDevelop/VersionControl/BlameViewHandler" name = "Blame view handler"> + <Description>Handler used to create the a blame view which can display the current file.</Description> + <ExtensionNode name="Handler" objectType="MonoDevelop.VersionControl.IBlameViewHandler" /> + </ExtensionPoint> + + <Extension path = "/MonoDevelop/VersionControl/BlameViewHandler"> + <Handler class = "MonoDevelop.VersionControl.DefaultBlameViewHandler" /> + </Extension> + + <ExtensionPoint path = "/MonoDevelop/VersionControl/LogViewHandler" name = "Log view handler"> + <Description>Handler used to create the a log view which can display the current file.</Description> + <ExtensionNode name="Handler" objectType="MonoDevelop.VersionControl.ILogViewHandler" /> + </ExtensionPoint> + + <Extension path = "/MonoDevelop/VersionControl/LogViewHandler"> + <Handler class = "MonoDevelop.VersionControl.DefaultLogViewHandler" /> + </Extension> + + <ExtensionPoint path = "/MonoDevelop/VersionControl/MergeViewHandler" name = "Merge view handler"> + <Description>Handler used to create the a merge view which can display the current file.</Description> + <ExtensionNode name="Handler" objectType="MonoDevelop.VersionControl.IMergeViewHandler" /> + </ExtensionPoint> + + <Extension path = "/MonoDevelop/VersionControl/MergeViewHandler"> + <Handler class = "MonoDevelop.VersionControl.DefaultMergeViewHandler" /> + </Extension> + <ExtensionPoint path = "/MonoDevelop/VersionControl/DiffView/ContextMenu" name = "Diff view context menu"> <Description>Context menu for the diff view.</Description> <ExtensionNodeSet id="MonoDevelop.Components.Commands.ItemSet" /> |