Пример #1
0
        public int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
        {
            SelectionHandler1 handler = SelectionChangedEvent;
            if (handler != null) handler(pHierOld, itemidOld, pMISOld, pSCOld, pHierNew, itemidNew, pMISNew, pSCNew);

            return VSConstants.S_OK;
        }
 public int OnSelectionChanged(IVsHierarchy pHierOld,
                               uint itemidOld,
                               IVsMultiItemSelect pMISOld,
                               ISelectionContainer pSCOld,
                               IVsHierarchy pHierNew,
                               uint itemidNew,
                               IVsMultiItemSelect pMISNew,
                               ISelectionContainer pSCNew)
 {
     return VSConstants.S_OK;
 }
Пример #3
0
        int IVsSelectionEvents.OnSelectionChanged(
            IVsHierarchy pHierOld,
            uint itemidOld,
            IVsMultiItemSelect pMISOld,
            ISelectionContainer pSCOld,
            IVsHierarchy pHierNew,
            uint itemidNew,
            IVsMultiItemSelect pMISNew,
            ISelectionContainer pSCNew)
        {
            IVsHierarchy oldSelectedHierarchy = this.SelectedHierarchy;
            uint oldSelectedItemId = this.SelectedItemId;

            this.SelectedHierarchy = pHierNew;
            this.SelectedItemId = itemidNew;

            var selectedObjects = GetSelectedObjects(pSCNew);

            this.SelectedAnalyzerItems = selectedObjects
                                         .OfType<AnalyzerItem.BrowseObject>()
                                         .Select(b => b.AnalyzerItem)
                                         .ToImmutableArray();

            this.SelectedFolder = selectedObjects
                                  .OfType<AnalyzersFolderItem.BrowseObject>()
                                  .Select(b => b.Folder)
                                  .FirstOrDefault();

            var oldSelectedDiagnosticItems = this.SelectedDiagnosticItems;
            this.SelectedDiagnosticItems = selectedObjects
                                           .OfType<DiagnosticItem.BrowseObject>()
                                           .Select(b => b.DiagnosticItem)
                                           .ToImmutableArray();

            if (!object.ReferenceEquals(oldSelectedHierarchy, this.SelectedHierarchy))
            {
                this.SelectedHierarchyChanged?.Invoke(this, EventArgs.Empty);
            }

            if (oldSelectedItemId != this.SelectedItemId)
            {
                this.SelectedItemIdChanged?.Invoke(this, EventArgs.Empty);
            }

            if (oldSelectedDiagnosticItems != this.SelectedDiagnosticItems)
            {
                this.SelectedDiagnosticItemsChanged?.Invoke(this, EventArgs.Empty);
            }

            return VSConstants.S_OK;
        }
		public int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
		{
			bool isUnderSourceControl = false;
			if (pHierNew != null)
			{
				object fileName;
				pHierNew.GetProperty(itemidNew, (int)__VSHPROPID.VSHPROPID_Name, out fileName);
				if(fileName != null && fileName is String)
				{
					isUnderSourceControl = _locator((string) fileName);
				}
			}
			SelectionService.SetCmdUIContext(ContextCookie, Convert.ToInt32(isUnderSourceControl));
			return VSConstants.S_OK;
		}
Пример #5
0
 public int GetCurrentSelection(out IntPtr ppHier, out uint pitemid, out IVsMultiItemSelect ppMIS, out IntPtr ppSC) {
     if (_curHierarchy != null) {
         ppHier = Marshal.GetIUnknownForObject(_curHierarchy);
     } else {
         ppHier = IntPtr.Zero;
     }
     pitemid = _itemid;
     ppMIS = _multiSel;
     if (_selectionContainer != null) {
         ppSC = Marshal.GetIUnknownForObject(_selectionContainer);
     } else {
         ppSC = IntPtr.Zero;
     }
     return VSConstants.S_OK;
 }
Пример #6
0
        public int OnSelectChangeEx(IntPtr pHier, uint itemid, IVsMultiItemSelect pMIS, IntPtr pSC) {
            if (pHier != HIERARCHY_DONTCHANGE) {
                if (pHier != IntPtr.Zero) {
                    _curHierarchy = Marshal.GetObjectForIUnknown(pHier) as IVsHierarchy;
                } else {
                    _curHierarchy = null;
                }
                _itemid = itemid;
            }
            _multiSel = pMIS;
            if (pSC != null) {
                _selectionContainer = (ISelectionContainer)Marshal.GetObjectForIUnknown(pSC);
            } else {
                _selectionContainer = null;
            }

            _monSel.NotifySelectionContextChanged(this);

            return VSConstants.S_OK;
        }
Пример #7
0
        int IVsSelectionEvents.OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
        {
            // No-op on multi-selection.
            if (pMISNew == null &&
                pHierNew != null &&
                pHierNew.GetCanonicalName(itemidNew, out var path) == 0)
            {
                UpdateStartupFile(path);
            }

            return(0);
        }
Пример #8
0
 public int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
 {
     // NOTE: We don't care about selection changes like the solution explorer
     return(VSConstants.S_OK);
 }
Пример #9
0
 public int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
 {
     _vs._projectTarget = pHierNew as IOleCommandTarget;
     _vs._focusTarget   = pSCNew as IOleCommandTarget;
     return(VSConstants.S_OK);
 }
