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

Commit 2f84d73

Browse files
committed
Merge branch 'master' into localization
2 parents acc46cf + d3641f4 commit 2f84d73

File tree

11 files changed

+154
-17
lines changed

11 files changed

+154
-17
lines changed

src/GitHub.App/Services/DialogService.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,19 @@ public async Task<string> ShowReCloneDialog(IRepositoryModel repository)
5151
return (string)await showDialog.ShowWithFirstConnection(viewModel);
5252
}
5353

54-
public async Task ShowCreateGist()
54+
public async Task ShowCreateGist(IConnection connection)
5555
{
5656
var viewModel = factory.CreateViewModel<IGistCreationViewModel>();
57-
await showDialog.ShowWithFirstConnection(viewModel);
57+
58+
if (connection != null)
59+
{
60+
await viewModel.InitializeAsync(connection);
61+
await showDialog.Show(viewModel);
62+
}
63+
else
64+
{
65+
await showDialog.ShowWithFirstConnection(viewModel);
66+
}
5867
}
5968

6069
public async Task ShowCreateRepositoryDialog(IConnection connection)
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 GitHub Enterprise gist from the currently selected text.
7+
/// </summary>
8+
public interface ICreateGistEnterpriseCommand : IVsCommand
9+
{
10+
}
11+
}

src/GitHub.Exports/GitHub.Exports.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
<ItemGroup>
150150
<Compile Include="Commands\ICopyLinkCommand.cs" />
151151
<Compile Include="Commands\IBlameLinkCommand.cs" />
152+
<Compile Include="Commands\ICreateGistEnterpriseCommand.cs" />
152153
<Compile Include="Commands\IOpenFromClipboardCommand.cs" />
153154
<Compile Include="Commands\IOpenFromUrlCommand.cs" />
154155
<Compile Include="Commands\IToggleInlineCommentMarginCommand.cs" />

src/GitHub.Exports/Services/IDialogService.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ public interface IDialogService
3939
/// <summary>
4040
/// Shows the Create Gist dialog.
4141
/// </summary>
42-
Task ShowCreateGist();
42+
/// <param name="connection">
43+
/// The connection to use. If null, the first connection will be used, or the user promted
44+
/// to log in if there are no connections.
45+
/// </param>
46+
Task ShowCreateGist(IConnection connection);
4347

4448
/// <summary>
4549
/// Shows the Create Repository dialog.

src/GitHub.Exports/Settings/PkgCmdID.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static class PkgCmdIDList
1919
public const int refreshCommand = 0x302;
2020
public const int pullRequestCommand = 0x310;
2121
public const int createGistCommand = 0x400;
22+
public const int createGistEnterpriseCommand = 0x401;
2223
public const int openLinkCommand = 0x100;
2324
public const int copyLinkCommand = 0x101;
2425
public const int goToSolutionOrPullRequestFileCommand = 0x102;
Lines changed: 93 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
11
using System;
2+
using System.Linq;
23
using System.ComponentModel.Composition;
34
using System.Threading.Tasks;
5+
using GitHub.Models;
46
using GitHub.Commands;
57
using GitHub.Logging;
68
using GitHub.Services;
9+
using GitHub.Extensions;
710
using GitHub.Services.Vssdk.Commands;
811

