示例#1
0
 public IEnumerator GetEnumerator()
 {
     return(UIThread.DoOnUIThread(delegate(){
         List <Reference> references = new List <Reference>();
         IEnumerator baseEnum = container.EnumReferences().GetEnumerator();
         if (null == baseEnum)
         {
             return references.GetEnumerator();
         }
         while (baseEnum.MoveNext())
         {
             ReferenceNode refNode = baseEnum.Current as ReferenceNode;
             if (null == refNode)
             {
                 continue;
             }
             Reference reference = refNode.Object as Reference;
             if (null != reference)
             {
                 references.Add(reference);
             }
         }
         return references.GetEnumerator();
     }));
 }
        protected override object GetService(Type serviceType)
        {
            object result = null;

            UIThread.DoOnUIThread(() => result = MyGetService(serviceType));
            return(result);
        }
示例#3
0
        /// <summary>
        /// Removes the item from its project and its storage.
        /// </summary>
        public virtual void Delete()
        {
            if (this.node == null || this.node.ProjectMgr == null || this.node.ProjectMgr.IsClosed || this.node.ProjectMgr.Site == null)
            {
                throw new InvalidOperationException();
            }

            UIThread.DoOnUIThread(delegate() {
                IVsExtensibility3 extensibility = this.Node.ProjectMgr.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3;

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

                extensibility.EnterAutomationFunction();

                try
                {
                    this.node.Remove(removeFromStorage: true, promptSave: false);
                }
                finally
                {
                    extensibility.ExitAutomationFunction();
                }
            });
        }
示例#4
0
        /// <summary>
        /// Removes the project from the current solution.
        /// </summary>
        public virtual void Delete()
        {
            if (this.project == null || this.project.Site == null || this.project.IsClosed)
            {
                throw new InvalidOperationException();
            }

            UIThread.DoOnUIThread(delegate() {
                IVsExtensibility3 extensibility = this.project.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3;

                if (extensibility == null)
                {
                    throw new InvalidOperationException();
                }
                extensibility.EnterAutomationFunction();

                try
                {
                    this.project.Remove(false);
                }
                finally
                {
                    extensibility.ExitAutomationFunction();
                }
            });
        }
示例#5
0
        /// <summary>
        /// Expands the view of Solution Explorer to show project items.
        /// </summary>
        public virtual void ExpandView()
        {
            if (this.node == null || this.node.ProjectMgr == null || this.node.ProjectMgr.IsClosed || this.node.ProjectMgr.Site == null)
            {
                throw new InvalidOperationException();
            }

            UIThread.DoOnUIThread(delegate() {
                IVsExtensibility3 extensibility = this.Node.ProjectMgr.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3;

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

                extensibility.EnterAutomationFunction();

                try
                {
                    IVsUIHierarchyWindow uiHierarchy = UIHierarchyUtilities.GetUIHierarchyWindow(this.node.ProjectMgr.Site, HierarchyNode.SolutionExplorer);
                    if (uiHierarchy == null)
                    {
                        throw new InvalidOperationException();
                    }

                    uiHierarchy.ExpandItem(node.ProjectMgr.InteropSafeIVsUIHierarchy, this.node.ID, EXPANDFLAGS.EXPF_ExpandFolder);
                }
                finally
                {
                    extensibility.ExitAutomationFunction();
                }
            });
        }
示例#6
0
        public object GetService(Type serviceType)
        {
            object result = null;

            UIThread.DoOnUIThread(() => result = vsServiceProvider.GetService(serviceType));
            return(result);
        }
示例#7
0
        /// <summary>
        /// Adds an item to the project.
        /// </summary>
        /// <param name="path">The full path of the item to add.</param>
        /// <param name="op">The <paramref name="VSADDITEMOPERATION"/> to use when adding the item.</param>
        /// <returns>A ProjectItem object. </returns>
        protected virtual EnvDTE.ProjectItem AddItem(string path, VSADDITEMOPERATION op)
        {
            if (this.Project == null || this.Project.Project == null || this.Project.Project.Site == null || this.Project.Project.IsClosed)
            {
                throw new InvalidOperationException();
            }

            return(UIThread.DoOnUIThread(delegate()
            {
                ProjectNode proj = this.Project.Project;

                EnvDTE.ProjectItem itemAdded = null;
                using (AutomationScope scope = new AutomationScope(this.Project.Project.Site))
                {
                    VSADDRESULT[] result = new VSADDRESULT[1];
                    ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, path, 0, new string[1] {
                        path
                    }, IntPtr.Zero, result));

                    string fileName = System.IO.Path.GetFileName(path);
                    string fileDirectory = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems);
                    string filePathInProject = System.IO.Path.Combine(fileDirectory, fileName);

                    itemAdded = this.EvaluateAddResult(result[0], filePathInProject);
                }

                return itemAdded;
            }));
        }