Пример #10
0
 public int GetCurrentSelection(out IntPtr ppHier, out uint pitemid, out IVsMultiItemSelect ppMIS) {
     throw new NotImplementedException();
 }
 public int OnSelectionChanged(IVsHierarchy pHierOld, [ComAliasName("Microsoft.VisualStudio.Shell.Interop.VSITEMID")]uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, [ComAliasName("Microsoft.VisualStudio.Shell.Interop.VSITEMID")]uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
 {
     return VSConstants.E_NOTIMPL;
 }
Пример #12
0
        public int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
        {
            // The selected item can be a Solution, Project, meta ProjectItem or file ProjectItem

            // Don't update the tool window if the selection has not changed
            if (itemidOld == itemidNew)
            {
                return(VSConstants.E_NOTIMPL);
            }

            // Don't update the tool window if it doesn't exist
            if (toolWindow == null)
            {
                return(VSConstants.E_NOTIMPL);
            }

            // Don't update the tool window if it isn't visible
            IVsWindowFrame windowFrame = (IVsWindowFrame)toolWindow.Frame;

            if (windowFrame.IsVisible() == VSConstants.S_FALSE)
            {
                return(VSConstants.E_NOTIMPL);
            }

            Debug.WriteLine(itemidOld + "->" + itemidNew);

            EnvDTE.SelectedItem si   = dte.SelectedItems.Item(1);
            EnvDTE.ProjectItem  item = si.ProjectItem;

            // Solutions and Projects don't have ProjectItems
            if (item != null && item.FileCount != 0)
            {
                string filePath = item.FileNames[0];

                // Only update for project items that exist (Not all of them do).
                if (File.Exists(filePath))
                {
                    UpdateToolWindow(filePath);

                    return(VSConstants.E_NOTIMPL);
                }
            }

            ClearToolWindow();

            return(VSConstants.E_NOTIMPL);
        }
Пример #13
0
 public int GetCurrentSelection(out IntPtr ppHier, out uint pitemid, out IVsMultiItemSelect ppMIS, out IntPtr ppSC)
 {
     return(_selection.GetCurrentSelection(out ppHier, out pitemid, out ppMIS, out ppSC));
 }
Пример #14
0
 int IVsSelectionEvents.OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
 {
     if (pHierNew != null)
     {
         string itemName;
         //pHierNew.GetProperty(itemidNew, (int)__VSHPROPID.VSHPROPID_Name, out itemName);
         pHierNew.GetCanonicalName(itemidNew, out itemName);
         bool activectx = itemName != null && (itemName.ToString().Contains("Views") || itemName.ToString().Contains("views"));
         if (activectx)
         {
             object temp;
             hierarchy = pHierNew;
             pHierNew.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectDir, out temp);
             projectDir = temp.ToString();
             //root = projectFullName.Substring(0, projectFullName.LastIndexOf('\\') + 1);
             pHierNew.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectName, out temp);
             projectName     = temp.ToString();
             viewsFolderName = itemName.ToString();
         }
         int factive = (activectx)? 1 : 0;
         SelectionService.SetCmdUIContext(contextCookie, factive);
     }
     return(VSConstants.S_OK);
 }
        public static bool GetSingleSelectedItem(out IVsHierarchy hierarchy, out uint itemID)
        {
            hierarchy = null;
            itemID    = VSConstants.VSITEMID_NIL;
            int hresult = VSConstants.S_OK;

            var monitorSelection = Package.GetGlobalService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;
            var solution         = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution;

            if ((monitorSelection == null) || (solution == null))
            {
                return(false);
            }

            IVsMultiItemSelect multiItemSelect       = null;
            IntPtr             hierarchyPtr          = IntPtr.Zero;
            IntPtr             selectionContainerPtr = IntPtr.Zero;

            try {
                hresult = monitorSelection.GetCurrentSelection(out hierarchyPtr, out itemID, out multiItemSelect, out selectionContainerPtr);
                if (ErrorHandler.Failed(hresult) || (hierarchyPtr == IntPtr.Zero) || (itemID == VSConstants.VSITEMID_NIL))
                {
                    return(false);
                }

                if (multiItemSelect != null)
                {
                    return(false);
                }

                if (itemID == VSConstants.VSITEMID_ROOT)
                {
                    return(false);
                }

                hierarchy = Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy;
                if (hierarchy == null)
                {
                    return(false);
                }

                Guid guidProjectID = Guid.Empty;

                if (ErrorHandler.Failed(solution.GetGuidOfProject(hierarchy, out guidProjectID)))
                {
                    return(false);
                }

                return(true);
            } finally {
                if (selectionContainerPtr != IntPtr.Zero)
                {
                    Marshal.Release(selectionContainerPtr);
                }

                if (hierarchyPtr != IntPtr.Zero)
                {
                    Marshal.Release(hierarchyPtr);
                }
            }
        }
 public int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
 {
     _activeFormChanged();
     return(0);
 }
Пример #17
0
        public static IVsHierarchy GetSelectedHierarchy(this IVsMonitorSelection monitorSelection, IUIThread uiThread)
        {
            var hierarchyPtr       = IntPtr.Zero;
            var selectionContainer = IntPtr.Zero;

            return(uiThread.Invoke(() =>
            {
                try
                {
                    // Get the current project hierarchy, project item, and selection container for the current selection
                    // If the selection spans multiple hierarchies, hierarchyPtr is Zero.
                    // So fast path is for non-zero result (most common case of single active project/item).
                    uint itemid;
                    IVsMultiItemSelect multiItemSelect = null;
                    ErrorHandler.ThrowOnFailure(monitorSelection.GetCurrentSelection(out hierarchyPtr, out itemid, out multiItemSelect, out selectionContainer));

                    // There may be no selection at all.
                    if (itemid == VSConstants.VSITEMID_NIL)
                    {
                        return null;
                    }

                    if (itemid == VSConstants.VSITEMID_ROOT)
                    {
                        // The root selection could be the solution itself, so no project is active.
                        if (hierarchyPtr == IntPtr.Zero)
                        {
                            return null;
                        }
                        else
                        {
                            return (IVsHierarchy)Marshal.GetTypedObjectForIUnknown(hierarchyPtr, typeof(IVsHierarchy));
                        }
                    }

                    // We may have a single item selection, so we can safely pick its owning project/hierarchy.
                    if (itemid != VSConstants.VSITEMID_SELECTION)
                    {
                        return (IVsHierarchy)Marshal.GetTypedObjectForIUnknown(hierarchyPtr, typeof(IVsHierarchy));
                    }

                    // Otherwise, this is a multiple item selection within the same hierarchy,
                    // we select he hierarchy.
                    uint numberOfSelectedItems;
                    int isSingleHierarchyInt;
                    ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectionInfo(out numberOfSelectedItems, out isSingleHierarchyInt));
                    var isSingleHierarchy = (isSingleHierarchyInt != 0);

                    if (isSingleHierarchy)
                    {
                        return (IVsHierarchy)Marshal.GetTypedObjectForIUnknown(hierarchyPtr, typeof(IVsHierarchy));
                    }

                    return null;
                }
                finally
                {
                    if (hierarchyPtr != IntPtr.Zero)
                    {
                        Marshal.Release(hierarchyPtr);
                    }
                    if (selectionContainer != IntPtr.Zero)
                    {
                        Marshal.Release(selectionContainer);
                    }
                }
            }));
        }
