示例#1
0
        /// <summary>
        /// Subscribe to the events of this NavMenu's TopMenus. We should monitor them and then bubble them upwards via this menu's own NavigationMenuEvent.
        /// </summary>
        /// <param name="topMenu">The TopMenu effecting the event.</param>
        /// <param name="eventType">The type of event handled.</param>
        public void TopMenuEventHandler(TopMenu topMenu, TopMenuEventType eventType)
        {
            // Determine the type of event and handle it accordingly
            switch (eventType)
            {
            // A TopMenu has been modified (buttons added or removed)
            case TopMenuEventType.MENU_MODIFIED:
            {
                if (_navMenuEvent != null)
                {
                    // Bubble this event upwards
                    _navMenuEvent(this, NavigationMenuEventType.MENU_MODIFIED);
                }

                break;
            }

            // One of the MenuItems in this TopMenu were selected
            case TopMenuEventType.MENUITEM_SELECTED:
            {
                if (_navMenuEvent != null)
                {
                    _navMenuEvent(this, NavigationMenuEventType.MENUITEM_SELECTED);
                }

                break;
            }

            // The TopMenu itself was selected
            case TopMenuEventType.TOPMENU_SELECTED:
            {
                // De-select the old TopMenu
                _selectedTopMenu.IsSelected = false;

                // Set the new TopMenu
                _selectedTopMenu = topMenu;

                // Set the newly selected TopMenu to selected
                _selectedTopMenu.IsSelected = true;

                // Bubble the event up
                if (_navMenuEvent != null)
                {
                    _navMenuEvent(this, NavigationMenuEventType.TOPMENU_SELECTED);
                }

                break;
            }
            }
        }
示例#2
0
        /// <summary>
        /// Add another TopMenu to this NavigationMenu.
        /// </summary>
        /// <param name="topMenu">The new TopMenu to be added.</param>
        public void AddTopMenu(TopMenu topMenu)
        {
            // Get an Enumerator for the collection of TopMenus
            IEnumerator <TopMenu> topMenusEnum = _topMenus.GetEnumerator();

            // Determine if the TopMenu already exists
            while (topMenusEnum.MoveNext())
            {
                if (topMenusEnum.Current.MenuId.Equals(topMenu.MenuId))
                {
                    topMenusEnum.Dispose();
                    throw new ApplicationException("Attempting to add TopMenu with non-unique ID.");
                }
            }

            // Add our TopMenu event handler to the TopMenuEvent for this new menu
            topMenu.AddTopMenuEventListener(TopMenuEventHandler);

            // If no matches are found, add the new TopMenu
            _topMenus.Add(topMenu);

            // If this is the first TopMenu to be added, default it to selected
            if (_topMenus.Count == 1)
            {
                // Set the TopMenu to selected
                topMenu.IsSelected = true;

                // Store a reference to the selected TopMenu
                _selectedTopMenu = topMenu;
            }

            // Trigger a NavigationMenuEvent
            if (_navMenuEvent != null)
            {
                _navMenuEvent(this, NavigationMenuEventType.MENU_MODIFIED);
            }
        }
        /// <summary>
        /// Add another TopMenu to this NavigationMenu.
        /// </summary>
        /// <param name="topMenu">The new TopMenu to be added.</param>
        public void AddTopMenu(TopMenu topMenu)
        {
            // Get an Enumerator for the collection of TopMenus
            IEnumerator<TopMenu> topMenusEnum = _topMenus.GetEnumerator();

            // Determine if the TopMenu already exists
            while (topMenusEnum.MoveNext())
            {
                if (topMenusEnum.Current.MenuId.Equals(topMenu.MenuId))
                {
                    topMenusEnum.Dispose();
                    throw new ApplicationException("Attempting to add TopMenu with non-unique ID.");
                }
            }

            // Add our TopMenu event handler to the TopMenuEvent for this new menu
            topMenu.AddTopMenuEventListener(TopMenuEventHandler);

            // If no matches are found, add the new TopMenu
            _topMenus.Add(topMenu);

            // If this is the first TopMenu to be added, default it to selected
            if (_topMenus.Count == 1)
            {
                // Set the TopMenu to selected
                topMenu.IsSelected = true;

                // Store a reference to the selected TopMenu
                _selectedTopMenu = topMenu;
            }

            // Trigger a NavigationMenuEvent
            if (_navMenuEvent != null)
            {
                _navMenuEvent(this, NavigationMenuEventType.MENU_MODIFIED);
            }
        }
