Пример #1
0
        /// <summary>
        /// Verifies that the input in the textbox is a unique name and is non-empty, calls in to
        /// OutputSwitcher.Core to create and save the new preset.
        /// </summary>
        /// <returns>True if preset created and saved. False if input is invalid or failed to save new preset.</returns>
        private bool TryCreateNewPresetWithEnteredName()
        {
            if (TextboxEnterNewPresetName.Text.Length < 1)
            {
                MessageBox.Show("Please enter at least one character.", "OutputSwitcher");
                return(false);
            }

            string newPresetName = TextboxEnterNewPresetName.Text;

            DisplayPresetCollection displayPresetCollection = DisplayPresetCollection.GetDisplayPresetCollection();
            DisplayPreset           existingPreset          = displayPresetCollection.GetPreset(newPresetName);

            if (existingPreset != null)
            {
                MessageBox.Show("Name already exists, please enter a unique name.", "OutputSwitcher");
                return(false);
            }

            DisplayPreset newPreset = DisplayPresetRecorderAndApplier.RecordCurrentConfiguration(newPresetName);

            if (!displayPresetCollection.TryAddDisplayPreset(newPreset))
            {
                MessageBox.Show("Failed to save new display preset configuration.", "OutputSwitcher");
                return(false);
            }
            else
            {
                return(true);
            }
        }
Пример #2
0
        static public void CaptureCurrentConfigAndSaveAsPreset()
        {
            bool uniqueNameEntered = false;

            string presetName;

            DisplayPresetCollection displayPresetCollection = DisplayPresetCollection.GetDisplayPresetCollection();

            do
            {
                Console.Write("Enter name for new preset: ");
                presetName = Console.ReadLine();

                DisplayPreset existingDisplayPreset = displayPresetCollection.GetPreset(presetName);

                uniqueNameEntered = existingDisplayPreset == null;

                if (!uniqueNameEntered)
                {
                    Console.WriteLine("Preset with name '" + presetName + "' already exists. Please choose a different name.");
                }
            } while (!uniqueNameEntered);

            DisplayPreset newPreset = DisplayPresetRecorderAndApplier.RecordCurrentConfiguration(presetName);

            if (!displayPresetCollection.TryAddDisplayPreset(newPreset))
            {
                throw new Exception("Failed to add new preset to saved presets collection.");   // This is really unexpected because we've checked for existence already.
            }

            Console.WriteLine("Added new preset!");
            ConsoleOutputUtilities.WriteDisplayPresetToConsole(newPreset);
        }
Пример #3
0
        /// <summary>
        /// Event handler when a global hotkey event for this app has been raised. Finds the
        /// preset that corresponds to the hotkey pressed and applies it.
        /// </summary>
        /// <param name="modifierKeyFlags">Modifier keys for the hotkey.</param>
        /// <param name="keycode">Key code for the hotkey.</param>
        private void OnPresetSwitchHotkeyPressed(ushort modifierKeyFlags, ushort keycode)
        {
            // TODO: This kinda sucks because it sorta relies on abusing the interface of PresetToHotkeyMap.
            foreach (KeyValuePair <string, VirtualHotkey> presetHotkeyPair in mPresetToHotkeyMap.GetHotkeyMappings().ToArray())
            {
                // Chop off the MOD_NOREPEAT that is added by HotkeyRegistrar.
                ushort presetModifierKeyFlags =
                    unchecked ((ushort)(presetHotkeyPair.Value.ModifierKeyCode &
                                        (VirtualKeyCodes.MOD_ALT |
                                         VirtualKeyCodes.MOD_CONTROL |
                                         VirtualKeyCodes.MOD_SHIFT |
                                         VirtualKeyCodes.MOD_WIN)));

                ushort presetKeyCode = (unchecked ((ushort)(presetHotkeyPair.Value.KeyCode)));

                if (presetModifierKeyFlags == modifierKeyFlags && presetKeyCode == keycode)
                {
                    DisplayPreset invokedPreset = DisplayPresetCollection.GetDisplayPresetCollection().GetPreset(presetHotkeyPair.Key);

                    if (invokedPreset != null)
                    {
                        SafePresetApplier.ApplyPresetWithRevertCountdown(invokedPreset);
                    }
                    else
                    {
                        throw new Exception("Hotkey pressed for unknown preset.");
                    }

                    break;
                }
            }
        }
        private PresetToHotkeyMap()
        {
            Dictionary <string, VirtualHotkey> dictionary = PresetToHotkeyMapPersistence.LoadPresetToHotkeysMap();

            mPresetToHotkeyDictionary = dictionary != null ? new Dictionary <string, VirtualHotkey>(dictionary) : new Dictionary <string, VirtualHotkey>();

            DisplayPresetCollection.GetDisplayPresetCollection().DisplayPresetCollectionChanged += OnDisplayPresetCollectionChanged;
        }