Пример #18
0
        public static IEnumerable <Tuple <IVsHierarchy, uint> > GetSelection(this IVsMonitorSelection monitorSelection, IUIThread uiThread, IVsHierarchy solution)
        {
            var hierarchyPtr       = IntPtr.Zero;
            var selectionContainer = IntPtr.Zero;

            return(uiThread.Invoke(() =>
            {
                try
                {
                    // Get the current project hierarchy, project item, and selection container for the current selection
                    // If the selection spans multiple hierarchies, hierarchyPtr is Zero
                    uint itemid;
                    IVsMultiItemSelect multiItemSelect = null;
                    ErrorHandler.ThrowOnFailure(monitorSelection.GetCurrentSelection(out hierarchyPtr, out itemid, out multiItemSelect, out selectionContainer));

                    if (itemid == VSConstants.VSITEMID_NIL)
                    {
                        return Enumerable.Empty <Tuple <IVsHierarchy, uint> >();
                    }

                    if (itemid == VSConstants.VSITEMID_ROOT)
                    {
                        if (hierarchyPtr == IntPtr.Zero)
                        {
                            return new[] { Tuple.Create(solution, VSConstants.VSITEMID_ROOT) }
                        }
                        ;
                        else
                        {
                            return new[] { Tuple.Create(
                                               (IVsHierarchy)Marshal.GetTypedObjectForIUnknown(hierarchyPtr, typeof(IVsHierarchy)),
                                               VSConstants.VSITEMID_ROOT) }
                        };
                    }

                    if (itemid != VSConstants.VSITEMID_SELECTION)
                    {
                        return new[] { Tuple.Create(
                                           (IVsHierarchy)Marshal.GetTypedObjectForIUnknown(hierarchyPtr, typeof(IVsHierarchy)),
                                           itemid) }
                    }
                    ;

                    // This is a multiple item selection.

                    uint numberOfSelectedItems;
                    int isSingleHierarchyInt;
                    ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectionInfo(out numberOfSelectedItems, out isSingleHierarchyInt));
                    var isSingleHierarchy = (isSingleHierarchyInt != 0);

                    var vsItemSelections = new VSITEMSELECTION[numberOfSelectedItems];
                    var flags = (isSingleHierarchy) ? (uint)__VSGSIFLAGS.GSI_fOmitHierPtrs : 0;
                    ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectedItems(flags, numberOfSelectedItems, vsItemSelections));

                    return vsItemSelections.Where(sel => sel.pHier != null)
                    // NOTE: we can return lazy results here, since
                    // the GetSelectedItems has already returned in the UI thread
                    // the array of results. We're just delaying the creation of the tuples
                    // in case they aren't all needed.
                    .Select(sel => Tuple.Create(sel.pHier, sel.itemid));
                }
                finally
                {
                    if (hierarchyPtr != IntPtr.Zero)
                    {
                        Marshal.Release(hierarchyPtr);
                    }
                    if (selectionContainer != IntPtr.Zero)
                    {
                        Marshal.Release(selectionContainer);
                    }
                }
            }));
        }
 int IVsSelectionEvents.OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
 {
     return S_OK;
 }
Пример #20
0
 public void OnSelectChangeEx(IVsHierarchy pHier, uint itemid, IVsMultiItemSelect pMIS, ISelectionContainer pSC) {
     _curHierarchy = pHier;
     _itemid = itemid;
     OnSelectChangeEx(pMIS, pSC);
 }
        public int GetCurrentSelection(out IntPtr ppHier, out uint pitemid, out IVsMultiItemSelect ppMIS, out IntPtr ppSC) {
            ppMIS = _mis;
            ppSC = IntPtr.Zero;

            if (_hier != null) {
                ppHier = Marshal.GetIUnknownForObject(_hier);
                if (_mis == null) {
                    pitemid = _itemid;
                } else {
                    pitemid = VSConstants.VSITEMID_SELECTION;
                }
            } else {
                ppHier = IntPtr.Zero;
                pitemid = 0;
            }

            return VSConstants.S_OK;
        }
Пример #22
0
        private static VSITEMSELECTION[] GetSelectedItems(IVsMultiItemSelect multiSelect)
        {
            var selectedItemsCount = GetSelectedItemsCount(multiSelect);
            var selectedItems = new VSITEMSELECTION[selectedItemsCount];

            if (selectedItemsCount > 0)
            {
                ErrorHandler.ThrowOnFailure(multiSelect.GetSelectedItems(0, selectedItemsCount, selectedItems));
            }

            return selectedItems;
        }
Пример #23
0
        private static uint GetSelectedItemsCount(IVsMultiItemSelect multiSelect)
        {
            uint selectedItemsCount;
            int isSingleHierarchy;

            ErrorHandler.ThrowOnFailure(multiSelect.GetSelectionInfo(out selectedItemsCount, out isSingleHierarchy));

            return selectedItemsCount;
        }
 int IVsMonitorSelection.GetCurrentSelection(out IntPtr ppHier, out uint pitemid, out IVsMultiItemSelect ppMIS, out IntPtr ppSC)
 {
     throw new NotImplementedException();
 }
