Пример #1
0
        private void Execute(Folder folder, IWin32Window ownerWindow)
        {
            IXenConnection connection;
            String         name;

            // Different dialogs depending whether we're at the top level or adding a subfolder.
            // Also offer them a choice of connections if the connection they're on is Read Only
            // (although we will also sudo a Read Only command when the FolderAction is run).
            if (folder == null || folder.IsRootFolder || folder.Connection == null || CrossConnectionCommand.IsReadOnly(folder.Connection))
            {
                NameAndConnectionPrompt dialog = new NameAndConnectionPrompt();
                dialog.Text   = Messages.NEW_FOLDER_DIALOG_TITLE;
                dialog.OKText = Messages.CREATE_MNEMONIC_R;
                dialog.HelpID = "NewFolderDialog";
                if (dialog.ShowDialog(ownerWindow) != DialogResult.OK)
                {
                    return;
                }
                name       = dialog.PromptedName;
                connection = dialog.Connection;
            }
            else
            {
                name       = InputPromptDialog.Prompt(ownerWindow, Messages.NEW_FOLDER_NAME, Messages.NEW_FOLDER_DIALOG_TITLE, "NewFolderDialog");
                connection = folder.Connection;
            }

            if (name == null)
            {
                return;  // Happens if InputPromptDialog was cancelled
            }
            List <string> newPaths = new List <string>();

            foreach (string s in name.Split(';'))
            {
                string n = s;
                Folders.FixupRelativePath(ref n);
                if (string.IsNullOrEmpty(n))
                {
                    continue;
                }

                newPaths.Add(Folders.AppendPath(folder == null ? Folders.PATH_SEPARATOR : folder.opaque_ref, n));
            }

            if (newPaths.Count > 0)
            {
                FolderAction action = new FolderAction(connection, FolderAction.Kind.New, newPaths.ToArray());

                Action <ActionBase> completed = null;
                completed = delegate
                {
                    action.Completed -= completed;
                    if (action.Succeeded)
                    {
                        Program.MainWindow.TrySelectNewNode(delegate(object o)
                        {
                            Folder ff = o as Folder;
                            return(ff != null && newPaths[0] == ff.opaque_ref);
                        }, true, true, true);
                    }
                };

                action.Completed += completed;
                action.RunAsync();
            }
        }
Пример #2
0
        private void Execute(Folder folder, IWin32Window ownerWindow)
        {
            IXenConnection connection;
            String         name;

            // Different dialogs depending whether we're at the top level or adding a subfolder.
            // Also offer them a choice of connections if the connection they're on is Read Only
            // (although we will also sudo a Read Only command when the FolderAction is run).
            if (folder == null || folder.IsRootFolder || folder.Connection == null || CrossConnectionCommand.IsReadOnly(folder.Connection))
            {
                using (var dialog = new NameAndConnectionPrompt
                {
                    Text = Messages.NEW_FOLDER_DIALOG_TITLE,
                    OKText = Messages.CREATE_MNEMONIC_R,
                    HelpID = "NewFolderDialog"
                })
                {
                    if (dialog.ShowDialog(ownerWindow) != DialogResult.OK)
                    {
                        return;
                    }
                    name       = dialog.PromptedName;
                    connection = dialog.Connection;
                }
            }
            else
            {
                using (var dialog = new InputPromptDialog {
                    Text = Messages.NEW_FOLDER_DIALOG_TITLE,
                    PromptText = Messages.NEW_FOLDER_NAME,
                    OkButtonText = Messages.NEW_FOLDER_BUTTON,
                    HelpID = "NewFolderDialog"
                })
                {
                    if (dialog.ShowDialog(ownerWindow) != DialogResult.OK)
                    {
                        return;
                    }
                    name = dialog.InputText;
                }
                connection = folder.Connection;
            }


            List <string> newPaths = new List <string>();

            foreach (string s in name.Split(';'))
            {
                string n = s;
                Folders.FixupRelativePath(ref n);
                if (string.IsNullOrEmpty(n))
                {
                    continue;
                }

                newPaths.Add(Folders.AppendPath(folder == null ? Folders.PATH_SEPARATOR : folder.opaque_ref, n));
            }

            if (newPaths.Count > 0)
            {
                var action = new CreateFolderAction(connection, newPaths.ToArray());

                action.Completed += Action_Completed;
                action.RunAsync();
            }
        }