コード例 #1
0
        /// <summary>
        /// Collapses this node and all its children.
        /// </summary>
        public virtual void Collapse()
        {
            foreach (var child in Nodes)
            {
                child.Collapse();
            }

            ErrorHandler.ThrowOnFailure(solutionExplorer.GetValue().ExpandItem(
                                            hierarchy as IVsUIHierarchy, itemId, EXPANDFLAGS.EXPF_CollapseFolder));
        }
コード例 #2
0
ファイル: MessageBoxService.cs プロジェクト: adalon/clide
 public bool?Show(string message,
                  string title                   = MessageBoxServiceDefaults.DefaultTitle,
                  MessageBoxButton button        = MessageBoxServiceDefaults.DefaultButton,
                  MessageBoxImage icon           = MessageBoxServiceDefaults.DefaultIcon,
                  MessageBoxResult defaultResult = MessageBoxServiceDefaults.DefaultResult)
 {
     return(jtf.Run(async() =>
     {
         await jtf.SwitchToMainThreadAsync();
         return uiShell.GetValue().ShowMessageBox(message, title, button, icon, defaultResult);
     }));
 }
コード例 #3
0
        bool Supports(IVsHierarchyItem item, out IVsHierarchyItem actualItem)
        {
            actualItem = item;
            if (!item.HierarchyIdentity.IsRoot)
            {
                return(false);
            }

            // We need the hierarchy fully loaded if it's not yet.
            if (!item.GetProperty <bool>(__VSPROPID4.VSPROPID_IsSolutionFullyLoaded))
            {
                // EnsureProjectIsLoaded MUST be executed in the UI/Main thread
                // Otherwise (if the Supports method is being invoked from a worker thread) duplicate keys might be generated
                actualItem = asyncManager.Run(async() =>
                {
                    await asyncManager.SwitchToMainThreadAsync();

                    Guid guid;
                    if (ErrorHandler.Succeeded(item.GetActualHierarchy().GetGuidProperty((uint)VSConstants.VSITEMID.Root, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out guid)) &&
                        // For the solution root item itself, the GUID will be empty.
                        guid != Guid.Empty)
                    {
                        if (ErrorHandler.Succeeded(((IVsSolution4)solution.GetValue()).EnsureProjectIsLoaded(ref guid, (uint)__VSBSLFLAGS.VSBSLFLAGS_None)))
                        {
                            return(hierarchyManager.GetHierarchyItem(item.GetActualHierarchy(), item.GetActualItemId()));
                        }
                    }

                    return(item);
                });
            }

            var hierarchy = actualItem.GetActualHierarchy();

            if (!(actualItem.GetActualHierarchy() is IVsProject) && !(hierarchy is FlavoredProjectBase))
            {
                return(false);
            }

            // Finally, solution folders look like projects, but they are not.
            // We need to filter them out too.
            var extenderObject = actualItem.GetExtenderObject();
            var dteProject     = extenderObject as EnvDTE.Project;

            if (extenderObject != null && extenderObject.GetType().FullName == "Microsoft.VisualStudio.Project.Automation.OAProject")
            {
                return(false);
            }

            if (extenderObject != null && dteProject != null && (dteProject.Object is EnvDTE80.SolutionFolder))
            {
                return(false);
            }

            return(true);
        }
コード例 #4
0
        TView CreateDialogImpl <TView>() where TView : IDialogWindow, new()
        {
            var dialog = new TView();

            if (dialog is Window dialogWindow)
            {
                jtf.Run(async() =>
                {
                    await jtf.SwitchToMainThreadAsync();
                    ErrorHandler.ThrowOnFailure(uiShell.GetValue().GetDialogOwnerHwnd(out var owner));
                    new WindowInteropHelper(dialogWindow).Owner = owner;
                    dialogWindow.WindowStartupLocation          = WindowStartupLocation.CenterScreen;
                    dialogWindow.ShowInTaskbar = false;
                });
            }

            return(dialog);
        }