示例#8
0
        protected virtual EnvDTE.ProjectItem EvaluateAddResult(VSADDRESULT result, string path)
        {
            return(UIThread.DoOnUIThread(delegate()
            {
                if (result == VSADDRESULT.ADDRESULT_Success)
                {
                    HierarchyNode nodeAdded = this.NodeWithItems.FindChild(path);
                    Debug.Assert(nodeAdded != null, "We should have been able to find the new element in the hierarchy");
                    if (nodeAdded != null)
                    {
                        EnvDTE.ProjectItem item = null;
                        if (nodeAdded is FileNode)
                        {
                            item = new OAFileItem(this.Project, nodeAdded as FileNode);
                        }
                        else if (nodeAdded is NestedProjectNode)
                        {
                            item = new OANestedProjectItem(this.Project, nodeAdded as NestedProjectNode);
                        }
                        else
                        {
                            item = new OAProjectItem <HierarchyNode>(this.Project, nodeAdded);
                        }

                        this.Items.Add(item);
                        return item;
                    }
                }
                return null;
            }));
        }
示例#9
0
        public Reference AddProject(EnvDTE.Project pProject)
        {
            if (null == pProject)
            {
                return(null);
            }
            return(UIThread.DoOnUIThread(delegate(){
                // Get the soulution.
                IVsSolution solution = container.ProjectMgr.Site.GetService(typeof(SVsSolution)) as IVsSolution;
                if (null == solution)
                {
                    return null;
                }

                // Get the hierarchy for this project.
                IVsHierarchy projectHierarchy;
                ErrorHandler.ThrowOnFailure(solution.GetProjectOfUniqueName(pProject.UniqueName, out projectHierarchy));

                // Create the selector data.
                VSCOMPONENTSELECTORDATA selector = new VSCOMPONENTSELECTORDATA();
                selector.type = VSCOMPONENTTYPE.VSCOMPONENTTYPE_Project;

                // Get the project reference string.
                ErrorHandler.ThrowOnFailure(solution.GetProjrefOfProject(projectHierarchy, out selector.bstrProjRef));

                selector.bstrTitle = pProject.Name;
                selector.bstrFile = pProject.FullName;
                return AddFromSelectorData(selector);
            }));
        }
示例#10
0
        /// <summary>
        /// Opens the file item in the specified view.
        /// </summary>
        /// <param name="ViewKind">Specifies the view kind in which to open the item (file)</param>
        /// <returns>Window object</returns>
        public override EnvDTE.Window Open(string viewKind)
        {
            return(UIThread.DoOnUIThread(delegate()
            {
                if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed || this.Node.ProjectMgr.Site == null)
                {
                    throw new InvalidOperationException();
                }

                IVsWindowFrame windowFrame = null;
                IntPtr docData = IntPtr.Zero;

                using (AutomationScope scope = new AutomationScope(this.Node.ProjectMgr.Site))
                {
                    try
                    {
                        // Validate input params
                        Guid logicalViewGuid = VSConstants.LOGVIEWID_Primary;
                        try
                        {
                            if (!(String.IsNullOrEmpty(viewKind)))
                            {
                                logicalViewGuid = new Guid(viewKind);
                            }
                        }
                        catch (FormatException)
                        {
                            // Not a valid guid
                            throw new ArgumentException(SR.GetString(SR.ParameterMustBeAValidGuid, CultureInfo.CurrentUICulture), "viewKind");
                        }

                        uint itemid;
                        IVsHierarchy ivsHierarchy;
                        uint docCookie;
                        IVsRunningDocumentTable rdt = this.Node.ProjectMgr.Site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
                        Debug.Assert(rdt != null, " Could not get running document table from the services exposed by this project");
                        if (rdt == null)
                        {
                            throw new InvalidOperationException();
                        }

                        ErrorHandler.ThrowOnFailure(rdt.FindAndLockDocument((uint)_VSRDTFLAGS.RDT_NoLock, this.Node.Url, out ivsHierarchy, out itemid, out docData, out docCookie));

                        // Open the file using the IVsProject3 interface
                        ErrorHandler.ThrowOnFailure(this.Node.ProjectMgr.OpenItem(this.Node.ID, ref logicalViewGuid, docData, out windowFrame));
                    }
                    finally
                    {
                        if (docData != IntPtr.Zero)
                        {
                            Marshal.Release(docData);
                        }
                    }
                }

                // Get the automation object and return it
                return ((windowFrame != null) ? VsShellUtilities.GetWindowObject(windowFrame) : null);
            }));
        }