Пример #5
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);
            }
        }
Пример #6
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));
            }
        }
Пример #7
0
        static public void ListPresets()
        {
            DisplayPresetCollection presetCollection = DisplayPresetCollection.GetDisplayPresetCollection();

            int index = 1;

            foreach (DisplayPreset displayPreset in presetCollection.GetPresets())
            {
                Console.WriteLine(String.Format("{0}. {1}", index, displayPreset.Name));
                index++;
            }
        }
Пример #8
0
        /// <summary>
        /// Creates the app's context menu items.
        /// </summary>
        private void InitializeContextMenu()
        {
            ToolStripItem[] afterPresetsToolStripItems = new ToolStripItem[3];
            afterPresetsToolStripItems[0] = new ToolStripButton("Capture current display configuration as preset", null, CaptureNewPreset_ItemClicked);
            afterPresetsToolStripItems[1] = new ToolStripButton("Edit global hotkeys", null, EditGlobalHotkeys_ItemClicked);
            afterPresetsToolStripItems[2] = new ToolStripButton("Exit", null, ContextMenuStrip_Exit);

            List <DisplayPreset> displayPresets = DisplayPresetCollection.GetDisplayPresetCollection().GetPresets();

            List <ToolStripItem> applyPresetDropDownItems  = new List <ToolStripItem>();
            List <ToolStripItem> removePresetDropDownItems = new List <ToolStripItem>();

            if (displayPresets.Count > 0)
            {
                foreach (DisplayPreset preset in displayPresets)
                {
                    applyPresetDropDownItems.Add(new PresetContextMenuItem(preset.Name, ApplyPresetDropDown_ItemClicked));
                    removePresetDropDownItems.Add(new PresetContextMenuItem(preset.Name, RemovePresetDropDown_ItemClicked));
                }
            }
            else
            {
                applyPresetDropDownItems.Add(new NoPresetPresetContextMenuItem());
                removePresetDropDownItems.Add(new NoPresetPresetContextMenuItem());
            }

            applyPresetDropDownButton  = new ToolStripDropDownButton("Apply display preset...", null, applyPresetDropDownItems.ToArray());
            removePresetDropDownButton = new ToolStripDropDownButton("Remove display preset...", null, removePresetDropDownItems.ToArray());

            ToolStripItem[] mAddRemovePresetsToolStripItems = new ToolStripItem[2];
            mAddRemovePresetsToolStripItems[0] = applyPresetDropDownButton;
            mAddRemovePresetsToolStripItems[1] = removePresetDropDownButton;

            ToolStripItem[] beforePresetsToolStripItems = new ToolStripItem[1];
            beforePresetsToolStripItems[0]      = new ToolStripLabel("OutputSwitcher");
            beforePresetsToolStripItems[0].Font = new System.Drawing.Font(beforePresetsToolStripItems[0].Font, System.Drawing.FontStyle.Bold);

            mNotifyIcon.ContextMenuStrip.Items.Clear();
            mNotifyIcon.ContextMenuStrip.Items.AddRange(beforePresetsToolStripItems);
            mNotifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator());
            mNotifyIcon.ContextMenuStrip.Items.AddRange(mAddRemovePresetsToolStripItems);
            mNotifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator());
            mNotifyIcon.ContextMenuStrip.Items.AddRange(afterPresetsToolStripItems);

            mNotifyIcon.ContextMenuStrip.PerformLayout();

            DisplayPresetCollection.GetDisplayPresetCollection().DisplayPresetCollectionChanged += OnDisplayPresetCollectionChanged;
        }
Пример #9
0
 /// <summary>
 /// Event handler for when "Edit global hotkeys" context menu item is clicked. Launches
 /// a form to allow the user to edit global hotkeys for the display presets.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void EditGlobalHotkeys_ItemClicked(object sender, EventArgs e)
 {
     if (mPresetHotkeyForm == null)
     {
         mPresetHotkeyForm             = new PresetHotkeyForm(DisplayPresetCollection.GetDisplayPresetCollection(), PresetToHotkeyMap.GetInstance());
         mPresetHotkeyForm.FormClosed += MPresetHotkeyForm_FormClosed;
     }
     else if (!mPresetHotkeyForm.Visible)
     {
         mPresetHotkeyForm.ShowDialog();
     }
     else
     {
         mPresetHotkeyForm.Activate();
     }
 }
