/// <summary>
        /// Adds the main MySQL instance's menu itemText and its sub-items to the given context menu strip.
        /// </summary>
        /// <param name="menu">Context menu strip to add the MySQL instance's menu items to.</param>
        public void AddToContextMenu(ContextMenuStrip menu)
        {
            if (menu.InvokeRequired)
            {
                menu.Invoke(new MethodInvoker(() => AddToContextMenu(menu)));
            }
            else
            {
                var index = FindMenuItemWithinMenuStrip(menu, Resources.Actions);
                if (index < 0)
                {
                    index = 0;
                }

                InstanceMenuItem.Text = $@"{BoundInstance.DisplayConnectionSummaryText} - {BoundInstance.ConnectionStatusText}";
                menu.Items.Insert(index++, InstanceMenuItem);
                if (BoundInstance.WorkbenchConnection != null)
                {
                    if (ConfigureMenuItem != null)
                    {
                        menu.Items.Insert(index++, ConfigureMenuItem);
                    }

                    if (SqlEditorMenuItem != null)
                    {
                        menu.Items.Insert(index++, SqlEditorMenuItem);
                    }
                }

                menu.Items.Insert(index, Separator);
                menu.Refresh();
            }
        }
예제 #2
0
        /// <summary>
        /// Refreshes the menu items of this menu group.
        /// </summary>
        /// <param name="menu">The Notifier's context menu.</param>
        public void RefreshMenu(ContextMenuStrip menu)
        {
            if (menu.InvokeRequired)
            {
                menu.Invoke(new MethodInvoker(() => RefreshMenu(menu)));
            }
            else
            {
                if (!_boundService.IsRealMySqlService)
                {
                    return;
                }

                _boundService.FindMatchingWbConnections();

                int index = FindMenuItemWithinMenuStrip(menu, _boundService.ServiceId);
                if (index < 0)
                {
                    return;
                }

                // We dispose of ConfigureInstance and SQLEditor items to recreate a clear menu.
                if (menu.Items[index + 1].Text.Equals(Resources.ManageInstance))
                {
                    menu.Items.RemoveAt(index + 1);
                }

                if (menu.Items[index + 1].Text.Equals(Resources.SQLEditor))
                {
                    menu.Items.RemoveAt(index + 1);
                }

                // If Workbench is installed on the system, we add ConfigureInstance and SQLEditor items back.
                if (MySqlWorkbench.AllowsExternalConnectionsManagement)
                {
                    if (_configureMenu == null)
                    {
                        _configureMenu        = new ToolStripMenuItem(Resources.ManageInstance);
                        _configureMenu.Click += configureInstanceItem_Click;
                    }

                    CreateEditorMenus();

                    if (_configureMenu != null)
                    {
                        menu.Items.Insert(++index, _configureMenu);
                    }

                    if (_editorMenu != null)
                    {
                        menu.Items.Insert(++index, _editorMenu);
                    }
                }

                menu.Refresh();
            }
        }
        /// <summary>
        /// Removes the main MySQL instance's menu itemText and its sub-items from the given context menu strip.
        /// </summary>
        /// <param name="menu">Context menu strip to remove the MySQL instance's menu items from..</param>
        public void RemoveFromContextMenu(ContextMenuStrip menu)
        {
            if (menu.InvokeRequired)
            {
                menu.Invoke(new MethodInvoker(() => RemoveFromContextMenu(menu)));
            }
            else
            {
                var menuItemTexts = new string[4];
                var index         = FindInstanceMenuItemWithinMenuStrip(menu);

                if (index < 0)
                {
                    return;
                }

                // if index + 1 is a ConfigureInstance item, we need to dispose of the whole item.
                if (menu.Items[index + 1].Text.Equals(Resources.ManageInstance))
                {
                    // The last itemText we delete is the service name itemText which is the reference for the others.
                    menuItemTexts[0] = "Configure Menu";
                    menuItemTexts[1] = "Editor Menu";
                    menuItemTexts[2] = "Separator";
                    menuItemTexts[3] = InstanceMenuItem.Text;
                }
                else
                {
                    menuItemTexts[0] = "Separator";
                    menuItemTexts[1] = InstanceMenuItem.Text;
                }

                foreach (var itemText in menuItemTexts)
                {
                    if (string.IsNullOrEmpty(itemText))
                    {
                        continue;
                    }

                    index = FindInstanceMenuItemWithinMenuStrip(menu);
                    if (index < 0)
                    {
                        continue;
                    }

                    if (!itemText.Equals(InstanceMenuItem.Text))
                    {
                        index++;
                    }

                    menu.Items.RemoveAt(index);
                }

                menu.Refresh();
            }
        }
