// Check the validate of the selected course view/selected object and update accordingly. void UpdateSelection() { // Check the selection validity. if (!activeCourseDesignator.IsAllControls && !eventDB.IsCoursePresent(activeCourseDesignator.CourseId)) { // Active course was deleted. Switch to all controls. activeCourseDesignator = CourseDesignator.AllControls; ClearSelection(); } // Check that variation still exists. if (activeCourseDesignator.IsVariation && QueryEvent.HasVariations(eventDB, activeCourseDesignator.CourseId)) { IEnumerable<VariationInfo> variations = QueryEvent.GetAllVariations(eventDB, activeCourseDesignator.CourseId); if (!variations.Any(v => v.Equals(activeCourseDesignator.VariationInfo))) activeCourseDesignator = activeCourseDesignator.WithAllVariations(); } // Does the current part still exist? int numberOfParts = QueryEvent.CountCourseParts(eventDB, activeCourseDesignator); if (!activeCourseDesignator.IsAllControls && !activeCourseDesignator.AllParts && (numberOfParts == 1 || activeCourseDesignator.Part >= numberOfParts)) { // No part that large any more. if (numberOfParts > 1) activeCourseDesignator = activeCourseDesignator.WithPart(numberOfParts - 1); else activeCourseDesignator = activeCourseDesignator.WithAllParts(); ClearSelection(); } if (selectedCourseControl.IsNotNone && !eventDB.IsCourseControlPresent(selectedCourseControl)) { // Selected course control is no longer there. selectedCourseControl = Id<CourseControl>.None; ClearSelection(); } if (selectedCourseControl.IsNotNone && activeCourseDesignator.IsNotAllControls && (!activeCourseDesignator.AllParts || activeCourseDesignator.IsVariation) && !QueryEvent.IsCourseControlInPart(eventDB, activeCourseDesignator, selectedCourseControl)) { // Selected course control is not in active part. // Could be allowed if it's the finish. Id<ControlPoint> controlId = eventDB.GetCourseControl(selectedCourseControl).control; if (!(eventDB.IsControlPresent(controlId) && eventDB.GetControl(controlId).kind == ControlPointKind.Finish && QueryEvent.GetPartOptions(eventDB, activeCourseDesignator).ShowFinish)) { selectedCourseControl = Id<CourseControl>.None; ClearSelection(); } } if (selectedCourseControl2.IsNotNone && !eventDB.IsCourseControlPresent(selectedCourseControl2)) { // Selected course control 2 is no longer there. selectedCourseControl2 = Id<CourseControl>.None; ClearSelection(); } if (selectedCourseControl2.IsNotNone && activeCourseDesignator.IsNotAllControls && !activeCourseDesignator.AllParts && !QueryEvent.IsCourseControlInPart(eventDB, activeCourseDesignator, selectedCourseControl2)) { // Selected course control 2 is not in active part. selectedCourseControl2 = Id<CourseControl>.None; ClearSelection(); } if (selectedControl.IsNotNone && !eventDB.IsControlPresent(selectedControl)) { // Selected control is no longer there. ClearSelection(); } if (selectedSpecial.IsNotNone && !eventDB.IsSpecialPresent(selectedSpecial)) { // Selected special is no longer there. ClearSelection(); } if (selectedSpecial.IsNotNone && !(activeCourseDesignator.IsAllControls || QueryEvent.CourseContainsSpecial(eventDB, activeCourseDesignator, selectedSpecial))) { // Selected special is not in current course ClearSelection(); } }
private void LoadList() { if (eventDB != null && !loaded) { if (showAllControls) { courseTreeView.Nodes.Add(new TreeNode(MiscText.AllControls) { Tag = CourseDesignator.AllControls }); } foreach (Id <Course> courseId in QueryEvent.SortedCourseIds(eventDB)) { TreeNode[] parts = null; // If the course has parts, get all the parts. int numberParts = QueryEvent.CountCourseParts(eventDB, new CourseDesignator(courseId), true); if (showCourseParts && numberParts > 1) { parts = new TreeNode[numberParts]; for (int part = 0; part < numberParts; ++part) { CourseDesignator partDesignator = new CourseDesignator(courseId, part); if (CheckFilter(partDesignator)) { parts[part] = new TreeNode(string.Format(MiscText.PartN, part + 1)) { Tag = partDesignator, Checked = true }; } } } // Add node for the course to the tree. CourseDesignator designator = new CourseDesignator(courseId); if (CheckFilter(designator)) { TreeNode node; if (parts != null) { node = new TreeNode(eventDB.GetCourse(courseId).name, parts); } else { node = new TreeNode(eventDB.GetCourse(courseId).name); } node.Tag = designator; node.Checked = true; courseTreeView.Nodes.Add(node); } } courseTreeView.ExpandAll(); buttonChooseVariations.Visible = (ShowVariationChooser && eventHasVariations); loaded = true; } }