Example #1
0
        protected override bool CanExecute(OleMenuCommand command)
        {
            try
            {
                if (base.CanExecute(command))
                {
                    var project = VsShellHelper.Dte.SelectedItems.Item(1).Project;

                    if (project != null && project.Kind == PrjKind.prjKindCSharpProject)
                    {
                        return(true);
                    }
                    var projectItem = VsShellHelper.Dte.SelectedItems.Item(1).ProjectItem;
                    if (projectItem != null)
                    {
                        //Executed at the folder level / item level
                        if (projectItem.FileCodeModel != null &&
                            projectItem.FileCodeModel.Language == CodeModelLanguageConstants.vsCMLanguageCSharp)
                        {
                            return(true);
                        }

                        //TODO:probably a folder inside the solution
                        return(true);
                    }
                    //Executed at the solution level
                    var selectedHierarchy = VsShellHelper.GetSelectedHierarchy();
                    if (selectedHierarchy != null)
                    {
                        Project selectedProject = selectedHierarchy.ToProject();
                        if (selectedProject != null)
                        {
                            VSProject vsProject = selectedProject.Object as VSProject;
                            if (vsProject != null)
                            {
                                return(true);
                            }
                            return(false);
                        }
                    }
                    else if (VsShellHelper.Dte.Solution.IsOpen)
                    {
                        return(true);
                    }
                    return(false);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            return(false);
        }
 private void CastToTreeViewModel(Tree <TreeNode> modes, TreeViewModel root)
 {
     root.IsExpanded = true;
     root.Icon       = VsShellHelper.GetIcon(modes.ItemType);
     foreach (var treeItem in modes)
     {
         foreach (var child in treeItem.Children)
         {
             var childNode = root.AddChild(child.Node);
             childNode.Icon = VsShellHelper.GetIcon(child.ItemType);
             CastToTreeViewModel(child, childNode);
             if (child.ItemType == ItemType.File)
             {
                 childNode.IsExpanded = false;
             }
         }
     }
 }
Example #3
0
        private static void OnExecute(object sender, EventArgs e)
        {
            try
            {
                ToolWindowPane window = BreakpointGeneratorPackage.BreakpointGeneratorToolWindow;
                if ((window == null) || (window.Frame == null))
                {
                    throw new COMException("Cannot create toolwindow");
                }

                IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
                ErrorHandler.ThrowOnFailure(windowFrame.Show());

                var    viewModel = BreakpointGeneratorToolWindowViewModel.Instance;
                var    project   = VsShellHelper.Dte.SelectedItems.Item(1).Project;
                string path;

                if (project != null && project.Kind == PrjKind.prjKindCSharpProject)
                {
                    //Executed at the project level
                    path = project.FullName;
                    viewModel.AnalyzeProject(VsShellHelper.Dte, path);
                    return;
                }
                var projectItem = VsShellHelper.Dte.SelectedItems.Item(1).ProjectItem;
                if (projectItem != null)
                {
                    var containingProject = projectItem.ContainingProject;

                    //Executed at the folder level / item level
                    if (projectItem.FileCodeModel != null &&
                        projectItem.FileCodeModel.Language == CodeModelLanguageConstants.vsCMLanguageCSharp)
                    {
                        path = projectItem.FileNames[0];

                        viewModel.AnalyzeFile(VsShellHelper.Dte, containingProject.FullName, path);
                        return;
                    }

                    //probably a folder inside the solution

                    viewModel.AnalyzeProject(VsShellHelper.Dte, containingProject.FullName);
                    return;
                }
                //Executed at the solution level
                var selectedHierarchy = VsShellHelper.GetSelectedHierarchy();
                if (selectedHierarchy != null)
                {
                    Project selectedProject = selectedHierarchy.ToProject();
                    if (selectedProject != null)
                    {
                        VSProject vsProject = selectedProject.Object as VSProject;
                        if (vsProject != null)
                        {
                            path = vsProject.Project.FullName;
                            viewModel.AnalyzeProject(VsShellHelper.Dte, path);
                        }
                    }
                }
                else if (VsShellHelper.Dte.Solution.IsOpen)
                {
                    path = VsShellHelper.Dte.Solution.FullName;
                    viewModel.AnalyzeSolution(VsShellHelper.Dte, path);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }