dcgc
dcgc

Reputation: 45

Global service of the Team explorer's Query results window

What is the Query results window's global service (interface)? Code below:

var dteService = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
if (dteService == null)
{
   Debug.WriteLine("");
   return;
}

var something=Package.GetGlobalService(typeof(???)) as ???;

EDIT: The goal is, when I press the context menu button, I want the function callback to be able to access the service where the work item is selected (or the results list

The goal is, when I press the context menu button, I want the function callback to be able to access the service where the work item is selected (or the results list

Upvotes: 1

Views: 85

Answers (2)

Vicky - MSFT
Vicky - MSFT

Reputation: 5010

Please check this case in MSDN forum for the details how to get it work: https://social.msdn.microsoft.com/Forums/vstudio/en-US/2d158b9c-dec1-4c59-82aa-f1f2312d770b/sdk-packageget-selected-item-from-query-results-list

The following code is quoted from above link for your quick reference:

Document activeDocument = _applicationObject.ActiveDocument;
        if (activeDocument != null)
        {
            DocumentService globalService = (DocumentService)Package.GetGlobalService(typeof(DocumentService));
            if (globalService != null)
            {
                string fullName = activeDocument.FullName;
                IWorkItemTrackingDocument document2 = globalService.FindDocument(fullName, null);
                if ((document2 != null) && (document2 is IResultsDocument))
                {
                    int[] selectedItemIds = ((IResultsDocument)document2).SelectedItemIds;
                }
            }
        }

Upvotes: 1

dcgc
dcgc

Reputation: 45

var dteService = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
if (dteService == null)
{
   Debug.WriteLine("");
   return;
}

DocumentService documentService = Package.GetGlobalService(typeof(DocumentService)) as DocumentService;
if (documentService == null)
      return;

string fullName = dteService.ActiveDocument.FullName;

IWorkItemTrackingDocument activeDocument = documentService.FindDocument(fullName, null);

if (activeDocument == null || !(activeDocument is IResultsDocument))
             return;

Upvotes: 0

Related Questions