public void AddNode(NodeViewModel node) { Debug.Assert(node.ItemId != VSConstants.VSITEMID_NIL); _itemIdMap.Add(node.ItemId, node); if (node.ItemId != RootNodeItemId) { _maxItemId = Math.Max(_maxItemId, node.ItemId); } }
public CommandArgs(CommandID commandId, VsHierarchy hierarchy, NodeViewModel node, IntPtr variantIn, IntPtr variantOut) { Hierarchy = hierarchy; CommandId = commandId; Node = node; VariantIn = variantIn; VariantOut = variantOut; }
public bool FindNode(uint itemid, out NodeViewModel node) { node = null; if (itemid == 0 || itemid == VSConstants.VSITEMID_NIL || itemid == VSConstants.VSITEMID_SELECTION) return false; if (itemid != RootNodeItemId) return _itemIdMap.TryGetValue(itemid, out node); node = _rootNode; return node != null; }
public void AddChild(NodeViewModel node) { node._parent = this; node.ChildIndex = ChildrenImpl.Count; ChildrenImpl.Add(node); }
protected override void AddChildImpl(NodeViewModel node) { Invariants.CheckOperation(false, "Cannot add child node to a file node"); }
public FileNodeViewModel(NodeViewModel parent) : base(parent) { Invariants.CheckArgumentNotNull(parent, nameof(parent)); }
protected abstract void AddChildImpl(NodeViewModel node);
public void AddChild(NodeViewModel node) { AddChildImpl(node); }
private bool FindNodeByMonikerHelper(NodeViewModel parentNode, string searchMoniker, out NodeViewModel foundNode) { foundNode = null; if (parentNode == null) { return(false); } if (SystemPathComparer.Instance.StringComparer.Equals(parentNode.FullPath, searchMoniker)) { foundNode = parentNode; return(true); } foreach (var child in parentNode.ChildrenImpl) { if (FindNodeByMonikerHelper(child, searchMoniker, out foundNode)) { return(true); } } return(false); }
private static NodeViewModel GetCommonOldNode(NodeViewModel newParent, int index, ArrayDiffsResult <NodeViewModel> diffs, NodeViewModel newChildNode) { if (diffs.CommonItems.Count == newParent.Children.Count) { return(diffs.CommonItems[index].LeftItem); } foreach (var pair in diffs.CommonItems.ToForeachEnum()) { if (pair.RigthtItem == newChildNode) { return(pair.LeftItem); } } return(null); }
private void AddNodeForChildren(FileSystemEntry entry, NodeViewModel oldParent, NodeViewModel newParent) { Debug.Assert(entry != null); Debug.Assert(newParent != null); Debug.Assert(newParent.Children.Count == 0); // Create children nodes var directoryEntry = entry as DirectoryEntry; if (directoryEntry != null) { foreach (var childEntry in directoryEntry.Entries.ToForeachEnum()) { var child = CreateNodeViewModel(childEntry, newParent); newParent.AddChild(child); } } // Note: It is correct to compare the "Name" property only for computing // diffs, as we are guaranteed that both nodes have the same parent, hence // are located in the same directory. We also use the // System.Reflection.Type to handle the fact a directory can be deleted // and then a name with the same name can be added. We need to consider // that as a pair of "delete/add" instead of a "no-op". var diffs = ArrayUtilities.BuildArrayDiffs( oldParent == null ? ArrayUtilities.EmptyList <NodeViewModel> .Instance : oldParent.Children, newParent.Children, NodeTypeAndNameComparer.Instance); foreach (var item in diffs.LeftOnlyItems.ToForeachEnum()) { _changes.DeletedItems.Add(item.ItemId); } foreach (var newChild in diffs.RightOnlyItems.ToForeachEnum()) { newChild.ItemId = _newNodeNextItemId; _newNodeNextItemId++; newChild.IsExpanded = newParent.IsRoot; _newNodes.AddNode(newChild); if (oldParent != null) { _changes.AddedItems.Add(newChild.ItemId); } } foreach (var pair in diffs.CommonItems.ToForeachEnum()) { pair.RigthtItem.ItemId = pair.LeftItem.ItemId; pair.RigthtItem.IsExpanded = pair.LeftItem.IsExpanded; _newNodes.AddNode(pair.RigthtItem); } // Call recursively on all children if (directoryEntry != null) { Debug.Assert(directoryEntry.Entries.Count == newParent.Children.Count); for (var i = 0; i < newParent.Children.Count; i++) { var childEntry = directoryEntry.Entries[i]; var newChildNode = newParent.Children[i]; var oldChildNode = GetCommonOldNode(newParent, i, diffs, newChildNode); AddNodeForChildren(childEntry, oldChildNode, newChildNode); } } }
private void ExpandNode(NodeViewModel node) { CheckOnUIThread(); var uiHierarchyWindow = VsHierarchyUtilities.GetSolutionExplorer(_serviceProvider); if (uiHierarchyWindow == null) return; uint pdwState; if (ErrorHandler.Failed(uiHierarchyWindow.GetItemState(this, node.ItemId, (int)__VSHIERARCHYITEMSTATE.HIS_Expanded, out pdwState))) return; if (pdwState == (uint)__VSHIERARCHYITEMSTATE.HIS_Expanded) return; if (ErrorHandler.Failed(uiHierarchyWindow.ExpandItem(this, node.ItemId, EXPANDFLAGS.EXPF_ExpandParentsToShowItem)) || ErrorHandler.Failed(uiHierarchyWindow.ExpandItem(this, node.ItemId, EXPANDFLAGS.EXPF_ExpandFolder))) { return; } }
public void SelectNode(NodeViewModel node) { CheckOnUIThread(); var uiHierarchyWindow = VsHierarchyUtilities.GetSolutionExplorer(_serviceProvider); if (uiHierarchyWindow == null) return; if (ErrorHandler.Failed(uiHierarchyWindow.ExpandItem(this, node.ItemId, EXPANDFLAGS.EXPF_SelectItem))) { Logger.LogError("Error selecting item in solution explorer."); } }
protected override void AddChildImpl(NodeViewModel node) { ChildrenLoaded = true; node.ChildIndex = _childrenList.Count; _childrenList.Add(node); }
public DirectoryNodeViewModel(NodeViewModel parent) : base(parent) { }
private bool FindNodeByMonikerHelper(NodeViewModel parentNode, string searchMoniker, out NodeViewModel foundNode) { foundNode = null; if (parentNode == null) return false; if (SystemPathComparer.Instance.StringComparer.Equals(parentNode.FullPath, searchMoniker)) { foundNode = parentNode; return true; } foreach (var child in parentNode.ChildrenImpl) { if (FindNodeByMonikerHelper(child, searchMoniker, out foundNode)) { return true; } } return false; }
public bool FindNodeByMoniker(string searchMoniker, out NodeViewModel node) { node = null; if (!IsRoot) return false; return FindNodeByMonikerHelper(this, searchMoniker, out node); }
private void ShowContextMenu(NodeViewModel node, IntPtr variantIn) { // See https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vsconstants.vsuihierarchywindowcmdids.aspx // // The UIHWCMDID_RightClick command is what tells the interface // IVsUIHierarchy in a IVsUIHierarchyWindow to display the context menu. // Since the mouse position may change between the mouse down and the // mouse up events and the right click command might even originate from // the keyboard Visual Studio provides the proper menu position into // pvaIn by performing a memory copy operation on a POINTS structure // into the VT_UI4 part of the pvaIn variant. // // To show the menu use the derived POINTS as the coordinates to show // the context menu, calling ShowContextMenu. To ensure proper command // handling you should pass a NULL command target into ShowContextMenu // menu so that the IVsUIHierarchyWindow will have the first chance to // handle commands like delete. object variant = Marshal.GetObjectForNativeVariant(variantIn); var pointsAsUint = (UInt32)variant; var x = (short)(pointsAsUint & 0xffff); var y = (short)(pointsAsUint >> 16); var points = new POINTS(); points.x = x; points.y = y; var shell = _visualStudioPackageProvider.Package.ServiceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell; if (shell == null) { Logger.LogError("Error accessing IVsUIShell service."); return; } var pointsIn = new POINTS[1]; pointsIn[0].x = points.x; pointsIn[0].y = points.y; var groupGuid = VsMenus.guidSHLMainMenu; var menuId = (node.IsRoot) ? VsMenus.IDM_VS_CTXT_PROJNODE : (node is DirectoryNodeViewModel) ? VsMenus.IDM_VS_CTXT_FOLDERNODE : VsMenus.IDM_VS_CTXT_ITEMNODE; int hresult = shell.ShowContextMenu(0, ref groupGuid, menuId, pointsIn, null); if (!ErrorHandler.Succeeded(hresult)) { Logger.LogHResult(hresult, "Error showing context menu."); return; } }
private void OpenDocument(VsHierarchy hierarchy, NodeViewModel node, bool openWith = false) { Logger.WrapActionInvocation( () => { if (!_fileSystem.FileExists(new FullPath(node.FullPath))) return; if (openWith) _openDocumentHelper.OpenDocumentWith(node.FullPath, hierarchy, node.ItemId, view => null); else _openDocumentHelper.OpenDocument(node.FullPath, view => null); }); }