Пример #10
0
        public static void ListPresetDetail()
        {
            DisplayPresetCollection displayPresetCollection = DisplayPresetCollection.GetDisplayPresetCollection();

            List <DisplayPreset> displayPresets = displayPresetCollection.GetPresets();

            Console.WriteLine("Available presets: ");

            IEnumerator <DisplayPreset> displayPresetsEnumerator = displayPresets.GetEnumerator();

            for (int i = 0; i < displayPresets.Count; i++)
            {
                displayPresetsEnumerator.MoveNext();
                Console.WriteLine(String.Format("[{0}] {1}", i, displayPresetsEnumerator.Current.Name));
            }

            Console.Write("Select preset: ");
            string selection = Console.ReadLine();

            int    selectedPresetIndex = -1;
            string selectedPresetName  = String.Empty;

            if (!Int32.TryParse(selection, out selectedPresetIndex))
            {
                // If it's not a number, assume the user typed in a name
                selectedPresetName = selection;
            }
            else if (selectedPresetIndex >= displayPresets.Count)
            {
                Console.WriteLine("Invalid selection!");
                return;
            }
            else
            {
                selectedPresetName = displayPresets[selectedPresetIndex].Name;
            }

            DisplayPreset selectedPreset = displayPresetCollection.GetPreset(selectedPresetName);

            if (selectedPreset == null)
            {
                Console.WriteLine("Invalid preset name: " + selectedPresetName);
                return;
            }

            ConsoleOutputUtilities.WriteDisplayPresetToConsole(selectedPreset);
        }
Пример #11
0
        static public void DeletePreset()
        {
            Console.Write("Enter name of preset to delete: ");
            string targetPresetName = Console.ReadLine();

            DisplayPresetCollection displayPresetCollection = DisplayPresetCollection.GetDisplayPresetCollection();
            bool presetDeleted = displayPresetCollection.TryRemoveDisplayPreset(targetPresetName);

            if (presetDeleted)
            {
                Console.WriteLine("Deleted preset '" + targetPresetName + "'.");
            }
            else
            {
                Console.WriteLine("Preset '" + targetPresetName + "' does not exist.");
            }
        }
Пример #12
0
        static public void ApplyPreset()
        {
            Console.Write("Enter name of preset to apply: ");
            string presetName = Console.ReadLine();

            DisplayPresetCollection displayPresetCollection = DisplayPresetCollection.GetDisplayPresetCollection();

            DisplayPreset targetPreset = displayPresetCollection.GetPreset(presetName);

            if (targetPreset == null)
            {
                Console.WriteLine("Preset with name '" + presetName + "' does not exist.");
                return;
            }

            Console.WriteLine("Applying preset '" + presetName + "'...");
            DisplayPresetRecorderAndApplier.ApplyPreset(targetPreset);
        }
        public static void ApplyPreset(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Insufficient arguments.");
                return;
            }

            // Trim quotes in case the preset name has spaces
            string presetName = args[1].Trim(new char[] { '"', '\'' });

            DisplayPresetCollection displayPresetCollection = DisplayPresetCollection.GetDisplayPresetCollection();

            DisplayPreset displayPreset = displayPresetCollection.GetPreset(presetName);

            if (displayPreset == null)
            {
                Console.WriteLine(String.Format("Preset '{0}' does not exist.", presetName));
                return;
            }

            DisplayPresetRecorderAndApplier.ApplyPreset(displayPreset);
        }
        public static void CaptureCurrentConfigAndSaveAsPreset(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Insufficient arguments.");
                return;
            }

            // Trim quotes in case the preset name has spaces
            string presetName = args[1].Trim(new char[] { '"', '\'' });

            DisplayPreset displayPreset = DisplayPresetRecorderAndApplier.RecordCurrentConfiguration(presetName);

            DisplayPresetCollection displayPresetCollection = DisplayPresetCollection.GetDisplayPresetCollection();

            if (displayPresetCollection.TryAddDisplayPreset(displayPreset))
            {
                Console.WriteLine(String.Format("New display preset '{0}' saved!", presetName));
            }
            else
            {
                Console.WriteLine("Failed to save preset.");
            }
        }