public void LoadTrainingCourseFromFile(string path) { if (string.IsNullOrEmpty(path) || File.Exists(path) == false) { return; } ICourse course = SaveManager.LoadTrainingCourseFromFile(path); string filename = Path.GetFileNameWithoutExtension(path); if (course.Data.Name.Equals(filename) == false) { bool userConfirmation = TestableEditorElements.DisplayDialog("Course name does not match filename.", string.Format("The training course name (\"{0}\") does not match the filename (\"{1}\"). To be able to load the training course, it must be renamed to \"{1}\".", course.Data.Name, filename), "Rename Course", "Cancel"); if (userConfirmation == false) { return; } course.Data.Name = filename; SaveManager.SaveTrainingCourseToFile(course); } SetTrainingCourseWithUserConfirmation(course); IsDirty = false; }
/// <summary> /// Save the training to given path. /// </summary> public static bool SaveTrainingCourseToFile(ICourse course) { try { if (course == null) { throw new NullReferenceException("The training course is not saved because it doesn't exist."); } string path = GetTrainingPath(course); string directory = Path.GetDirectoryName(path); if (string.IsNullOrEmpty(directory) == false && Directory.Exists(directory) == false) { Directory.CreateDirectory(directory); } string serialized = JsonTrainingSerializer.Serialize(course); File.WriteAllText(path, serialized); // Check if saved as asset. If true, import it. TryReloadAssetByFullPath(path); return(true); } catch (Exception e) { TestableEditorElements.DisplayDialog("Error while saving the training course!", e.ToString(), "Close"); logger.Error(e); return(false); } }
private static void PreserveTrainingState() { try { if (TrainingWindow.IsOpen == false) { return; } TrainingWindow.GetWindow().MakeTemporarySave(); } catch (Exception e) { logger.Error(e); if (EditorApplication.isPlaying == false && EditorApplication.isPlayingOrWillChangePlaymode) { EditorApplication.isPlaying = false; TestableEditorElements.DisplayDialog("Error while serializing the training!", e.ToString(), "Close"); } } }
private void OnGUI() { if (course == null || focusedWindow != this) { Close(); instance.IsClosed = true; } GUI.SetNextControlName(textFieldIdentifier.ToString()); newName = EditorGUILayout.TextField(newName); newName = newName.Trim(); if (isFocusSet == false) { isFocusSet = true; EditorGUI.FocusTextInControl(textFieldIdentifier.ToString()); } if ((Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter)) { if (CourseAssetUtils.CanRename(course, newName, out string error) == false) { if (string.IsNullOrEmpty(error) == false && string.IsNullOrEmpty(error) == false) { TestableEditorElements.DisplayDialog("Cannot rename the course", error, "OK"); } } else { string oldName = course.Data.Name; RevertableChangesHandler.Do(new CourseCommand( () => { if (CourseAssetUtils.CanRename(course, newName, out string errorMessage) == false) { if (string.IsNullOrEmpty(errorMessage) == false) { TestableEditorElements.DisplayDialog("Cannot rename the course", errorMessage, "OK"); } RevertableChangesHandler.FlushStack(); } else { CourseAssetManager.RenameCourse(course, newName); } }, () => { if (CourseAssetUtils.CanRename(course, newName, out string errorMessage) == false) { if (string.IsNullOrEmpty(errorMessage) == false) { TestableEditorElements.DisplayDialog("Cannot rename the course", errorMessage, "OK"); } RevertableChangesHandler.FlushStack(); } else { CourseAssetManager.RenameCourse(course, oldName); } } )); } Close(); instance.IsClosed = true; Event.current.Use(); } else if (Event.current.keyCode == KeyCode.Escape) { Close(); instance.IsClosed = true; Event.current.Use(); } }