示例#11
0
        public virtual object GetService(Type serviceType)
        {
            // This is were we will load the IVSMDProvider interface
            object result = null;

            UIThread.DoOnUIThread(() => result = _serviceProvider.GetService(serviceType));
            return(result);
        }
示例#12
0
        /// <summary>
        /// Creates a new project item from an existing item template file and adds it to the project.
        /// </summary>
        /// <param name="fileName">The full path and file name of the template project file.</param>
        /// <param name="name">The file name to use for the new project item.</param>
        /// <returns>A ProjectItem object. </returns>
        public override EnvDTE.ProjectItem AddFromTemplate(string fileName, string name)
        {
            if (this.Project == null || this.Project.Project == null || this.Project.Project.Site == null || this.Project.Project.IsClosed)
            {
                throw new InvalidOperationException();
            }

            return(UIThread.DoOnUIThread(delegate()
            {
                ProjectNode proj = this.Project.Project;
                EnvDTE.ProjectItem itemAdded = null;

                using (AutomationScope scope = new AutomationScope(this.Project.Project.Site))
                {
                    string fixedFileName = fileName;

                    if (!File.Exists(fileName))
                    {
                        string tempFileName = GetTemplateNoZip(fileName);
                        if (File.Exists(tempFileName))
                        {
                            fixedFileName = tempFileName;
                        }
                    }

                    // Determine the operation based on the extension of the filename.
                    // We should run the wizard only if the extension is vstemplate
                    // otherwise it's a clone operation
                    VSADDITEMOPERATION op;

                    if (Utilities.IsTemplateFile(fixedFileName))
                    {
                        op = VSADDITEMOPERATION.VSADDITEMOP_RUNWIZARD;
                    }
                    else
                    {
                        op = VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE;
                    }

                    VSADDRESULT[] result = new VSADDRESULT[1];

                    // It is not a very good idea to throw since the AddItem might return Cancel or Abort.
                    // The problem is that up in the call stack the wizard code does not check whether it has received a ProjectItem or not and will crash.
                    // The other problem is that we cannot get add wizard dialog back if a cancel or abort was returned because we throw and that code will never be executed. Typical catch 22.
                    ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, name, 0, new string[1] {
                        fixedFileName
                    }, IntPtr.Zero, result));

                    string fileDirectory = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems);
                    string templateFilePath = System.IO.Path.Combine(fileDirectory, name);
                    itemAdded = this.EvaluateAddResult(result[0], templateFilePath);
                }

                return itemAdded;
            }));
        }
示例#13
0
        /// <summary>
        /// Removes the project from the current solution.
        /// </summary>
        public virtual void Delete()
        {
            CheckProjectIsValid();

            UIThread.DoOnUIThread(delegate()
            {
                using (AutomationScope scope = new AutomationScope(this.project.Site))
                {
                    this.project.Remove(false);
                }
            });
        }
示例#14
0
        /// <summary>
        /// Removes the item from its project and its storage.
        /// </summary>
        public virtual void Delete()
        {
            CheckProjectIsValid();

            UIThread.DoOnUIThread(delegate()
            {
                using (AutomationScope scope = new AutomationScope(this.Node.ProjectMgr.Site))
                {
                    this.node.Remove(true);
                }
            });
        }