コード例 #5
0
 public void Clear() => vsStatusBar.GetValue().Clear();
コード例 #6
0
 public ISolutionNode Adapt(Solution from) =>
 nodeFactory
 .Value
 .CreateNode(
     hierarchyItemManager.GetValue().GetHierarchyItem(
         vsSolution.GetValue() as IVsHierarchy, VSConstants.VSITEMID_ROOT)) as ISolutionNode;
コード例 #7
0
ファイル: VsToSolutionAdapter.cs プロジェクト: tondat/clide
 public IProjectNode Adapt(IVsHierarchy from) =>
 nodeFactory
 .Value
 .CreateNode(hierarchyItemManager.GetValue().GetHierarchyItem(from, VSConstants.VSITEMID_ROOT))
 as IProjectNode;
コード例 #8
0
        public SolutionFixture(string solutionFile, bool useCopy = false)
        {
            if (!Path.IsPathRooted(solutionFile))
            {
                var rootedFile = Path.Combine(Path.GetDirectoryName(GetType().Assembly.ManifestModule.FullyQualifiedName), solutionFile);
                if (!File.Exists(rootedFile))
                {
                    rootedFile = Path.Combine(baseDirectory, solutionFile);
                    var currentDir = new DirectoryInfo(Directory.GetCurrentDirectory());
                    while (!File.Exists(rootedFile) && currentDir != null)
                    {
                        rootedFile = Path.Combine(currentDir.FullName, solutionFile);
                        currentDir = currentDir.Parent;
                    }
                }

                solutionFile = rootedFile;
            }

            this.solutionFile = solutionFile;

            if (!File.Exists(solutionFile))
            {
                throw new FileNotFoundException("Could not find solution file " + solutionFile, solutionFile);
            }

            if (useCopy)
            {
                tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
                if (!Directory.Exists(tempDir))
                {
                    Directory.CreateDirectory(tempDir);
                }

                DirectoryCopy(Path.GetDirectoryName(solutionFile), tempDir, true);
                solutionFile = Path.Combine(tempDir, Path.GetFileName(solutionFile));
            }

            solution = new JoinableLazy <ISolutionNode>(async() =>
            {
                try
                {
                    var dte = GlobalServices.GetService <DTE>();
                    if (!dte.Solution.IsOpen || !dte.Solution.FullName.Equals(this.solutionFile, StringComparison.OrdinalIgnoreCase))
                    {
                        // Ensure no .suo is loaded, since that would dirty the state across runs.
                        var suoFile = Path.ChangeExtension(this.solutionFile, ".suo");
                        if (File.Exists(suoFile))
                        {
                            Try(() => File.Delete(suoFile));
                        }

                        var sdfFile = Path.ChangeExtension(this.solutionFile, ".sdf");
                        if (File.Exists(sdfFile))
                        {
                            Try(() => File.Delete(sdfFile));
                        }

                        var vsDir = Path.Combine(Path.GetDirectoryName(this.solutionFile), ".vs");
                        if (Directory.Exists(vsDir))
                        {
                            Try(() => Directory.Delete(vsDir, true));
                        }

                        dte.Solution.Open(this.solutionFile);
                        GlobalServices.GetService <SVsSolution, IVsSolution4>()
                        .EnsureSolutionIsLoaded((uint)(__VSBSLFLAGS.VSBSLFLAGS_LoadAllPendingProjects | __VSBSLFLAGS.VSBSLFLAGS_LoadBuildDependencies));
                    }

                    return(await GlobalServices.GetService <SComponentModel, IComponentModel>().GetService <ISolutionExplorer>().Solution);
                }
                catch (Exception ex)
                {
                    throw new ArgumentException("Failed to open and access solution: " + solutionFile, ex);
                }
            });

            // If the collection is being created inside the VS process,
            // instantiate the value right now to cause the solution to open.
            if (GlobalServices.GetService <DTE>() != null)
            {
                Assert.NotNull(solution.GetValue());
            }
        }