Пример #25
0
        /// <summary>
        /// Gets all of the currently selected items.
        /// </summary>
        /// <returns></returns>
        private IEnumerable <VSITEMSELECTION> GetSelectedItems()
        {
            IVsMonitorSelection monitorSelection = _package.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection;

            IntPtr hierarchyPtr       = IntPtr.Zero;
            IntPtr selectionContainer = IntPtr.Zero;

            try {
                uint selectionItemId;
                IVsMultiItemSelect multiItemSelect = null;
                ErrorHandler.ThrowOnFailure(monitorSelection.GetCurrentSelection(out hierarchyPtr, out selectionItemId, out multiItemSelect, out selectionContainer));

                if (selectionItemId != VSConstants.VSITEMID_NIL && hierarchyPtr != IntPtr.Zero)
                {
                    IVsHierarchy hierarchy = Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy;

                    if (selectionItemId != VSConstants.VSITEMID_SELECTION)
                    {
                        // This is a single selection. Compare hirarchy with our hierarchy and get node from itemid
                        if (Utilities.IsSameComObject(this, hierarchy))
                        {
                            yield return(new VSITEMSELECTION()
                            {
                                itemid = selectionItemId, pHier = hierarchy
                            });
                        }
                    }
                    else if (multiItemSelect != null)
                    {
                        // This is a multiple item selection.
                        // Get number of items selected and also determine if the items are located in more than one hierarchy

                        uint numberOfSelectedItems;
                        int  isSingleHierarchyInt;
                        ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectionInfo(out numberOfSelectedItems, out isSingleHierarchyInt));
                        bool isSingleHierarchy = (isSingleHierarchyInt != 0);

                        // Now loop all selected items and add to the list only those that are selected within this hierarchy
                        if (!isSingleHierarchy || (isSingleHierarchy && Utilities.IsSameComObject(this, hierarchy)))
                        {
                            Debug.Assert(numberOfSelectedItems > 0, "Bad number of selected itemd");
                            VSITEMSELECTION[] vsItemSelections = new VSITEMSELECTION[numberOfSelectedItems];
                            uint flags = (isSingleHierarchy) ? (uint)__VSGSIFLAGS.GSI_fOmitHierPtrs : 0;
                            ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectedItems(flags, numberOfSelectedItems, vsItemSelections));

                            foreach (VSITEMSELECTION vsItemSelection in vsItemSelections)
                            {
                                yield return(new VSITEMSELECTION()
                                {
                                    itemid = vsItemSelection.itemid, pHier = hierarchy
                                });
                            }
                        }
                    }
                }
            } finally {
                if (hierarchyPtr != IntPtr.Zero)
                {
                    Marshal.Release(hierarchyPtr);
                }
                if (selectionContainer != IntPtr.Zero)
                {
                    Marshal.Release(selectionContainer);
                }
            }
        }
Пример #26
0
		public int GetCurrentSelection(out IntPtr ppHier, out uint pitemid, out IVsMultiItemSelect ppMIS, out IntPtr ppSC) {
			pitemid = 0;
			ppHier = IntPtr.Zero;
			ppMIS = null;
			ppSC = IntPtr.Zero;
			return 0;
		}
 int IVsSelectionEvents.OnSelectionChanged(IVsHierarchy pHierOld, [ComAliasName("Microsoft.VisualStudio.Shell.Interop.VSITEMID")] uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, [ComAliasName("Microsoft.VisualStudio.Shell.Interop.VSITEMID")] uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
 => VSConstants.E_NOTIMPL;
Пример #28
0
        public int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
        {
            if (pHierNew == this)
            {
                if (HierarchyNode.FirstChild == null)
                {
                    RefreshTree();
                }
                return(VSConstants.S_OK);
            }

            return(VSConstants.S_OK);
        }
Пример #29
0
        private void OnBeforeQueryStatus(object sender, EventArgs e)
        {
            projects.Clear();

            var cmd = sender as OleMenuCommand;

            if (cmd == null)
            {
                return;
            }

            IVsMonitorSelection monitorSelection = sp.GetService(typeof(IVsMonitorSelection)) as IVsMonitorSelection;

            if (monitorSelection == null)
            {
                return;
            }

            IntPtr             hier = IntPtr.Zero;
            UInt32             itemid;
            IVsMultiItemSelect multiitem = null;
            IntPtr             container = IntPtr.Zero;

            try
            {
                monitorSelection.GetCurrentSelection(out hier, out itemid, out multiitem, out container);

                /* Bail out if nothing is selected */
                if (itemid != VSConstants.VSITEMID_SELECTION && itemid != VSConstants.VSITEMID_NIL)
                {
                    if (hier == IntPtr.Zero)
                    {
                        /* FIXME: parse the whole solution */
                    }
                    else
                    {
                        object project = null;

                        IVsHierarchy hierarchy = (IVsHierarchy)Marshal.GetObjectForIUnknown(hier);
                        hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out project);
                        projects.Add(project as Project);
                    }
                }
            }
            finally
            {
                if (hier != IntPtr.Zero)
                {
                    Marshal.Release(hier);
                }

                if (container != IntPtr.Zero)
                {
                    Marshal.Release(container);
                }
            }

            // If there are .l or .y files in this project, display the context menu
            Visible = false;
            foreach (Project project in projects)
            {
                foreach (ProjectItem item in ParseProjectItems(project))
                {
                    if (item.Name.EndsWith("-scanner.l", StringComparison.CurrentCultureIgnoreCase) ||
                        item.Name.EndsWith("-parser.y", StringComparison.CurrentCultureIgnoreCase))
                    {
                        Visible = true;
                    }
                }
            }
        }
Пример #30
0
        /// <summary>
        /// Verifies if a single object is selected
        /// </summary>
        /// <param name="hierarchy">Current selected project hierarchy</param>
        /// <param name="itemid">ID of the selected item</param>
        /// <returns>True if a single item is selected</returns>
        public static bool IsSingleProjectItemSelection(out IVsHierarchy hierarchy, out uint itemid)
        {
            hierarchy = null;
            itemid    = VSConstants.VSITEMID_NIL;
            int hr = VSConstants.S_OK;

            IVsMonitorSelection monitorSelection = Package.GetGlobalService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;
            IVsSolution         solution         = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution;

            if (monitorSelection == null || solution == null)
            {
                return(false);
            }

            IVsMultiItemSelect multiItemSelect       = null;
            IntPtr             hierarchyPtr          = IntPtr.Zero;
            IntPtr             selectionContainerPtr = IntPtr.Zero;

            try
            {
                hr = monitorSelection.GetCurrentSelection(out hierarchyPtr, out itemid, out multiItemSelect, out selectionContainerPtr);

                if (ErrorHandler.Failed(hr) || hierarchyPtr == IntPtr.Zero || itemid == VSConstants.VSITEMID_NIL)
                {
                    // there is no selection
                    return(false);
                }

                if (multiItemSelect != null)
                {
                    // multiple items are selected
                    return(false);
                }

                if (itemid == VSConstants.VSITEMID_ROOT)
                {
                    // there is a hierarchy root node selected, thus it is not a single item inside a project
                    return(false);
                }

                hierarchy = Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy;
                if (hierarchy == null)
                {
                    return(false);
                }

                Guid guidProjectID = Guid.Empty;

                if (ErrorHandler.Failed(solution.GetGuidOfProject(hierarchy, out guidProjectID)))
                {
                    return(false); // hierarchy is not a project inside the Solution if it does not have a ProjectID Guid
                }

                // if we got this far then there is a single project item selected
                return(true);
            }
            finally
            {
                if (selectionContainerPtr != IntPtr.Zero)
                {
                    Marshal.Release(selectionContainerPtr);
                }

                if (hierarchyPtr != IntPtr.Zero)
                {
                    Marshal.Release(hierarchyPtr);
                }
            }
        }
