private (string documentPath, string projectRootPath) GetRunningDocumentPaths(uint docCookie)
        {
            runningDocumentTable.GetDocumentInfo(docCookie,
                                                 out var flags, out var dummyReadLocks,
                                                 out var dummyEditLocks, out string documentPath,
                                                 out var dummyHierarchy,
                                                 out var dummyItemId, out var dummyData);

            const int excludeFlags =
                (int)VsRdtFlags.VirtualDocument |
                (int)VsRdtFlags.ProjSlnDocument |
                (int)VsRdtFlags.DontSaveAs |
                (int)VsRdtFlags.DontAddToMRU;

            if (((int)flags & excludeFlags) != 0)
            {
                return(null, null);
            }

            string projectRootFolder = null;

            if (documentPath.StartsWith(CurrentSolutionPath, StringComparison.OrdinalIgnoreCase))
            {
                var projectHierarchy = VsShellUtilities.GetProject(this, documentPath);
                if (projectHierarchy != null)
                {
                    projectHierarchy.GetCanonicalName((uint)VSConstants.VSITEMID.Root, out string canonicalName);
                    if (canonicalName != null &&
                        //For projectless solution items GetCanonicalName returns a guid
                        !Guid.TryParse(canonicalName, out var dummyGuid))
                    {
                        projectRootFolder = Helpers.GetProperlyCasedPath(canonicalName);
                    }
                }
            }

            //We need this because sometimes GetDocumentInfo returns the path lowercased
            documentPath = Helpers.GetProperlyCasedPath(documentPath);

            return(documentPath, projectRootFolder);
        }
