Пример #1
0
        // Will be called as a new NTWindow is created. It will be called in the thread of that window
        protected override void OnWindowCreated(Window window)
        {
            // We want to place our AddOn in the Control Center's menus
            ControlCenter cc = window as ControlCenter;

            if (cc == null)
            {
                return;
            }

            /* Determine we want to place our AddOn in the Control Center's "New" menu
             * Other menus can be accessed via the control's "Automation ID". For example: toolsMenuItem, workspacesMenuItem, connectionsMenuItem, helpMenuItem. */
            existingMenuItemInControlCenter = cc.FindFirst("ControlCenterMenuItemNew") as NTMenuItem;
            if (existingMenuItemInControlCenter == null)
            {
                return;
            }

            // 'Header' sets the name of our AddOn seen in the menu structure
            addOnFrameworkMenuItem = new NTMenuItem {
                Header = "AddOn Framework", Style = Application.Current.TryFindResource("MainMenuItem") as Style
            };

            // Add our AddOn into the "New" menu
            existingMenuItemInControlCenter.Items.Add(addOnFrameworkMenuItem);

            // Subscribe to the event for when the user presses our AddOn's menu item
            addOnFrameworkMenuItem.Click += OnMenuItemClick;
        }
Пример #2
0
        // Will be called as a new NTWindow is destroyed. It will be called in the thread of that window
        protected override void OnWindowDestroyed(Window window)
        {
            if (addOnFrameworkMenuItem != null && window is ControlCenter)
            {
                if (existingMenuItemInControlCenter != null && existingMenuItemInControlCenter.Items.Contains(addOnFrameworkMenuItem))
                {
                    existingMenuItemInControlCenter.Items.Remove(addOnFrameworkMenuItem);
                }

                addOnFrameworkMenuItem.Click -= OnMenuItemClick;
                addOnFrameworkMenuItem        = null;
            }
        }
Пример #3
0
        // Will be called as a new NTWindow is destroyed. It will be called in the thread of that window
        protected override void OnWindowDestroyed(Window window)
        {
            // This checks if there is not a menu item or if the destroyed window is not the control center.
            if (AddonShellMenuItem != null && window is ControlCenter)
            {
                if (existingMenuItemInControlCenter != null && existingMenuItemInControlCenter.Items.Contains(AddonShellMenuItem))
                {
                    existingMenuItemInControlCenter.Items.Remove(AddonShellMenuItem);
                }

                // if the destroyed window was the control center, we clean up the click handler and remove the custom menu item and set it to null.
                AddonShellMenuItem.Click -= OnMenuItemClick;
                AddonShellMenuItem        = null;
            }
        }
Пример #4
0
        // Will be called as a new NTWindow is created. It will be called in the thread of that window
        protected override void OnWindowCreated(Window window)
        {
            /*
             * The following checks if the control center window is present.
             * If the control center is found, the MainMenu is checked for existing menu items with the same name as this addon.
             * If no existing items are found, a new menu item is added for this addon.
             */
            // We want to place our AddOn in the Control Center's menus
            ControlCenter controlCenter = window as ControlCenter;

            if (controlCenter == null)
            {
                return;
            }

            /* Determine we want to place our AddOn in the Control Center's "New" menu
             * Other menus can be accessed via the control's "Automation ID". For example: toolsMenuItem, workspacesMenuItem, connectionsMenuItem, helpMenuItem. */
            existingMenuItemInControlCenter = controlCenter.FindFirst("ControlCenterMenuItemNew") as NTMenuItem;
            if (existingMenuItemInControlCenter == null)
            {
                return;
            }

            // This is the new menu item to be created, this assigns the menu text and will be used to Add this item to the Main Menu.
            // 'Header' sets the name of our AddOn seen in the menu structure
            AddonShellMenuItem = new NTMenuItem {
                Header = "Addon Shell", Style = Application.Current.TryFindResource("MainMenuItem") as Style
            };

            // Add our AddOn into the "New" menu
            existingMenuItemInControlCenter.Items.Add(AddonShellMenuItem);

            // The new menu item will do nothing by its self, a click handler is added to complete the menu item and allow for clicks.
            // Subscribe to the event for when the user presses our AddOn's menu item
            AddonShellMenuItem.Click += OnMenuItemClick;
        }