Exemple #1
0
        private void PromptAndDelete(HierarchyItem item, IVsHierarchyDeleteHandler deleteHandler, __VSDELETEITEMOPERATION deleteType, string message)
        {
            Guid unused = Guid.Empty;
            int  result;

            // show delete dialog...
            if (ErrorHandler.Succeeded(
                    _mockVs.UIShell.ShowMessageBox(
                        0,
                        ref unused,
                        null,
                        message,
                        null,
                        0,
                        OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL,
                        OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                        OLEMSGICON.OLEMSGICON_WARNING,
                        0,
                        out result
                        )) && result == DialogResult.OK)
            {
                int hr = deleteHandler.DeleteItem(
                    (uint)deleteType,
                    item.ItemId
                    );

                if (ErrorHandler.Failed(hr) && hr != VSConstants.OLE_E_PROMPTSAVECANCELLED)
                {
                    _mockVs.UIShell.ReportErrorInfo(hr);
                }
            }
        }
Exemple #2
0
        private bool ShouldShowSpecificMessage(HierarchyItem item, int canRemoveItem, int canDeleteItem)
        {
            __VSDELETEITEMOPERATION op = 0;

            if (canRemoveItem != 0)
            {
                op |= __VSDELETEITEMOPERATION.DELITEMOP_RemoveFromProject;
            }
            if (canDeleteItem != 0)
            {
                op |= __VSDELETEITEMOPERATION.DELITEMOP_DeleteFromStorage;
            }

            IVsHierarchyDeleteHandler2 deleteHandler = item.Hierarchy as IVsHierarchyDeleteHandler2;

            if (deleteHandler != null)
            {
                int  dwShowStandardMessage;
                uint pdwDelItemOp;
                deleteHandler.ShowSpecificDeleteRemoveMessage(
                    (uint)op,
                    1,
                    new[] { item.ItemId },
                    out dwShowStandardMessage,
                    out pdwDelItemOp
                    );
                return(dwShowStandardMessage != 0);
            }
            return(false);
        }
Exemple #3
0
        public ITreeNode FindItem(params string[] items)
        {
            HierarchyItem res = WaitForItem(items);

            if (res.IsNull)
            {
                return(null);
            }
            return(new MockTreeNode(this, res));
        }
Exemple #4
0
        ITreeNode IVisualStudioInstance.WaitForItem(params string[] items)
        {
            HierarchyItem res = WaitForItem(items);

            if (res.IsNull)
            {
                return(null);
            }
            return(new MockTreeNode(this, res));
        }
Exemple #5
0
        private HierarchyItem WaitForItemWorker(string[] items)
        {
            IVsHierarchy hierarchy;

            if (ErrorHandler.Failed(Solution.GetProjectOfUniqueName(items[0], out hierarchy)))
            {
                return(new HierarchyItem());
            }
            if (items.Length == 1)
            {
                return(new HierarchyItem(hierarchy, (uint)VSConstants.VSITEMID.Root));
            }

            var firstItem     = items[1];
            var firstHierItem = new HierarchyItem();

            foreach (var item in hierarchy.GetHierarchyItems())
            {
                if (item.Caption == firstItem)
                {
                    firstHierItem = item;
                    break;
                }
            }

            if (firstHierItem.IsNull)
            {
                return(new HierarchyItem());
            }

            for (int i = 2; i < items.Length; i++)
            {
                bool found = false;
                foreach (var item in firstHierItem.Children)
                {
                    if (item.Caption == items[i])
                    {
                        firstHierItem = item;
                        found         = true;
                        break;
                    }
                }

                if (!found)
                {
                    firstHierItem = new HierarchyItem();
                    break;
                }
            }

            return(firstHierItem);
        }
 public void AddSelectedItem(HierarchyItem item) {
     _selectedItems.Add(item);
     if (_selectedItems.Count > 1) {
         _multiSelect = new MultiItemSelect(_selectedItems.ToArray());
     } else {
         _multiSelect = null;
     }
     _mockVs._monSel._emptyCtx.OnSelectChangeEx(
         item.Hierarchy,
         item.ItemId,
         _multiSelect,
         this
     );
 }
