/// <summary>
        /// Handles the event when the display preset collection has changed. If a preset has been
        /// deleted, the corresponding hotkey (if existing) should be deleted as well.
        /// </summary>
        /// <param name="changeType">The type of collection change.</param>
        /// <param name="presetName">The name of the changed preset.</param>
        private void OnDisplayPresetCollectionChanged(DisplayPresetCollection.DisplayPresetCollectionChangeType changeType, string presetName)
        {
            // Really it seems a better idea to just unify all the persistence into one data structure and
            // collection rather than trying to keep two collections in sync.

            if (changeType == DisplayPresetCollection.DisplayPresetCollectionChangeType.PresetRemoved &&
                mPresetToHotkeyDictionary.ContainsKey(presetName))
            {
                RemoveHotkey(presetName);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Event handler for when display preset collection changes and we need to update the context menu
        /// items containing the presets that are available for apply/remove.
        /// </summary>
        /// <param name="changeType">The type of collection change.</param>
        /// <param name="presetName">The name of the preset added or removed.</param>
        private void OnDisplayPresetCollectionChanged(DisplayPresetCollection.DisplayPresetCollectionChangeType changeType, string presetName)
        {
            if (changeType == DisplayPresetCollection.DisplayPresetCollectionChangeType.PresetAdded)
            {
                // If this is the first new preset added, remove the "None" disabled items.
                if (applyPresetDropDownButton.DropDown.Items.Count == 1 &&
                    applyPresetDropDownButton.DropDown.Items[0] is NoPresetPresetContextMenuItem)
                {
                    applyPresetDropDownButton.DropDown.Items.RemoveAt(0);
                }

                if (removePresetDropDownButton.DropDown.Items.Count == 1 &&
                    removePresetDropDownButton.DropDown.Items[0] is NoPresetPresetContextMenuItem)
                {
                    removePresetDropDownButton.DropDown.Items.RemoveAt(0);
                }

                applyPresetDropDownButton.DropDown.Items.Add(new PresetContextMenuItem(presetName, ApplyPresetDropDown_ItemClicked));
                removePresetDropDownButton.DropDown.Items.Add(new PresetContextMenuItem(presetName, RemovePresetDropDown_ItemClicked));
            }
            else
            {
                int applyIndex  = 0;
                int removeIndex = 0;

                foreach (ToolStripItem menuItem in applyPresetDropDownButton.DropDown.Items)
                {
                    PresetContextMenuItem presetItem = menuItem as PresetContextMenuItem;

                    if (presetItem != null && presetItem.PresetName.Equals(presetName))
                    {
                        applyPresetDropDownButton.DropDown.Items.RemoveAt(applyIndex);
                        break;
                    }

                    applyIndex++;
                }

                foreach (PresetContextMenuItem menuItem in removePresetDropDownButton.DropDown.Items)
                {
                    PresetContextMenuItem presetItem = menuItem as PresetContextMenuItem;

                    if (presetItem != null && presetItem.PresetName.Equals(presetName))
                    {
                        removePresetDropDownButton.DropDown.Items.RemoveAt(removeIndex);
                        break;
                    }

                    removeIndex++;
                }

                // If all presets have been removed, place the "None" disabled menu item back into the drop down.
                if (applyPresetDropDownButton.DropDown.Items.Count == 0)
                {
                    applyPresetDropDownButton.DropDown.Items.Add(new NoPresetPresetContextMenuItem());
                }

                if (removePresetDropDownButton.DropDown.Items.Count == 0)
                {
                    removePresetDropDownButton.DropDown.Items.Add(new NoPresetPresetContextMenuItem());
                }
            }

            applyPresetDropDownButton.DropDown.PerformLayout();
            removePresetDropDownButton.DropDown.PerformLayout();
            mNotifyIcon.ContextMenuStrip.PerformLayout();   // Refresh the layout
        }