Ejemplo n.º 1
0
        /// <summary>
        ///     Removes a menu component from this menu.
        /// </summary>
        /// <param name="component">
        ///     <see cref="AMenuComponent" /> component instance
        /// </param>
        /// <returns>
        ///     The <see cref="bool" />.
        /// </returns>
        public bool Remove(AMenuComponent component)
        {
            if (this.Components.ContainsKey(component.Name))
            {
                component.Save();
                component.Parent = null;
                return(this.Components.Remove(component.Name));
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Add a menu component to this menu.
        /// </summary>
        /// <typeparam name="T">
        ///     <see cref="AMenuComponent" /> type
        /// </typeparam>
        /// <param name="component">
        ///     <see cref="AMenuComponent" /> component
        /// </param>
        /// <returns>
        ///     The <see cref="AMenuComponent" /> instance.
        /// </returns>
        public virtual T Add <T>(T component) where T : AMenuComponent
        {
            if (!this.Components.ContainsKey(component.Name))
            {
                component.Parent = this;
                this.Components[component.Name] = component;

                AMenuComponent comp = this;
                while (comp.Parent != null)
                {
                    comp = comp.Parent;
                }

                if (comp.Root)
                {
                    comp.Load();
                }
            }
            else
            {
                var existingComponent = this.Components[component.Name] as Menu;
                var newComponent      = component as Menu;
                if (existingComponent != null && newComponent != null)
                {
                    foreach (var comp in newComponent.Components)
                    {
                        existingComponent.Add(comp.Value);
                    }
                }
                else
                {
                    //throw new Exception("This menu already contains a component with the name " + component.Name);
                }
            }

            MenuManager.Instance.ResetWidth();
            return(component);
        }