예제 #4
0
        private void BuildDynamicItems(bool clean)
        {
            if (!clean)
            {
                mainMenu.SuspendLayout();

                foreach (var dynamicMenuItem in dynamicMenuItems)
                {
                    mainMenu.Items.Remove(dynamicMenuItem);
                }

                dynamicMenuItems.Clear();
            }


            if (registry.MostPlayedGames.Count != 0)
            {
                dynamicMenuItems.Add(AddMenuSeparator(mainMenu.Items, insertToTop: true));
                var mpgItems = AddGameMenuItems(mainMenu.Items, registry.MostPlayedGames, insertToTop: true);

                foreach (var mpgItem in mpgItems)
                {
                    dynamicMenuItems.Add(mpgItem);
                }

                dynamicMenuItems.Add(AddLabel(mainMenu.Items, "Most played games:", insertToTop: true));
            }

            if (registry.FavoriteGames.Count != 0)
            {
                dynamicMenuItems.Add(AddMenuSeparator(mainMenu.Items, insertToTop: true));
                var favItems = AddGameMenuItems(mainMenu.Items, registry.FavoriteGames, insertToTop: true);

                foreach (var favItem in favItems)
                {
                    dynamicMenuItems.Add(favItem);
                }

                dynamicMenuItems.Add(AddLabel(mainMenu.Items, "Favorites:", insertToTop: true));
            }

            if (!clean)
            {
                mainMenu.ResumeLayout();
                mainMenu.PerformLayout();
                mainMenu.Refresh();

                if (mainMenuWidth < mainMenu.Width)
                {
                    mainMenuWidth = mainMenu.Width;
                }
            }
        }
        /// <summary>
        /// Refreshes the menu items of this menu group.
        /// </summary>
        /// <param name="menu">The Notifier's context menu.</param>
        public void RefreshMenu(ContextMenuStrip menu)
        {
            if (menu.InvokeRequired)
            {
                menu.Invoke(new MethodInvoker(() => RefreshMenu(menu)));
            }
            else
            {
                var index = FindMenuItemWithinMenuStrip(menu, BoundInstance.InstanceId);
                if (index < 0)
                {
                    return;
                }

                // We dispose of ConfigureInstance and SQLEditor items to recreate a clear menu.
                if (menu.Items[index + 1].Text.Equals(Resources.ManageInstance))
                {
                    menu.Items.RemoveAt(index + 1);
                }

                if (menu.Items[index + 1].Text.Equals(Resources.SQLEditor))
                {
                    menu.Items.RemoveAt(index + 1);
                }

                // If Workbench is installed on the system, we add ConfigureInstance and SQLEditor items back.
                if (MySqlWorkbench.AllowsExternalConnectionsManagement)
                {
                    if (ConfigureMenuItem == null)
                    {
                        ConfigureMenuItem        = new ToolStripMenuItem(Resources.ManageInstance);
                        ConfigureMenuItem.Click += ConfigureMenuItem_Click;
                        RecreateSqlEditorMenus();
                    }

                    if (ConfigureMenuItem != null)
                    {
                        menu.Items.Insert(++index, ConfigureMenuItem);
                    }

                    if (SqlEditorMenuItem != null)
                    {
                        menu.Items.Insert(++index, SqlEditorMenuItem);
                    }
                }

                menu.Refresh();
            }
        }
예제 #6
0
        /// <summary>
        /// Removes all menu items related to this service menu group from the main Notifier's context menu.
        /// </summary>
        /// <param name="menu">Main Notifier's context menu.</param>
        public void RemoveFromContextMenu(ContextMenuStrip menu)
        {
            if (menu.InvokeRequired)
            {
                menu.Invoke(new MethodInvoker(() => RemoveFromContextMenu(menu)));
            }
            else
            {
                var menuItems = new string[4];

                if (_boundService?.StartupParameters == null)
                {
                    return;
                }

                if (_boundService.StartupParameters.IsForMySql &&
                    MySqlWorkbench.AllowsExternalConnectionsManagement)
                {
                    menuItems[0] = Resources.ManageInstance;
                    menuItems[1] = Resources.SQLEditor;
                    menuItems[2] = "Separator";
                    menuItems[3] = _statusMenu.Text; // the last itemText we delete is the service name itemText which is the reference for the others
                }
                else
                {
                    menuItems[0] = "Separator";
                    menuItems[1] = _statusMenu.Text;
                }

                var index = FindMenuItemWithinMenuStrip(menu, _boundService.ServiceId);
                if (index <= 0)
                {
                    return;
                }

                // Hide the separator just above this new menu item if needed.
                if (index > 0 && menu.Items[index - 1] is ToolStripSeparator)
                {
                    menu.Items[index - 1].Visible = menu.Items[index + 1].BackColor != SystemColors.MenuText;
                }

                foreach (var plusItem in from item in menuItems where !string.IsNullOrEmpty(item) select item.Equals(_statusMenu.Text) ? 0 : 1)
                {
                    menu.Items.RemoveAt(index + plusItem);
                }

                menu.Refresh();
            }
        }
예제 #7
0
        /// <summary>
        /// 快捷菜单点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void contextMenuStripWrite_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            ListView         listView  = null;
            ContextMenuStrip menuStrip = sender as ContextMenuStrip;

            if (menuStrip != null)
            {
                listView = menuStrip.SourceControl as ListView;
                if (listView == null)
                {
                    return;
                }
            }
            menuStrip.Close();
            menuStrip.Refresh();
            switch (e.ClickedItem.Name)
            {
            case "WriteCleanToolStripMenuItem":
                CleanWriteConfig();
                break;

            case "WriteImportToolStripMenuItem":
                InputWriteConfig();
                break;

            case "WriteOutputToolStripMenuItem":
                OutputWriteConfig();
                break;

            case "WriteDeleteToolStripMenuItem":
                DeleteWriteConfig(listView);
                break;

            case "WriteUpToolStripMenuItem":
                MoveWriteConfig(listView, true);
                break;

            case "WriteDownToolStripMenuItem":
                MoveWriteConfig(listView, false);
                break;

            default:
                break;
            }
        }