Exemple #1
0
        public void SetTrainingCourse(ICourse course)
        {
            RevertableChangesHandler.FlushStack();
            activeCourse = course;

            chapterMenu.Initialise(course, this);
            chapterMenu.ChapterChanged += (sender, args) =>
            {
                chapterRepresentation.SetChapter(args.CurrentChapter);
            };

            chapterRepresentation.SetChapter(course.Data.FirstChapter);

            IsDirty = true;
        }
Exemple #2
0
        /// <summary>
        /// Sets the <paramref name="course"/> to be displayed and edited in this window.
        /// </summary>
        public void SetCourse(ICourse course)
        {
            RevertableChangesHandler.FlushStack();

            activeCourse = course;

            if (course == null)
            {
                return;
            }

            chapterMenu.Initialise(course, this);
            chapterMenu.ChapterChanged += (sender, args) =>
            {
                chapterRepresentation.SetChapter(args.CurrentChapter);
            };

            chapterRepresentation.SetChapter(course.Data.FirstChapter);
        }
        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();
            }
        }