912
namespace GitHub.VisualStudio.Commands
1013
{
1114
/// <summary>
12-
/// Creates a gist from the currently selected text.
15+
/// Creates a GitHub Gist from the currently selected text.
1316
/// </summary>
1417
[Export(typeof(ICreateGistCommand))]
15-
public class CreateGistCommand : VsCommand, ICreateGistCommand
18+
public class CreateGistCommand : CreateGistCommandBase, ICreateGistCommand
1619
{
17-
readonly Lazy<IDialogService> dialogService;
18-
readonly Lazy<ISelectedTextProvider> selectedTextProvider;
19-
2020
[ImportingConstructor]
21-
protected CreateGistCommand(Lazy<IDialogService> dialogService, Lazy<ISelectedTextProvider> selectedTextProvider)
22-
: base(CommandSet, CommandId)
21+
protected CreateGistCommand(
22+
Lazy<IDialogService> dialogService,
23+
Lazy<ISelectedTextProvider> selectedTextProvider,
24+
Lazy<IConnectionManager> connectionManager)
25+
: base(CommandSet, CommandId, dialogService, selectedTextProvider, connectionManager, true,
26+
isNotLoggedInDefault: true)
2327
{
24-
this.dialogService = dialogService;
25-
this.selectedTextProvider = selectedTextProvider;
2628
}
2729

2830
/// <summary>
@@ -34,21 +36,100 @@ protected CreateGistCommand(Lazy<IDialogService> dialogService, Lazy<ISelectedTe
3436
/// Gets the numeric identifier of the command.
3537
/// </summary>
3638
public const int CommandId = PkgCmdIDList.createGistCommand;
39+
}
40+
41+
/// <summary>
42+
/// Creates a GitHub Enterprise Gist from the currently selected text.
43+
/// </summary>
44+
[Export(typeof(ICreateGistEnterpriseCommand))]
45+
public class CreateGistEnterpriseCommand : CreateGistCommandBase, ICreateGistEnterpriseCommand
46+
{
47+
[ImportingConstructor]
48+
protected CreateGistEnterpriseCommand(
49+
Lazy<IDialogService> dialogService,
50+
Lazy<ISelectedTextProvider> selectedTextProvider,
51+
Lazy<IConnectionManager> connectionManager)
52+
: base(CommandSet, CommandId, dialogService, selectedTextProvider, connectionManager, false)
53+
{
54+
}
55+
56+
/// <summary>
57+
/// Gets the GUID of the group the command belongs to.
58+
/// </summary>
59+
public static readonly Guid CommandSet = Guids.guidContextMenuSet;
60+
61+
/// <summary>
62+
/// Gets the numeric identifier of the command.
63+
/// </summary>
64+
public const int CommandId = PkgCmdIDList.createGistEnterpriseCommand;
65+
}
66+
67+
/// <summary>
68+
/// Creates a GitHub or GitHub Enterprise Gist from the currently selected text.
69+
/// </summary>
70+
public abstract class CreateGistCommandBase : VsCommand
71+
{
72+
readonly bool isGitHubDotCom;
73+
readonly bool isNotLoggedInDefault;
74+
readonly Lazy<IDialogService> dialogService;
75+
readonly Lazy<ISelectedTextProvider> selectedTextProvider;
76+
readonly Lazy<IConnectionManager> connectionManager;
77+
78+
protected CreateGistCommandBase(
79+
Guid commandSet, int commandId,
80+
Lazy<IDialogService> dialogService,
81+
Lazy<ISelectedTextProvider> selectedTextProvider,
82+
Lazy<IConnectionManager> connectionManager,
83+
bool isGitHubDotCom,
84+
bool isNotLoggedInDefault = false)
85+
: base(commandSet, commandId)
86+
{
87+
this.dialogService = dialogService;
88+
this.selectedTextProvider = selectedTextProvider;
89+
this.connectionManager = connectionManager;
90+
this.isGitHubDotCom = isGitHubDotCom;
91+
this.isNotLoggedInDefault = isNotLoggedInDefault;
92+
}
3793

3894
ISelectedTextProvider SelectedTextProvider => selectedTextProvider.Value;
3995

4096
/// <summary>
4197
/// Shows the Create Gist dialog.
4298
/// </summary>
43-
public override Task Execute()
99+
public override async Task Execute()
44100
{
45-
return dialogService.Value.ShowCreateGist();
101+
var connection = await FindConnectionAsync();
102+
await dialogService.Value.ShowCreateGist(connection);
46103
}
47104

48105
protected override void QueryStatus()
49106
{
50107
Log.Assert(SelectedTextProvider != null, "Could not get an instance of ISelectedTextProvider");
51-
Visible = !string.IsNullOrWhiteSpace(SelectedTextProvider?.GetSelectedText());
108+
Visible = !string.IsNullOrWhiteSpace(SelectedTextProvider?.GetSelectedText()) &&
109+
(HasConnection() || isNotLoggedInDefault && IsLoggedIn() == false);
110+
}
111+
112+
bool HasConnection()
113+
{
114+
var task = FindConnectionAsync();
115+
return task.IsCompleted && task.Result != null;
116+
}
117+
118+
async Task<IConnection> FindConnectionAsync()
119+
{
120+
var connections = await connectionManager.Value.GetLoadedConnections();
121+
return connections.FirstOrDefault(x => x.IsLoggedIn && x.HostAddress.IsGitHubDotCom() == isGitHubDotCom);
122+
}
123+
124+
bool? IsLoggedIn()
125+
{
126+
var task = connectionManager.Value.IsLoggedIn();
127+
if (task.IsCompleted)
128+
{
129+
return task.Result;
130+
}
131+
132+
return null;
52133
}
53134
}
54135
}

src/GitHub.VisualStudio/GitHub.VisualStudio.en-US.vsct

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,18 @@
206206
</Strings>
207207
</Button>
208208

209+
<Button guid="guidContextMenuSet" id="idCreateGistEnterpriseCommand" priority="0x0101" type="Button">
210+
<Icon guid="guidImages" id="logo" />
211+
<CommandFlag>IconIsMoniker</CommandFlag>
212+
<CommandFlag>DefaultInvisible</CommandFlag>
213+
<CommandFlag>DynamicVisibility</CommandFlag>
214+
<Strings>
215+
<ButtonText>Create an Enterprise Gist</ButtonText>
216+
<CanonicalName>.GitHub.CreateGistEnterprise</CanonicalName>
217+
<LocCanonicalName>.GitHub.CreateGistEnterprise</LocCanonicalName>
218+
</Strings>
219+
</Button>
220+
209221
<Button guid="guidContextMenuSet" id="openLinkCommand" type="Button">
210222
<Icon guid="guidImages" id="link_external" />
211223
<CommandFlag>IconIsMoniker</CommandFlag>

src/GitHub.VisualStudio/GitHub.VisualStudio.vsct

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@
6262
<Parent guid="guidContextMenuSet" id="idGitHubContextSubMenuGroup"/>
6363
</CommandPlacement>
6464

65-
<CommandPlacement guid="guidContextMenuSet" id="idBlameCommand" priority="0x104">
65+
<CommandPlacement guid="guidContextMenuSet" id="idCreateGistEnterpriseCommand" priority="0x104">
66+
<Parent guid="guidContextMenuSet" id="idGitHubContextSubMenuGroup"/>
67+
</CommandPlacement>
68+
69+
<CommandPlacement guid="guidContextMenuSet" id="idBlameCommand" priority="0x105">
6670
<Parent guid="guidContextMenuSet" id="idGitHubContextSubMenuGroup"/>
6771
</CommandPlacement>
6872

@@ -169,6 +173,7 @@
169173
<IDSymbol name="copyLinkCommand" value="0x101"/>
170174
<IDSymbol name="goToSolutionOrPullRequestFileCommand" value="0x0102" />
171175
<IDSymbol name="idCreateGistCommand" value="0x0400" />
176+
<IDSymbol name="idCreateGistEnterpriseCommand" value="0x0401" />
172177
<IDSymbol name="idBlameCommand" value="0x0500" />
173178
</GuidSymbol>
174179

src/GitHub.VisualStudio/GitHub.VisualStudio.zh-Hans.vsct

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,18 @@
206206
</Strings>
207207
</Button>
208208

209+
<Button guid="guidContextMenuSet" id="idCreateGistEnterpriseCommand" priority="0x0101" type="Button">
210+
<Icon guid="guidImages" id="logo" />
211+
<CommandFlag>IconIsMoniker</CommandFlag>
212+
<CommandFlag>DefaultInvisible</CommandFlag>
213+
<CommandFlag>DynamicVisibility</CommandFlag>
214+
<Strings>
215+
<ButtonText>创建企业 Gist</ButtonText>
216+
<CanonicalName>.GitHub.CreateGistEnterprise</CanonicalName>
217+
<LocCanonicalName>.GitHub.CreateGistEnterprise</LocCanonicalName>
218+
</Strings>
219+
</Button>
220+
209221
<Button guid="guidContextMenuSet" id="openLinkCommand" type="Button">
210222
<Icon guid="guidImages" id="link_external" />
211223
<CommandFlag>IconIsMoniker</CommandFlag>

src/GitHub.VisualStudio/GitHubPackage.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ async Task InitializeMenus()
8585
exports.GetExportedValue<IBlameLinkCommand>(),
8686
exports.GetExportedValue<ICopyLinkCommand>(),
8787
exports.GetExportedValue<ICreateGistCommand>(),
88+
exports.GetExportedValue<ICreateGistEnterpriseCommand>(),
8889
exports.GetExportedValue<IOpenLinkCommand>(),
8990
exports.GetExportedValue<IOpenPullRequestsCommand>(),
9091
exports.GetExportedValue<IShowCurrentPullRequestCommand>(),

0 commit comments

Comments
 (0)