Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Merged
2 changes: 2 additions & 0 deletions src/GitHub.App/GitHub.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@
<Compile Include="ViewModels\BaseViewModel.cs" />
<Compile Include="Models\ConnectionRepositoryHostMap.cs" />
<Compile Include="ViewModels\GistCreationViewModel.cs" />
<Compile Include="ViewModels\NotAGitRepositoryViewModel.cs" />
<Compile Include="ViewModels\NotAGitHubRepositoryViewModel.cs" />
<Compile Include="ViewModels\LoggedOutViewModel.cs" />
<Compile Include="ViewModels\LogoutRequiredViewModel.cs" />
<Compile Include="ViewModels\PullRequestCreationViewModel.cs" />
Expand Down
44 changes: 44 additions & 0 deletions src/GitHub.App/ViewModels/NotAGitHubRepositoryViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.ComponentModel.Composition;
using GitHub.Exports;
using GitHub.Models;
using GitHub.Services;
using GitHub.UI;
using ReactiveUI;

namespace GitHub.ViewModels
{
/// <summary>
/// The view model for the "Not a GitHub repository" view in the GitHub pane.
/// </summary>
[ExportViewModel(ViewType = UIViewType.NotAGitHubRepository)]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class NotAGitHubRepositoryViewModel : BaseViewModel, INotAGitHubRepositoryViewModel
{
ITeamExplorerServices teamExplorerServices;

/// <summary>
/// Initializes a new instance of the <see cref="NotAGitHubRepositoryViewModel"/> class.
/// </summary>
[ImportingConstructor]
public NotAGitHubRepositoryViewModel(ITeamExplorerServices teamExplorerServices)
{
this.teamExplorerServices = teamExplorerServices;
Publish = ReactiveCommand.Create();
Publish.Subscribe(_ => OnPublish());
}

/// <summary>
/// Gets the command executed when the user clicks the "Publish to GitHub" link.
/// </summary>
public IReactiveCommand<object> Publish { get; }

/// <summary>
/// Called when the <see cref="Publish"/> command is executed.
/// </summary>
private void OnPublish()
{
teamExplorerServices.ShowPublishSection();
}
}
}
19 changes: 19 additions & 0 deletions src/GitHub.App/ViewModels/NotAGitRepositoryViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.ComponentModel.Composition;
using GitHub.Exports;
using GitHub.Models;
using GitHub.Services;
using GitHub.UI;
using ReactiveUI;

namespace GitHub.ViewModels
{
/// <summary>
/// The view model for the "Not a Git repository" view in the GitHub pane.
/// </summary>
[ExportViewModel(ViewType = UIViewType.NotAGitRepository)]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class NotAGitRepositoryViewModel : BaseViewModel, INotAGitRepositoryViewModel
{
}
}
2 changes: 2 additions & 0 deletions src/GitHub.Exports.Reactive/GitHub.Exports.Reactive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
<Compile Include="Services\IGistPublishService.cs" />
<Compile Include="ViewModels\IGistCreationViewModel.cs" />
<Compile Include="Services\NotificationDispatcher.cs" />
<Compile Include="ViewModels\INotAGitRepositoryViewModel.cs" />
<Compile Include="ViewModels\INotAGitHubRepositoryViewModel.cs" />
<Compile Include="ViewModels\ILoggedOutViewModel.cs" />
<Compile Include="ViewModels\ILogoutRequiredViewModel.cs" />
<Compile Include="ViewModels\ILoginControlViewModel.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using ReactiveUI;

