Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLluis Sanchez <llsan@microsoft.com>2018-08-31 13:03:38 +0300
committerLluis Sanchez <llsan@microsoft.com>2018-08-31 13:03:38 +0300
commit2ec62045843434db157523ae843d77c0f9064b3f (patch)
tree09320d7cdf228e81a19cebc0150f8637d8d1737a
parente965cf80cc7df8cf3300ccd988b35994ce924d4b (diff)
Implemented document extension for version controldocument-extensions
Added new OnSaved method. Adjusted visibility of extension methods.
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/VersionControlDocumentExtension.cs (renamed from main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/SubviewAttachmentHandler.cs)75
-rw-r--r--main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.csproj2
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document.cs12
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DocumentExtension.cs32
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document_Extensions.cs19
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/ExportDocumentExtensionAttribute.cs11
6 files changed, 91 insertions, 60 deletions
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/SubviewAttachmentHandler.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/VersionControlDocumentExtension.cs
index 649b930411..164ae30247 100644
--- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/SubviewAttachmentHandler.cs
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.Views/VersionControlDocumentExtension.cs
@@ -1,21 +1,21 @@
-//
-// SubviewAttachmentHandler.cs
-//
+//
+// VersionControlDocumentExtension.cs
+//
// Author:
-// Mike Krüger <mkrueger@novell.com>
-//
-// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
-//
+// Lluis Sanchez <llsan@microsoft.com>
+//
+// Copyright (c) 2018 Microsoft
+//
// 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
@@ -25,34 +25,40 @@
// THE SOFTWARE.
using System;
using System.Linq;
-using MonoDevelop.Components.Commands;
-using Mono.Addins;
-using MonoDevelop.VersionControl;
+using System.Threading.Tasks;
using MonoDevelop.Ide.Gui;
-using MonoDevelop.Core;
using MonoDevelop.Projects;
+using MonoDevelop.Core;
+using Mono.Addins;
namespace MonoDevelop.VersionControl.Views
{
- class SubviewAttachmentHandler : CommandHandler
+ [ExportDocumentExtension (FileExtensions = "*")]
+ class VersionControlDocumentExtension : DocumentExtension
{
- protected override void Run ()
+ protected override Task OnLoaded (FileOpenInformation fileOpenInformation)
{
- Ide.IdeApp.Workbench.ActiveDocumentChanged += HandleDocumentChanged;
+ UpdateViews ();
+ return base.OnLoaded (fileOpenInformation);
}
- static void HandleDocumentChanged (object sender, EventArgs e)
+ protected override void OnSaved (FileSaveInformation fileSaveInformation)
{
- var document = Ide.IdeApp.Workbench.ActiveDocument;
- try {
- if (document == null || !document.IsFile || document.Window.FindView<ILogView> () >= 0)
- return;
+ UpdateViews ();
+ base.OnSaved (fileSaveInformation);
+ }
- WorkspaceObject project = document.Project;
+ void UpdateViews ()
+ {
+ if (!Document.IsFile || Window.FindView<ILogView> () >= 0)
+ return;
+
+ try {
+ WorkspaceObject project = Document.Project;
if (project == null) {
// Fix for broken .csproj and .sln files not being seen as having a project.
foreach (var projItem in Ide.IdeApp.Workspace.GetAllItems<UnknownSolutionItem> ()) {
- if (projItem.FileName == document.FileName) {
+ if (projItem.FileName == Document.FileName) {
project = projItem;
}
}
@@ -60,21 +66,21 @@ namespace MonoDevelop.VersionControl.Views
if (project == null)
return;
}
-
+
var repo = VersionControlService.GetRepository (project);
if (repo == null)
return;
- var versionInfo = repo.GetVersionInfo (document.FileName, VersionInfoQueryFlags.IgnoreCache);
+ var versionInfo = repo.GetVersionInfo (Document.FileName, VersionInfoQueryFlags.IgnoreCache);
if (!versionInfo.IsVersioned)
return;
- var item = new VersionControlItem (repo, project, document.FileName, false, null);
- var vcInfo = new VersionControlDocumentInfo (document.PrimaryView, item, item.Repository);
- TryAttachView (document, vcInfo, DiffCommand.DiffViewHandlers);
- TryAttachView (document, vcInfo, BlameCommand.BlameViewHandlers);
- TryAttachView (document, vcInfo, LogCommand.LogViewHandlers);
- TryAttachView (document, vcInfo, MergeCommand.MergeViewHandlers);
+ var item = new VersionControlItem (repo, project, Document.FileName, false, null);
+ var vcInfo = new VersionControlDocumentInfo (Document.PrimaryView, item, item.Repository);
+ TryAttachView (vcInfo, DiffCommand.DiffViewHandlers);
+ TryAttachView (vcInfo, BlameCommand.BlameViewHandlers);
+ TryAttachView (vcInfo, LogCommand.LogViewHandlers);
+ TryAttachView (vcInfo, MergeCommand.MergeViewHandlers);
} catch (Exception ex) {
// If a user is hitting this, it will show a dialog box every time they
// switch to a document or open a document, so suppress the crash dialog
@@ -82,14 +88,13 @@ namespace MonoDevelop.VersionControl.Views
LoggingService.LogInternalError (ex);
}
}
-
- static void TryAttachView (Document document, VersionControlDocumentInfo info, string type)
+
+ void TryAttachView (VersionControlDocumentInfo info, string type)
{
var handler = AddinManager.GetExtensionObjects<IVersionControlViewHandler> (type)
.FirstOrDefault (h => h.CanHandle (info.Item, info.Document));
if (handler != null)
- document.Window.AttachViewContent (handler.CreateView (info));
+ Window.AttachViewContent (handler.CreateView (info));
}
}
}
-
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.csproj b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.csproj
index c6a7a8e22c..1e7fc7cf0d 100644
--- a/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.csproj
+++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl/MonoDevelop.VersionControl.csproj
@@ -488,7 +488,6 @@
<Compile Include="MonoDevelop.VersionControl.Views\EditorCompareWidgetBase.cs" />
<Compile Include="MonoDevelop.VersionControl.Views\DiffView.cs" />
<Compile Include="MonoDevelop.VersionControl.Views\DiffWidget.cs" />
- <Compile Include="MonoDevelop.VersionControl.Views\SubviewAttachmentHandler.cs" />
<Compile Include="MonoDevelop.VersionControl.Views\LogWidget.cs" />
<Compile Include="MonoDevelop.VersionControl\IRepositoryEditor.cs" />
<Compile Include="MonoDevelop.VersionControl\VersionControlOperation.cs" />
@@ -522,6 +521,7 @@
<Compile Include="Gui\MonoDevelop.VersionControl.UrlBasedRepositoryEditor.cs" />
<Compile Include="Gui\MonoDevelop.VersionControl.Views.DiffWidget.cs" />
<Compile Include="Gui\MonoDevelop.VersionControl.Views.LogWidget.cs" />
+ <Compile Include="MonoDevelop.VersionControl.Views\VersionControlDocumentExtension.cs" />
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="MonoDevelop.VersionControl.Git.Tests" />
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document.cs
index 7c1a1b8cce..43505e2908 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document.cs
@@ -171,7 +171,7 @@ namespace MonoDevelop.Ide.Gui
internal ProjectReloadCapability ProjectReloadCapability {
get {
- return documentExtension.GetProjectReloadCapability ();
+ return documentExtension.OnGetProjectReloadCapability ();
}
}
@@ -431,7 +431,7 @@ namespace MonoDevelop.Ide.Gui
internal void DiscardChanges ()
{
- documentExtension.DiscardChanges ();
+ documentExtension.OnDiscardChanges ();
}
internal Task NotifyLoaded (FileOpenInformation fileOpenInformation)
@@ -588,11 +588,9 @@ namespace MonoDevelop.Ide.Gui
internal async Task SaveViewContent (Encoding encoding = null)
{
try {
- if (Window.ViewContent.IsFile)
- await documentExtension.OnSave (new FileSaveInformation (Window.ViewContent.ContentName, encoding));
- else
- await documentExtension.OnSave (null);
- OnSaved (EventArgs.Empty);
+ var fileInfo = Window.ViewContent.IsFile ? new FileSaveInformation (Window.ViewContent.ContentName, encoding) : null;
+ await documentExtension.OnSave (fileInfo);
+ documentExtension.OnSaved (fileInfo);
} catch (Exception ex) {
LoggingService.LogError ("File could not be saved", ex);
}
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DocumentExtension.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DocumentExtension.cs
index 540d584806..aac21445d7 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DocumentExtension.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/DocumentExtension.cs
@@ -37,6 +37,9 @@ using MonoDevelop.Projects;
namespace MonoDevelop.Ide.Gui
{
+ /// <summary>
+ /// An extension that is attached to a document
+ /// </summary>
public class DocumentExtension: ChainedExtension, ICommandRouter
{
DocumentExtension next;
@@ -65,7 +68,7 @@ namespace MonoDevelop.Ide.Gui
/// <summary>
/// Window that shows the view of the document
/// </summary>
- public IWorkbenchWindow WorkbenchWindow => document.Window;
+ public IWorkbenchWindow Window => document.Window;
/// <summary>
/// Project to which the document belongs
@@ -100,23 +103,32 @@ namespace MonoDevelop.Ide.Gui
/// Invoked when the document is being saved. <paramref name="fileSaveInformation"/> can be <see langword="null"/> if the document is not a file.
/// </summary>
/// <param name="fileSaveInformation">File information.</param>
- public virtual Task OnSave (FileSaveInformation fileSaveInformation)
+ internal protected virtual Task OnSave (FileSaveInformation fileSaveInformation)
{
return next.OnSave (fileSaveInformation);
}
/// <summary>
+ /// Invoked after the document has been saved. <paramref name="fileSaveInformation"/> can be <see langword="null"/> if the document is not a file.
+ /// </summary>
+ /// <param name="fileSaveInformation">File information.</param>
+ internal protected virtual void OnSaved (FileSaveInformation fileSaveInformation)
+ {
+ next.OnSaved (fileSaveInformation);
+ }
+
+ /// <summary>
/// Invoked when changes in the document have to be discarded
/// </summary>
- public virtual void DiscardChanges ()
+ internal protected virtual void OnDiscardChanges ()
{
- next.DiscardChanges ();
+ next.OnDiscardChanges ();
}
/// <summary>
/// Invoked after a document has been loaded.
/// </summary>
- public virtual Task OnLoaded (FileOpenInformation fileOpenInformation)
+ internal protected virtual Task OnLoaded (FileOpenInformation fileOpenInformation)
{
return next.OnLoaded (fileOpenInformation);
}
@@ -125,7 +137,7 @@ namespace MonoDevelop.Ide.Gui
/// Invoked after a new document is created from a file template.
/// </summary>
/// <param name="fileCreationInformation">File creation data</param>
- public virtual Task OnLoadedNew (FileCreationInformation fileCreationInformation)
+ internal protected virtual Task OnLoadedNew (FileCreationInformation fileCreationInformation)
{
return next.OnLoadedNew (fileCreationInformation);
}
@@ -158,7 +170,7 @@ namespace MonoDevelop.Ide.Gui
/// <summary>
/// Invoked when the project of the document changes
/// </summary>
- public virtual void OnOwnerChanged ()
+ internal protected virtual void OnOwnerChanged ()
{
next.OnOwnerChanged ();
}
@@ -166,7 +178,7 @@ namespace MonoDevelop.Ide.Gui
/// <summary>
/// Invoked when the document becomes the active document in the shell
/// </summary>
- public virtual void OnActivated ()
+ internal protected virtual void OnActivated ()
{
next.OnActivated ();
}
@@ -175,9 +187,9 @@ namespace MonoDevelop.Ide.Gui
/// Gets the project reload capability.
/// </summary>
/// <returns>The project reload capability.</returns>
- public virtual ProjectReloadCapability GetProjectReloadCapability ()
+ internal protected virtual ProjectReloadCapability OnGetProjectReloadCapability ()
{
- return next.GetProjectReloadCapability ();
+ return next.OnGetProjectReloadCapability ();
}
object ICommandRouter.GetNextCommandTarget ()
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document_Extensions.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document_Extensions.cs
index 72c52ebe35..5f3da3b12f 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document_Extensions.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/Document_Extensions.cs
@@ -187,38 +187,43 @@ namespace MonoDevelop.Ide.Gui
class DefaultDocumentExtension : DocumentExtension, ICommandRouter
{
- public override Task OnSave (FileSaveInformation fileSaveInformation)
+ internal protected override Task OnSave (FileSaveInformation fileSaveInformation)
{
return Document.DoSaveViewContent (fileSaveInformation);
}
- public override Task OnLoaded (FileOpenInformation fileOpenInformation)
+ internal protected override void OnSaved (FileSaveInformation fileSaveInformation)
+ {
+ Document.OnSaved (EventArgs.Empty);
+ }
+
+ internal protected override Task OnLoaded (FileOpenInformation fileOpenInformation)
{
// Do nothing, since the view content has already been loaded at this point
return Task.CompletedTask;
}
- public override Task OnLoadedNew (FileCreationInformation fileCreationInformation)
+ internal protected override Task OnLoadedNew (FileCreationInformation fileCreationInformation)
{
// Do nothing, since the view content has already been initialized at this point
return Task.CompletedTask;
}
- public override void DiscardChanges ()
+ internal protected override void OnDiscardChanges ()
{
Document.window.ViewContent.DiscardChanges ();
}
- public override void OnOwnerChanged ()
+ internal protected override void OnOwnerChanged ()
{
}
- public override void OnActivated ()
+ internal protected override void OnActivated ()
{
// Do nothing
}
- public override ProjectReloadCapability GetProjectReloadCapability ()
+ internal protected override ProjectReloadCapability OnGetProjectReloadCapability ()
{
return Document.Window.ViewContent.ProjectReloadCapability;
}
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/ExportDocumentExtensionAttribute.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/ExportDocumentExtensionAttribute.cs
index 8160ddaff5..775d2b9425 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/ExportDocumentExtensionAttribute.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui/ExportDocumentExtensionAttribute.cs
@@ -32,12 +32,23 @@ namespace MonoDevelop.Ide.Gui
{
public class ExportDocumentExtensionAttribute: CustomExtensionAttribute
{
+ /// <summary>
+ /// File extensions to which apply this extension. Comma separated list. Specify '*' to match all files.
+ /// </summary>
[NodeAttribute ("fileExtensions")]
public string FileExtensions { get; set; }
+ /// <summary>
+ /// Mime types to which apply this extension. Comma separated list. Specify '*' to match all files.
+ /// </summary>
+ /// <value>The MIME types.</value>
[NodeAttribute ("mimeTypes")]
public string MimeTypes { get; set; }
+ /// <summary>
+ /// File name(s) to which apply this extension. Comma separated list. Specify '*' to match all files
+ /// </summary>
+ /// <value>The name.</value>
[NodeAttribute ("name")]
public string Name { get; set; }
}