Esempio n. 2
0
        public override void OnExecute(CommandEventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            AnkhMessageBox mb = new AnkhMessageBox(e.Context);

            // Cache items to avoid problems when selection changes by opening editor
            List <SvnItem> items = new List <SvnItem>(e.Selection.GetSelectedSvnItems(false));

            foreach (SvnItem item in items)
            {
                if (!item.Exists)
                {
                    continue;
                }

                bool selectInSolutionExplorer = false;

                try
                {
                    switch (e.Command)
                    {
                    case AnkhCommand.ItemOpenVisualStudio:
                        IProjectFileMapper mapper = e.GetService <IProjectFileMapper>();

                        if (mapper.IsProjectFileOrSolution(item.FullPath))
                        {
                            selectInSolutionExplorer = true;
                            break;
                        }
                        if (item.IsDirectory)
                        {
                            goto case AnkhCommand.ItemOpenWindows;
                        }

                        VsShellUtilities.OpenDocument(e.Context, item.FullPath);
                        break;

                    case AnkhCommand.ItemOpenTextEditor:
                    {
                        IVsUIHierarchy hier;
                        IVsWindowFrame frame;
                        uint           id;

                        if (!item.IsFile)
                        {
                            continue;
                        }

                        VsShellUtilities.OpenDocument(e.Context, item.FullPath, VSConstants.LOGVIEWID_TextView, out hier, out id, out frame);
                    }
                    break;

                    case AnkhCommand.ItemOpenWindows:
                        System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(item.FullPath);
                        psi.Verb = "open";
                        System.Diagnostics.Process.Start(psi);
                        break;
                    }
                }
                catch (IOException ee)
                {
                    mb.Show(ee.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (COMException ee)
                {
                    mb.Show(ee.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (InvalidOperationException ee)
                {
                    mb.Show(ee.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (System.ComponentModel.Win32Exception ee)
                {
                    mb.Show(ee.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                if (selectInSolutionExplorer)
                {
                    IVsUIHierarchyWindow hierWindow = VsShellUtilities.GetUIHierarchyWindow(e.Context, new Guid(ToolWindowGuids80.SolutionExplorer));

                    IVsProject project = VsShellUtilities.GetProject(e.Context, item.FullPath) as IVsProject;

                    if (hierWindow != null)
                    {
                        int  found;
                        uint id;
                        VSDOCUMENTPRIORITY[] prio = new VSDOCUMENTPRIORITY[1];
                        if (project != null && VSErr.Succeeded(project.IsDocumentInProject(item.FullPath, out found, prio, out id)) && found != 0)
                        {
                            hierWindow.ExpandItem(project as IVsUIHierarchy, id, EXPANDFLAGS.EXPF_SelectItem);
                        }
                        else if (string.Equals(item.FullPath, e.Selection.SolutionFilename, StringComparison.OrdinalIgnoreCase))
                        {
                            hierWindow.ExpandItem(e.GetService <IVsUIHierarchy>(typeof(SVsSolution)), VSItemId.Root, EXPANDFLAGS.EXPF_SelectItem);
                        }

                        // Now try to activate the solution explorer
                        IVsWindowFrame solutionExplorer;
                        Guid           solutionExplorerGuid = new Guid(ToolWindowGuids80.SolutionExplorer);
                        IVsUIShell     shell = e.GetService <IVsUIShell>(typeof(SVsUIShell));

                        if (shell != null)
                        {
                            shell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref solutionExplorerGuid, out solutionExplorer);

                            if (solutionExplorer != null)
                            {
                                solutionExplorer.Show();
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public override void OnExecute(CommandEventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            SvnItem node = EnumTools.GetFirst(e.Selection.GetSelectedSvnItems(false));

            IAnkhCommandService cmd = e.GetService <IAnkhCommandService>();

            switch (e.Command)
            {
            case AnkhCommand.ItemSelectInRepositoryExplorer:
                if (node == null || node.Uri == null)
                {
                    return;
                }

                if (cmd != null)
                {
                    cmd.DirectlyExecCommand(AnkhCommand.RepositoryBrowse, node.FullPath);
                }
                break;

            case AnkhCommand.ItemSelectInWorkingCopyExplorer:
                if (node == null || !node.Exists)
                {
                    return;
                }

                if (cmd != null)
                {
                    cmd.DirectlyExecCommand(AnkhCommand.WorkingCopyBrowse, node.FullPath);
                }
                break;

            case AnkhCommand.ItemSelectInFileExplorer:
                if (node == null || !node.Exists)
                {
                    return;
                }

                SelectInFileExplorer(node.FullPath);
                break;

            case AnkhCommand.ItemSelectInSolutionExplorer:
                if (node == null)
                {
                    return;
                }

                IVsUIHierarchyWindow hierWindow = VsShellUtilities.GetUIHierarchyWindow(e.Context, new Guid(ToolWindowGuids80.SolutionExplorer));

                IVsProject project = VsShellUtilities.GetProject(e.Context, node.FullPath) as IVsProject;

                if (hierWindow != null)
                {
                    int  found;
                    uint id;
                    VSDOCUMENTPRIORITY[] prio = new VSDOCUMENTPRIORITY[1];
                    if (project != null && VSErr.Succeeded(project.IsDocumentInProject(node.FullPath, out found, prio, out id)) && found != 0)
                    {
                        hierWindow.ExpandItem(project as IVsUIHierarchy, id, EXPANDFLAGS.EXPF_SelectItem);
                    }
                    else if (string.Equals(node.FullPath, e.Selection.SolutionFilename, StringComparison.OrdinalIgnoreCase))
                    {
                        hierWindow.ExpandItem(e.GetService <IVsUIHierarchy>(typeof(SVsSolution)), VSItemId.Root, EXPANDFLAGS.EXPF_SelectItem);
                    }

                    // Now try to activate the solution explorer
                    IVsWindowFrame solutionExplorer;
                    Guid           solutionExplorerGuid = new Guid(ToolWindowGuids80.SolutionExplorer);
                    IVsUIShell     shell = e.GetService <IVsUIShell>(typeof(SVsUIShell));

                    if (shell != null)
                    {
                        shell.FindToolWindow((uint)__VSFINDTOOLWIN.FTW_fForceCreate, ref solutionExplorerGuid, out solutionExplorer);

                        if (solutionExplorer != null)
                        {
                            solutionExplorer.Show();
                        }
                    }
                }
                break;
            }
        }