示例#15
0
        private IntPtr CreateFormView(
            IVsHierarchy hierarchy,
            uint itemid,
            IVsTextLines textLines,
            ref string editorCaption,
            ref Guid cmdUI)
        {
            // Request the Designer Service
            IVSMDDesignerService designerService = (IVSMDDesignerService)GetService(typeof(IVSMDDesignerService));

            // Create loader for the designer
            IVSMDDesignerLoader designerLoader =
                (IVSMDDesignerLoader)designerService.CreateDesignerLoader(
                    "Microsoft.VisualStudio.Designer.Serialization.VSDesignerLoader");

            bool loaderInitalized = false;

            try
            {
                IOleServiceProvider service = null;
                UIThread.DoOnUIThread(() => service = (IOleServiceProvider)_serviceProvider.GetService(typeof(IOleServiceProvider)));

                // Initialize designer loader
                designerLoader.Initialize(service, hierarchy, (int)itemid, textLines);
                loaderInitalized = true;

                // Create the designer
                IVSMDDesigner designer = designerService.CreateDesigner(service, designerLoader);

                // Get editor caption
                editorCaption = designerLoader.GetEditorCaption((int)READONLYSTATUS.ROSTATUS_Unknown);

                // Get view from designer
                object docView = designer.View;

                // Get command guid from designer
                cmdUI = designer.CommandGuid;

                return(Marshal.GetIUnknownForObject(docView));
            }
            catch
            {
                // The designer loader may have created a reference to the shell or the text buffer.
                // In case we fail to create the designer we should manually dispose the loader
                // in order to release the references to the shell and the textbuffer
                if (loaderInitalized)
                {
                    designerLoader.Dispose();
                }
                throw;
            }
        }
示例#16
0
        /// <summary>
        /// Adds a folder to the collection of ProjectItems with the given name.
        ///
        /// The kind must be null, empty string, or the string value of vsProjectItemKindPhysicalFolder.
        /// Virtual folders are not supported by this implementation.
        /// </summary>
        /// <param name="name">The name of the new folder to add</param>
        /// <param name="kind">A string representing a Guid of the folder kind.</param>
        /// <returns>A ProjectItem representing the newly added folder.</returns>
        public override ProjectItem AddFolder(string name, string kind)
        {
            return(UIThread.DoOnUIThread(delegate() {
                if (this.Project == null || this.Project.Project == null || this.Project.Project.Site == null || this.Project.Project.IsClosed)
                {
                    throw new InvalidOperationException();
                }
                //Verify name is not null or empty
                Utilities.ValidateFileName(this.Project.Project.Site, name);

                //Verify that kind is null, empty, or a physical folder
                if (!(string.IsNullOrEmpty(kind) || kind.Equals(EnvDTE.Constants.vsProjectItemKindPhysicalFolder)))
                {
                    throw new ArgumentException("Parameter specification for AddFolder was not meet", "kind");
                }

                for (HierarchyNode child = this.NodeWithItems.FirstChild; child != null; child = child.NextSibling)
                {
                    if (child.Caption.Equals(name, StringComparison.OrdinalIgnoreCase))
                    {
                        throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, "Folder already exists with the name '{0}'", name));
                    }
                }

                ProjectNode proj = this.Project.Project;

                IVsExtensibility3 extensibility = this.Project.Project.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3;

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

                HierarchyNode newFolder = null;
                extensibility.EnterAutomationFunction();

                //In the case that we are adding a folder to a folder, we need to build up
                //the path to the project node.
                name = Path.Combine(this.NodeWithItems.VirtualNodeName, name);

                try
                {
                    newFolder = proj.CreateFolderNodes(name);
                }
                finally
                {
                    extensibility.ExitAutomationFunction();
                }

                return newFolder.GetAutomationObject() as ProjectItem;
            }));
        }
