Example #1
0
        public void MaybeMigrate()
        {
            IAnkhPackage        pkg = GetService <IAnkhPackage>();
            IAnkhCommandService cs  = GetService <IAnkhCommandService>();

            if (pkg == null || cs == null)
            {
                return;
            }

            using (RegistryKey rkRoot = pkg.UserRegistryRoot)
                using (RegistryKey ankhMigration = rkRoot.CreateSubKey("AnkhSVN-Trigger"))
                {
                    int    migrateFrom = 0;
                    object value       = ankhMigration.GetValue(MigrateId, migrateFrom);

                    if (value is int)
                    {
                        migrateFrom = (int)value;
                    }
                    else
                    {
                        ankhMigration.DeleteValue(MigrateId, false);
                    }

                    if (migrateFrom < 0)
                    {
                        migrateFrom = 0;
                    }

                    if (migrateFrom >= AnkhId.MigrateVersion)
                    {
                        return;                 // Nothing to do
                    }
                    try
                    {
                        if (cs.DirectlyExecCommand(AnkhCommand.MigrateSettings).Success)
                        {
                            ankhMigration.SetValue(MigrateId, AnkhId.MigrateVersion);
                        }
                    }
                    catch
                    { /* NOP: Don't fail here... ever! */ }
                }
        }
Example #2
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;
            }
        }