Пример #31
0
        public int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
        {
            bool isUnderSourceControl = false;

            if (pHierNew != null)
            {
                object fileName;
                pHierNew.GetProperty(itemidNew, (int)__VSHPROPID.VSHPROPID_Name, out fileName);
                if (fileName != null && fileName is String)
                {
                    isUnderSourceControl = _locator((string)fileName);
                }
            }
            SelectionService.SetCmdUIContext(ContextCookie, Convert.ToInt32(isUnderSourceControl));
            return(VSConstants.S_OK);
        }
 int IVsSelectionEvents.OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
 {
     return(S_OK);
 }
Пример #33
0
        /// <summary>
        /// Retrieves the selected hierarchy item in the given solution
        /// </summary>
        /// <param name="solution">Current solution</param>
        /// <returns>Selected hierarchy</returns>
        public static IVsHierarchy GetSelectedHierarchy(this IVsSolution solution, out uint itemId)
        {
            // Set default item id
            itemId = VSConstants.VSITEMID_NIL;

            // Check for solution is null or not!
            if (solution == null)
            {
                return(null);
            }

            // Create handles
            IVsMultiItemSelect multiItemSelect       = null;
            IntPtr             hierarchyPtr          = IntPtr.Zero;
            IntPtr             selectionContainerPtr = IntPtr.Zero;
            IVsHierarchy       selectedHierarchy     = null;
            Guid guidProjectID = Guid.Empty;

            // Get global service
            IVsMonitorSelection monitorSelection = Package.GetGlobalService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;

            // Check monitor selection is null or not!
            if (monitorSelection == null)
            {
                return(null);
            }

            try
            {
                // Retrieve selection
                int hr = monitorSelection.GetCurrentSelection(out hierarchyPtr, out itemId, out multiItemSelect, out selectionContainerPtr);

                // Check check check
                if (ErrorHandler.Failed(hr) || hierarchyPtr == IntPtr.Zero ||
                    itemId == VSConstants.VSITEMID_NIL || multiItemSelect != null ||
                    itemId == VSConstants.VSITEMID_ROOT)
                {
                    return(null);
                }

                // Retrieve hierarchy
                if ((selectedHierarchy = Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy) == null)
                {
                    return(null);
                }

                if (ErrorHandler.Failed(solution.GetGuidOfProject(selectedHierarchy, out guidProjectID)))
                {
                    return(null); // hierarchy is not a project inside the Solution if it does not have a ProjectID Guid
                }
                // if we got this far then there is a single project item selected
                return(selectedHierarchy);
            }
            finally
            {
                if (selectionContainerPtr != IntPtr.Zero)
                {
                    Marshal.Release(selectionContainerPtr);
                }

                if (hierarchyPtr != IntPtr.Zero)
                {
                    Marshal.Release(hierarchyPtr);
                }
            }
        }
Пример #34
0
        public int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
        {
            SelectionHandler1 handler = SelectionChangedEvent;

            if (handler != null)
            {
                handler(pHierOld, itemidOld, pMISOld, pSCOld, pHierNew, itemidNew, pMISNew, pSCNew);
            }

            return(VSConstants.S_OK);
        }
Пример #35
0
        private bool IsSingleProjectItemSelection(out IVsHierarchy hierarchy, out uint itemid)
        {
            hierarchy = null;
            itemid    = VSConstants.VSITEMID_NIL;
            var hr = VSConstants.S_OK;

            var monitorSelection = Package.GetGlobalService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;

            var solution = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution;

            if (monitorSelection == null || solution == null)
            {
                return(false);
            }

            IVsMultiItemSelect multiItemSelect = null;
            var hierarchyPtr          = IntPtr.Zero;
            var selectionContainerPtr = IntPtr.Zero;

            try
            {
                hr = monitorSelection.GetCurrentSelection(out hierarchyPtr, out itemid, out multiItemSelect,
                                                          out selectionContainerPtr);

                if (ErrorHandler.Failed(hr) || hierarchyPtr == IntPtr.Zero || itemid == VSConstants.VSITEMID_NIL)
                {
                    return(false);
                }

                if (multiItemSelect != null)
                {
                    return(false);
                }

                if (itemid == VSConstants.VSITEMID_ROOT)
                {
                    return(false);
                }

                hierarchy = Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy;
                if (hierarchy == null)
                {
                    return(false);
                }

                var guidProjectID = Guid.Empty;

                if (ErrorHandler.Failed(solution.GetGuidOfProject(hierarchy, out guidProjectID)))
                {
                    // hierarchy is not a project inside the Solution if it does not have a ProjectID Guid
                    return(false);
                }

                return(true);
            }
            finally
            {
                if (selectionContainerPtr != IntPtr.Zero)
                {
                    Marshal.Release(selectionContainerPtr);
                }

                if (hierarchyPtr != IntPtr.Zero)
                {
                    Marshal.Release(hierarchyPtr);
                }
            }
        }
Пример #36
0
 public int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
 {
     return(VSConstants.S_OK);
 }
 int IVsMonitorSelection.GetCurrentSelection(out IntPtr ppHier, out uint pitemid, out IVsMultiItemSelect ppMIS, out IntPtr ppSC)
 {
     throw new NotImplementedException();
 }
Пример #38
0
 public int GetCurrentSelection(out IntPtr ppHier, out uint pitemid, out IVsMultiItemSelect ppMIS)
 {
     throw new NotImplementedException();
 }
        int IVsSelectionEvents.OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
        {
            SelectedGraphNode = GetCurrentSelectionGraphNode(pSCNew);
            SelectedFileName = null;
            if (pHierNew != null)
            {
                string itemName;
                pHierNew.GetCanonicalName(itemidNew, out itemName);
                if (itemName != null)
                    SelectedFileName = itemName.ToString();
            }

            return VSConstants.S_OK;
        }
Пример #40
0
 public int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
 {
     // NOTE: We don't care about selection changes like the solution explorer
     return VSConstants.S_OK;
 }