Exemple #7
0
        private MockVsTextView OpenItemWorker(string project, string[] path)
        {
            // matching the API of VisualStudioSolution.OpenItem
            string[] temp = new string[path.Length + 1];
            temp[0] = project;
            Array.Copy(path, 0, temp, 1, path.Length);
            HierarchyItem item = WaitForItemWorker(temp);

            if (item.IsNull)
            {
                return(null);
            }

            if (!CachedInfo._languageNamesByExtension.TryGetValue(Path.GetExtension(item.CanonicalName), out global::System.String languageName))
            {
                languageName = "code";
            }

            MockVsTextView res = CreateTextViewWorker(languageName, File.ReadAllText(item.CanonicalName), view =>
            {
                ErrorHandler.ThrowOnFailure(((IVsTextView)view).GetBuffer(out IVsTextLines lines));
                IntPtr linesPtr = Marshal.GetIUnknownForObject(lines);
                try
                {
                    ErrorHandler.ThrowOnFailure(
                        _rdt.RegisterAndLockDocument(
                            (uint)_VSRDTFLAGS.RDT_NoLock,
                            item.CanonicalName,
                            item.Hierarchy,
                            item.ItemId,
                            linesPtr,
                            out global::System.UInt32 cookie
                            )
                        );
                }
                finally
                {
                    Marshal.Release(linesPtr);
                }
            }, item.CanonicalName);

            if (_docCmdTarget != null)
            {
                ((IFocusable)_docCmdTarget).LostFocus();
            }
            _docCmdTarget = res;
            ((IFocusable)res).GetFocus();

            return(res);
        }
Exemple #8
0
 public void AddSelectedItem(HierarchyItem item)
 {
     _selectedItems.Add(item);
     if (_selectedItems.Count > 1)
     {
         _multiSelect = new MultiItemSelect(_selectedItems.ToArray());
     }
     else
     {
         _multiSelect = null;
     }
     _mockVs._monSel._emptyCtx.OnSelectChangeEx(
         item.Hierarchy,
         item.ItemId,
         _multiSelect,
         this
         );
 }
Exemple #9
0
        private void DeleteItem(HierarchyItem item)
        {
            var deleteHandler = item.Hierarchy as IVsHierarchyDeleteHandler;
            int canRemoveItem = 0, canDeleteItem = 0;

            if (deleteHandler != null &&
                ErrorHandler.Succeeded(deleteHandler.QueryDeleteItem((uint)__VSDELETEITEMOPERATION.DELITEMOP_RemoveFromProject, item.ItemId, out canRemoveItem)))
            {
                deleteHandler.QueryDeleteItem((uint)__VSDELETEITEMOPERATION.DELITEMOP_DeleteFromStorage, item.ItemId, out canDeleteItem);
            }
            bool showSpecificMsg = ShouldShowSpecificMessage(item, canRemoveItem, canDeleteItem);

            if (canRemoveItem != 0)
            {
                if (canDeleteItem != 0)
                {
                    // show delete or remove dialog...
                }
                else
                {
                    // show remove dialog...
                    PromptAndDelete(
                        item,
                        deleteHandler,
                        __VSDELETEITEMOPERATION.DELITEMOP_RemoveFromProject,
                        ""
                        );
                }
            }
            else if (canDeleteItem != 0)
            {
                object name;
                ErrorHandler.ThrowOnFailure(item.Hierarchy.GetProperty(item.ItemId, (int)__VSHPROPID.VSHPROPID_Name, out name));
                string message = string.Format("'{0}' will be deleted permanently.", name);
                PromptAndDelete(
                    item,
                    deleteHandler,
                    __VSDELETEITEMOPERATION.DELITEMOP_DeleteFromStorage,
                    message
                    );
            }
        }
