Click here to Skip to main content
12,953,479 members (54,617 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

4.5K views
1 bookmarked
Posted 10 Jan 2014

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

, 10 Jan 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
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:

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:

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)

Share

About the Author

Gordon Beeming (RSA)
Software Developer Nologo Studios
South Africa South Africa
Gordon Beeming works at Nologo Studios in the sunny city of Durban, South Africa. His current focus is on Devloper Efficiencies and R&D. When he's not hacking away at a keyboard in Visual Studio he'll generally be relaxing with his family or hitting the black top getting in some mileage. He is a Visual Studio ALM Rangers, Visual Studio ALM MVP.

http://beeming.net

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 10 Jan 2014
Article Copyright 2014 by Gordon Beeming (RSA)
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid