/// <summary> /// Update the custom events node based on user's selections /// </summary> private void UpdateCustomNode() { CustomNode.RemoveChild(CustomPropertiesNode); CustomNode.RemoveChild(EditBtnNode); var custom = (from e in ConfigurationManager.GetDefaultInstance().EventConfig.Events where e.IsRecorded select e.Id).ToList(); CustomNode.Children.Where(c => c.Type != EventConfigNodeType.Group && !custom.Contains(c.Id)).ToList().ForEach(c => CustomNode.RemoveChild(c)); var add = custom.Where(id => !CustomNode.Children.Select(c => c.Id).Contains(id)).ToList(); CustomNode.AddChildren(add, EventConfigNodeType.Event); CustomNode.SortChildren(); CustomNode.InsertChildAtIndex(0, EditBtnNode); custom = (from e in ConfigurationManager.GetDefaultInstance().EventConfig.Properties where e.IsRecorded select e.Id).ToList(); CustomPropertiesNode.Children.Where(c => c.Type != EventConfigNodeType.Group && !custom.Contains(c.Id)).ToList().ForEach(c => CustomPropertiesNode.RemoveChild(c)); add = custom.Where(id => !CustomPropertiesNode.Children.Select(c => c.Id).Contains(id)).ToList(); CustomPropertiesNode.AddChildren(add, EventConfigNodeType.Property); CustomPropertiesNode.SortChildren(); if (CustomPropertiesNode.Children.Count > 0) { CustomNode.AddChild(CustomPropertiesNode); } }
/// <summary> /// Populate treeview based on selected element /// </summary> /// <param name="el"></param> public void SetElement(A11yElement el) { if (el == null) { throw new ArgumentNullException(nameof(el)); } this.tbElement.Text = el.Glimpse; RootNodes = new List <EventConfigNodeViewModel>(); trviewConfigEvents.ItemsSource = RootNodes; var ids = SupportedEvents.GetEventsForControl(el.ControlTypeId, el.Patterns); SuggestedNode = new EventConfigNodeViewModel(string.Format(CultureInfo.InvariantCulture, Properties.Resources.EventConfigTabControl_SetElement_Expected_Events_based_on_the_0_control_type, Axe.Windows.Core.Types.ControlType.GetInstance().GetNameById(el.ControlTypeId)), isThreeState: true) { IsExpanded = true }; if (ids.Any()) { SuggestedNode.AddChildren(ids, EventConfigNodeType.Event, true); SuggestedNode.SortChildren(); } var properties = new EventConfigNodeViewModel("Properties", isThreeState: true) { Depth = 1 }; properties.AddChildren(el.Properties.Values); if (properties.Children.Any()) { properties.SortChildren(); SuggestedNode.AddChild(properties); } if (SuggestedNode.Children.Any()) { RootNodes.Add(SuggestedNode); } CustomNode = new EventConfigNodeViewModel("My Events", isThreeState: true); CustomPropertiesNode = new EventConfigNodeViewModel("Properties", isThreeState: true) { Depth = 1 }; EditBtnNode = new EventConfigNodeViewModel("", Visibility.Visible, Properties.Resources.EventConfigTabControl_SetElement_Edit_My_Events) { Depth = 1, TextVisibility = Visibility.Collapsed }; UpdateCustomNode(); RootNodes.Add(CustomNode); trviewConfigEvents.Items.Refresh(); trviewConfigEvents.UpdateLayout(); }