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

Commit 99c8e70

Browse files
committed
Merge pull request #220 from github/feature/status-bar-notifications
Add a status bar notification service
2 parents 2a676a1 + 19580cc commit 99c8e70

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

src/GitHub.Exports/GitHub.Exports.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@
116116
<Compile Include="Services\IMenuHandler.cs" />
117117
<Compile Include="Services\IMenuProvider.cs" />
118118
<Compile Include="Services\INotificationDispatcher.cs" />
119+
<Compile Include="Services\IStatusBarNotificationService.cs" />
119120
<Compile Include="Services\ITeamExplorerServices.cs" />
120121
<Compile Include="Services\ITeamExplorerServiceHolder.cs" />
121122
<Compile Include="Services\INotificationService.cs" />
122123
<Compile Include="Services\Logger.cs" />
123124
<Compile Include="Services\Services.cs" />
125+
<Compile Include="Services\StatusBarNotificationService.cs" />
124126
<Compile Include="Services\TeamExplorerServices.cs" />
125127
<Compile Include="Services\VSServices.cs" />
126128
<Compile Include="Models\IConnection.cs" />
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace GitHub.Services
2+
{
3+
// for mef purposes
4+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1040:AvoidEmptyInterfaces")]
5+
public interface IStatusBarNotificationService : INotificationService
6+
{
7+
}
8+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using GitHub.Extensions;
2+
using Microsoft.VisualStudio;
3+
using Microsoft.VisualStudio.Shell;
4+
using Microsoft.VisualStudio.Shell.Interop;
5+
using System;
6+
using System.ComponentModel.Composition;
7+
using System.Windows.Input;
8+
9+
namespace GitHub.Services
10+
{
11+
[Export(typeof(IStatusBarNotificationService))]
12+
[PartCreationPolicy(CreationPolicy.Shared)]
13+
public class StatusBarNotificationService : IStatusBarNotificationService
14+
{
15+
readonly IServiceProvider serviceProvider;
16+
17+
[ImportingConstructor]
18+
public StatusBarNotificationService([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
19+
{
20+
this.serviceProvider = serviceProvider;
21+
}
22+
23+
public void ShowError(string message)
24+
{
25+
ShowText(message);
26+
}
27+
28+
public void ShowMessage(string message)
29+
{
30+
ShowText(message);
31+
}
32+
33+
public void ShowMessage(string message, ICommand command)
34+
{
35+
ShowText(message);
36+
}
37+
38+
public void ShowWarning(string message)
39+
{
40+
ShowText(message);
41+
}
42+
43+
void ShowText(string text)
44+
{
45+
var statusBar = serviceProvider.TryGetService<IVsStatusbar>();
46+
int frozen;
47+
if (!ErrorHandler.Succeeded(statusBar.IsFrozen(out frozen)))
48+
return;
49+
// If it's frozen, someone else is grabbing the status bar and we
50+
// can't show the message until they release it
51+
// so might as well not show it.
52+
if (frozen == 0)
53+
ErrorHandler.Succeeded(statusBar.SetText(text));
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)