Beispiel #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);
        }
        public override void OnExecute(CommandEventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            Uri selectedUri = null;
            Uri rootUri     = null;

            bool addingProject = (e.Command == AnkhCommand.FileFileAddFromSubversion ||
                                  e.Command == AnkhCommand.FileSccAddFromSubversion);

            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())
                {
                    if (addingProject)
                    {
                        dlg.Text = CommandStrings.AddProjectFromSubversion;
                    }

                    dlg.Filter = settings.OpenProjectFilterName + "|" + settings.AllProjectExtensionsFilter + "|All Files (*.*)|*";

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

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

                    selectedUri = dlg.SelectedUri;
                    rootUri     = dlg.SelectedRepositoryRoot;
                }
            }
            else if (rootUri == null)
            {
                if (!e.GetService <IProgressRunner>().RunModal(CommandStrings.RetrievingRepositoryRoot,
                                                               delegate(object sender, ProgressWorkerArgs a)
                {
                    rootUri = a.Client.GetRepositoryRoot(selectedUri);
                }).Succeeded)
                {
                    return;
                }
            }

            string defaultPath = settings.NewProjectLocation;

            if (addingProject)
            {
                IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>();

                if (!string.IsNullOrEmpty(ss.ProjectRoot))
                {
                    defaultPath = ss.ProjectRoot;
                }
            }

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

            string newPath;
            int    n = 0;

            do
            {
                newPath = Path.Combine(defaultPath, 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;

                if (addingProject)
                {
                    dlg.Text = CommandStrings.AddProjectFromSubversion;
                }
                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;
                }

                if (!addingProject)
                {
                    OpenSolution(e, dlg);
                }
                else
                {
                    CheckOutAndOpenProject(e, dlg.ProjectTop, dlg.Revision, dlg.ProjectTop, dlg.SelectedPath, dlg.ProjectUri);
                }
            }
        }