public virtual void OnRequestUserSaveWorkflow(Object sender, WorkspaceSaveEventArgs e) { if (RequestUserSaveWorkflow != null) { RequestUserSaveWorkflow(this, e); } }
/// <summary> /// Requests a message box asking the user to save the workspace and allows saving. /// </summary> /// <param name="workspace">The workspace for which to show the dialog</param> /// <returns>False if the user cancels, otherwise true</returns> public bool AskUserToSaveWorkspaceOrCancel(dynWorkspaceModel workspace, bool allowCancel = true) { var args = new WorkspaceSaveEventArgs(workspace, allowCancel); OnRequestUserSaveWorkflow(this, args); if (!args.Success) { return(false); } return(true); }
/// <summary> /// Ask the user if they want to save any unsaved changes, return false if the user cancels. /// </summary> /// <param name="allowCancel">Whether to show cancel button to user. </param> /// <returns>Whether the cleanup was completed or cancelled.</returns> public bool AskUserToSaveWorkspacesOrCancel(bool allowCancel = true) { foreach (var wvm in Workspaces.Where((wvm) => wvm.Model.HasUnsavedChanges)) { //if (!AskUserToSaveWorkspaceOrCancel(wvm.Model, allowCancel)) // return false; var args = new WorkspaceSaveEventArgs(wvm.Model, allowCancel); OnRequestUserSaveWorkflow(this, args); if (!args.Success) { return(false); } } return(true); }
private void RequestUserSaveWorkflow(object sender, WorkspaceSaveEventArgs e) { // Some test cases may create nodes or modify nodes, so when Dynamo // is shutting down, Dynamo will fire RequestUserSaveWorkflow event // to save the change, if there is no a corresponding event handler, // or the event handler fails to save the change, shut down process // will be aborted and a lot of resource will not be released // (details refer to DynamoViewModel.PerformShutdownSequence()). // // As this test fixture is UIless, DynamoView, which implements // event handler for DynamoViewModel.RequestUserSaveWorkflow event, // won't be created. To ensure resource be released properly, we // implement event handler here and simply mark the save event's // susccess status to true to notify Dynamo to continue the shut // down process. e.Success = true; }
/// <summary> /// Ask the user if they want to save any unsaved changes, return false if the user cancels. /// </summary> /// <param name="allowCancel">Whether to show cancel button to user. </param> /// <returns>Whether the cleanup was completed or cancelled.</returns> public bool AskUserToSaveWorkspacesOrCancel(bool allowCancel = true) { if (null != automationSettings) { // In an automation run, Dynamo should not be asking user to save // the modified file. Instead it should be shutting down, leaving // behind unsaved changes (if saving is desired, then the save command // should have been recorded for the test case to it can be replayed). // if (automationSettings.IsInPlaybackMode) return true; // In playback mode, just exit without saving. } foreach (var wvm in Workspaces.Where((wvm) => wvm.Model.HasUnsavedChanges)) { //if (!AskUserToSaveWorkspaceOrCancel(wvm.Model, allowCancel)) // return false; var args = new WorkspaceSaveEventArgs(wvm.Model, allowCancel); OnRequestUserSaveWorkflow(this, args); if (!args.Success) return false; } return true; }
/// <summary> /// Requests a message box asking the user to save the workspace and allows saving. /// </summary> /// <param name="workspace">The workspace for which to show the dialog</param> /// <returns>False if the user cancels, otherwise true</returns> public bool AskUserToSaveWorkspaceOrCancel(WorkspaceModel workspace, bool allowCancel = true) { var args = new WorkspaceSaveEventArgs(workspace, allowCancel); OnRequestUserSaveWorkflow(this, args); if (!args.Success) return false; return true; }
void DynamoViewModelRequestUserSaveWorkflow(object sender, WorkspaceSaveEventArgs e) { var dialogText = ""; if (e.Workspace is CustomNodeWorkspaceModel) { dialogText = String.Format(Dynamo.Wpf.Properties.Resources.MessageConfirmToSaveCustomNode, e.Workspace.Name); } else // homeworkspace { if (string.IsNullOrEmpty(e.Workspace.FileName)) { dialogText = Dynamo.Wpf.Properties.Resources.MessageConfirmToSaveHomeWorkSpace; } else { dialogText = String.Format(Dynamo.Wpf.Properties.Resources.MessageConfirmToSaveNamedHomeWorkSpace, Path.GetFileName(e.Workspace.FileName)); } } var buttons = e.AllowCancel ? MessageBoxButton.YesNoCancel : MessageBoxButton.YesNo; var result = System.Windows.MessageBox.Show(dialogText, Dynamo.Wpf.Properties.Resources.SaveConfirmationMessageBoxTitle, buttons, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { e.Success = dynamoViewModel.ShowSaveDialogIfNeededAndSave(e.Workspace); } else if (result == MessageBoxResult.Cancel) { //return false; e.Success = false; } else { e.Success = true; } }
void _vm_RequestUserSaveWorkflow(object sender, WorkspaceSaveEventArgs e) { var dialogText = ""; if (e.Workspace is CustomNodeWorkspaceModel) { dialogText = "You have unsaved changes to custom node workspace: \"" + e.Workspace.Name + "\"\n\n Would you like to save your changes?"; } else // homeworkspace { if (string.IsNullOrEmpty(e.Workspace.FileName)) { dialogText = "You have unsaved changes to the Home workspace." + "\n\n Would you like to save your changes?"; } else { dialogText = "You have unsaved changes to " + Path.GetFileName(e.Workspace.FileName) + "\n\n Would you like to save your changes?"; } } var buttons = e.AllowCancel ? MessageBoxButton.YesNoCancel : MessageBoxButton.YesNo; var result = System.Windows.MessageBox.Show(dialogText, "Confirmation", buttons, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { _vm.ShowSaveDialogIfNeededAndSave(e.Workspace); e.Success = true; } else if (result == MessageBoxResult.Cancel) { //return false; e.Success = false; } else { e.Success = true; } }