示例#17
0
        public Reference AddActiveX(string bstrTypeLibGuid, int lMajorVer, int lMinorVer, int lLocaleId, string bstrWrapperTool)
        {
            return(UIThread.DoOnUIThread(delegate(){
                VSCOMPONENTSELECTORDATA selector = new VSCOMPONENTSELECTORDATA();
                selector.type = VSCOMPONENTTYPE.VSCOMPONENTTYPE_Com2;
                selector.guidTypeLibrary = new Guid(bstrTypeLibGuid);
                selector.lcidTypeLibrary = (uint)lLocaleId;
                selector.wTypeLibraryMajorVersion = (ushort)lMajorVer;
                selector.wTypeLibraryMinorVersion = (ushort)lMinorVer;

                return AddFromSelectorData(selector);
            }));
        }
 public void OpenInBrowser(string url)
 {
     UIThread.DoOnUIThread(() =>
     {
         IVsWebBrowsingService service = GetService(typeof(SVsWebBrowsingService)) as IVsWebBrowsingService;
         if (service != null)
         {
             IVsWindowFrame frame = null;
             service.Navigate(url, (uint)(__VSWBNAVIGATEFLAGS.VSNWB_WebURLOnly | __VSWBNAVIGATEFLAGS.VSNWB_ForceNew), out frame);
             frame.Show();
         }
     });
 }
        /// <summary>
        /// Gets a value indicating whether the project item is open in a particular view type.
        /// </summary>
        /// <param name="viewKind">A Constants.vsViewKind* indicating the type of view to check.</param>
        /// <returns>A Boolean value indicating true if the project is open in the given view type; false if not. </returns>
        public override bool get_IsOpen(string viewKind)
        {
            return(UIThread.DoOnUIThread(delegate() {
                if (this.Node == null || this.Node.ProjectMgr == null || this.Node.ProjectMgr.IsClosed || this.Node.ProjectMgr.Site == null)
                {
                    throw new InvalidOperationException();
                }

                // Validate input params
                Guid logicalViewGuid = VSConstants.LOGVIEWID_Primary;
                try
                {
                    if (!(String.IsNullOrEmpty(viewKind)))
                    {
                        logicalViewGuid = new Guid(viewKind);
                    }
                }
                catch (FormatException)
                {
                    // Not a valid guid
                    throw new ArgumentException(SR.GetString(SR.ParameterMustBeAValidGuid, CultureInfo.CurrentUICulture), "viewKind");
                }

                IVsExtensibility3 extensibility = this.Node.ProjectMgr.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3;

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

                bool isOpen = false;
                extensibility.EnterAutomationFunction();

                try
                {
                    IVsUIHierarchy hier;
                    uint itemid;

                    IVsWindowFrame windowFrame;

                    isOpen = VsShellUtilities.IsDocumentOpen(this.Node.ProjectMgr.Site, this.Node.Url, logicalViewGuid, out hier, out itemid, out windowFrame);
                }
                finally
                {
                    extensibility.ExitAutomationFunction();
                }

                return isOpen;
            }));
        }
示例#20
0
        /// <summary>
        /// Removes the item from its project and its storage.
        /// </summary>
        public virtual void Delete()
        {
            if (this.node == null || this.node.ProjectMgr == null || this.node.ProjectMgr.IsClosed || this.node.ProjectMgr.Site == null)
            {
                throw new InvalidOperationException();
            }

            UIThread.DoOnUIThread(delegate()
            {
                using (AutomationScope scope = new AutomationScope(this.Node.ProjectMgr.Site))
                {
                    this.node.Remove(true);
                }
            });
        }
示例#21
0
        /// <summary>
        /// Removes the project from the current solution.
        /// </summary>
        public virtual void Delete()
        {
            if (this.project == null || this.project.Site == null || this.project.IsClosed)
            {
                throw new InvalidOperationException();
            }

            UIThread.DoOnUIThread(delegate()
            {
                using (AutomationScope scope = new AutomationScope(this.project.Site))
                {
                    this.project.Remove(false);
                }
            });
        }
 protected override void Dispose(bool disposing)
 {
     try
     {
         UIThread.DoOnUIThread(() => this.UnRegisterDebuggerEvents());
         if (null != _libraryManager)
         {
             _libraryManager.Dispose();
             _libraryManager = null;
         }
     }
     finally
     {
         UIThread.DoOnUIThread(() => base.Dispose(disposing));
     }
 }
        /// <summary>
        /// Retrives a list of items associated with the current node.
        /// </summary>
        /// <returns>A List of project items</returns>
        protected virtual IList <EnvDTE.ProjectItem> GetListOfProjectItems()
        {
            return(UIThread.DoOnUIThread(delegate()
            {
                List <EnvDTE.ProjectItem> list = new List <EnvDTE.ProjectItem>();
                for (HierarchyNode child = this.NodeWithItems.FirstChild; child != null; child = child.NextSibling)
                {
                    EnvDTE.ProjectItem item = child.GetAutomationObject() as EnvDTE.ProjectItem;
                    if (null != item)
                    {
                        list.Add(item);
                    }
                }

                return list;
            }));
        }
