Beispiel #1
0
        /// <summary>
        /// Populates the display list with the provided data elements.
        /// </summary>
        ///
        /// <param name="data">The data to use when populating the list.</param>
        ///
        /// <remarks>
        /// Any existing view elements will be removed from the list before populating
        /// the list with <paramref name="data"/>. One display element is added for each
        /// element in <paramref name="data"/>, and the display element is automatically
        /// populated with the corresponding data element. Any existing display elements
        /// will be reused in order to reduce object instantiation costs.
        /// </remarks>
        public void Populate(List <D> data)
        {
            _data = data ?? throw new ArgumentNullException();

            // "Remove" all active elements.
            foreach (var element in this)
            {
                OnElementRemoved(element);
                ElementRemoved?.Invoke(element);
            }

            // Add a display element for every data element in the list.
            for (int index = 0; index < _data.Count; index += 1)
            {
                var element = GetOrAddElement(index);
                element.Populate(_data[index]);

                OnElementAdded(element);
                ElementAdded?.Invoke(element);
            }

            // Disable any leftover display elements that were previously active in the
            // list but are no longer needed.
            for (int index = _data.Count; index < _elements.Count; index += 1)
            {
                _elements[index].gameObject.SetActive(false);
            }

            OnPopulated();
        }
Beispiel #2
0
        private TreeNode <T> Remove(TreeNode <T> parent, T key)
        {
            if (parent == null)
            {
                return(parent);
            }
            if (parent.CompareTo(key) > 0)
            {
                parent.Left = Remove(parent.Left, key);
            }
            else if (parent.CompareTo(key) < 0)
            {
                parent.Right = Remove(parent.Right, key);
            }
            else
            {
                if (parent.Left == null)
                {
                    return(parent.Right);
                }
                else if (parent.Right == null)
                {
                    return(parent.Left);
                }

                parent.Value = MinValue(parent.Right);

                ElementRemoved?.Invoke(this, new TreeEventArgs <T>(key, "Element removed"));
                parent.Right = Remove(parent.Right, parent.Value);
            }
            return(parent);
        }
Beispiel #3
0
        private void OnRemoveClick(object sender, EventArgs e)
        {
            var temp = Focus;

            RemoveElement(Focus);
            ElementRemoved?.Invoke(temp);
        }
Beispiel #4
0
 private void nameTxtBox_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.D && Keyboard.Modifiers == ModifierKeys.Control)
     {
         ElementRemoved.Invoke(this);
     }
 }
Beispiel #5
0
        private static void RemoveCurrentElement()
        {
            if (CurrentElement != null)
            {
                ElementRemoved?.Invoke(CurrentElement.AssociatedIElement);
                CurrentElement.Destroy();

                SpriteManager.RemoveAllParticleSprites();
            }
        }
        public void Remove(T element)
        {
            if (!content.Contains(element))
            {
                throw new Exception($"Container does not contain {element}");
            }

            content.Remove(element);
            ElementRemoved?.Invoke(this, new ElementEventArgs <T>(element));
        }
Beispiel #7
0
        /// <summary>
        /// Removes the element from the hash set.
        /// </summary>
        public bool Remove(T element)
        {
            var removed = hashSet.Remove(element);

            if (removed)
            {
                ElementRemoved?.Invoke(this, new ElementRemovedEventArgs <T>(element));
            }
            return(removed);
        }
Beispiel #8
0
        /// <summary>
        /// Removes all elements from the hash set.
        /// </summary>
        public void Clear()
        {
            var oldKvps = hashSet.ToList();

            hashSet.Clear();
            foreach (var element in oldKvps)
            {
                ElementRemoved?.Invoke(this, new ElementRemovedEventArgs <T>(element));
            }
        }
Beispiel #9
0
        public void RemoveElement(IDsiElement element)
        {
            Logger.LogDataModelMessage($"Remove element id={element.Id} name={element.Name} type={element.Type} source={element.Source}");

            string key = element.Name.ToLower();

            _elementsByName.Remove(key);
            _elementsById.Remove(element.Id);

            ElementRemoved?.Invoke(this, element.Id);
        }
Beispiel #10
0
 internal bool RemoveUIElement(UIElement element)
 {
     if (currentElements.Contains(element))
     {
         ElementRemoved?.Invoke(element);
         currentElements.Remove(element);
         GameObject.Destroy(element.gameObject);
         return(true);
     }
     return(false);
 }
Beispiel #11
0
 internal void OnLayoutElementRemoved(LayoutElement element)
 {
     if (element.Descendents().OfType <LayoutContent>().Any(c => Equals(c, LastFocusedDocument)))
     {
         LastFocusedDocument = null;
     }
     if (element.Descendents().OfType <LayoutContent>().Any(c => Equals(c, ActiveContent)))
     {
         ActiveContent = null;
     }
     ElementRemoved?.Invoke(this, new LayoutElementEventArgs(element));
 }
Beispiel #12
0
        public void RemoveAllUIElements()
        {
            for (int i = currentElements.Count - 1; i >= 0; i--)
            {
                ElementRemoved?.Invoke(currentElements[i]);
                GameObject.Destroy(currentElements[i].gameObject);
            }

            /*foreach (var element in currentElements)
             * {
             *      ElementRemoved?.Invoke(element);
             *      GameObject.Destroy(element.gameObject);
             * }*/

            currentElements.Clear();
        }
Beispiel #13
0
        void RebuildInterface()
        {
            DeselectCurrentTab();

            foreach (var tab in tabs)
            {
                GameObject.Destroy(tab.gameObject);
            }

            foreach (var element in currentElements)
            {
                ElementRemoved?.Invoke(element);
                GameObject.Destroy(element.gameObject);
            }

            tabs.Clear();
            currentElements.Clear();

            foreach (var panel in _panels)
            {
                CreateTab(panel);
            }
        }