Пример #41
0
 public int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
 {
     LogMessage($"{nameof(OnSelectionChanged)}");
     return(VSConstants.S_OK);
 }
Пример #42
0
        public void OnSelectChangeEx(IVsMultiItemSelect pMIS, ISelectionContainer pSC) {
            _multiSel = pMIS;
            _selectionContainer = pSC;

            _monSel.NotifySelectionContextChanged(this);
        }
Пример #43
0
 public void OnSelectChangeEx(IVsHierarchy pHier, uint itemid, IVsMultiItemSelect pMIS, ISelectionContainer pSC)
 {
     _curHierarchy = pHier;
     _itemid       = itemid;
     OnSelectChangeEx(pMIS, pSC);
 }
Пример #44
0
 public void GetCurrentSelection(out IVsHierarchy ppHier, out uint pitemid, out IVsMultiItemSelect ppMIS, out ISelectionContainer ppSC) {
     ppHier = _curHierarchy;
     pitemid = _itemid;
     ppMIS = _multiSel;
     ppSC = _selectionContainer;
 }
        /// <summary>
        /// Returns a list of valid shader files from the current file selection
        /// </summary>
        /// <param name="shaderFileNames">List to be filled with all valid shader files from the current selection</param>
        /// <returns>True if at least one shader has been selected</returns>
        public bool GetSelectedShaderFiles(List <ShaderFile> shaderFiles)
        {
            IVsHierarchy hierarchy = null;
            uint         itemid    = VSConstants.VSITEMID_NIL;
            int          hr        = VSConstants.S_OK;

            var monitorSelection = Package.GetGlobalService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection;
            var solution         = Package.GetGlobalService(typeof(SVsSolution)) as IVsSolution;

            if (monitorSelection == null || solution == null)
            {
                return(false);
            }

            IVsMultiItemSelect multiItemSelect       = null;
            IntPtr             hierarchyPtr          = IntPtr.Zero;
            IntPtr             selectionContainerPtr = IntPtr.Zero;

            try
            {
                hr = monitorSelection.GetCurrentSelection(out hierarchyPtr, out itemid, out multiItemSelect, out selectionContainerPtr);

                if (ErrorHandler.Failed(hr) || hierarchyPtr == IntPtr.Zero || itemid == VSConstants.VSITEMID_NIL)
                {
                    return(false);
                }

                hierarchy = Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy;
                if (hierarchy == null)
                {
                    return(false);
                }

                List <uint> itemids = new List <uint>();

                if (multiItemSelect == null)
                {
                    ReadItemHierarchy(itemid, hierarchy, itemids);
                }
                else
                {
                    // todo: Read hierarchy for multi selects
                    uint itemCount        = 0;
                    int  fSingleHierarchy = 0;
                    hr = multiItemSelect.GetSelectionInfo(out itemCount, out fSingleHierarchy);

                    VSITEMSELECTION[] items = new VSITEMSELECTION[itemCount];
                    hr = multiItemSelect.GetSelectedItems(0, itemCount, items);

                    foreach (var item in items)
                    {
                        itemids.Add(item.itemid);
                    }
                }

                foreach (var id in itemids)
                {
                    string filepath = null;
                    ((IVsProject)hierarchy).GetMkDocument(id, out filepath);
                    if (filepath != null && ReferenceCompiler.IsShaderFile(filepath))
                    {
                        var transformFileInfo = new FileInfo(filepath);
                        shaderFiles.Add(new ShaderFile(id, hierarchy, filepath));
                    }
                }

                // todo: hierarchy node
                if (itemid == VSConstants.VSITEMID_ROOT)
                {
                    return(false);
                }

                Guid guidProjectID = Guid.Empty;

                if (ErrorHandler.Failed(solution.GetGuidOfProject(hierarchy, out guidProjectID)))
                {
                    return(false);
                }

                return(shaderFiles.Count > 0);
            }
            finally
            {
                if (selectionContainerPtr != IntPtr.Zero)
                {
                    Marshal.Release(selectionContainerPtr);
                }
                if (hierarchyPtr != IntPtr.Zero)
                {
                    Marshal.Release(hierarchyPtr);
                }
            }
        }
        /// <summary>
        /// Monitor for changes to the active project and notify the topic previewer user control when a
        /// new SHFB project is selected as the active project.
        /// </summary>
        /// <param name="pHierOld">The hierarchy for the previously selected item</param>
        /// <param name="itemidOld">Project item identifier for the previously selected item</param>
        /// <param name="pMISOld">Interface for previous multi-selection items</param>
        /// <param name="pSCOld">Interface for the previous selection container</param>
        /// <param name="pHierNew">The hierarchy for the new selection</param>
        /// <param name="itemidNew">Project item identifier for the new selection</param>
        /// <param name="pMISNew">Interface for new multi-selection items</param>
        /// <param name="pSCNew">Interface for the new selection container</param>
        /// <returns></returns>
        int IVsSelectionEvents.OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld,
          IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew,
          IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
        {
            SandcastleProject shfbProject = null;
            object project;

            if(pHierOld == null || !pHierOld.Equals(pHierNew))
            {
                if(ucTopicPreviewer != null)
                {
                    if(pHierNew != null)
                    {
                        ErrorHandler.ThrowOnFailure(pHierNew.GetProperty(VSConstants.VSITEMID_ROOT,
                            (int)__VSHPROPID.VSHPROPID_ExtObject, out project));

                        EnvDTE.Project envDTEProject = project as EnvDTE.Project;

                        if(envDTEProject != null)
                        {
                            SandcastleBuilderProjectNode projectNode =
                                envDTEProject.Object as SandcastleBuilderProjectNode;

                            if(projectNode != null)
                                shfbProject = projectNode.SandcastleProject;
                        }
                    }

                    // We'll keep the existing reference unless it changes or the project is closed
                    if((shfbProject == null && pHierNew == null && ucTopicPreviewer.CurrentProject != null) ||
                      (shfbProject != null && (ucTopicPreviewer.CurrentProject == null ||
                      ucTopicPreviewer.CurrentProject.Filename != shfbProject.Filename)))
                        ucTopicPreviewer.CurrentProject = shfbProject;
                }
            }

            return VSConstants.S_OK;
        }
        /// <summary>
        /// Gets the list of directly selected VSITEMSELECTION objects
        /// </summary>
        /// <returns>A list of VSITEMSELECTION objects</returns>
        private async Task <IList <VSITEMSELECTION> > GetSelectedNodes()
        {
            // Retrieve shell interface in order to get current selection
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsMonitorSelection monitorSelection = await _sccProvider.GetServiceAsync(typeof(IVsMonitorSelection)) as IVsMonitorSelection;

            Debug.Assert(monitorSelection != null, "Could not get the IVsMonitorSelection object from the services exposed by this project");

            if (monitorSelection == null)
            {
                throw new InvalidOperationException();
            }

            List <VSITEMSELECTION> selectedNodes = new List <VSITEMSELECTION>();
            IntPtr hierarchyPtr       = IntPtr.Zero;
            IntPtr selectionContainer = IntPtr.Zero;

            try
            {
                // Get the current project hierarchy, project item, and selection container for the current selection
                // If the selection spans multiple hierachies, hierarchyPtr is Zero
                uint itemid;
                IVsMultiItemSelect multiItemSelect = null;
                ErrorHandler.ThrowOnFailure(monitorSelection.GetCurrentSelection(out hierarchyPtr, out itemid, out multiItemSelect, out selectionContainer));

                if (itemid != VSConstants.VSITEMID_SELECTION)
                {
                    // We only care if there are nodes selected in the tree
                    if (itemid != VSConstants.VSITEMID_NIL)
                    {
                        if (hierarchyPtr == IntPtr.Zero)
                        {
                            // Solution is selected
                            VSITEMSELECTION vsItemSelection;
                            vsItemSelection.pHier  = null;
                            vsItemSelection.itemid = itemid;
                            selectedNodes.Add(vsItemSelection);
                        }
                        else
                        {
                            IVsHierarchy hierarchy = (IVsHierarchy)Marshal.GetObjectForIUnknown(hierarchyPtr);
                            // Single item selection
                            VSITEMSELECTION vsItemSelection;
                            vsItemSelection.pHier  = hierarchy;
                            vsItemSelection.itemid = itemid;
                            selectedNodes.Add(vsItemSelection);
                        }
                    }
                }
                else
                {
                    if (multiItemSelect != null)
                    {
                        // This is a multiple item selection.

                        //Get number of items selected and also determine if the items are located in more than one hierarchy
                        uint numberOfSelectedItems;
                        int  isSingleHierarchyInt;
                        ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectionInfo(out numberOfSelectedItems, out isSingleHierarchyInt));
                        bool isSingleHierarchy = (isSingleHierarchyInt != 0);

                        // Now loop all selected items and add them to the list
                        Debug.Assert(numberOfSelectedItems > 0, "Bad number of selected itemd");
                        if (numberOfSelectedItems > 0)
                        {
                            VSITEMSELECTION[] vsItemSelections = new VSITEMSELECTION[numberOfSelectedItems];
                            ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectedItems(0, numberOfSelectedItems, vsItemSelections));
                            foreach (VSITEMSELECTION vsItemSelection in vsItemSelections)
                            {
                                selectedNodes.Add(vsItemSelection);
                            }
                        }
                    }
                }
            }
            finally
            {
                if (hierarchyPtr != IntPtr.Zero)
                {
                    Marshal.Release(hierarchyPtr);
                }
                if (selectionContainer != IntPtr.Zero)
                {
                    Marshal.Release(selectionContainer);
                }
            }

            return(selectedNodes);
        }
        public int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
        {
            // The selected item can be a Solution, Project, meta ProjectItem or file ProjectItem

              // Don't update the tool window if the selection has not changed
              if (itemidOld == itemidNew)
              {
            return VSConstants.E_NOTIMPL;
              }

              // Don't update the tool window if it doesn't exist
              if (toolWindow == null)
              {
            return VSConstants.E_NOTIMPL;
              }

              // Don't update the tool window if it isn't visible
              IVsWindowFrame windowFrame = (IVsWindowFrame)toolWindow.Frame;
              if (windowFrame.IsVisible() == VSConstants.S_FALSE)
              {
            return VSConstants.E_NOTIMPL;
              }

              Debug.WriteLine(itemidOld +"->" + itemidNew);

              EnvDTE.SelectedItem si = dte.SelectedItems.Item(1);
              EnvDTE.ProjectItem item = si.ProjectItem;

              // Solutions and Projects don't have ProjectItems
              if (item != null && item.FileCount != 0)
              {
            string filePath = item.FileNames[0];

            // Only update for project items that exist (Not all of them do).
            if (File.Exists(filePath))
            {
              UpdateToolWindow(filePath);

              return VSConstants.E_NOTIMPL;
            }
              }

              ClearToolWindow();

              return VSConstants.E_NOTIMPL;
        }
