/// <summary> /// Initializes a new instance of the <see cref="OptionsViewModel"/> class. /// </summary> /// <param name="optionsService">The options service.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="optionsService"/> is <see langword="null"/>. /// </exception> public OptionsViewModel(IOptionsService optionsService) : this() { if (optionsService == null) { throw new ArgumentNullException(nameof(optionsService)); } _rootNode = new MergeableNode <OptionsPageViewModel>(null) { Children = new MergeableNodeCollection <OptionsPageViewModel>() }; OkCommand = new DelegateCommand(Ok); ApplyCommand = new DelegateCommand(Apply); CancelCommand = new DelegateCommand(Cancel); // Merge all options node collections. _rootNode.Children.Clear(); var merger = new OptionsMergeAlgorithm(); foreach (var optionsNodes in optionsService.OptionsNodeCollections) { merger.Merge(_rootNode.Children, optionsNodes); } SelectedNode = OptionsNodes.FirstOrDefault(); }
public void Constructor1() { MergeableNode<NamedObject> node = new MergeableNode<NamedObject>(); Assert.IsNull(node.Content); Assert.IsNull(node.Parent); Assert.That(node.Children, Is.Null.Or.Empty); Assert.IsNull(node.Next); Assert.IsNull(node.Previous); Assert.That(node.MergePoints.Count(), Is.EqualTo(1)); Assert.That(node.MergePoints.First(), Is.EqualTo(new MergePoint(MergeOperation.Append, null))); }
public void Constructor1() { MergeableNode <NamedObject> node = new MergeableNode <NamedObject>(); Assert.IsNull(node.Content); Assert.IsNull(node.Parent); Assert.That(node.Children, Is.Null.Or.Empty); Assert.IsNull(node.Next); Assert.IsNull(node.Previous); Assert.That(node.MergePoints.Count(), Is.EqualTo(1)); Assert.That(node.MergePoints.First(), Is.EqualTo(new MergePoint(MergeOperation.Append, null))); }
private void Show(MergeableNode <OptionsPageViewModel> optionsNode) { Logger.Info("Showing Options dialog."); if (optionsNode != null) { Options.SelectedNode = optionsNode; } _windowService.ShowDialog(Options); Logger.Info("Options dialog closed."); }
protected override void OnMerge(MergeableNode <OptionsPageViewModel> existingNode, MergeableNode <OptionsPageViewModel> node) { if (!(existingNode.Content is OptionsGroupViewModel) || !(node.Content is OptionsGroupViewModel)) { // Nodes cannot be merged. string message = Invariant( $"Cannot merge options \"{existingNode.Content.DisplayName}\" - only nodes containing OptionsPageGroup objects can be merged."); Logger.Error(message); throw new MergeException(message); } // Call base method to merge children. base.OnMerge(existingNode, node); }
/// <summary> /// Gets the title of the Quick Launch item for the specified options node. /// </summary> /// <param name="optionsNode">The options node.</param> /// <returns>The title of the Quick Launch item.</returns> private static string GetTitle(MergeableNode <OptionsPageViewModel> optionsNode) { var stringBuilder = new StringBuilder("Options → "); foreach (var node in optionsNode.GetAncestors().Reverse()) { if (node.Content != null) { stringBuilder.Append(node.Content.DisplayName); stringBuilder.Append(" → "); } } stringBuilder.Append(optionsNode.Content.DisplayName); return(stringBuilder.ToString()); }
private void ActivateNode(MergeableNode <OptionsPageViewModel> node) { if (node == null || node.Content == ActiveItem) { return; } // Find a suitable node to activate. If the node contains an OptionsGroupViewModel // then find the first descendant which isn't an OptionsGroupViewModel. while (node.Content is OptionsGroupViewModel && node.Children != null && node.Children.Count > 0) { node = node.Children[0]; } ActivateItem(node.Content); }
/// <summary> /// Gets the title of the Quick Launch item for the specified options node. /// </summary> /// <param name="optionsNode">The options node.</param> /// <returns>The title of the Quick Launch item.</returns> private static string GetTitle(MergeableNode<OptionsPageViewModel> optionsNode) { var stringBuilder = new StringBuilder("Options → "); foreach (var node in optionsNode.GetAncestors().Reverse()) { if (node.Content != null) { stringBuilder.Append(node.Content.DisplayName); stringBuilder.Append(" → "); } } stringBuilder.Append(optionsNode.Content.DisplayName); return stringBuilder.ToString(); }
public void GetRelativeNodeInGroup() { var namedObject = new NamedObject("Node"); var children = new[] { new MergeableNode <NamedObject>(new NamedObject("ChildA")), new MergeableNode <NamedObject>(new NamedObject("ChildB")), new MergeableNode <NamedObject>(new NamedObject("ChildC")), }; MergeableNode <NamedObject> node = new MergeableNode <NamedObject>(namedObject, children); Assert.IsNull(node.Children[0].Previous); Assert.AreSame(children[0], node.Children[1].Previous); Assert.AreSame(children[1], node.Children[2].Previous); Assert.AreSame(children[1], node.Children[0].Next); Assert.AreSame(children[2], node.Children[1].Next); Assert.IsNull(node.Children[2].Next); }
public void GetRelativeNodeInGroup() { var namedObject = new NamedObject("Node"); var children = new[] { new MergeableNode<NamedObject>(new NamedObject("ChildA")), new MergeableNode<NamedObject>(new NamedObject("ChildB")), new MergeableNode<NamedObject>(new NamedObject("ChildC")), }; MergeableNode<NamedObject> node = new MergeableNode<NamedObject>(namedObject, children); Assert.IsNull(node.Children[0].Previous); Assert.AreSame(children[0], node.Children[1].Previous); Assert.AreSame(children[1], node.Children[2].Previous); Assert.AreSame(children[1], node.Children[0].Next); Assert.AreSame(children[2], node.Children[1].Next); Assert.IsNull(node.Children[2].Next); }
/// <summary> /// Initializes a new instance of the <see cref="OptionsViewModel"/> class. /// </summary> /// <param name="optionsService">The options service.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="optionsService"/> is <see langword="null"/>. /// </exception> public OptionsViewModel(IOptionsService optionsService) : this() { if (optionsService == null) throw new ArgumentNullException(nameof(optionsService)); _rootNode = new MergeableNode<OptionsPageViewModel>(null) { Children = new MergeableNodeCollection<OptionsPageViewModel>() }; OkCommand = new DelegateCommand(Ok); ApplyCommand = new DelegateCommand(Apply); CancelCommand = new DelegateCommand(Cancel); // Merge all options node collections. _rootNode.Children.Clear(); var merger = new OptionsMergeAlgorithm(); foreach (var optionsNodes in optionsService.OptionsNodeCollections) merger.Merge(_rootNode.Children, optionsNodes); SelectedNode = OptionsNodes.FirstOrDefault(); }
public void Constructor3() { var namedObject = new NamedObject("Node"); var children = new[] { new MergeableNode<NamedObject>(new NamedObject("ChildA")), new MergeableNode<NamedObject>(new NamedObject("ChildB")), new MergeableNode<NamedObject>(new NamedObject("ChildC")), }; MergeableNode<NamedObject> node = new MergeableNode<NamedObject>(namedObject, children); Assert.AreSame(namedObject, node.Content); Assert.IsNull(node.Parent); Assert.IsNotNull(node.Children); Assert.AreEqual(3, node.Children.Count); Assert.AreSame(children[0], node.Children[0]); Assert.AreSame(children[1], node.Children[1]); Assert.AreSame(children[2], node.Children[2]); Assert.IsNull(node.Next); Assert.IsNull(node.Previous); Assert.That(node.MergePoints.Count(), Is.EqualTo(1)); Assert.That(node.MergePoints.First(), Is.EqualTo(new MergePoint(MergeOperation.Append, null))); }
public void Constructor3() { var namedObject = new NamedObject("Node"); var children = new[] { new MergeableNode <NamedObject>(new NamedObject("ChildA")), new MergeableNode <NamedObject>(new NamedObject("ChildB")), new MergeableNode <NamedObject>(new NamedObject("ChildC")), }; MergeableNode <NamedObject> node = new MergeableNode <NamedObject>(namedObject, children); Assert.AreSame(namedObject, node.Content); Assert.IsNull(node.Parent); Assert.IsNotNull(node.Children); Assert.AreEqual(3, node.Children.Count); Assert.AreSame(children[0], node.Children[0]); Assert.AreSame(children[1], node.Children[1]); Assert.AreSame(children[2], node.Children[2]); Assert.IsNull(node.Next); Assert.IsNull(node.Previous); Assert.That(node.MergePoints.Count(), Is.EqualTo(1)); Assert.That(node.MergePoints.First(), Is.EqualTo(new MergePoint(MergeOperation.Append, null))); }
private void ActivateNode(MergeableNode<OptionsPageViewModel> node) { if (node == null || node.Content == ActiveItem) return; // Find a suitable node to activate. If the node contains an OptionsGroupViewModel // then find the first descendant which isn't an OptionsGroupViewModel. while (node.Content is OptionsGroupViewModel && node.Children != null && node.Children.Count > 0) node = node.Children[0]; ActivateItem(node.Content); }