Click here to Skip to main content
15,890,415 members
Articles / Visual Studio / Visual Studio 2013

Getting Started with a Team Explorer Plugin for VS 2013 - Part 2

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
10 Jan 2014CPOL1 min read 7.7K   1  
How to get started with a Team Explorer plugin for VS 2013

In Getting started with a Team Explorer plug in for VS 2013 - Part 1, we setup a base to start extending Team Explorer. This post assumes you already have the base project setup.

Creating a New Team Explorer Navigation Item

Add a new const to the GuidList class (in the Guids file) like below:

C#
public const string sampleTeamExplorerNavigationItem = "8C35B3DF-D7CC-45BC-B958-BFAE3E157A21";

Add any image (to be used as the icon) to the Resources.resx file and call it SampleImage like below:

image

Create a class called SampleTeamExplorerNavigationItem and replace the contents with code below:

C#
namespace Company.TeamExplorerSamplePlugin
{
    using System;
    using System.ComponentModel;
    using System.ComponentModel.Composition;
    using System.Drawing;
    using System.Windows.Forms;

    using Microsoft.TeamFoundation.Controls;
    using Microsoft.VisualStudio.Shell;

    [TeamExplorerNavigationItem(GuidList.sampleTeamExplorerNavigationItem, 100)]
    public class SampleTeamExplorerNavigationItem : ITeamExplorerNavigationItem
    {
        private Image image = Resources.SampleImage;

        private bool isVisible = true;

        private string text = "Sample Button";

        [ImportingConstructor]
        public SampleTeamExplorerNavigationItem
        ([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider;
        }

        private IServiceProvider serviceProvider { get; set; }

        public Image Image
        {
            get
            {
                return this.image;
            }
            set
            {
                this.image = value;
                this.FirePropertyChanged("Image");
            }
        }

        public bool IsVisible
        {
            get
            {
                return this.isVisible;
            }
            set
            {
                this.isVisible = value;
                this.FirePropertyChanged("IsVisible");
            }
        }

        public string Text
        {
            get
            {
                return this.text;
            }
            set
            {
                this.text = value;
                this.FirePropertyChanged("Text");
            }
        }

        public void Execute()
        {
            MessageBox.Show("Execute Called");
        }

        public void Invalidate()
        {
        }

        public void Dispose()
        {
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void FirePropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public T GetService<T>()
        {
            if (this.serviceProvider != null)
            {
                return (T)this.serviceProvider.GetService(typeof(T));
            }
            return default (T);
        }
    }
}

Note how we used the GuidList.sampleTeamExplorerNavigationItem guid string that we created in the TeamExplorerNavigationItem attribute, we also specified a priority of 100 saying that this navigation item should be high up on the list of navigation items. We specified in the Execute method that we want to see a message box to make sure our event is being fired. We'll change this at a later stage. We also set some basic properties for the display of our button including the image we added earlier. If you run the project, you will see in the Team Explorer that our Sample Button is visible.

image

Note when you click the button, the message box displays as expected.

image

In the Getting started with a Team Explorer plug in for VS 2013 - Part 3, we will be creating a new Team Explorer Page and then changing our Execute method to navigate to this page.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect SSW
South Africa South Africa

Comments and Discussions

 
-- There are no messages in this forum --