Пример #49
0
        /// <summary>
        /// Builds a list of nodes currently selected in the solution explorer
        /// </summary>
        /// <returns></returns>
        public List <ItemNode> GetSelectedNodes()
        {
            var    selected_nodes     = new List <ItemNode>();
            IntPtr hierarchyPtr       = IntPtr.Zero;
            IntPtr selectionContainer = IntPtr.Zero;

            try
            {
                // Get the current project hierarchy, project item, and selection container for the current selection
                // If the selection spans multiple hierachies, hierarchyPtr is Zero
                uint itemid;
                IVsMultiItemSelect multiItemSelect = null;
                ErrorHandler.ThrowOnFailure(GlobalServices.SelectionMonitor.GetCurrentSelection(out hierarchyPtr, out itemid, out multiItemSelect, out selectionContainer));
                // We only care if there are one ore more nodes selected in the tree
                if (itemid != VSConstants.VSITEMID_NIL && hierarchyPtr != IntPtr.Zero)
                {
                    IVsHierarchy hierarchy = Marshal.GetObjectForIUnknown(hierarchyPtr) as IVsHierarchy;

                    if (itemid != VSConstants.VSITEMID_SELECTION)
                    {
                        // This is a single selection. Compare hirarchy with our hierarchy and get node from itemid
                        ItemNode node;
                        if (GlobalServices.IsSameComObject(Project, hierarchy) && itemMap.TryGetValue(itemid, out node))
                        {
                            selected_nodes.Add(node);
                        }
                    }
                    else if (multiItemSelect != null)
                    {
                        // This is a multiple item selection.

                        //Get number of items selected and also determine if the items are located in more than one hierarchy
                        uint numberOfSelectedItems;
                        int  isSingleHierarchyInt;
                        ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectionInfo(out numberOfSelectedItems, out isSingleHierarchyInt));
                        bool isSingleHierarchy = (isSingleHierarchyInt != 0);

                        // Now loop all selected items and add to the list only those that are selected within this hierarchy
                        if (!isSingleHierarchy || (isSingleHierarchy && GlobalServices.IsSameComObject(Project, hierarchy)))
                        {
                            Debug.Assert(numberOfSelectedItems > 0, "Bad number of selected items");
                            VSITEMSELECTION[] vsItemSelections = new VSITEMSELECTION[numberOfSelectedItems];
                            uint flags = (isSingleHierarchy) ? (uint)__VSGSIFLAGS.GSI_fOmitHierPtrs : 0;
                            ErrorHandler.ThrowOnFailure(multiItemSelect.GetSelectedItems(flags, numberOfSelectedItems, vsItemSelections));
                            foreach (VSITEMSELECTION vsItemSelection in vsItemSelections)
                            {
                                if (isSingleHierarchy || GlobalServices.IsSameComObject(Project, vsItemSelection.pHier))
                                {
                                    ItemNode node;
                                    if (itemMap.TryGetValue(vsItemSelection.itemid, out node))
                                    {
                                        selected_nodes.Add(node);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                if (hierarchyPtr != IntPtr.Zero)
                {
                    Marshal.Release(hierarchyPtr);
                }
                if (selectionContainer != IntPtr.Zero)
                {
                    Marshal.Release(selectionContainer);
                }
            }
            return(selected_nodes);
        }
        int IVsSelectionEvents.OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (SelectionChanged != null)
            {
                SolutionItem?from = SolutionItem.FromHierarchy(pHierOld, itemidOld);
                SolutionItem?to   = SolutionItem.FromHierarchy(pHierNew, itemidNew);

                SelectionChanged.Invoke(this, new SelectionChangedEventArgs(from, to));
            }
            return(VSConstants.S_OK);
        }
        int IVsSelectionEvents.OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
        {
            SelectedGraphNode = GetCurrentSelectionGraphNode(pSCNew);
            SelectedFileName  = null;
            if (pHierNew != null)
            {
                string itemName;
                pHierNew.GetCanonicalName(itemidNew, out itemName);
                if (itemName != null)
                {
                    SelectedFileName = itemName.ToString();
                }
            }

            return(VSConstants.S_OK);
        }
Пример #52
0
        int IVsSelectionEvents.OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld,IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld,IVsHierarchy pHierNew, uint itemidNew,IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
        {
            if (pHierNew != null)
            {
                string itemName;
                //pHierNew.GetProperty(itemidNew, (int)__VSHPROPID.VSHPROPID_Name, out itemName);
                pHierNew.GetCanonicalName(itemidNew, out itemName);
                bool activectx = itemName != null && (itemName.ToString().Contains("Views") ||itemName.ToString().Contains("views"));
                if (activectx)
                {
                    object temp;
                    hierarchy = pHierNew;
                    pHierNew.GetProperty(VSConstants.VSITEMID_ROOT,(int)__VSHPROPID.VSHPROPID_ProjectDir, out temp);
                    projectDir = temp.ToString();
                    //root = projectFullName.Substring(0, projectFullName.LastIndexOf('\\') + 1);
                    pHierNew.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectName, out temp);
                    projectName = temp.ToString();
                    viewsFolderName = itemName.ToString();
                }
                int factive = (activectx)? 1 : 0;
                SelectionService.SetCmdUIContext(contextCookie, factive);

            }
            return VSConstants.S_OK;
        }
Пример #53
0
 /// <summary>
 /// Reports that the project hierarchy, item and/or selection container has changed.
 /// </summary>
 /// <returns>
 /// If the method succeeds, it returns <see cref="F:Microsoft.VisualStudio.VSConstants.S_OK"/>. If it fails, it returns an error code.
 /// </returns>
 /// <param name="pHierOld">[in] Pointer to the <see cref="T:Microsoft.VisualStudio.Shell.Interop.IVsHierarchy"/> interface of the project hierarchy for the previous selection.</param><param name="itemidOld">[in] Identifier of the project item for previous selection. For valid <paramref name="itemidOld"/> values, see VSITEMID.</param><param name="pMISOld">[in] Pointer to the <see cref="T:Microsoft.VisualStudio.Shell.Interop.IVsMultiItemSelect"/> interface to access a previous multiple selection.</param><param name="pSCOld">[in] Pointer to the <see cref="T:Microsoft.VisualStudio.Shell.Interop.ISelectionContainer"/> interface to access Properties window data for the previous selection.</param><param name="pHierNew">[in] Pointer to the <see cref="T:Microsoft.VisualStudio.Shell.Interop.IVsHierarchy"/> interface of the project hierarchy for the current selection.</param><param name="itemidNew">[in] Identifier of the project item for the current selection. For valid <paramref name="itemidNew"/> values, see VSITEMID.</param><param name="pMISNew">[in] Pointer to the <see cref="T:Microsoft.VisualStudio.Shell.Interop.IVsMultiItemSelect"/> interface for the current selection.</param><param name="pSCNew">[in] Pointer to the <see cref="T:Microsoft.VisualStudio.Shell.Interop.ISelectionContainer"/> interface for the current selection.</param>
 public int OnSelectionChanged(IVsHierarchy pHierOld, uint itemidOld, IVsMultiItemSelect pMISOld, ISelectionContainer pSCOld, IVsHierarchy pHierNew, uint itemidNew, IVsMultiItemSelect pMISNew, ISelectionContainer pSCNew)
 {
     string fullPath = "";
     if (pHierNew != null)
     {
         // Get the full path
         pHierNew.GetCanonicalName(itemidNew, out fullPath);
     }
     //if path is null, get it from solution level
     if (string.IsNullOrEmpty(fullPath))
     {
         fullPath = getSolutionFileName();
     }
     var directory = Path.GetDirectoryName(fullPath);
     //set the current dir var so we can use it in other parts of the service
     currentDir = directory;
     // Setup the rake menu for this path
     //setupRakeTasksMenu(directory);
     return VSConstants.S_OK;
 }