protected override void ExecuteCore(SelectedItemCollection selection) { VM snapshot = (VM)selection[0].XenObject; // Generate list of all taken VM/snapshot/template names List <string> takenNames = new List <VM>(snapshot.Connection.Cache.VMs).ConvertAll(v => v.Name()); // Generate a unique suggested name for the new template string defaultName = Helpers.MakeUniqueName(String.Format(Messages.TEMPLATE_FROM_SNAPSHOT_DEFAULT_NAME, snapshot.Name()), takenNames); using (var dialog = new InputPromptDialog { Text = Messages.SAVE_AS_TEMPLATE, PromptText = Messages.NEW_TEMPLATE_PROMPT, InputText = defaultName, HelpID = "VMSnapshotPage" }) { if (dialog.ShowDialog(Parent) == DialogResult.OK) { // TODO: work out what the new description should be var action = new VMCloneAction(snapshot, dialog.InputText, ""); action.Completed += action_Completed; action.RunAsync(); } } }
protected override void ExecuteCore(SelectedItemCollection selection) { VM snapshot = (VM)selection[0].XenObject; // Generate list of all taken VM/snapshot/template names List <string> takenNames = new List <VM>(snapshot.Connection.Cache.VMs).ConvertAll(v => v.Name); // Generate a unique suggested name for the new template string defaultName = Helpers.MakeUniqueName(String.Format(Messages.TEMPLATE_FROM_SNAPSHOT_DEFAULT_NAME, snapshot.Name), takenNames); string newName = InputPromptDialog.Prompt(Parent, Messages.NEW_TEMPLATE_PROMPT, Messages.SAVE_AS_TEMPLATE, defaultName, "VMSnapshotPage"); if (newName != null) // is null if user cancelled { // TODO: work out what the new description should be var action = new VMCloneAction(snapshot, newName, ""); action.Completed += action_Completed; action.RunAsync(); } }
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(); } }
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(); } }