Beispiel #14
0
 protected void OnRemoved(SvgElement element)
 {
     ElementRemoved?.Invoke(this._document, new SvgElementEventArgs {
         Element = element
     });
 }
        /// <summary>
        /// Removes element from tree by its reference
        /// </summary>
        /// <param name="item">Object that should be removed from tree</param>
        /// <returns>True if element was deleted succesfully, false if element wasn't found in tree</returns>
        public bool Remove(T item)
        {
            BinaryTreeNode <T> current;

            // Find removal node
            current = FindWithParent(item, out BinaryTreeNode <T> parent);

            if (current == null)
            {
                return(false);
            }

            Count--;

            if (current.Right == null)
            {
                if (parent == null)
                {
                    root = current.Left;
                }
                else
                {
                    int result = Comparer.Compare(parent.Value, current.Value);
                    if (result > 0)
                    {
                        parent.Left = current.Left;
                    }
                    else if (result < 0)
                    {
                        parent.Right = current.Left;
                    }
                }
            }
            else if (current.Right.Left == null)
            {
                current.Right.Left = current.Left; if (parent == null)
                {
                    root = current.Right;
                }
                else
                {
                    int result = Comparer.Compare(parent.Value, current.Value);
                    if (result > 0)
                    {
                        parent.Left = current.Right;
                    }
                    else if (result < 0)
                    {
                        parent.Right = current.Right;
                    }
                }
            }
            else
            {
                BinaryTreeNode <T> leftmost       = current.Right.Left;
                BinaryTreeNode <T> leftmostParent = current.Right;
                while (leftmost.Left != null)
                {
                    leftmostParent = leftmost;
                    leftmost       = leftmost.Left;
                }

                leftmostParent.Left = leftmost.Right;

                leftmost.Left  = current.Left;
                leftmost.Right = current.Right;
                if (parent == null)
                {
                    root = leftmost;
                }
                else
                {
                    int result = Comparer.Compare(parent.Value, current.Value);
                    if (result > 0)
                    {
                        parent.Left = leftmost;
                    }
                    else if (result < 0)
                    {
                        parent.Right = leftmost;
                    }
                }
            }
            var EventArg = new TreeEventArgs <T>(item, "Item has been removed");

            ElementRemoved?.Invoke(this, EventArg);
            return(true);
        }
Beispiel #16
0
 /// <summary>
 /// Fires the ElementRemoved event.
 /// </summary>
 /// <param name="element">The removed OpenXmlElement element.</param>
 /// <param name="parent">The parent element.</param>
 internal void ElementRemovedEvent(OpenXmlElement element, OpenXmlElement parent)
 {
     ElementRemoved?.Invoke(this, new ElementEventArgs(element, parent));
 }
 public void CallBeforeElementRemoved()
 {
     ElementRemoved?.Invoke();
 }
Beispiel #18
0
        /// <summary>
        /// Removes element from tree by its reference
        /// </summary>
        /// <param name="item">Object that should be removed from tree</param>
        /// <returns>True if element was deleted succesfully, false if element wasn't found in tree</returns>
        public bool Remove(T item)
        {
            Node <T> current = Root;
            Node <T> father  = null;

            while (current != null)
            {
                if (ComparerT.Compare(current.Data, item) < 0)
                {
                    father  = current;
                    current = current.Right;
                }
                else if (ComparerT.Compare(current.Data, item) > 0)
                {
                    father  = current;
                    current = current.Left;
                }
                else
                {
                    break;
                }
            }
            if (current == null)
            {
                return(false);
            }

            Count--;

            // checking if node is a leaf and deleting it
            if (current.Right == null && current.Left == null)
            {
                // checking if node to delete is root
                if (father == null)
                {
                    Root = null;
                }
                // comparing what node of children should we use for replacing
                else if (ComparerT.Compare(father.Data, current.Data) > 0)
                {
                    father.Left = null;
                }
                else
                {
                    father.Right = null;
                }
            }
            //checking if node has only left child
            else if (current.Right == null)
            {
                // checking if node to delete is root
                if (father == null)
                {
                    Root = current.Left;
                }
                else
                {
                    father.Left = current.Left;
                }
            }
            //checking if node has only right child
            else if (current.Left == null)
            {
                // checking if node to delete is root
                if (father == null)
                {
                    Root = current.Right;
                }
                else
                {
                    father.Left = current.Right;
                }
            }
            // if node has both left and right
            // we should replace node with the smallest node of right sub-tree
            else
            {
                // temporary node to replace
                Node <T> tmp = current.Right;
                if (tmp.Left == null)
                {
                    tmp.Left = current.Left;
                }
                else
                {
                    while (tmp.Left.Left != null)
                    {
                        tmp = tmp.Left;
                    }
                    // one more temporary node, we need it for saving node to replace
                    Node <T> tmp2 = tmp.Left;
                    // deleting node from this place
                    tmp.Left   = null;
                    tmp2.Left  = current.Left;
                    tmp2.Right = current.Right;
                    tmp        = tmp2;
                }
                if (father == null)
                {
                    Root = tmp;
                }
                else if (ComparerT.Compare(father.Data, current.Data) > 0)
                {
                    father.Left = tmp;
                }
                else
                {
                    father.Right = tmp;
                }
            }
            TreeEventArgs <T> args = new TreeEventArgs <T>(item, $"Element {item} was removed from tree");

            ElementRemoved?.Invoke(this, args);
            return(true);
        }