예제 #1
0
        /// <summary>
        /// Event handler for when an item in the Remove Preset drop down is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RemovePresetDropDown_ItemClicked(object sender, EventArgs e)
        {
            PresetContextMenuItem presetContextMenuItem = sender as PresetContextMenuItem;

            if (presetContextMenuItem != null)
            {
                DisplayPresetCollection.GetDisplayPresetCollection().TryRemoveDisplayPreset(presetContextMenuItem.PresetName);
            }
        }
예제 #2
0
        /// <summary>
        /// Event handler for when an item in the Apply Preset drop down is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ApplyPresetDropDown_ItemClicked(object sender, EventArgs e)
        {
            PresetContextMenuItem presetContextMenuItem = sender as PresetContextMenuItem;

            if (presetContextMenuItem != null)
            {
                SafePresetApplier.ApplyPresetWithRevertCountdown(
                    DisplayPresetCollection.GetDisplayPresetCollection().GetPreset(presetContextMenuItem.PresetName));
            }
        }
예제 #3
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
        }