Пример #1
0
        public static Uri DisplayBrowseDialogAndGetResult(WizardPage page, SvnItem target, Uri baseUri)
        {
            IAnkhServiceProvider context = ((MergeWizard)page.Wizard).Context;

            if (((MergeWizard)page.Wizard).MergeTarget.IsDirectory)
            {
                using (RepositoryFolderBrowserDialog dlg = new RepositoryFolderBrowserDialog())
                {
                    dlg.SelectedUri = baseUri;

                    if (dlg.ShowDialog(context) == DialogResult.OK)
                    {
                        return dlg.SelectedUri;
                    }
                }
            }
            else
            {
                using (RepositoryOpenDialog dlg = new RepositoryOpenDialog())
                {
                    string fileName = Path.GetFileName(target.FullPath);

                    dlg.Context = context;
                    dlg.Filter = fileName + "|" + fileName + "|All Files (*.*)|*";

                    dlg.SelectedUri = baseUri;

                    if (dlg.ShowDialog(context) == DialogResult.OK)
                        return dlg.SelectedUri;
                }
            }

            return null;
        }
Пример #2
0
 public ItemSorter(RepositoryOpenDialog dlg)
 {
     if (dlg == null)
     {
         throw new ArgumentNullException("dlg");
     }
     _dlg = dlg;
 }
Пример #3
0
        public override void OnExecute(CommandEventArgs e)
        {
            Uri selectedUri = null;
            Uri rootUri = null;

            if (e.Argument is string && Uri.TryCreate((string)e.Argument, UriKind.Absolute, out selectedUri))
            { }
            else if (e.Argument is SvnOrigin)
            {
                SvnOrigin origin = (SvnOrigin)e.Argument;
                selectedUri = origin.Uri;
                rootUri = origin.RepositoryRoot;
            }
            else if (e.Argument is Uri)
                selectedUri = (Uri)e.Argument;

            IAnkhSolutionSettings settings = e.GetService<IAnkhSolutionSettings>();

            if (e.PromptUser || selectedUri == null)
            {
                using (RepositoryOpenDialog dlg = new RepositoryOpenDialog())
                {
                    dlg.Context = e.Context;
                    dlg.Filter = settings.OpenProjectFilterName + "|" + settings.AllProjectExtensionsFilter + "|All Files (*.*)|*";

                    if (selectedUri != null)
                        dlg.SelectedUri = selectedUri;

                    if (e.Command != AnkhCommand.FileFileOpenFromSubversion && e.Command != AnkhCommand.FileSccOpenFromSubversion)
                    {
                        foreach (string ext in settings.SolutionFilter.Split(';'))
                        {
                            dlg.Filter = dlg.Filter.Replace(ext.Trim() + ';', "");
                        }
                    }

                    if (dlg.ShowDialog(e.Context) != DialogResult.OK)
                        return;

                    selectedUri = dlg.SelectedUri;
                    rootUri = dlg.SelectedRepositoryRoot;
                }
            }
            else if (rootUri == null)
            {
                if (!e.GetService<IProgressRunner>().RunModal("Retrieving Repository Root",
                    delegate(object sender, ProgressWorkerArgs a)
                    {

                        rootUri = a.Client.GetRepositoryRoot(selectedUri);

                    }).Succeeded)
                {
                    return;
                }
            }

            string path = settings.NewProjectLocation;

            string name = Path.GetFileNameWithoutExtension(SvnTools.GetFileName(selectedUri));

            string newPath;
            int n = 0;
            do
            {
                newPath = Path.Combine(path, name);
                if (n > 0)
                    newPath += string.Format("({0})", n);
                n++;
            }
            while (File.Exists(newPath) || Directory.Exists(newPath));

            using (CheckoutProject dlg = new CheckoutProject())
            {
                dlg.Context = e.Context;
                dlg.ProjectUri = selectedUri;
                dlg.RepositoryRootUri = rootUri;
                dlg.SelectedPath = newPath;
                dlg.SvnOrigin = new SvnOrigin(selectedUri, rootUri);
                dlg.HandleCreated += delegate
                {
                    FindRoot(e.Context, selectedUri, dlg);
                };

                if (dlg.ShowDialog(e.Context) != DialogResult.OK)
                    return;

                IVsSolution2 sol = e.GetService<IVsSolution2>(typeof(SVsSolution));

                if (sol != null)
                {
                    sol.CloseSolutionElement(VSConstants.VSITEMID_ROOT, null, 0); // Closes the current solution
                }

                IAnkhSccService scc = e.GetService<IAnkhSccService>();

                if (scc != null)
                    scc.RegisterAsPrimarySccProvider(); // Make us the current SCC provider!

                CheckOutAndOpenSolution(e, dlg.ProjectTop, null, dlg.ProjectTop, dlg.SelectedPath, dlg.ProjectUri);

                sol = e.GetService<IVsSolution2>(typeof(SVsSolution));

                if (sol != null)
                {
                    string file, user, dir;

                    if (ErrorHandler.Succeeded(sol.GetSolutionInfo(out dir, out file, out user))
                        && !string.IsNullOrEmpty(file))
                    {
                        scc.SetProjectManaged(null, true);
                    }
                }
            }
        }