namespace GitHub.ViewModels
{
/// <summary>
/// Defines the view model for the "Sign in to GitHub" view in the GitHub pane.
/// </summary>
public interface INotAGitHubRepositoryViewModel : IViewModel
{
/// <summary>
/// Gets the command executed when the user clicks the "Publish to GitHub" link.
/// </summary>
IReactiveCommand<object> Publish { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace GitHub.ViewModels
{
/// <summary>
/// Defines the view model for the "Not a git repository" view in the GitHub pane.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1040:AvoidEmptyInterfaces")]
public interface INotAGitRepositoryViewModel : IViewModel
{
}
}
4 changes: 3 additions & 1 deletion src/GitHub.Exports/Exports/ExportMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public enum UIViewType
PRCreation,
LogoutRequired,
GitHubPane,
LoggedOut
LoggedOut,
NotAGitRepository,
NotAGitHubRepository,
}

public enum MenuType
Expand Down
1 change: 1 addition & 0 deletions src/GitHub.Exports/Services/ITeamExplorerServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace GitHub.Services
{
public interface ITeamExplorerServices : INotificationService
{
void ShowPublishSection();
void ClearNotifications();
}
}
11 changes: 10 additions & 1 deletion src/GitHub.TeamFoundation.14/Services/TeamExplorerServices.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.ComponentModel.Composition;
using System.Windows.Input;
using GitHub.Extensions;
using GitHub.VisualStudio.TeamExplorer.Sync;
using Microsoft.TeamFoundation.Controls;
using Microsoft.VisualStudio.Shell;
using GitHub.Extensions;

namespace GitHub.Services
{
Expand All @@ -27,6 +28,14 @@ public TeamExplorerServices([Import(typeof(SVsServiceProvider))] IServiceProvide
this.serviceProvider = serviceProvider;
}

public void ShowPublishSection()
{
var te = serviceProvider.TryGetService<ITeamExplorer>();
var foo = te.NavigateToPage(new Guid(TeamExplorerPageIds.GitCommits), null);
var publish = foo?.GetSection(new Guid(GitHubPublishSection.GitHubPublishSectionId)) as GitHubPublishSection;
publish?.ShowPublish();
}

public void ShowMessage(string message)
{
manager = serviceProvider.TryGetService<ITeamExplorer>() as ITeamExplorerNotificationManager;
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.TeamFoundation.14/Sync/GitHubPublishSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void StartFlow(UIControllerFlow controllerFlow)
uiProvider.RunUI();
}

void ShowPublish()
public void ShowPublish()
{
IsBusy = true;
var uiProvider = ServiceProvider.GetExportedValue<IUIProvider>();
Expand Down
30 changes: 25 additions & 5 deletions src/GitHub.VisualStudio.UI/Base/TeamExplorerItemBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using GitHub.VisualStudio.Helpers;
using NullGuard;
using GitHub.ViewModels;
using GitHub.VisualStudio.UI;

namespace GitHub.VisualStudio.Base
{
Expand Down Expand Up @@ -98,22 +99,41 @@ protected virtual void RepoChanged(bool changed)
}
}

protected async Task<bool> IsAGitHubRepo()
protected async Task<RepositoryOrigin> GetRepositoryOrigin()
{
if (ActiveRepo == null)
return RepositoryOrigin.NonGitRepository;

var uri = ActiveRepoUri;
if (uri == null)
return false;
return RepositoryOrigin.Other;

Debug.Assert(apiFactory != null, "apiFactory cannot be null. Did you call the right constructor?");
SimpleApiClient = apiFactory.Create(uri);

var isdotcom = HostAddress.IsGitHubDotComUri(uri.ToRepositoryUrl());
if (!isdotcom)

if (isdotcom)
{
return RepositoryOrigin.DotCom;
}
else
{
var repo = await SimpleApiClient.GetRepository();
return (repo.FullName == ActiveRepoName || repo.Id == 0) && SimpleApiClient.IsEnterprise();

if ((repo.FullName == ActiveRepoName || repo.Id == 0) && SimpleApiClient.IsEnterprise())
{
return RepositoryOrigin.Enterprise;
}
}
return isdotcom;

return RepositoryOrigin.Other;
}

protected async Task<bool> IsAGitHubRepo()
{
var origin = await GetRepositoryOrigin();
return origin == RepositoryOrigin.DotCom || origin == RepositoryOrigin.Enterprise;
}

bool disposed;
Expand Down
1 change: 1 addition & 0 deletions src/GitHub.VisualStudio.UI/GitHub.VisualStudio.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Compile Include="Base\TeamExplorerItemBase.cs" />
<Compile Include="Colors.cs" />
<Compile Include="Constants.cs" />
<Compile Include="RepositoryOrigin.cs" />
<Compile Include="Resources.Designer.cs">
<DependentUpon>Resources.resx</DependentUpon>
<AutoGen>True</AutoGen>
Expand Down
11 changes: 11 additions & 0 deletions src/GitHub.VisualStudio.UI/RepositoryOrigin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace GitHub.VisualStudio.UI
{
public enum RepositoryOrigin
{
Unknown,
DotCom,
Enterprise,
Other,
NonGitRepository,
}
Copy link
Contributor

@shana shana Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the Other value up to the first position, or add a None value. enums always have a default value, and distinguishing between DotCom and haven't probed yet / this is a default is hard if they're the same value.

EDIT: maybe Unknown...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well strictly speaking, the Unknown state is RepositoryOrigin == null as the RepositoryOrigin property is currently nullable, because it came from the nullable IsGitHubRepo property. However I agree that it would be better the have that Unknown value as an enum value rather than the null state: will change.

}
36 changes: 36 additions & 0 deletions src/GitHub.VisualStudio.UI/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/GitHub.VisualStudio.UI/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,16 @@
<data name="openInBrowser" xml:space="preserve">
<value>Open in Browser</value>
</data>
<data name="NotAGitHubRepositoryMessage" xml:space="preserve">
<value>Publish this repository to GitHub and get powerful collaboration, code review, and code management for open source and private projects.</value>
</data>
<data name="NotAGitHubRepository" xml:space="preserve">
<value>This repository is not on GitHub</value>
</data>
<data name="NotAGitRepository" xml:space="preserve">
<value>No repository</value>
</data>
<data name="NotAGitRepositoryMessage" xml:space="preserve">
<value>We couldn't find a git repository here. Open a git project or click "File -&gt; Add to Source Control" in a project to get started.</value>
</data>
</root>
14 changes: 14 additions & 0 deletions src/GitHub.VisualStudio/GitHub.VisualStudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@
<DependentUpon>GitHubPaneView.xaml</DependentUpon>
</Compile>
<Compile Include="UI\Views\GitHubPaneViewModel.cs" />
<Compile Include="UI\Views\NotAGitRepositoryView.xaml.cs">
<DependentUpon>NotAGitRepositoryView.xaml</DependentUpon>
</Compile>
<Compile Include="UI\Views\NotAGitHubRepositoryView.xaml.cs">
<DependentUpon>NotAGitHubRepositoryView.xaml</DependentUpon>
</Compile>
<Compile Include="UI\Views\LoggedOutView.xaml.cs">
<DependentUpon>LoggedOutView.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -469,6 +475,14 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UI\Views\NotAGitRepositoryView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="UI\Views\NotAGitHubRepositoryView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="UI\Views\LoggedOutView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
Loading