Exemple #10
0
 public MockTreeNode(MockVs mockVs, HierarchyItem res)
 {
     _mockVs = mockVs;
     _item   = res;
 }
Exemple #11
0
 public MockTreeNode(MockVs mockVs, HierarchyItem res) {
     _mockVs = mockVs;
     _item = res;
 }
        private bool ShouldShowSpecificMessage(HierarchyItem item, int canRemoveItem, int canDeleteItem) {
            __VSDELETEITEMOPERATION op = 0;
            if (canRemoveItem != 0) {
                op |= __VSDELETEITEMOPERATION.DELITEMOP_RemoveFromProject;
            }
            if (canDeleteItem != 0) {
                op |= __VSDELETEITEMOPERATION.DELITEMOP_DeleteFromStorage;
            }

            IVsHierarchyDeleteHandler2 deleteHandler = item.Hierarchy as IVsHierarchyDeleteHandler2;
            if (deleteHandler != null) {
                int dwShowStandardMessage;
                uint pdwDelItemOp;
                deleteHandler.ShowSpecificDeleteRemoveMessage(
                    (uint)op,
                    1,
                    new[] { item.ItemId },
                    out dwShowStandardMessage,
                    out pdwDelItemOp
                );
                return dwShowStandardMessage != 0;
            }
            return false;
        }
        private void PromptAndDelete(HierarchyItem item, IVsHierarchyDeleteHandler deleteHandler, __VSDELETEITEMOPERATION deleteType, string message) {
            Guid unused = Guid.Empty;
            int result;
            // show delete dialog...
            if (ErrorHandler.Succeeded(
                _mockVs.UIShell.ShowMessageBox(
                    0,
                    ref unused,
                    null,
                    message,
                    null,
                    0,
                    OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                    OLEMSGICON.OLEMSGICON_WARNING,
                    0,
                    out result
                )) && result == DialogResult.OK) {
                int hr = deleteHandler.DeleteItem(
                    (uint)deleteType,
                    item.ItemId
                );

                if (ErrorHandler.Failed(hr) && hr != VSConstants.OLE_E_PROMPTSAVECANCELLED) {
                    _mockVs.UIShell.ReportErrorInfo(hr);
                }
            }
        }
        private void DeleteItem(HierarchyItem item) {
            var deleteHandler = item.Hierarchy as IVsHierarchyDeleteHandler;
            int canRemoveItem = 0, canDeleteItem = 0;
            if (deleteHandler != null &&
                ErrorHandler.Succeeded(deleteHandler.QueryDeleteItem((uint)__VSDELETEITEMOPERATION.DELITEMOP_RemoveFromProject, item.ItemId, out canRemoveItem))) {
                deleteHandler.QueryDeleteItem((uint)__VSDELETEITEMOPERATION.DELITEMOP_DeleteFromStorage, item.ItemId, out canDeleteItem);
            }
            bool showSpecificMsg = ShouldShowSpecificMessage(item, canRemoveItem, canDeleteItem);
            if (canRemoveItem != 0) {
                if (canDeleteItem != 0) {
                    // show delete or remove dialog...
                } else {
                    // show remove dialog...
                    PromptAndDelete(
                        item,
                        deleteHandler,
                        __VSDELETEITEMOPERATION.DELITEMOP_RemoveFromProject,
                        ""
                    );
                }

            } else if (canDeleteItem != 0) {
                object name;
                ErrorHandler.ThrowOnFailure(item.Hierarchy.GetProperty(item.ItemId, (int)__VSHPROPID.VSHPROPID_Name, out name));
                string message = string.Format("'{0}' will be deleted permanently.", name);
                PromptAndDelete(
                    item,
                    deleteHandler,
                    __VSDELETEITEMOPERATION.DELITEMOP_DeleteFromStorage,
                    message
                );
            }
        }
 public MultiItemSelect(HierarchyItem[] hierarchyItem) {
     _items = hierarchyItem;
 }