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

Commit 2e04cf3

Browse files
Functionality to add Publish to GitHub Essentials
co-authored-by: Jamie Cansdale <[email protected]>
1 parent be97369 commit 2e04cf3

10 files changed

+713
-0
lines changed
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved. This code released
3+
* under the terms of the Microsoft Limited Public License (MS-LPL).
4+
*/
5+
using System;
6+
using System.ComponentModel;
7+
using System.Diagnostics;
8+
using Microsoft.TeamFoundation.Client;
9+
using Microsoft.TeamFoundation.Controls;
10+
11+
namespace Microsoft.TeamExplorerSample
12+
{
13+
/// <summary>
14+
/// Team Explorer plugin common base class.
15+
/// </summary>
16+
public class TeamExplorerBase : IDisposable, INotifyPropertyChanged
17+
{
18+
#region Members
19+
20+
private bool m_contextSubscribed = false;
21+
22+
#endregion
23+
24+
/// <summary>
25+
/// Get/set the service provider.
26+
/// </summary>
27+
public IServiceProvider ServiceProvider
28+
{
29+
get { return m_serviceProvider; }
30+
set
31+
{
32+
// Unsubscribe from Team Foundation context changes
33+
if (m_serviceProvider != null)
34+
{
35+
UnsubscribeContextChanges();
36+
}
37+
38+
m_serviceProvider = value;
39+
40+
// Subscribe to Team Foundation context changes
41+
if (m_serviceProvider != null)
42+
{
43+
SubscribeContextChanges();
44+
}
45+
}
46+
}
47+
private IServiceProvider m_serviceProvider = null;
48+
49+
/// <summary>
50+
/// Get the requested service from the service provider.
51+
/// </summary>
52+
public T GetService<T>()
53+
{
54+
Debug.Assert(this.ServiceProvider != null, "GetService<T> called before service provider is set");
55+
if (this.ServiceProvider != null)
56+
{
57+
return (T)this.ServiceProvider.GetService(typeof(T));
58+
}
59+
60+
return default(T);
61+
}
62+
63+
/// <summary>
64+
/// Show a notification in the Team Explorer window.
65+
/// </summary>
66+
protected Guid ShowNotification(string message, NotificationType type)
67+
{
68+
ITeamExplorer teamExplorer = GetService<ITeamExplorer>();
69+
if (teamExplorer != null)
70+
{
71+
Guid guid = Guid.NewGuid();
72+
teamExplorer.ShowNotification(message, type, NotificationFlags.None, null, guid);
73+
return guid;
74+
}
75+
76+
return Guid.Empty;
77+
}
78+
79+
#region IDisposable
80+
81+
/// <summary>
82+
/// Dispose.
83+
/// </summary>
84+
public virtual void Dispose()
85+
{
86+
UnsubscribeContextChanges();
87+
}
88+
89+
#endregion
90+
91+
#region INotifyPropertyChanged
92+
93+
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
94+
95+
/// <summary>
96+
/// Raise the PropertyChanged event for the specified property.
97+
/// </summary>
98+
/// <param name="propertyName">Property name</param>
99+
protected void RaisePropertyChanged(string propertyName)
100+
{
101+
if (this.PropertyChanged != null)
102+
{
103+
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
104+
}
105+
}
106+
107+
#endregion
108+
109+
#region Team Foundation Context
110+
111+
/// <summary>
112+
/// Subscribe to context changes.
113+
/// </summary>
114+
protected void SubscribeContextChanges()
115+
{
116+
Debug.Assert(this.ServiceProvider != null, "ServiceProvider must be set before subscribing to context changes");
117+
if (this.ServiceProvider == null || m_contextSubscribed)
118+
{
119+
return;
120+
}
121+
122+
ITeamFoundationContextManager tfContextManager = GetService<ITeamFoundationContextManager>();
123+
if (tfContextManager != null)
124+
{
125+
tfContextManager.ContextChanged += ContextChanged;
126+
m_contextSubscribed = true;
127+
}
128+
}
129+
130+
/// <summary>
131+
/// Unsubscribe from context changes.
132+
/// </summary>
133+
protected void UnsubscribeContextChanges()
134+
{
135+
if (this.ServiceProvider == null || !m_contextSubscribed)
136+
{
137+
return;
138+
}
139+
140+
ITeamFoundationContextManager tfContextManager = GetService<ITeamFoundationContextManager>();
141+
if (tfContextManager != null)
142+
{
143+
tfContextManager.ContextChanged -= ContextChanged;
144+
}
145+
}
146+
147+
/// <summary>
148+
/// ContextChanged event handler.
149+
/// </summary>
150+
protected virtual void ContextChanged(object sender, ContextChangedEventArgs e)
151+
{
152+
}
153+
154+
/// <summary>
155+
/// Get the current Team Foundation context.
156+
/// </summary>
157+
protected ITeamFoundationContext CurrentContext
158+
{
159+
get
160+
{
161+
ITeamFoundationContextManager tfContextManager = GetService<ITeamFoundationContextManager>();
162+
if (tfContextManager != null)
163+
{
164+
return tfContextManager.CurrentContext;
165+
}
166+
167+
return null;
168+
}
169+
}
170+
171+
#endregion
172+
}
173+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved. This code released
3+
* under the terms of the Microsoft Limited Public License (MS-LPL).
4+
*/
5+
using System;
6+
using System.ComponentModel.Composition;
7+
using Microsoft.TeamFoundation.Controls;
8+
using Microsoft.VisualStudio.Shell;
9+
10+
namespace Microsoft.TeamExplorerSample
11+
{
12+
/// <summary>
13+
/// Team Explorer base navigation item class.
14+
/// </summary>
15+
public class TeamExplorerBaseNavigationItem : TeamExplorerBase, ITeamExplorerNavigationItem
16+
{
17+
/// <summary>
18+
/// Constructor.
19+
/// </summary>
20+
public TeamExplorerBaseNavigationItem(IServiceProvider serviceProvider)
21+
{
22+
this.ServiceProvider = serviceProvider;
23+
}
24+
25+
#region ITeamExplorerNavigationItem
26+
27+
/// <summary>
28+
/// Get/set the item text.
29+
/// </summary>
30+
public string Text
31+
{
32+
get { return m_text; }
33+
set { m_text = value; RaisePropertyChanged("Text"); }
34+
}
35+
private string m_text;
36+
37+
/// <summary>
38+
/// Get/set the item image.
39+
/// </summary>
40+
public System.Drawing.Image Image
41+
{
42+
get { return m_image; }
43+
set { m_image = value; RaisePropertyChanged("Image"); }
44+
}
45+
private System.Drawing.Image m_image;
46+
47+
/// <summary>
48+
/// Get/set the IsVisible flag.
49+
/// </summary>
50+
public bool IsVisible
51+
{
52+
get { return m_isVisible; }
53+
set { m_isVisible = value; RaisePropertyChanged("IsVisible"); }
54+
}
55+
private bool m_isVisible = true;
56+
57+
/// <summary>
58+
/// Invalidate the item state.
59+
/// </summary>
60+
public virtual void Invalidate()
61+
{
62+
}
63+
64+
/// <summary>
65+
/// Execute the item action.
66+
/// </summary>
67+
public virtual void Execute()
68+
{
69+
}
70+
71+
#endregion
72+
}
73+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved. This code released
3+
* under the terms of the Microsoft Limited Public License (MS-LPL).
4+
*/
5+
using System;
6+
using System.ComponentModel.Composition;
7+
using Microsoft.TeamFoundation.Controls;
8+
using Microsoft.VisualStudio.Shell;
9+
10+
namespace Microsoft.TeamExplorerSample
11+
{
12+
/// <summary>
13+
/// Team Explorer base navigation link class.
14+
/// </summary>
15+
public class TeamExplorerBaseNavigationLink : TeamExplorerBase, ITeamExplorerNavigationLink
16+
{
17+
/// <summary>
18+
/// Constructor.
19+
/// </summary>
20+
public TeamExplorerBaseNavigationLink(IServiceProvider serviceProvider)
21+
{
22+
this.ServiceProvider = serviceProvider;
23+
}
24+
25+
#region ITeamExplorerNavigationLink
26+
27+
/// <summary>
28+
/// Get/set the item text.
29+
/// </summary>
30+
public string Text
31+
{
32+
get { return m_text; }
33+
set { m_text = value; RaisePropertyChanged("Text"); }
34+
}
35+
private string m_text;
36+
37+
/// <summary>
38+
/// Get/set the IsEnabled flag.
39+
/// </summary>
40+
public bool IsEnabled
41+
{
42+
get { return m_isEnabled; }
43+
set { m_isEnabled = value; RaisePropertyChanged("IsEnabled"); }
44+
}
45+
private bool m_isEnabled = true;
46+
47+
/// <summary>
48+
/// Get/set the IsVisible flag.
49+
/// </summary>
50+
public bool IsVisible
51+
{
52+
get { return m_isVisible; }
53+
set { m_isVisible = value; RaisePropertyChanged("IsVisible"); }
54+
}
55+
private bool m_isVisible = true;
56+
57+
/// <summary>
58+
/// Invalidate the link state.
59+
/// </summary>
60+
public virtual void Invalidate()
61+
{
62+
}
63+
64+
/// <summary>
65+
/// Execute the link action.
66+
/// </summary>
67+
public virtual void Execute()
68+
{
69+
}
70+
71+
#endregion
72+
}
73+
}

0 commit comments

Comments
 (0)