示例#1
0
        private void Searcher_SaveRequested()
        {
            Search newSearch = Search;

            string        saveName         = newSearch.Name ?? String.Empty;
            List <Search> existingSearches = new List <Search>(Search.Searches);

            if (null != existingSearches.Find(search => search.Name == saveName))
            {
                // name already exists: choose a new name by appending an integer (CA-34780)
                for (int i = 2; ; ++i)
                {
                    string possName = string.Format("{0} ({1})", saveName, i);
                    if (null == existingSearches.Find(search => search.Name == possName))  // here's a good name
                    {
                        saveName = possName;
                        break;
                    }
                }
            }

            using (var dialog = new NameAndConnectionPrompt
            {
                PromptedName = saveName,
                HelpID = "SaveSearchDialog"
            })
            {
                if (dialog.ShowDialog(this) == DialogResult.OK &&
                    dialog.Connection != null) // CA-40307
                {
                    newSearch.Name       = dialog.PromptedName;
                    newSearch.Connection = dialog.Connection;

                    new SearchAction(newSearch, SearchAction.Operation.save).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))
            {
                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();
            }
        }
示例#3
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();
            }
        }