Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit b80e0ab

Browse files
committed
Use VsCommand in GitHub.VisualStudio.
And remove old menu framework-related code.
1 parent 0ccf448 commit b80e0ab

40 files changed

+682
-662
lines changed

src/GitHub.App/ViewModels/GitHubPane/GitHubPaneViewModel.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public sealed class GitHubPaneViewModel : ViewModelBase, IGitHubPaneViewModel, I
5050
readonly ReactiveCommand<Unit> refresh;
5151
readonly ReactiveCommand<Unit> showPullRequests;
5252
readonly ReactiveCommand<object> openInBrowser;
53+
readonly ReactiveCommand<object> help;
5354
readonly SemaphoreSlim initializing = new SemaphoreSlim(1);
5455
bool initialized;
5556
IViewModel content;
@@ -157,6 +158,13 @@ public GitHubPaneViewModel(
157158
if (url != null) browser.OpenUrl(url);
158159
});
159160

161+
help = ReactiveCommand.Create();
162+
help.Subscribe(_ =>
163+
{
164+
browser.OpenUrl(new Uri(GitHubUrls.Documentation));
165+
usageTracker.IncrementCounter(x => x.NumberOfGitHubPaneHelpClicks).Forget();
166+
});
167+
160168
navigator.WhenAnyObservable(x => x.Content.NavigationRequested)
161169
.Subscribe(x => NavigateTo(x).Forget());
162170

@@ -231,13 +239,7 @@ public async Task InitializeAsync(IServiceProvider paneServiceProvider)
231239
BindNavigatorCommand(menuService, PkgCmdIDList.forwardCommand, navigator.NavigateForward);
232240
BindNavigatorCommand(menuService, PkgCmdIDList.refreshCommand, refresh);
233241
BindNavigatorCommand(menuService, PkgCmdIDList.githubCommand, openInBrowser);
234-
235-
paneServiceProvider.AddCommandHandler(Guids.guidGitHubToolbarCmdSet, PkgCmdIDList.helpCommand,
236-
(_, __) =>
237-
{
238-
browser.OpenUrl(new Uri(GitHubUrls.Documentation));
239-
usageTracker.IncrementCounter(x => x.NumberOfGitHubPaneHelpClicks).Forget();
240-
});
242+
BindNavigatorCommand(menuService, PkgCmdIDList.helpCommand, help);
241243
}
242244
finally
243245
{
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace GitHub.Commands
4+
{
5+
/// <summary>
6+
/// Opens the login dialog to add a new connection to Team Explorer.
7+
/// </summary>
8+
public interface IAddConnectionCommand : IVsCommand
9+
{
10+
}
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace GitHub.Commands
4+
{
5+
/// <summary>
6+
/// Opens the blame view for the currently selected text on GitHub.com or an Enterprise
7+
/// instance.
8+
/// </summary>
9+
public interface IBlameLinkCommand : IVsCommand
10+
{
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace GitHub.Commands
4+
{
5+
/// <summary>
6+
/// Copies a link to the clipboard of the currently selected text on GitHub.com or an
7+
/// Enterprise instance.
8+
/// </summary>
9+
public interface ICopyLinkCommand : IVsCommand
10+
{
11+
}
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace GitHub.Commands
4+
{
5+
/// <summary>
6+
/// Creates a gist from the currently selected text.
7+
/// </summary>
8+
public interface ICreateGistCommand : IVsCommand
9+
{
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace GitHub.Commands
4+
{
5+
/// <summary>
6+
/// Opens the currently selected text on GitHub.com or an Enterprise instance.
7+
/// </summary>
8+
public interface IOpenLinkCommand : IVsCommand
9+
{
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace GitHub.Commands
4+
{
5+
/// <summary>
6+
/// Opens the GitHub pane and shows the pull request list.
7+
/// </summary>
8+
public interface IOpenPullRequestsCommand : IVsCommand
9+
{
10+
}
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace GitHub.Commands
4+
{
5+
/// <summary>
6+
/// Opens the GitHub pane and shows the currently checked out pull request.
7+
/// </summary>
8+
/// <remarks>
9+
/// Does nothing if there is no checked out pull request.
10+
/// </remarks>
11+
public interface IShowCurrentPullRequestCommand : IVsCommand
12+
{
13+
}
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace GitHub.Commands
4+
{
5+
/// <summary>
6+
/// Opens the GitHub pane.
7+
/// </summary>
8+
public interface IShowGitHubPaneCommand : IVsCommand
9+
{
10+
}
11+
}
Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
using System;
22
using System.ComponentModel.Composition;
33
using System.Diagnostics.CodeAnalysis;
4-
using System.Linq;
5-
using System.Reflection;
64
using System.Windows;
7-
using GitHub.VisualStudio;
85

96
namespace GitHub.Exports
107
{
@@ -45,21 +42,6 @@ public ExportViewForAttribute(Type viewModelType)
4542
public string ViewModelType { get; }
4643
}
4744

48-
/// <summary>
49-
/// A MEF export attribute that defines an export of type <see cref="IMenuHandler"/> with
50-
/// <see cref="MenuType"/> metadata.
51-
/// </summary>
52-
[MetadataAttribute]
53-
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
54-
public sealed class ExportMenuAttribute : ExportAttribute
55-
{
56-
public ExportMenuAttribute() : base(typeof(IMenuHandler))
57-
{
58-
}
59-
60-
public MenuType MenuType { get; set; }
61-
}
62-
6345
/// <summary>
6446
/// Defines a MEF metadata view that matches <see cref="ExportViewModelForAttribute"/> and
6547
/// <see cref="ExportViewForAttribute"/>.
@@ -73,35 +55,4 @@ public interface IViewModelMetadata
7355
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
7456
string[] ViewModelType { get; }
7557
}
76-
77-
/// <summary>
78-
/// Defines a MEF metadata view that matches <see cref="ExportMenuAttribute"/>.
79-
/// </summary>
80-
/// <remarks>
81-
/// For more information see the Metadata and Metadata views section at
82-
/// https://msdn.microsoft.com/en-us/library/ee155691(v=vs.110).aspx#Anchor_3
83-
/// </remarks>
84-
public interface IMenuMetadata
85-
{
86-
MenuType MenuType { get; }
87-
}
88-
89-
public static class ExportMetadataAttributeExtensions
90-
{
91-
public static bool IsMenuType(this IMenuHandler c, MenuType type)
92-
{
93-
return c.GetType().GetCustomAttributesData().Any(attr => IsMenuType(attr, type));
94-
}
95-
96-
static bool IsMenuType(CustomAttributeData attributeData, MenuType type)
97-
{
98-
if (attributeData.NamedArguments == null)
99-
{
100-
throw new GitHubLogicException("attributeData.NamedArguments may not be null");
101-
}
102-
103-
return attributeData.AttributeType == typeof(ExportMenuAttribute)
104-
&& (MenuType)attributeData.NamedArguments[0].TypedValue.Value == type;
105-
}
106-
}
10758
}

0 commit comments

Comments
 (0)