Пример #1
0
        /// <summary>
        /// Adds references to this container from a MSBuild project.
        /// </summary>
        public void LoadReferencesFromBuildProject(MSBuild.Project buildProject)
        {
            UIThread.MustBeCalledFromUIThread();

            foreach (string referenceType in SupportedReferenceTypes)
            {
                IEnumerable <MSBuild.ProjectItem> referencesGroup = this.ProjectMgr.BuildProject.GetItems(referenceType);

                bool isAssemblyReference = referenceType == ProjectFileConstants.Reference;
                // If the project was loaded for browsing we should still create the nodes but as not resolved.
                if (isAssemblyReference &&
                    (!ProjectMgr.BuildProject.Targets.ContainsKey(MsBuildTarget.ResolveAssemblyReferences) || this.ProjectMgr.Build(MsBuildTarget.ResolveAssemblyReferences) != MSBuildResult.Successful))
                {
                    continue;
                }

                foreach (MSBuild.ProjectItem item in referencesGroup)
                {
                    ProjectElement element = new MsBuildProjectElement(this.ProjectMgr, item);

                    ReferenceNode node = CreateReferenceNode(referenceType, element);

                    if (node != null)
                    {
                        // Make sure that we do not want to add the item twice to the ui hierarchy
                        // We are using here the UI representation of the Node namely the Caption to find that out, in order to
                        // avoid different representation problems.
                        // Example :<Reference Include="EnvDTE80, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
                        //		  <Reference Include="EnvDTE80" />
                        bool found = false;
                        for (HierarchyNode n = this.FirstChild; n != null && !found; n = n.NextSibling)
                        {
                            if (String.Compare(n.Caption, node.Caption, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                found = true;
                            }
                        }

                        if (!found)
                        {
                            this.AddChild(node);
                        }
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Constructor.  Inititialize member data.
        /// </summary>
        public IDEBuildLogger(IVsOutputWindowPane output, TaskProvider taskProvider, IVsHierarchy hierarchy)
        {
            UIThread.MustBeCalledFromUIThread();
            Utilities.ArgumentNotNull("taskProvider", taskProvider);
            Utilities.ArgumentNotNull("hierarchy", hierarchy);

            Trace.WriteLineIf(Thread.CurrentThread.GetApartmentState() != ApartmentState.STA, "WARNING: IDEBuildLogger constructor running on the wrong thread.");

            IOleServiceProvider site;

            Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(hierarchy.GetSite(out site));

            this.taskProvider     = taskProvider;
            this.outputWindowPane = output;
            this.hierarchy        = hierarchy;
            this.serviceProvider  = new ServiceProvider(site);
            this.dispatcher       = Dispatcher.CurrentDispatcher;
        }
Пример #3
0
        /// <summary>
        /// Handles the exclude from project command.
        /// </summary>
        /// <returns></returns>
        internal override int ExcludeFromProject()
        {
            UIThread.MustBeCalledFromUIThread();

            Debug.Assert(this.ProjectMgr != null, "The project item " + this.ToString() + " has not been initialised correctly. It has a null ProjectMgr");
            if (!ProjectMgr.QueryEditProjectFile(false) ||
                !ProjectMgr.QueryFolderRemove(Parent, Url))
            {
                return(VSConstants.E_FAIL);
            }

            for (var child = FirstChild; child != null; child = child.NextSibling)
            {
                // we automatically exclude all children below us too
                int hr = child.ExcludeFromProject();
                if (ErrorHandler.Failed(hr))
                {
                    return(hr);
                }
            }

            ResetNodeProperties();
            ItemNode.RemoveFromProjectFile();
            if (!Directory.Exists(CommonUtils.TrimEndSeparator(Url)))
            {
                ProjectMgr.OnItemDeleted(this);
                Parent.RemoveChild(this);
            }
            else
            {
                ItemNode = new AllFilesProjectElement(Url, ItemNode.ItemTypeName, ProjectMgr);
                if (!ProjectMgr.IsShowingAllFiles)
                {
                    IsVisible = false;
                    ProjectMgr.OnInvalidateItems(Parent);
                }
                ProjectMgr.ReDrawNode(this, UIHierarchyElement.Icon);
                ProjectMgr.OnPropertyChanged(this, (int)__VSHPROPID.VSHPROPID_IsNonMemberItem, 0);
            }
            ((IVsUIShell)GetService(typeof(SVsUIShell))).RefreshPropertyBrowser(0);

            return(VSConstants.S_OK);
        }
Пример #4
0
        /// <summary>
        /// Links a reference node to the project and hierarchy.
        /// </summary>
        protected override void BindReferenceData()
        {
            UIThread.MustBeCalledFromUIThread();

            Debug.Assert(this.assemblyName != null, "The AssemblyName field has not been initialized");

            // If the item has not been set correctly like in case of a new reference added it now.
            // The constructor for the AssemblyReference node will create a default project item. In that case the Item is null.
            // We need to specify here the correct project element.
            if (this.ItemNode == null || this.ItemNode is VirtualProjectElement)
            {
                this.ItemNode = new MsBuildProjectElement(this.ProjectMgr, this.assemblyName.FullName, ProjectFileConstants.Reference);
            }

            // Set the basic information we know about
            this.ItemNode.SetMetadata(ProjectFileConstants.Name, this.assemblyName.Name);
            this.ItemNode.SetMetadata(ProjectFileConstants.AssemblyName, Path.GetFileName(this.assemblyPath));

            this.SetReferenceProperties();
        }
Пример #5
0
        /// <summary>
        /// Gets or creates the specified output pane.
        /// </summary>
        /// <exception cref="InvalidOperationException">The output pane could
        /// not be found or created.</exception>
        public static OutputWindowRedirector Get(IServiceProvider provider, Guid id, string title)
        {
            var outputWindow = provider.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;

            if (outputWindow == null)
            {
                throw new InvalidOperationException("Unable to get output window service");
            }

            IVsOutputWindowPane pane;

            if (ErrorHandler.Failed(outputWindow.GetPane(id, out pane)) || pane == null)
            {
                if (ErrorHandler.Failed(UIThread.Invoke(() => outputWindow.CreatePane(id, title, 1, 0))))
                {
                    throw new InvalidOperationException("Unable to create output pane");
                }
            }
            return(new OutputWindowRedirector(provider, id));
        }
Пример #6
0
        public uint Add(HierarchyNode node)
        {
            UIThread.MustBeCalledFromUIThread();

#if DEBUG
            foreach (var item in _ids)
            {
                Debug.Assert(node != item);
            }
#endif
            if (_freedIds.Count > 0)
            {
                var i = _freedIds.Pop();
                _ids[i] = node;
                return((uint)i + 1);
            }
            else
            {
                _ids.Add(node);
                // ids are 1 based
                return((uint)_ids.Count);
            }
        }
Пример #7
0
 public virtual IList <Output> EnumerateOutputs()
 {
     UIThread.Invoke(Refresh);
     return(_outputs);
 }
Пример #8
0
 public override void Show()
 {
     UIThread.Invoke(() => ErrorHandler.ThrowOnFailure(_pane.Activate()));
 }