示例#24
0
        /// <summary>
        /// Expands the view of Solution Explorer to show project items.
        /// </summary>
        public virtual void ExpandView()
        {
            CheckProjectIsValid();

            UIThread.DoOnUIThread(delegate()
            {
                using (AutomationScope scope = new AutomationScope(this.Node.ProjectMgr.Site))
                {
                    IVsUIHierarchyWindow uiHierarchy = UIHierarchyUtilities.GetUIHierarchyWindow(this.node.ProjectMgr.Site, HierarchyNode.SolutionExplorer);
                    if (uiHierarchy == null)
                    {
                        throw new InvalidOperationException();
                    }

                    ErrorHandler.ThrowOnFailure(uiHierarchy.ExpandItem(this.node.ProjectMgr, this.node.ID, EXPANDFLAGS.EXPF_ExpandFolder));
                }
            });
        }
示例#25
0
        /// <summary>
        /// Retrives a list of items associated with the current node.
        /// </summary>
        /// <returns>A List of project items</returns>
        public IList <EnvDTE.ProjectItem> GetListOfProjectItems()
        {
            return(UIThread.DoOnUIThread(delegate() {
                List <EnvDTE.ProjectItem> list = new List <EnvDTE.ProjectItem>();
                for (HierarchyNode child = this.NodeWithItems.FirstChild; child != null; child = child.NextSibling)
                {
                    if (!(child is ReferenceContainerNode))  // skip 'references' node when navigating over project items, to behave more like C#/VB
                    {
                        EnvDTE.ProjectItem item = child.GetAutomationObject() as EnvDTE.ProjectItem;
                        if (null != item)
                        {
                            list.Add(item);
                        }
                    }
                }

                return list;
            }));
        }
示例#26
0
 public Reference Find(string bstrIdentity)
 {
     if (string.IsNullOrEmpty(bstrIdentity))
     {
         return(null);
     }
     return(UIThread.DoOnUIThread(delegate(){
         foreach (Reference refNode in this)
         {
             if (null != refNode)
             {
                 if (0 == string.Compare(bstrIdentity, refNode.Identity, StringComparison.Ordinal))
                 {
                     return refNode;
                 }
             }
         }
         return null;
     }));
 }
示例#27
0
        /// <summary>
        /// Adds an item to the project.
        /// </summary>
        /// <param name="path">The full path of the item to add.</param>
        /// <param name="op">The VSADDITEMOPERATION to use when adding the item.</param>
        /// <returns>A ProjectItem object. </returns>
        public virtual EnvDTE.ProjectItem AddItem(string path, VSADDITEMOPERATION op)
        {
            return(UIThread.DoOnUIThread(delegate() {
                if (this.Project == null || this.Project.Project == null || this.Project.Project.Site == null || this.Project.Project.IsClosed)
                {
                    throw new InvalidOperationException();
                }

                ProjectNode proj = this.Project.Project;

                IVsExtensibility3 extensibility = this.Project.Project.Site.GetService(typeof(IVsExtensibility)) as IVsExtensibility3;

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

                EnvDTE.ProjectItem itemAdded = null;
                extensibility.EnterAutomationFunction();

                try
                {
                    VSADDRESULT[] result = new VSADDRESULT[1];
                    ErrorHandler.ThrowOnFailure(proj.AddItem(this.NodeWithItems.ID, op, path, 0, new string[1] {
                        path
                    }, IntPtr.Zero, result));

                    string fileName = System.IO.Path.GetFileName(path);
                    string fileDirectory = proj.GetBaseDirectoryForAddingFiles(this.NodeWithItems);
                    string filePathInProject = System.IO.Path.Combine(fileDirectory, fileName);

                    itemAdded = this.EvaluateAddResult(result[0], filePathInProject);
                }
                finally
                {
                    extensibility.ExitAutomationFunction();
                }

                return itemAdded;
            }));
        }
