示例#1
0
        /// <summary>
        /// Returns true if an ancestor between the root and the parentName has true for the ToImport property.
        /// </summary>
        public bool AncestorToImportIsTrue(string parentName)
        {
            List <string> pathToParent = DeckNameEx.GetNamePath(parentName);

            if (pathToParent != null && pathToParent.Count > 0)
            {
                var rootDeck = this[pathToParent[0]];
                if (rootDeck.ToImport)
                {
                    return(true);
                }

                pathToParent.RemoveAt(0);
                var currentDeck = rootDeck;
                foreach (var deck in pathToParent)
                {
                    if (currentDeck.ChildDecks[deck].ToImport)
                    {
                        return(true);
                    }
                    currentDeck = currentDeck.ChildDecks[deck];
                }
            }

            return(false);
        }
示例#2
0
        /// <summary>
        /// Attempts to find a deck in the tree according to its name.
        /// </summary>
        /// <param name="childName"></param>
        /// <returns></returns>
        public Deck Find(string name)
        {
            Deck target = null;

            // Root deck
            if (!name.Contains("::"))
            {
                if (!this.TryGetValue(name, out target))
                {
                    LogTo.Warning($"Failed to Find deck {name} in DeckTreeDictionary");
                }
            }
            else
            {
                // Start by getting the root deck
                List <string> pathToDeck = DeckNameEx.GetNamePath(name);
                if (!this.TryGetValue(pathToDeck[0], out var cur))
                {
                    LogTo.Error($"Failed to find deck {name} in deck tree because root doesn't exist");
                    return(null);
                }

                // Remove the root path
                pathToDeck.RemoveAt(0);

                // Iterate through child decks along the path to target
                foreach (string path in pathToDeck)
                {
                    cur.ChildDecks.TryGetValue(path, out cur);
                }
                target = cur;
            }
            return(target);
        }
示例#3
0
        public void GetNamePathNullReturnsNull()
        {
            string name   = null;
            var    output = DeckNameEx.GetNamePath(name);

            Assert.Null(output);
        }
        /// <summary>
        /// Intercepts the checkbox mouse click to implement custom checking behaviour.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CheckBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            var checkBox     = ((CheckBox)sender);
            var deck         = ((Deck)checkBox.Tag);
            var pathToParent = DeckNameEx.GetNamePath(deck.Parentname);

            if (checkBox.IsChecked == true)
            {
                if (Trees.AncestorToImportIsTrue(deck.Parentname))
                {
                    // Uncheck from this deck's root until this deck's parent
                    Trees.SetToImportOverRange(pathToParent, false);
                }
                else
                {
                    // Uncheck this deck down through the hierarchy to the leaf decks
                    deck.RecursivelySetToImport(false);
                }
            }
            else
            {
                // Check from this deck down through the hierarchy to the leaf decks
                deck.RecursivelySetToImport(true);
            }

            RefreshSMKT();
            RefreshDeckGrid();
            e.Handled = true;
        }
示例#5
0
        public void GetNamePathReturnsPath()
        {
            string name     = "parent::child::grandchild";
            var    expected = new List <string>()
            {
                "parent",
                "parent::child",
                "parent::child::grandchild"
            };
            var actual = DeckNameEx.GetNamePath(name);

            Assert.Equal(expected, actual);

            name     = "parent";
            expected = new List <string>()
            {
                "parent"
            };
            actual = DeckNameEx.GetNamePath(name);
            Assert.Equal(expected, actual);
        }