示例#4
0
        /// <summary>
        /// Removes a TopMenu by its ID.
        /// </summary>
        /// <param name="topMenuId">The ID of the TopMenu to be removed.</param>
        public void RemoveTopMenu(string topMenuId)
        {
            // Get an Enumerator for the collections of TopMenus
            IEnumerator <TopMenu> topMenuItems = _topMenus.GetEnumerator();

            // Store a reference to the item to be removed
            TopMenu toRemove = null;

            while (topMenuItems.MoveNext())
            {
                // If it does, remove it
                if (topMenuItems.Current.MenuId.Equals(topMenuId))
                {
                    toRemove = topMenuItems.Current;
                    topMenuItems.Dispose();
                    return;
                }
            }

            // If no matching item was found, throw and exception
            if (toRemove == null)
            {
                throw new ApplicationException("No TopMenu with a matching ID was found to be removed.");
            }
            else
            {
                // A match was found, so remove it
                _topMenus.Remove(toRemove);

                // Trigger a NavigationMenuEvent
                if (_navMenuEvent != null)
                {
                    _navMenuEvent(this, NavigationMenuEventType.MENU_MODIFIED);
                }
            }
        }
        /// <summary>
        /// Subscribe to the events of this NavMenu's TopMenus. We should monitor them and then bubble them upwards via this menu's own NavigationMenuEvent.
        /// </summary>
        /// <param name="topMenu">The TopMenu effecting the event.</param>
        /// <param name="eventType">The type of event handled.</param>
        public void TopMenuEventHandler(TopMenu topMenu, TopMenuEventType eventType)
        {
            // Determine the type of event and handle it accordingly
            switch (eventType)
            {
                // A TopMenu has been modified (buttons added or removed)
                case TopMenuEventType.MENU_MODIFIED:
                    {
                        if (_navMenuEvent != null)
                        {
                            // Bubble this event upwards
                            _navMenuEvent(this, NavigationMenuEventType.MENU_MODIFIED);
                        }

                        break;
                    }

                // One of the MenuItems in this TopMenu were selected
                case TopMenuEventType.MENUITEM_SELECTED:
                    {
                        if (_navMenuEvent != null)
                        {
                            _navMenuEvent(this, NavigationMenuEventType.MENUITEM_SELECTED);
                        }

                        break;
                    }

                // The TopMenu itself was selected
                case TopMenuEventType.TOPMENU_SELECTED:
                    {
                        // De-select the old TopMenu
                        _selectedTopMenu.IsSelected = false;

                        // Set the new TopMenu
                        _selectedTopMenu = topMenu;

                        // Set the newly selected TopMenu to selected
                        _selectedTopMenu.IsSelected = true;

                        // Bubble the event up
                        if (_navMenuEvent != null)
                        {
                            _navMenuEvent(this, NavigationMenuEventType.TOPMENU_SELECTED);
                        }

                        break;
                    }
            }
        }
        /// <summary>
        /// Handles post-render tasks.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BuildMenu()
        {
            DataStructures.MenuItem newMenuItem;

            /*
             * Build the NavigationMenu's data structure
             */
            TopMenu mainMenu = new TopMenu(Variables.TOP_MENU_ITEM_ID_MAIN, "Main");
            mainMenu.AddMenuItem(new DataStructures.MenuItem(Variables.MENU_ITEM_ID_HOME, "Home", "pack://application:,,,/ObdExpress;component/UI/Images/home_32.png"));
            mainMenu.AddMenuItem(new DataStructures.MenuItem(Variables.MENU_ITEM_ID_TROUBLE_CODES, "Troubleshooting", "pack://application:,,,/ObdExpress;component/UI/Images/warning_32.png"));

            TopMenu configMenu = new TopMenu(Variables.TOP_MENU_ITEM_ID_CONFIGURATION, "Configuration");
            configMenu.AddMenuItem(new DataStructures.MenuItem(Variables.MENU_ITEM_ID_CONFIGURATION, "Connection", "pack://application:,,,/ObdExpress;component/Ui/Images/connect.png"));

            _navMenu.AddTopMenu(mainMenu);
            _navMenu.AddTopMenu(configMenu);

            /*
             * Attach our event handler
             */
            _navMenu.AddNavigationMenuEventListener(NavigationMenuEventHandler);

            /*
             * Render the NavigationMenu in the GUI
             */
            RenderNavigationMenu();
        }