示例#28
0
        /// <summary>
        /// Expands the view of Solution Explorer to show project items.
        /// </summary>
        public virtual void ExpandView()
        {
            if (this.node == null || this.node.ProjectManager == null || this.node.ProjectManager.IsClosed || this.node.ProjectManager.Site == null)
            {
                throw new InvalidOperationException();
            }

            UIThread.DoOnUIThread(delegate()
            {
                using (AutomationScope scope = new AutomationScope(this.Node.ProjectManager.Site))
                {
                    IVsUIHierarchyWindow uiHierarchy = UIHierarchyUtilities.GetUIHierarchyWindow(this.node.ProjectManager.Site, HierarchyNode.SolutionExplorer);
                    if (uiHierarchy == null)
                    {
                        throw new InvalidOperationException();
                    }

                    ErrorHandler.ThrowOnFailure(uiHierarchy.ExpandItem(this.node.ProjectManager.InteropSafeIVsUIHierarchy, this.node.Id, EXPANDFLAGS.EXPF_ExpandFolder));
                }
            });
        }
示例#29
0
 public Reference Add(string bstrPath)
 {
     if (string.IsNullOrEmpty(bstrPath))
     {
         return(null);
     }
     return(UIThread.DoOnUIThread(delegate(){
         // approximate the C#/VB logic found in vsproject\vsproject\vsextrefs.cpp: STDMETHODIMP CVsProjExtRefMgr::Add(BSTR bstrPath, Reference** ppRefExtObject)
         bool isFusionName = bstrPath[0] == '*' || bstrPath.Contains(",");
         var isFullPath = false;
         VSCOMPONENTTYPE selectorType = VSCOMPONENTTYPE.VSCOMPONENTTYPE_ComPlus;
         // now we mimic behavior of CVsProjExtRefMgr::Add more precisely:
         // if bstrFile is absolute path and file exists - add file reference
         if (!isFusionName)
         {
             try
             {
                 if (System.IO.Path.IsPathRooted(bstrPath))
                 {
                     isFullPath = true;
                     if (System.IO.File.Exists(bstrPath))
                     {
                         selectorType = VSCOMPONENTTYPE.VSCOMPONENTTYPE_File;
                     }
                 }
             }
             catch (ArgumentException)
             {
             }
         }
         if (!isFullPath && bstrPath[0] != '*')
         {
             bstrPath = "*" + bstrPath; // may be e.g. just System.Xml, '*' will cause us to resolve it like MSBuild would
         }
         VSCOMPONENTSELECTORDATA selector = new VSCOMPONENTSELECTORDATA();
         selector.type = selectorType;
         selector.bstrFile = bstrPath;
         return AddFromSelectorData(selector);
     }));
 }
示例#30
0
        private IVsTextLines GetTextBuffer(System.IntPtr docDataExisting)
        {
            IVsTextLines textLines;

            if (docDataExisting == IntPtr.Zero)
            {
                // Create a new IVsTextLines buffer.
                Type textLinesType = typeof(IVsTextLines);
                Guid riid          = textLinesType.GUID;
                Guid clsid         = typeof(VsTextBufferClass).GUID;
                textLines = _package.CreateInstance(ref clsid, ref riid, textLinesType) as IVsTextLines;

                // set the buffer's site
                IOleServiceProvider provider = null;
                UIThread.DoOnUIThread(() => provider = (IOleServiceProvider)_serviceProvider.GetService(typeof(IOleServiceProvider)));
                ((IObjectWithSite)textLines).SetSite(provider);
            }
            else
            {
                // Use the existing text buffer
                Object dataObject = Marshal.GetObjectForIUnknown(docDataExisting);
                textLines = dataObject as IVsTextLines;
                if (textLines == null)
                {
                    // Try get the text buffer from textbuffer provider
                    IVsTextBufferProvider textBufferProvider = dataObject as IVsTextBufferProvider;
                    if (textBufferProvider != null)
                    {
                        textBufferProvider.GetTextBuffer(out textLines);
                    }
                }
                if (textLines == null)
                {
                    // Unknown docData type then, so we have to force VS to close the other editor.
                    ErrorHandler.ThrowOnFailure((int)VSConstants.VS_E_INCOMPATIBLEDOCDATA);
                }
            }
            return(textLines);
        }