From 2e04cf3805669434de0bcf53faf076c0368fb857 Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Wed, 22 May 2019 15:33:33 -0400 Subject: [PATCH 01/31] Functionality to add Publish to GitHub Essentials co-authored-by: Jamie Cansdale --- .../Base/TeamExplorerBase.cs | 173 ++++++++++++++++++ .../Base/TeamExplorerBaseNavigationItem.cs | 73 ++++++++ .../Base/TeamExplorerBaseNavigationLink.cs | 73 ++++++++ .../Base/TeamExplorerBasePage.cs | 96 ++++++++++ .../Base/TeamExplorerBaseSection.cs | 117 ++++++++++++ .../GitHub.VisualStudio.16.csproj | 23 +++ .../Sync/PublishSection.cs | 93 ++++++++++ .../Sync/PublishView.xaml | 14 ++ .../Sync/PublishView.xaml.cs | 50 +++++ .../source.extension.vsixmanifest | 1 + 10 files changed, 713 insertions(+) create mode 100644 src/GitHub.VisualStudio.16/Base/TeamExplorerBase.cs create mode 100644 src/GitHub.VisualStudio.16/Base/TeamExplorerBaseNavigationItem.cs create mode 100644 src/GitHub.VisualStudio.16/Base/TeamExplorerBaseNavigationLink.cs create mode 100644 src/GitHub.VisualStudio.16/Base/TeamExplorerBasePage.cs create mode 100644 src/GitHub.VisualStudio.16/Base/TeamExplorerBaseSection.cs create mode 100644 src/GitHub.VisualStudio.16/Sync/PublishSection.cs create mode 100644 src/GitHub.VisualStudio.16/Sync/PublishView.xaml create mode 100644 src/GitHub.VisualStudio.16/Sync/PublishView.xaml.cs diff --git a/src/GitHub.VisualStudio.16/Base/TeamExplorerBase.cs b/src/GitHub.VisualStudio.16/Base/TeamExplorerBase.cs new file mode 100644 index 0000000000..93f0714e11 --- /dev/null +++ b/src/GitHub.VisualStudio.16/Base/TeamExplorerBase.cs @@ -0,0 +1,173 @@ +/* +* Copyright (c) Microsoft Corporation. All rights reserved. This code released +* under the terms of the Microsoft Limited Public License (MS-LPL). +*/ +using System; +using System.ComponentModel; +using System.Diagnostics; +using Microsoft.TeamFoundation.Client; +using Microsoft.TeamFoundation.Controls; + +namespace Microsoft.TeamExplorerSample +{ + /// + /// Team Explorer plugin common base class. + /// + public class TeamExplorerBase : IDisposable, INotifyPropertyChanged + { + #region Members + + private bool m_contextSubscribed = false; + + #endregion + + /// + /// Get/set the service provider. + /// + public IServiceProvider ServiceProvider + { + get { return m_serviceProvider; } + set + { + // Unsubscribe from Team Foundation context changes + if (m_serviceProvider != null) + { + UnsubscribeContextChanges(); + } + + m_serviceProvider = value; + + // Subscribe to Team Foundation context changes + if (m_serviceProvider != null) + { + SubscribeContextChanges(); + } + } + } + private IServiceProvider m_serviceProvider = null; + + /// + /// Get the requested service from the service provider. + /// + public T GetService() + { + Debug.Assert(this.ServiceProvider != null, "GetService called before service provider is set"); + if (this.ServiceProvider != null) + { + return (T)this.ServiceProvider.GetService(typeof(T)); + } + + return default(T); + } + + /// + /// Show a notification in the Team Explorer window. + /// + protected Guid ShowNotification(string message, NotificationType type) + { + ITeamExplorer teamExplorer = GetService(); + if (teamExplorer != null) + { + Guid guid = Guid.NewGuid(); + teamExplorer.ShowNotification(message, type, NotificationFlags.None, null, guid); + return guid; + } + + return Guid.Empty; + } + + #region IDisposable + + /// + /// Dispose. + /// + public virtual void Dispose() + { + UnsubscribeContextChanges(); + } + + #endregion + + #region INotifyPropertyChanged + + public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + + /// + /// Raise the PropertyChanged event for the specified property. + /// + /// Property name + protected void RaisePropertyChanged(string propertyName) + { + if (this.PropertyChanged != null) + { + this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); + } + } + + #endregion + + #region Team Foundation Context + + /// + /// Subscribe to context changes. + /// + protected void SubscribeContextChanges() + { + Debug.Assert(this.ServiceProvider != null, "ServiceProvider must be set before subscribing to context changes"); + if (this.ServiceProvider == null || m_contextSubscribed) + { + return; + } + + ITeamFoundationContextManager tfContextManager = GetService(); + if (tfContextManager != null) + { + tfContextManager.ContextChanged += ContextChanged; + m_contextSubscribed = true; + } + } + + /// + /// Unsubscribe from context changes. + /// + protected void UnsubscribeContextChanges() + { + if (this.ServiceProvider == null || !m_contextSubscribed) + { + return; + } + + ITeamFoundationContextManager tfContextManager = GetService(); + if (tfContextManager != null) + { + tfContextManager.ContextChanged -= ContextChanged; + } + } + + /// + /// ContextChanged event handler. + /// + protected virtual void ContextChanged(object sender, ContextChangedEventArgs e) + { + } + + /// + /// Get the current Team Foundation context. + /// + protected ITeamFoundationContext CurrentContext + { + get + { + ITeamFoundationContextManager tfContextManager = GetService(); + if (tfContextManager != null) + { + return tfContextManager.CurrentContext; + } + + return null; + } + } + + #endregion + } +} diff --git a/src/GitHub.VisualStudio.16/Base/TeamExplorerBaseNavigationItem.cs b/src/GitHub.VisualStudio.16/Base/TeamExplorerBaseNavigationItem.cs new file mode 100644 index 0000000000..b9fe4c8622 --- /dev/null +++ b/src/GitHub.VisualStudio.16/Base/TeamExplorerBaseNavigationItem.cs @@ -0,0 +1,73 @@ +/* +* Copyright (c) Microsoft Corporation. All rights reserved. This code released +* under the terms of the Microsoft Limited Public License (MS-LPL). +*/ +using System; +using System.ComponentModel.Composition; +using Microsoft.TeamFoundation.Controls; +using Microsoft.VisualStudio.Shell; + +namespace Microsoft.TeamExplorerSample +{ + /// + /// Team Explorer base navigation item class. + /// + public class TeamExplorerBaseNavigationItem : TeamExplorerBase, ITeamExplorerNavigationItem + { + /// + /// Constructor. + /// + public TeamExplorerBaseNavigationItem(IServiceProvider serviceProvider) + { + this.ServiceProvider = serviceProvider; + } + + #region ITeamExplorerNavigationItem + + /// + /// Get/set the item text. + /// + public string Text + { + get { return m_text; } + set { m_text = value; RaisePropertyChanged("Text"); } + } + private string m_text; + + /// + /// Get/set the item image. + /// + public System.Drawing.Image Image + { + get { return m_image; } + set { m_image = value; RaisePropertyChanged("Image"); } + } + private System.Drawing.Image m_image; + + /// + /// Get/set the IsVisible flag. + /// + public bool IsVisible + { + get { return m_isVisible; } + set { m_isVisible = value; RaisePropertyChanged("IsVisible"); } + } + private bool m_isVisible = true; + + /// + /// Invalidate the item state. + /// + public virtual void Invalidate() + { + } + + /// + /// Execute the item action. + /// + public virtual void Execute() + { + } + + #endregion + } +} diff --git a/src/GitHub.VisualStudio.16/Base/TeamExplorerBaseNavigationLink.cs b/src/GitHub.VisualStudio.16/Base/TeamExplorerBaseNavigationLink.cs new file mode 100644 index 0000000000..960a67f80d --- /dev/null +++ b/src/GitHub.VisualStudio.16/Base/TeamExplorerBaseNavigationLink.cs @@ -0,0 +1,73 @@ +/* +* Copyright (c) Microsoft Corporation. All rights reserved. This code released +* under the terms of the Microsoft Limited Public License (MS-LPL). +*/ +using System; +using System.ComponentModel.Composition; +using Microsoft.TeamFoundation.Controls; +using Microsoft.VisualStudio.Shell; + +namespace Microsoft.TeamExplorerSample +{ + /// + /// Team Explorer base navigation link class. + /// + public class TeamExplorerBaseNavigationLink : TeamExplorerBase, ITeamExplorerNavigationLink + { + /// + /// Constructor. + /// + public TeamExplorerBaseNavigationLink(IServiceProvider serviceProvider) + { + this.ServiceProvider = serviceProvider; + } + + #region ITeamExplorerNavigationLink + + /// + /// Get/set the item text. + /// + public string Text + { + get { return m_text; } + set { m_text = value; RaisePropertyChanged("Text"); } + } + private string m_text; + + /// + /// Get/set the IsEnabled flag. + /// + public bool IsEnabled + { + get { return m_isEnabled; } + set { m_isEnabled = value; RaisePropertyChanged("IsEnabled"); } + } + private bool m_isEnabled = true; + + /// + /// Get/set the IsVisible flag. + /// + public bool IsVisible + { + get { return m_isVisible; } + set { m_isVisible = value; RaisePropertyChanged("IsVisible"); } + } + private bool m_isVisible = true; + + /// + /// Invalidate the link state. + /// + public virtual void Invalidate() + { + } + + /// + /// Execute the link action. + /// + public virtual void Execute() + { + } + + #endregion + } +} diff --git a/src/GitHub.VisualStudio.16/Base/TeamExplorerBasePage.cs b/src/GitHub.VisualStudio.16/Base/TeamExplorerBasePage.cs new file mode 100644 index 0000000000..98f5a60ffc --- /dev/null +++ b/src/GitHub.VisualStudio.16/Base/TeamExplorerBasePage.cs @@ -0,0 +1,96 @@ +/* +* Copyright (c) Microsoft Corporation. All rights reserved. This code released +* under the terms of the Microsoft Limited Public License (MS-LPL). +*/ +using System; +using System.ComponentModel; +using Microsoft.TeamFoundation.Controls; + +namespace Microsoft.TeamExplorerSample +{ + /// + /// Team Explorer page base class. + /// + public class TeamExplorerBasePage : TeamExplorerBase, ITeamExplorerPage + { + #region ITeamExplorerPage + + /// + /// Initialize the page. + /// + public virtual void Initialize(object sender, PageInitializeEventArgs e) + { + this.ServiceProvider = e.ServiceProvider; + } + + /// + /// Loaded handler that is called once the page and all sections + /// have been initialized. + /// + public virtual void Loaded(object sender, PageLoadedEventArgs e) + { + } + + /// + /// Save context handler that is called before a page is unloaded. + /// + public virtual void SaveContext(object sender, PageSaveContextEventArgs e) + { + } + + /// + /// Get/set the page title. + /// + public string Title + { + get { return m_title; } + set { m_title = value; RaisePropertyChanged("Title"); } + } + private string m_title; + + /// + /// Get/set the page content. + /// + public object PageContent + { + get { return m_pageContent; } + set { m_pageContent = value; RaisePropertyChanged("PageContent"); } + } + private object m_pageContent; + + /// + /// Get/set the IsBusy flag. + /// + public bool IsBusy + { + get { return m_isBusy; } + set { m_isBusy = value; RaisePropertyChanged("IsBusy"); } + } + private bool m_isBusy = false; + + /// + /// Refresh the page contents. + /// + public virtual void Refresh() + { + } + + /// + /// Cancel any running operations. + /// + public virtual void Cancel() + { + } + + /// + /// Get the requested extensibility service from the page. Return + /// null if the service is not offered by this page. + /// + public virtual object GetExtensibilityService(Type serviceType) + { + return null; + } + + #endregion + } +} diff --git a/src/GitHub.VisualStudio.16/Base/TeamExplorerBaseSection.cs b/src/GitHub.VisualStudio.16/Base/TeamExplorerBaseSection.cs new file mode 100644 index 0000000000..2eb2677106 --- /dev/null +++ b/src/GitHub.VisualStudio.16/Base/TeamExplorerBaseSection.cs @@ -0,0 +1,117 @@ +/* +* Copyright (c) Microsoft Corporation. All rights reserved. This code released +* under the terms of the Microsoft Limited Public License (MS-LPL). +*/ +using System; +using System.ComponentModel; +using Microsoft.TeamFoundation.Controls; + +namespace Microsoft.TeamExplorerSample +{ + /// + /// Team Explorer base section class. + /// + public class TeamExplorerBaseSection : TeamExplorerBase, ITeamExplorerSection + { + #region ITeamExplorerSection + + /// + /// Initialize the section. + /// + public virtual void Initialize(object sender, SectionInitializeEventArgs e) + { + this.ServiceProvider = e.ServiceProvider; + } + + /// + /// Save context handler that is called before a section is unloaded. + /// + public virtual void SaveContext(object sender, SectionSaveContextEventArgs e) + { + } + + /// + /// Get/set the section title. + /// + public string Title + { + get { return m_title; } + set { m_title = value; RaisePropertyChanged("Title"); } + } + private string m_title; + + /// + /// Get/set the section content. + /// + public object SectionContent + { + get { return m_sectionContent; } + set { m_sectionContent = value; RaisePropertyChanged("SectionContent"); } + } + private object m_sectionContent; + + /// + /// Get/set the IsVisible flag. + /// + public bool IsVisible + { + get { return m_isVisible; } + set { m_isVisible = value; RaisePropertyChanged("IsVisible"); } + } + private bool m_isVisible = true; + + /// + /// Get/set the IsExpanded flag. + /// + public bool IsExpanded + { + get { return m_isExpanded; } + set { m_isExpanded = value; RaisePropertyChanged("IsExpanded"); } + } + private bool m_isExpanded = true; + + /// + /// Get/set the IsBusy flag. + /// + public bool IsBusy + { + get { return m_isBusy; } + set { m_isBusy = value; RaisePropertyChanged("IsBusy"); } + } + private bool m_isBusy = false; + + /// + /// Called when the section is loaded. + /// + /// + /// + public virtual void Loaded(object sender, SectionLoadedEventArgs e) + { + } + + /// + /// Refresh the section contents. + /// + public virtual void Refresh() + { + } + + /// + /// Cancel any running operations. + /// + public virtual void Cancel() + { + } + + /// + /// Get the requested extensibility service from the section. Return + /// null if the service is not offered by this section. + /// + public virtual object GetExtensibilityService(Type serviceType) + { + return null; + } + + #endregion + } +} diff --git a/src/GitHub.VisualStudio.16/GitHub.VisualStudio.16.csproj b/src/GitHub.VisualStudio.16/GitHub.VisualStudio.16.csproj index 7e94f4e4dc..e3391b2e57 100644 --- a/src/GitHub.VisualStudio.16/GitHub.VisualStudio.16.csproj +++ b/src/GitHub.VisualStudio.16/GitHub.VisualStudio.16.csproj @@ -60,6 +60,11 @@ Properties\SolutionInfo.cs + + + + + @@ -73,6 +78,10 @@ Resources.resx + + + PublishView.xaml + @@ -155,6 +164,14 @@ ..\..\build\Content\Markdig.Wpf.dll + + False + ..\..\lib\16.0\Microsoft.TeamFoundation.Client.dll + + + False + ..\..\lib\16.0\Microsoft.TeamFoundation.Controls.dll + False ..\..\build\Content\Octokit.dll @@ -253,6 +270,12 @@ DebugSymbolsProjectOutputGroup%3b + + + MSBuild:Compile + Designer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +