public HierarchyItemPair GetActiveHierarchy()
        {
            return(asyncManager.Run(async() => {
                // The VS selection operations must be performed on the UI thread.
                await asyncManager.SwitchToMainThread();

                var selHier = IntPtr.Zero;
                var selContainer = IntPtr.Zero;
                uint selId;
                IVsMultiItemSelect selMulti;

                try {
                    // Get the current project hierarchy, project item, and selection container for the current selection
                    // If the selection spans multiple hierarchies, hierarchyPtr is Zero
                    ErrorHandler.ThrowOnFailure(monitorSelection.GetCurrentSelection(out selHier, out selId, out selMulti, out selContainer));

                    // There may be no selection at all.
                    if (selMulti == null && selHier == IntPtr.Zero)
                    {
                        return null;
                    }

                    // This is a single item selection, so we just grab the owning project/hierarchy.
                    if (selMulti == null)
                    {
                        return new HierarchyItemPair(
                            (IVsHierarchy)Marshal.GetTypedObjectForIUnknown(selHier, typeof(IVsHierarchy)), VSConstants.VSITEMID_ROOT);
                    }

                    // This is a multiple item selection.
                    // If this is a multiple item selection within the same hierarchy,
                    // we select the hierarchy too.
                    uint selCount;
                    int singleHier;
                    ErrorHandler.ThrowOnFailure(selMulti.GetSelectionInfo(out selCount, out singleHier));

                    if (singleHier == 1)
                    {
                        return new HierarchyItemPair(
                            (IVsHierarchy)Marshal.GetTypedObjectForIUnknown(selHier, typeof(IVsHierarchy)), VSConstants.VSITEMID_ROOT);
                    }

                    return null;
                } finally {
                    if (selHier != IntPtr.Zero)
                    {
                        Marshal.Release(selHier);
                    }
                    if (selContainer != IntPtr.Zero)
                    {
                        Marshal.Release(selContainer);
                    }
                }
            }));
        }
Exemple #2
0
        public IVsHierarchyItem GetActiveHierarchy()
        {
            return(asyncManager.Run(async() => {
                await asyncManager.SwitchToMainThread();
                IVsUIHierarchy uiHier;
                if (ErrorHandler.Failed(hierarchyWindow.FindCommonSelectedHierarchy((uint)__VSCOMHIEROPTIONS.COMHIEROPT_RootHierarchyOnly, out uiHier)))
                {
                    return null;
                }

                return hierarchyManager.GetHierarchyItem(uiHier, VSConstants.VSITEMID_ROOT);
            }));
        }
Exemple #3
0
 public VsShellProvider([Import(typeof(SVsServiceProvider))] IServiceProvider services, IAsyncManager async)
 {
     vsShell = new Lazy <IVsShell>(() => async.Run(async() => {
         await async.SwitchToMainThread();
         return(services.GetService <SVsShell, IVsShell>());
     }));
 }
Exemple #4
0
 public VsHierarchyItemManagerProvider([Import(typeof(SVsServiceProvider))] IServiceProvider services, IAsyncManager async)
 {
     hierarchyManager = new Lazy <IVsHierarchyItemManager> (() => async.Run(async() => {
         await async.SwitchToMainThread();
         return(services.GetService <SComponentModel, IComponentModel> ().GetService <IVsHierarchyItemManager> ());
     }));
 }
Exemple #5
0
		public VsShellProvider([Import(typeof(SVsServiceProvider))] IServiceProvider services, IAsyncManager async)
		{
			vsShell = new Lazy<IVsShell>(() => async.Run(async () => {
				await async.SwitchToMainThread();
				return services.GetService<SVsShell, IVsShell>();
			}));
		}
		public VsHierarchyItemManagerProvider ([Import (typeof (SVsServiceProvider))] IServiceProvider services, IAsyncManager async)
		{
			hierarchyManager = new Lazy<IVsHierarchyItemManager> (() => async.Run (async () => {
				await async.SwitchToMainThread ();
				return services.GetService<SComponentModel, IComponentModel> ().GetService<IVsHierarchyItemManager> ();
			}));
		}
        public VsBooleanSymbolExpressionEvaluatorProvider([Import(typeof(SVsServiceProvider))] IServiceProvider services, IAsyncManager async)
        {
            expressionEvaluator = new Lazy <IVsBooleanSymbolExpressionEvaluator>(() => async.Run(async() =>
            {
                await async.SwitchToMainThread();

                var registry = services.GetService <SLocalRegistry, ILocalRegistry>();

                // dev14+ should provide the evaluator using the BooleanSymbolExpressionEvaluator clsid
                var value = registry.CreateInstance(BooleanSymbolExpressionEvaluatorClsid) as IVsBooleanSymbolExpressionEvaluator;
                if (value == null)
                {
                    // Previous versions of VS provides the service using the VsProjectCapabilityExpressionMatcher interface
                    value = registry.CreateInstance(typeof(VsProjectCapabilityExpressionMatcher).GUID) as IVsBooleanSymbolExpressionEvaluator;
                }

                return(value);
            }));
        }
		public VsBooleanSymbolExpressionEvaluatorProvider([Import(typeof(SVsServiceProvider))] IServiceProvider services, IAsyncManager async)
		{
			expressionEvaluator = new Lazy<IVsBooleanSymbolExpressionEvaluator>(() => async.Run(async () =>
			{
				await async.SwitchToMainThread();

				var registry = services.GetService<SLocalRegistry, ILocalRegistry>();

				// dev14+ should provide the evaluator using the BooleanSymbolExpressionEvaluator interface
				var value = registry.CreateInstance(typeof(BooleanSymbolExpressionEvaluator).GUID) as IVsBooleanSymbolExpressionEvaluator;
				if (value == null)
				{
					// Previous versions of VS provides the service using the VsProjectCapabilityExpressionMatcher interface
					value = registry.CreateInstance(typeof(VsProjectCapabilityExpressionMatcher).GUID) as IVsBooleanSymbolExpressionEvaluator;
				}

				return value;
			}));
		}