Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions GitHubVS.sln
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.InlineReviews.UnitTe
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.Logging", "src\GitHub.Logging\GitHub.Logging.csproj", "{8D73575A-A89F-47CC-B153-B47DD06837F0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.Services.Vssdk", "src\GitHub.Services.Vssdk\GitHub.Services.Vssdk.csproj", "{2D3D2834-33BE-45CA-B3CC-12F853557D7B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -403,6 +405,16 @@ Global
{8D73575A-A89F-47CC-B153-B47DD06837F0}.Release|Any CPU.Build.0 = Release|Any CPU
{8D73575A-A89F-47CC-B153-B47DD06837F0}.ReleaseWithoutVsix|Any CPU.ActiveCfg = Release|Any CPU
{8D73575A-A89F-47CC-B153-B47DD06837F0}.ReleaseWithoutVsix|Any CPU.Build.0 = Release|Any CPU
{2D3D2834-33BE-45CA-B3CC-12F853557D7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D3D2834-33BE-45CA-B3CC-12F853557D7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D3D2834-33BE-45CA-B3CC-12F853557D7B}.DebugCodeAnalysis|Any CPU.ActiveCfg = DebugCodeAnalysis|Any CPU
{2D3D2834-33BE-45CA-B3CC-12F853557D7B}.DebugCodeAnalysis|Any CPU.Build.0 = DebugCodeAnalysis|Any CPU
{2D3D2834-33BE-45CA-B3CC-12F853557D7B}.DebugWithoutVsix|Any CPU.ActiveCfg = DebugCodeAnalysis|Any CPU
{2D3D2834-33BE-45CA-B3CC-12F853557D7B}.DebugWithoutVsix|Any CPU.Build.0 = DebugCodeAnalysis|Any CPU
{2D3D2834-33BE-45CA-B3CC-12F853557D7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D3D2834-33BE-45CA-B3CC-12F853557D7B}.Release|Any CPU.Build.0 = Release|Any CPU
{2D3D2834-33BE-45CA-B3CC-12F853557D7B}.ReleaseWithoutVsix|Any CPU.ActiveCfg = Release|Any CPU
{2D3D2834-33BE-45CA-B3CC-12F853557D7B}.ReleaseWithoutVsix|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
4 changes: 4 additions & 0 deletions src/GitHub.App/GitHub.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@
<Project>{8d73575a-a89f-47cc-b153-b47dd06837f0}</Project>
<Name>GitHub.Logging</Name>
</ProjectReference>
<ProjectReference Include="..\GitHub.Services.Vssdk\GitHub.Services.Vssdk.csproj">
<Project>{2D3D2834-33BE-45CA-B3CC-12F853557D7B}</Project>
<Name>GitHub.Services.Vssdk</Name>
</ProjectReference>
<ProjectReference Include="..\GitHub.UI.Reactive\GitHub.UI.Reactive.csproj">
<Project>{158b05e8-fdbc-4d71-b871-c96e28d5adf5}</Project>
<Name>GitHub.UI.Reactive</Name>
Expand Down
60 changes: 23 additions & 37 deletions src/GitHub.App/ViewModels/GitHubPane/GitHubPaneViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel.Composition;
using System.ComponentModel.Design;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
Expand All @@ -15,6 +16,7 @@
using GitHub.Models;
using GitHub.Primitives;
using GitHub.Services;
using GitHub.Services.Vssdk.Commands;
using GitHub.VisualStudio;
using ReactiveUI;
using Serilog;
Expand All @@ -36,8 +38,6 @@ public sealed class GitHubPaneViewModel : ViewModelBase, IGitHubPaneViewModel, I
readonly ISimpleApiClientFactory apiClientFactory;
readonly IConnectionManager connectionManager;
readonly ITeamExplorerContext teamExplorerContext;
readonly IVisualStudioBrowser browser;
readonly IUsageTracker usageTracker;
readonly INavigationViewModel navigator;
readonly ILoggedOutViewModel loggedOut;
readonly INotAGitHubRepositoryViewModel notAGitHubRepository;
Expand All @@ -49,6 +49,7 @@ public sealed class GitHubPaneViewModel : ViewModelBase, IGitHubPaneViewModel, I
readonly ReactiveCommand<Unit> refresh;
readonly ReactiveCommand<Unit> showPullRequests;
readonly ReactiveCommand<object> openInBrowser;
readonly ReactiveCommand<object> help;
Task initializeTask;
IViewModel content;
ILocalRepositoryModel localRepository;
Expand Down Expand Up @@ -82,8 +83,6 @@ public GitHubPaneViewModel(
this.apiClientFactory = apiClientFactory;
this.connectionManager = connectionManager;
this.teamExplorerContext = teamExplorerContext;
this.browser = browser;
this.usageTracker = usageTracker;
this.navigator = navigator;
this.loggedOut = loggedOut;
this.notAGitHubRepository = notAGitHubRepository;
Expand Down Expand Up @@ -147,6 +146,13 @@ public GitHubPaneViewModel(
if (url != null) browser.OpenUrl(url);
});

help = ReactiveCommand.Create();
help.Subscribe(_ =>
{
browser.OpenUrl(new Uri(GitHubUrls.Documentation));
usageTracker.IncrementCounter(x => x.NumberOfGitHubPaneHelpClicks).Forget();
});

navigator.WhenAnyObservable(x => x.Content.NavigationRequested)
.Subscribe(x => NavigateTo(x).Forget());

Expand Down Expand Up @@ -280,47 +286,27 @@ async Task CreateInitializeTask(IServiceProvider paneServiceProvider)
{
await UpdateContent(teamExplorerContext.ActiveRepository);
teamExplorerContext.WhenAnyValue(x => x.ActiveRepository)
.Skip(1)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(x => UpdateContent(x).Forget());
.Skip(1)
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(x => UpdateContent(x).Forget());

connectionManager.Connections.CollectionChanged += (_, __) => UpdateContent(LocalRepository).Forget();

BindNavigatorCommand(paneServiceProvider, PkgCmdIDList.pullRequestCommand, showPullRequests);
BindNavigatorCommand(paneServiceProvider, PkgCmdIDList.backCommand, navigator.NavigateBack);
BindNavigatorCommand(paneServiceProvider, PkgCmdIDList.forwardCommand, navigator.NavigateForward);
BindNavigatorCommand(paneServiceProvider, PkgCmdIDList.refreshCommand, refresh);
BindNavigatorCommand(paneServiceProvider, PkgCmdIDList.githubCommand, openInBrowser);

paneServiceProvider.AddCommandHandler(Guids.guidGitHubToolbarCmdSet, PkgCmdIDList.helpCommand,
(_, __) =>
{
browser.OpenUrl(new Uri(GitHubUrls.Documentation));
usageTracker.IncrementCounter(x => x.NumberOfGitHubPaneHelpClicks).Forget();
});
var menuService = (IMenuCommandService)paneServiceProvider.GetService(typeof(IMenuCommandService));
BindNavigatorCommand(menuService, PkgCmdIDList.pullRequestCommand, showPullRequests);
BindNavigatorCommand(menuService, PkgCmdIDList.backCommand, navigator.NavigateBack);
BindNavigatorCommand(menuService, PkgCmdIDList.forwardCommand, navigator.NavigateForward);
BindNavigatorCommand(menuService, PkgCmdIDList.refreshCommand, refresh);
BindNavigatorCommand(menuService, PkgCmdIDList.githubCommand, openInBrowser);
BindNavigatorCommand(menuService, PkgCmdIDList.helpCommand, help);
}

OleMenuCommand BindNavigatorCommand<T>(IServiceProvider paneServiceProvider, int commandId, ReactiveCommand<T> command)
OleMenuCommand BindNavigatorCommand<T>(IMenuCommandService menu, int commandId, ReactiveCommand<T> command)
{
Guard.ArgumentNotNull(paneServiceProvider, nameof(paneServiceProvider));
Guard.ArgumentNotNull(menu, nameof(menu));
Guard.ArgumentNotNull(command, nameof(command));

Func<bool> canExecute = () => Content == navigator && command.CanExecute(null);

var result = paneServiceProvider.AddCommandHandler(
Guids.guidGitHubToolbarCmdSet,
commandId,
canExecute,
() => command.Execute(null),
true);

Observable.CombineLatest(
this.WhenAnyValue(x => x.Content),
command.CanExecuteObservable,
(c, e) => c == navigator && e)
.Subscribe(x => result.Enabled = x);

return result;
return menu.BindCommand(new CommandID(Guids.guidGitHubToolbarCmdSet, commandId), command);
}

async Task NavigateTo<TViewModel>(Func<TViewModel, Task> initialize, Func<TViewModel, bool> match = null)
Expand Down
11 changes: 11 additions & 0 deletions src/GitHub.Exports/Commands/IAddConnectionCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace GitHub.Commands
{
/// <summary>
/// Opens the login dialog to add a new connection to Team Explorer.
/// </summary>
public interface IAddConnectionCommand : IVsCommand
{
}
}
12 changes: 12 additions & 0 deletions src/GitHub.Exports/Commands/IBlameLinkCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace GitHub.Commands
{
/// <summary>
/// Opens the blame view for the currently selected text on GitHub.com or an Enterprise
/// instance.
/// </summary>
public interface IBlameLinkCommand : IVsCommand
{
}
}
12 changes: 12 additions & 0 deletions src/GitHub.Exports/Commands/ICopyLinkCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace GitHub.Commands
{
/// <summary>
/// Copies a link to the clipboard of the currently selected text on GitHub.com or an
/// Enterprise instance.
/// </summary>
public interface ICopyLinkCommand : IVsCommand
{
}
}
11 changes: 11 additions & 0 deletions src/GitHub.Exports/Commands/ICreateGistCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace GitHub.Commands
{
/// <summary>
/// Creates a gist from the currently selected text.
/// </summary>
public interface ICreateGistCommand : IVsCommand
{
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using GitHub.Commands;

namespace GitHub.InlineReviews.Commands
namespace GitHub.Commands
{
/// <summary>
/// Navigates to and opens the the next inline comment thread in the currently active text view.
Expand Down
11 changes: 11 additions & 0 deletions src/GitHub.Exports/Commands/IOpenLinkCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace GitHub.Commands
{
/// <summary>
/// Opens the currently selected text on GitHub.com or an Enterprise instance.
/// </summary>
public interface IOpenLinkCommand : IVsCommand
{
}
}
11 changes: 11 additions & 0 deletions src/GitHub.Exports/Commands/IOpenPullRequestsCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace GitHub.Commands
{
/// <summary>
/// Opens the GitHub pane and shows the pull request list.
/// </summary>
public interface IOpenPullRequestsCommand : IVsCommand
{
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using GitHub.Commands;

namespace GitHub.InlineReviews.Commands
namespace GitHub.Commands
{
/// <summary>
/// Navigates to and opens the the previous inline comment thread in the currently active text view.
Expand Down
14 changes: 14 additions & 0 deletions src/GitHub.Exports/Commands/IShowCurrentPullRequestCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace GitHub.Commands
{
/// <summary>
/// Opens the GitHub pane and shows the currently checked out pull request.
/// </summary>
/// <remarks>
/// Does nothing if there is no checked out pull request.
/// </remarks>
public interface IShowCurrentPullRequestCommand : IVsCommand
{
}
}
11 changes: 11 additions & 0 deletions src/GitHub.Exports/Commands/IShowGitHubPaneCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace GitHub.Commands
{
/// <summary>
/// Opens the GitHub pane.
/// </summary>
public interface IShowGitHubPaneCommand : IVsCommand
{
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;

namespace GitHub.InlineReviews.Commands
namespace GitHub.Commands
{
/// <summary>
/// Represents a Visual Studio command that does not accept a parameter.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
using System;
using System.Windows.Input;

namespace GitHub.InlineReviews.Commands
namespace GitHub.Commands
{
/// <summary>
/// Represents a Visual Studio command.
/// Represents a Visual Studio command exposed as an <see cref="ICommand"/>.
/// </summary>
public interface IVsCommandBase : IPackageResource, ICommand
public interface IVsCommandBase : ICommand
{
/// <summary>
/// Gets a value indicating whether the command is enabled.
/// </summary>
bool IsEnabled { get; }
bool Enabled { get; }

/// <summary>
/// Gets a value indicating whether the command is visible.
/// </summary>
bool IsVisible { get; }
bool Visible { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace GitHub.InlineReviews.Commands
namespace GitHub.Commands
{
/// <summary>
/// Supplies parameters to <see cref="INextInlineCommentCommand"/> and
Expand Down
49 changes: 0 additions & 49 deletions src/GitHub.Exports/Exports/ExportMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using System.ComponentModel.Composition;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Windows;
using GitHub.VisualStudio;

namespace GitHub.Exports
{
Expand Down Expand Up @@ -45,21 +42,6 @@ public ExportViewForAttribute(Type viewModelType)
public string ViewModelType { get; }
}

/// <summary>
/// A MEF export attribute that defines an export of type <see cref="IMenuHandler"/> with
/// <see cref="MenuType"/> metadata.
/// </summary>
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class ExportMenuAttribute : ExportAttribute
{
public ExportMenuAttribute() : base(typeof(IMenuHandler))
{
}

public MenuType MenuType { get; set; }
}

/// <summary>
/// Defines a MEF metadata view that matches <see cref="ExportViewModelForAttribute"/> and
/// <see cref="ExportViewForAttribute"/>.
Expand All @@ -73,35 +55,4 @@ public interface IViewModelMetadata
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
string[] ViewModelType { get; }
}

/// <summary>
/// Defines a MEF metadata view that matches <see cref="ExportMenuAttribute"/>.
/// </summary>
/// <remarks>
/// For more information see the Metadata and Metadata views section at
/// https://msdn.microsoft.com/en-us/library/ee155691(v=vs.110).aspx#Anchor_3
/// </remarks>
public interface IMenuMetadata
{
MenuType MenuType { get; }
}

public static class ExportMetadataAttributeExtensions
{
public static bool IsMenuType(this IMenuHandler c, MenuType type)
{
return c.GetType().GetCustomAttributesData().Any(attr => IsMenuType(attr, type));
}

static bool IsMenuType(CustomAttributeData attributeData, MenuType type)
{
if (attributeData.NamedArguments == null)
{
throw new GitHubLogicException("attributeData.NamedArguments may not be null");
}

return attributeData.AttributeType == typeof(ExportMenuAttribute)
&& (MenuType)attributeData.NamedArguments[0].TypedValue.Value == type;
}
}
}
Loading