diff --git a/DisplayMagician/ProgramSettings.cs b/DisplayMagician/ProgramSettings.cs index dd3f45b..6051725 100644 --- a/DisplayMagician/ProgramSettings.cs +++ b/DisplayMagician/ProgramSettings.cs @@ -2,6 +2,8 @@ using System; using System.IO; using System.Text; +using System.Windows.Forms; + namespace DisplayMagician { @@ -20,6 +22,9 @@ namespace DisplayMagician private bool _startOnBootUp = false; private bool _minimiseOnStart = false; private string _logLevel = NLog.LogLevel.Info.ToString(); + private Keys _hotkeyMainWindow = Keys.None; + private Keys _hotkeyDisplayProfileWindow = Keys.None; + private Keys _hotkeyShortcutLibraryWindow = Keys.None; #endregion #region Class Properties @@ -97,6 +102,64 @@ namespace DisplayMagician } } + public Keys HotkeyMainWindow + { + get + { + return _hotkeyMainWindow; + } + set + { + _hotkeyMainWindow = value; + + // Because a value has changed, we need to save the setting + // to remember it for later. + if (_programSettingsLoaded) + { + SaveSettings(); + } + } + } + + public Keys HotkeyDisplayProfileWindow + { + get + { + return _hotkeyDisplayProfileWindow; + } + set + { + _hotkeyDisplayProfileWindow = value; + + // Because a value has changed, we need to save the setting + // to remember it for later. + if (_programSettingsLoaded) + { + SaveSettings(); + } + } + } + + public Keys HotkeyShortcutLibraryWindow + { + get + { + return _hotkeyShortcutLibraryWindow; + } + set + { + _hotkeyShortcutLibraryWindow = value; + + // Because a value has changed, we need to save the setting + // to remember it for later. + if (_programSettingsLoaded) + { + SaveSettings(); + } + } + } + + public static Version FileVersion { get => new Version(1, 0, 0); @@ -153,6 +216,7 @@ namespace DisplayMagician if (programSettings == null) programSettings = new ProgramSettings(); _programSettingsLoaded = true; + return programSettings ; } diff --git a/DisplayMagician/UIForms/DisplayProfileForm.cs b/DisplayMagician/UIForms/DisplayProfileForm.cs index 16f5185..66e0d13 100644 --- a/DisplayMagician/UIForms/DisplayProfileForm.cs +++ b/DisplayMagician/UIForms/DisplayProfileForm.cs @@ -491,8 +491,12 @@ namespace DisplayMagician.UIForms ProfileRepository.SaveProfiles(); // And if we get back and this is a Hotkey with a value, we need to show that in the UI UpdateHotkeyLabel(_selectedProfile.Hotkey); - // And then apply the Hotkey now - HotkeyManager.Current.AddOrReplace(_selectedProfile.UUID, _selectedProfile.Hotkey, OnWindowHotkeyPressed); + if (displayHotkeyForm.Hotkey == Keys.None) + // Remove the Hotkey if it needs to be removed + HotkeyManager.Current.Remove(_selectedProfile.UUID); + else + // And then apply the Hotkey now + HotkeyManager.Current.AddOrReplace(_selectedProfile.UUID, _selectedProfile.Hotkey, OnWindowHotkeyPressed); } } private void lbl_hotkey_assigned_Click(object sender, EventArgs e) diff --git a/DisplayMagician/UIForms/MainForm.cs b/DisplayMagician/UIForms/MainForm.cs index d08e129..dfe5c27 100644 --- a/DisplayMagician/UIForms/MainForm.cs +++ b/DisplayMagician/UIForms/MainForm.cs @@ -14,6 +14,7 @@ using Microsoft.Toolkit.Uwp.Notifications; using System.Collections.Generic; using NHotkey.WindowsForms; using NHotkey; +using System.Linq; namespace DisplayMagician.UIForms { @@ -41,12 +42,13 @@ namespace DisplayMagician.UIForms notifyIcon.ContextMenuStrip = mainContextMenuStrip; RefreshNotifyIconMenus(); - /*if (Program.AppProgramSettings.MainWindowHotkey) - HotkeyManager.Current.AddOrReplace("MainWindowHotkey", Program.AppProgramSettings.MainWindowHotkey, OnWindowHotkeyPressed); - if (Program.AppProgramSettings.ShortcutLibraryWindow) - HotkeyManager.Current.AddOrReplace("ShortcutLibraryWindow", Program.AppProgramSettings.ShortcutLibraryWindow, OnWindowHotkeyPressed); - if (Program.AppProgramSettings.DisplayProfileWindow) - HotkeyManager.Current.AddOrReplace("DisplayProfileWindow", Program.AppProgramSettings.DisplayProfileWindow, OnWindowHotkeyPressed);*/ + if (Program.AppProgramSettings.HotkeyMainWindow != Keys.None) + HotkeyManager.Current.AddOrReplace("HotkeyMainWindow", Program.AppProgramSettings.HotkeyMainWindow, OnWindowHotkeyPressed); + if (Program.AppProgramSettings.HotkeyDisplayProfileWindow != Keys.None) + HotkeyManager.Current.AddOrReplace("HotkeyDisplayProfileWindow", Program.AppProgramSettings.HotkeyDisplayProfileWindow, OnWindowHotkeyPressed); + if (Program.AppProgramSettings.HotkeyShortcutLibraryWindow != Keys.None) + HotkeyManager.Current.AddOrReplace("HotkeyShortcutLibraryWindow", Program.AppProgramSettings.HotkeyShortcutLibraryWindow, OnWindowHotkeyPressed); + // Add all the Profile Hotkeys that are set foreach (ProfileItem myProfile in ProfileRepository.AllProfiles) @@ -191,8 +193,20 @@ namespace DisplayMagician.UIForms private void btn_setup_display_profiles_Click(object sender, EventArgs e) { - var displayProfileForm = new DisplayProfileForm(); - displayProfileForm.ShowDialog(this); + DisplayProfileForm displayProfileForm = null; + if (Application.OpenForms.OfType().Any()) + { + displayProfileForm = Application.OpenForms.OfType().Single(); + displayProfileForm.Activate(); + displayProfileForm.Show(); + displayProfileForm.BringToFront(); + + } + else + { + displayProfileForm = new DisplayProfileForm(); + displayProfileForm.ShowDialog(this); + } } private void pb_game_shortcut_Click(object sender, EventArgs e) @@ -202,8 +216,19 @@ namespace DisplayMagician.UIForms private void btn_setup_game_shortcuts_Click(object sender, EventArgs e) { - var shortcutLibraryForm = new ShortcutLibraryForm(); - shortcutLibraryForm.ShowDialog(this); + ShortcutLibraryForm shortcutLibraryForm = null; + if (Application.OpenForms.OfType().Any()) + { + shortcutLibraryForm = Application.OpenForms.OfType().Single(); + shortcutLibraryForm.Activate(); + shortcutLibraryForm.Show(); + shortcutLibraryForm.BringToFront(); + } + else + { + shortcutLibraryForm = new ShortcutLibraryForm(); + shortcutLibraryForm.ShowDialog(this); + } } private void MainForm_Load(object sender, EventArgs e) @@ -537,7 +562,7 @@ namespace DisplayMagician.UIForms openApplicationWindow(); else if (e.Name == "HotkeyDisplayProfileWindow") btn_setup_display_profiles.PerformClick(); - else if (e.Name == "ShortcutLibraryWindow") + else if (e.Name == "HotkeyShortcutLibraryWindow") btn_setup_game_shortcuts.PerformClick(); else if (hotkeyDisplayProfiles.Contains(e.Name)) { diff --git a/DisplayMagician/UIForms/SettingsForm.Designer.cs b/DisplayMagician/UIForms/SettingsForm.Designer.cs index 825810f..f582ec2 100644 --- a/DisplayMagician/UIForms/SettingsForm.Designer.cs +++ b/DisplayMagician/UIForms/SettingsForm.Designer.cs @@ -29,47 +29,30 @@ namespace DisplayMagician.UIForms /// private void InitializeComponent() { - this.cb_minimise_notification_area = new System.Windows.Forms.CheckBox(); - this.cmb_loglevel = new System.Windows.Forms.ComboBox(); - this.label1 = new System.Windows.Forms.Label(); + System.Windows.Forms.ListViewGroup listViewGroup15 = new System.Windows.Forms.ListViewGroup("Display Profiles", System.Windows.Forms.HorizontalAlignment.Left); + System.Windows.Forms.ListViewGroup listViewGroup16 = new System.Windows.Forms.ListViewGroup("Game Shortcuts", System.Windows.Forms.HorizontalAlignment.Left); this.btn_back = new System.Windows.Forms.Button(); + this.gb_general = new System.Windows.Forms.GroupBox(); this.cb_start_on_boot = new System.Windows.Forms.CheckBox(); + this.label1 = new System.Windows.Forms.Label(); + this.cmb_loglevel = new System.Windows.Forms.ComboBox(); + this.cb_minimise_notification_area = new System.Windows.Forms.CheckBox(); + this.gb_hotkeys = new System.Windows.Forms.GroupBox(); + this.btn_hotkey_main_window = new System.Windows.Forms.Button(); + this.btn_hotkey_display_profile = new System.Windows.Forms.Button(); + this.btn_hotkey_shortcuts = new System.Windows.Forms.Button(); + this.lbl_hotkey_main_window_description = new System.Windows.Forms.Label(); + this.lbl_hotkey_display_profile_description = new System.Windows.Forms.Label(); + this.lbl_hotkey_shortcut_library_description = new System.Windows.Forms.Label(); + this.btn_clear_all_hotkeys = new System.Windows.Forms.Button(); + this.lv_dynamic_hotkeys = new System.Windows.Forms.ListView(); + this.lbl_hotkey_main_window = new System.Windows.Forms.Label(); + this.lbl_hotkey_display_profile = new System.Windows.Forms.Label(); + this.lbl_hotkey_shortcut_library = new System.Windows.Forms.Label(); + this.gb_general.SuspendLayout(); + this.gb_hotkeys.SuspendLayout(); this.SuspendLayout(); // - // cb_minimise_notification_area - // - this.cb_minimise_notification_area.Anchor = System.Windows.Forms.AnchorStyles.Top; - this.cb_minimise_notification_area.AutoSize = true; - this.cb_minimise_notification_area.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F); - this.cb_minimise_notification_area.ForeColor = System.Drawing.Color.White; - this.cb_minimise_notification_area.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.cb_minimise_notification_area.Location = new System.Drawing.Point(59, 61); - this.cb_minimise_notification_area.Name = "cb_minimise_notification_area"; - this.cb_minimise_notification_area.Size = new System.Drawing.Size(332, 20); - this.cb_minimise_notification_area.TabIndex = 6; - this.cb_minimise_notification_area.Text = "Start DisplayMagician minimised in notification area"; - this.cb_minimise_notification_area.UseVisualStyleBackColor = true; - // - // cmb_loglevel - // - this.cmb_loglevel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.cmb_loglevel.FormattingEnabled = true; - this.cmb_loglevel.Location = new System.Drawing.Point(199, 100); - this.cmb_loglevel.Name = "cmb_loglevel"; - this.cmb_loglevel.Size = new System.Drawing.Size(294, 24); - this.cmb_loglevel.TabIndex = 7; - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label1.ForeColor = System.Drawing.Color.Transparent; - this.label1.Location = new System.Drawing.Point(56, 103); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(137, 16); - this.label1.TabIndex = 8; - this.label1.Text = "What type of logging?"; - // // btn_back // this.btn_back.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); @@ -78,7 +61,7 @@ namespace DisplayMagician.UIForms this.btn_back.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown; this.btn_back.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.btn_back.ForeColor = System.Drawing.Color.White; - this.btn_back.Location = new System.Drawing.Point(457, 152); + this.btn_back.Location = new System.Drawing.Point(476, 650); this.btn_back.Name = "btn_back"; this.btn_back.Size = new System.Drawing.Size(75, 23); this.btn_back.TabIndex = 9; @@ -86,6 +69,21 @@ namespace DisplayMagician.UIForms this.btn_back.UseVisualStyleBackColor = true; this.btn_back.Click += new System.EventHandler(this.btn_back_Click); // + // gb_general + // + this.gb_general.Controls.Add(this.cb_start_on_boot); + this.gb_general.Controls.Add(this.label1); + this.gb_general.Controls.Add(this.cmb_loglevel); + this.gb_general.Controls.Add(this.cb_minimise_notification_area); + this.gb_general.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.gb_general.ForeColor = System.Drawing.Color.White; + this.gb_general.Location = new System.Drawing.Point(27, 21); + this.gb_general.Name = "gb_general"; + this.gb_general.Size = new System.Drawing.Size(525, 183); + this.gb_general.TabIndex = 11; + this.gb_general.TabStop = false; + this.gb_general.Text = "General Settings"; + // // cb_start_on_boot // this.cb_start_on_boot.Anchor = System.Windows.Forms.AnchorStyles.Top; @@ -93,24 +91,215 @@ namespace DisplayMagician.UIForms this.cb_start_on_boot.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F); this.cb_start_on_boot.ForeColor = System.Drawing.Color.White; this.cb_start_on_boot.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.cb_start_on_boot.Location = new System.Drawing.Point(59, 25); + this.cb_start_on_boot.Location = new System.Drawing.Point(28, 42); this.cb_start_on_boot.Name = "cb_start_on_boot"; this.cb_start_on_boot.Size = new System.Drawing.Size(389, 20); - this.cb_start_on_boot.TabIndex = 10; + this.cb_start_on_boot.TabIndex = 14; this.cb_start_on_boot.Text = "Start DisplayMagician automatically when the computer starts"; this.cb_start_on_boot.UseVisualStyleBackColor = true; // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.ForeColor = System.Drawing.Color.Transparent; + this.label1.Location = new System.Drawing.Point(26, 120); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(137, 16); + this.label1.TabIndex = 13; + this.label1.Text = "What type of logging?"; + // + // cmb_loglevel + // + this.cmb_loglevel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.cmb_loglevel.FormattingEnabled = true; + this.cmb_loglevel.Location = new System.Drawing.Point(169, 117); + this.cmb_loglevel.Name = "cmb_loglevel"; + this.cmb_loglevel.Size = new System.Drawing.Size(333, 24); + this.cmb_loglevel.TabIndex = 12; + // + // cb_minimise_notification_area + // + this.cb_minimise_notification_area.Anchor = System.Windows.Forms.AnchorStyles.Top; + this.cb_minimise_notification_area.AutoSize = true; + this.cb_minimise_notification_area.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F); + this.cb_minimise_notification_area.ForeColor = System.Drawing.Color.White; + this.cb_minimise_notification_area.ImeMode = System.Windows.Forms.ImeMode.NoControl; + this.cb_minimise_notification_area.Location = new System.Drawing.Point(28, 78); + this.cb_minimise_notification_area.Name = "cb_minimise_notification_area"; + this.cb_minimise_notification_area.Size = new System.Drawing.Size(332, 20); + this.cb_minimise_notification_area.TabIndex = 11; + this.cb_minimise_notification_area.Text = "Start DisplayMagician minimised in notification area"; + this.cb_minimise_notification_area.UseVisualStyleBackColor = true; + // + // gb_hotkeys + // + this.gb_hotkeys.Controls.Add(this.lbl_hotkey_shortcut_library); + this.gb_hotkeys.Controls.Add(this.lbl_hotkey_display_profile); + this.gb_hotkeys.Controls.Add(this.lbl_hotkey_main_window); + this.gb_hotkeys.Controls.Add(this.lv_dynamic_hotkeys); + this.gb_hotkeys.Controls.Add(this.btn_clear_all_hotkeys); + this.gb_hotkeys.Controls.Add(this.lbl_hotkey_shortcut_library_description); + this.gb_hotkeys.Controls.Add(this.lbl_hotkey_display_profile_description); + this.gb_hotkeys.Controls.Add(this.lbl_hotkey_main_window_description); + this.gb_hotkeys.Controls.Add(this.btn_hotkey_shortcuts); + this.gb_hotkeys.Controls.Add(this.btn_hotkey_display_profile); + this.gb_hotkeys.Controls.Add(this.btn_hotkey_main_window); + this.gb_hotkeys.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.gb_hotkeys.ForeColor = System.Drawing.Color.White; + this.gb_hotkeys.Location = new System.Drawing.Point(27, 235); + this.gb_hotkeys.Name = "gb_hotkeys"; + this.gb_hotkeys.Size = new System.Drawing.Size(525, 391); + this.gb_hotkeys.TabIndex = 12; + this.gb_hotkeys.TabStop = false; + this.gb_hotkeys.Text = "Hotkeys"; + // + // btn_hotkey_main_window + // + this.btn_hotkey_main_window.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btn_hotkey_main_window.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed; + this.btn_hotkey_main_window.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown; + this.btn_hotkey_main_window.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btn_hotkey_main_window.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btn_hotkey_main_window.ForeColor = System.Drawing.Color.White; + this.btn_hotkey_main_window.Location = new System.Drawing.Point(412, 27); + this.btn_hotkey_main_window.Name = "btn_hotkey_main_window"; + this.btn_hotkey_main_window.Size = new System.Drawing.Size(88, 33); + this.btn_hotkey_main_window.TabIndex = 36; + this.btn_hotkey_main_window.Text = "Set Hotkey"; + this.btn_hotkey_main_window.UseVisualStyleBackColor = true; + this.btn_hotkey_main_window.Click += new System.EventHandler(this.btn_hotkey_main_window_Click); + // + // btn_hotkey_display_profile + // + this.btn_hotkey_display_profile.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btn_hotkey_display_profile.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed; + this.btn_hotkey_display_profile.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown; + this.btn_hotkey_display_profile.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btn_hotkey_display_profile.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btn_hotkey_display_profile.ForeColor = System.Drawing.Color.White; + this.btn_hotkey_display_profile.Location = new System.Drawing.Point(411, 75); + this.btn_hotkey_display_profile.Name = "btn_hotkey_display_profile"; + this.btn_hotkey_display_profile.Size = new System.Drawing.Size(89, 33); + this.btn_hotkey_display_profile.TabIndex = 37; + this.btn_hotkey_display_profile.Text = "Set Hotkey"; + this.btn_hotkey_display_profile.UseVisualStyleBackColor = true; + this.btn_hotkey_display_profile.Click += new System.EventHandler(this.btn_hotkey_display_profile_Click); + // + // btn_hotkey_shortcuts + // + this.btn_hotkey_shortcuts.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btn_hotkey_shortcuts.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed; + this.btn_hotkey_shortcuts.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown; + this.btn_hotkey_shortcuts.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btn_hotkey_shortcuts.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btn_hotkey_shortcuts.ForeColor = System.Drawing.Color.White; + this.btn_hotkey_shortcuts.Location = new System.Drawing.Point(411, 125); + this.btn_hotkey_shortcuts.Name = "btn_hotkey_shortcuts"; + this.btn_hotkey_shortcuts.Size = new System.Drawing.Size(88, 33); + this.btn_hotkey_shortcuts.TabIndex = 38; + this.btn_hotkey_shortcuts.Text = "Set Hotkey"; + this.btn_hotkey_shortcuts.UseVisualStyleBackColor = true; + this.btn_hotkey_shortcuts.Click += new System.EventHandler(this.btn_hotkey_shortcuts_Click); + // + // lbl_hotkey_main_window_description + // + this.lbl_hotkey_main_window_description.AutoSize = true; + this.lbl_hotkey_main_window_description.Location = new System.Drawing.Point(26, 35); + this.lbl_hotkey_main_window_description.Name = "lbl_hotkey_main_window_description"; + this.lbl_hotkey_main_window_description.Size = new System.Drawing.Size(185, 16); + this.lbl_hotkey_main_window_description.TabIndex = 39; + this.lbl_hotkey_main_window_description.Text = "Hotkey to open Main Window:"; + // + // lbl_hotkey_display_profile_description + // + this.lbl_hotkey_display_profile_description.AutoSize = true; + this.lbl_hotkey_display_profile_description.Location = new System.Drawing.Point(25, 83); + this.lbl_hotkey_display_profile_description.Name = "lbl_hotkey_display_profile_description"; + this.lbl_hotkey_display_profile_description.Size = new System.Drawing.Size(243, 16); + this.lbl_hotkey_display_profile_description.TabIndex = 40; + this.lbl_hotkey_display_profile_description.Text = "Hotkey to open Display Profile Window:"; + // + // lbl_hotkey_shortcut_library_description + // + this.lbl_hotkey_shortcut_library_description.AutoSize = true; + this.lbl_hotkey_shortcut_library_description.Location = new System.Drawing.Point(25, 133); + this.lbl_hotkey_shortcut_library_description.Name = "lbl_hotkey_shortcut_library_description"; + this.lbl_hotkey_shortcut_library_description.Size = new System.Drawing.Size(197, 16); + this.lbl_hotkey_shortcut_library_description.TabIndex = 41; + this.lbl_hotkey_shortcut_library_description.Text = "Hotkey to open Shortcut Library:"; + // + // btn_clear_all_hotkeys + // + this.btn_clear_all_hotkeys.Anchor = System.Windows.Forms.AnchorStyles.Bottom; + this.btn_clear_all_hotkeys.FlatAppearance.MouseDownBackColor = System.Drawing.Color.IndianRed; + this.btn_clear_all_hotkeys.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Brown; + this.btn_clear_all_hotkeys.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btn_clear_all_hotkeys.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btn_clear_all_hotkeys.ForeColor = System.Drawing.Color.White; + this.btn_clear_all_hotkeys.Location = new System.Drawing.Point(197, 334); + this.btn_clear_all_hotkeys.Name = "btn_clear_all_hotkeys"; + this.btn_clear_all_hotkeys.Size = new System.Drawing.Size(127, 33); + this.btn_clear_all_hotkeys.TabIndex = 42; + this.btn_clear_all_hotkeys.Text = "Clear All Hotkeys"; + this.btn_clear_all_hotkeys.UseVisualStyleBackColor = true; + this.btn_clear_all_hotkeys.Click += new System.EventHandler(this.btn_clear_all_hotkeys_Click); + // + // lv_dynamic_hotkeys + // + listViewGroup15.Header = "Display Profiles"; + listViewGroup15.Name = "lvg_display_profiles"; + listViewGroup16.Header = "Game Shortcuts"; + listViewGroup16.Name = "lvg_shortcuts"; + this.lv_dynamic_hotkeys.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] { + listViewGroup15, + listViewGroup16}); + this.lv_dynamic_hotkeys.HideSelection = false; + this.lv_dynamic_hotkeys.Location = new System.Drawing.Point(27, 177); + this.lv_dynamic_hotkeys.Name = "lv_dynamic_hotkeys"; + this.lv_dynamic_hotkeys.Size = new System.Drawing.Size(473, 143); + this.lv_dynamic_hotkeys.TabIndex = 44; + this.lv_dynamic_hotkeys.UseCompatibleStateImageBehavior = false; + // + // lbl_hotkey_main_window + // + this.lbl_hotkey_main_window.Location = new System.Drawing.Point(237, 35); + this.lbl_hotkey_main_window.Name = "lbl_hotkey_main_window"; + this.lbl_hotkey_main_window.Size = new System.Drawing.Size(169, 16); + this.lbl_hotkey_main_window.TabIndex = 45; + this.lbl_hotkey_main_window.Text = "None Set"; + this.lbl_hotkey_main_window.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + this.lbl_hotkey_main_window.Click += new System.EventHandler(this.lbl_hotkey_main_window_Click); + // + // lbl_hotkey_display_profile + // + this.lbl_hotkey_display_profile.Location = new System.Drawing.Point(236, 83); + this.lbl_hotkey_display_profile.Name = "lbl_hotkey_display_profile"; + this.lbl_hotkey_display_profile.Size = new System.Drawing.Size(169, 16); + this.lbl_hotkey_display_profile.TabIndex = 46; + this.lbl_hotkey_display_profile.Text = "None Set"; + this.lbl_hotkey_display_profile.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + this.lbl_hotkey_display_profile.Click += new System.EventHandler(this.lbl_hotkey_display_profile_Click); + // + // lbl_hotkey_shortcut_library + // + this.lbl_hotkey_shortcut_library.Location = new System.Drawing.Point(236, 133); + this.lbl_hotkey_shortcut_library.Name = "lbl_hotkey_shortcut_library"; + this.lbl_hotkey_shortcut_library.Size = new System.Drawing.Size(169, 16); + this.lbl_hotkey_shortcut_library.TabIndex = 47; + this.lbl_hotkey_shortcut_library.Text = "None Set"; + this.lbl_hotkey_shortcut_library.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + this.lbl_hotkey_shortcut_library.Click += new System.EventHandler(this.lbl_hotkey_shortcut_library_Click); + // // SettingsForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.Black; - this.ClientSize = new System.Drawing.Size(544, 187); - this.Controls.Add(this.cb_start_on_boot); + this.ClientSize = new System.Drawing.Size(580, 697); + this.Controls.Add(this.gb_hotkeys); + this.Controls.Add(this.gb_general); this.Controls.Add(this.btn_back); - this.Controls.Add(this.label1); - this.Controls.Add(this.cmb_loglevel); - this.Controls.Add(this.cb_minimise_notification_area); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.MinimizeBox = false; @@ -122,17 +311,32 @@ namespace DisplayMagician.UIForms this.TopMost = true; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SettingsForm_FormClosing); this.Load += new System.EventHandler(this.SettingsForm_Load); + this.gb_general.ResumeLayout(false); + this.gb_general.PerformLayout(); + this.gb_hotkeys.ResumeLayout(false); + this.gb_hotkeys.PerformLayout(); this.ResumeLayout(false); - this.PerformLayout(); } #endregion - - private System.Windows.Forms.CheckBox cb_minimise_notification_area; - private System.Windows.Forms.ComboBox cmb_loglevel; - private System.Windows.Forms.Label label1; private System.Windows.Forms.Button btn_back; + private System.Windows.Forms.GroupBox gb_general; private System.Windows.Forms.CheckBox cb_start_on_boot; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ComboBox cmb_loglevel; + private System.Windows.Forms.CheckBox cb_minimise_notification_area; + private System.Windows.Forms.GroupBox gb_hotkeys; + private System.Windows.Forms.Button btn_hotkey_shortcuts; + private System.Windows.Forms.Button btn_hotkey_display_profile; + private System.Windows.Forms.Button btn_hotkey_main_window; + private System.Windows.Forms.Label lbl_hotkey_shortcut_library_description; + private System.Windows.Forms.Label lbl_hotkey_display_profile_description; + private System.Windows.Forms.Label lbl_hotkey_main_window_description; + private System.Windows.Forms.Button btn_clear_all_hotkeys; + private System.Windows.Forms.ListView lv_dynamic_hotkeys; + private System.Windows.Forms.Label lbl_hotkey_shortcut_library; + private System.Windows.Forms.Label lbl_hotkey_display_profile; + private System.Windows.Forms.Label lbl_hotkey_main_window; } } \ No newline at end of file diff --git a/DisplayMagician/UIForms/SettingsForm.cs b/DisplayMagician/UIForms/SettingsForm.cs index 64e3895..57555e5 100644 --- a/DisplayMagician/UIForms/SettingsForm.cs +++ b/DisplayMagician/UIForms/SettingsForm.cs @@ -1,4 +1,6 @@ -using System; +using NHotkey; +using NHotkey.WindowsForms; +using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; @@ -93,6 +95,14 @@ namespace DisplayMagician.UIForms break; } + // Set the Hotkey values in the form + UpdateHotkeyLabel(Program.AppProgramSettings.HotkeyMainWindow, lbl_hotkey_main_window); + logger.Info($"SettingsForm/SettingsForm_Load: AppProgramSettings HotkeyMainWindow set to {Program.AppProgramSettings.HotkeyMainWindow}"); + UpdateHotkeyLabel(Program.AppProgramSettings.HotkeyDisplayProfileWindow, lbl_hotkey_display_profile); + logger.Info($"SettingsForm/SettingsForm_Load: AppProgramSettings HotkeyMainWindow set to {Program.AppProgramSettings.HotkeyDisplayProfileWindow}"); + UpdateHotkeyLabel(Program.AppProgramSettings.HotkeyShortcutLibraryWindow, lbl_hotkey_shortcut_library); + logger.Info($"SettingsForm/SettingsForm_Load: AppProgramSettings HotkeyMainWindow set to {Program.AppProgramSettings.HotkeyShortcutLibraryWindow}"); + } private void SettingsForm_FormClosing(object sender, FormClosingEventArgs e) @@ -191,5 +201,149 @@ namespace DisplayMagician.UIForms { this.Close(); } + + private void btn_hotkey_main_window_Click(object sender, EventArgs e) + { + Keys testHotkey; + if (Program.AppProgramSettings.HotkeyMainWindow != Keys.None) + testHotkey = Program.AppProgramSettings.HotkeyMainWindow; + else + testHotkey = Keys.None; + string hotkeyHeading = $"Choose a Hotkey for the main DisplayMagician window"; + string hotkeyDescription = $"Choose a Hotkey (a keyboard shortcut) so that you can apply use to" + Environment.NewLine + + "open the main DisplayMgician window. This must be a Hotkey that" + Environment.NewLine + + "is unique across all your applications otherwise DisplayMagician" + Environment.NewLine + + "might not see it."; + HotkeyForm mainHotkeyForm = new HotkeyForm(testHotkey, hotkeyHeading, hotkeyDescription); + mainHotkeyForm.ShowDialog(this); + if (mainHotkeyForm.DialogResult == DialogResult.OK) + { + // now we save the Hotkey + Program.AppProgramSettings.HotkeyMainWindow = mainHotkeyForm.Hotkey; + // And if we get back and this is a Hotkey with a value, we need to show that in the UI + UpdateHotkeyLabel(Program.AppProgramSettings.HotkeyMainWindow,lbl_hotkey_main_window); + // Get the MainForm instance + var mainForm = Application.OpenForms.OfType().Single(); + if (mainHotkeyForm.Hotkey == Keys.None) + // Remove the Hotkey if it needs to be removed + HotkeyManager.Current.Remove("HotkeyMainWindow"); + else + // And then apply the Hotkey now + HotkeyManager.Current.AddOrReplace("HotkeyMainWindow", Program.AppProgramSettings.HotkeyMainWindow, mainForm.OnWindowHotkeyPressed); + } + } + + private void lbl_hotkey_main_window_Click(object sender, EventArgs e) + { + btn_hotkey_main_window.PerformClick(); + } + + private void UpdateHotkeyLabel(Keys myHotkey, Control myControl) + { + // And if we get back and this is a Hotkey with a value, we need to show that in the UI + if (myHotkey != Keys.None) + { + KeysConverter kc = new KeysConverter(); + + myControl.Text = "Hotkey: " + kc.ConvertToString(myHotkey); + } + else + { + myControl.Text = "None Set"; + } + + } + + private void btn_hotkey_display_profile_Click(object sender, EventArgs e) + { + Keys testHotkey; + if (Program.AppProgramSettings.HotkeyDisplayProfileWindow != Keys.None) + testHotkey = Program.AppProgramSettings.HotkeyDisplayProfileWindow; + else + testHotkey = Keys.None; + string hotkeyHeading = $"Choose a Hotkey for the Display Profile window"; + string hotkeyDescription = $"Choose a Hotkey (a keyboard shortcut) so that you can apply use to" + Environment.NewLine + + "open the Display Profile window. This must be a Hotkey that" + Environment.NewLine + + "is unique across all your applications otherwise DisplayMagician" + Environment.NewLine + + "might not see it."; + HotkeyForm dpHotkeyForm = new HotkeyForm(testHotkey, hotkeyHeading, hotkeyDescription); + dpHotkeyForm.ShowDialog(this); + if (dpHotkeyForm.DialogResult == DialogResult.OK) + { + // now we save the Hotkey + Program.AppProgramSettings.HotkeyDisplayProfileWindow = dpHotkeyForm.Hotkey; + // And if we get back and this is a Hotkey with a value, we need to show that in the UI + UpdateHotkeyLabel(Program.AppProgramSettings.HotkeyDisplayProfileWindow, lbl_hotkey_display_profile); + // Get the MainForm instance + var mainForm = Application.OpenForms.OfType().Single(); + if (dpHotkeyForm.Hotkey == Keys.None) + // Remove the Hotkey if it needs to be removed + HotkeyManager.Current.Remove("HotkeyDisplayProfileWindow"); + else + // And then apply the Hotkey now + HotkeyManager.Current.AddOrReplace("HotkeyDisplayProfileWindow", Program.AppProgramSettings.HotkeyDisplayProfileWindow, mainForm.OnWindowHotkeyPressed); + } + } + + private void lbl_hotkey_display_profile_Click(object sender, EventArgs e) + { + btn_hotkey_display_profile.PerformClick(); + } + + private void btn_hotkey_shortcuts_Click(object sender, EventArgs e) + { + Keys testHotkey; + if (Program.AppProgramSettings.HotkeyShortcutLibraryWindow != Keys.None) + testHotkey = Program.AppProgramSettings.HotkeyShortcutLibraryWindow; + else + testHotkey = Keys.None; + string hotkeyHeading = $"Choose a Hotkey for the Display Profile window"; + string hotkeyDescription = $"Choose a Hotkey (a keyboard shortcut) so that you can apply use to" + Environment.NewLine + + "open the Display Profile window. This must be a Hotkey that" + Environment.NewLine + + "is unique across all your applications otherwise DisplayMagician" + Environment.NewLine + + "might not see it."; + HotkeyForm scHotkeyForm = new HotkeyForm(testHotkey, hotkeyHeading, hotkeyDescription); + scHotkeyForm.ShowDialog(this); + if (scHotkeyForm.DialogResult == DialogResult.OK) + { + // now we save the Hotkey + Program.AppProgramSettings.HotkeyShortcutLibraryWindow = scHotkeyForm.Hotkey; + // And if we get back and this is a Hotkey with a value, we need to show that in the UI + UpdateHotkeyLabel(Program.AppProgramSettings.HotkeyShortcutLibraryWindow, lbl_hotkey_display_profile); + // Get the MainForm instance + var mainForm = Application.OpenForms.OfType().Single(); + if (scHotkeyForm.Hotkey == Keys.None) + // Remove the Hotkey if it needs to be removed + HotkeyManager.Current.Remove("HotkeyShortcutLibraryWindow"); + else + // And then apply the Hotkey now + HotkeyManager.Current.AddOrReplace("HotkeyShortcutLibraryWindow", Program.AppProgramSettings.HotkeyShortcutLibraryWindow, mainForm.OnWindowHotkeyPressed); + } + } + + private void lbl_hotkey_shortcut_library_Click(object sender, EventArgs e) + { + btn_hotkey_shortcuts.PerformClick(); + } + + private void btn_clear_all_hotkeys_Click(object sender, EventArgs e) + { + DialogResult result = MessageBox.Show("Do you want to clear all the Hotkeys, including the one that open the Main Window, Display Profile Window and Shortcut Library?", "Clear All Hotkeys?", MessageBoxButtons.YesNo); + if (result == DialogResult.Yes) + { + // Remove the Main Window + Program.AppProgramSettings.HotkeyMainWindow = Keys.None; + HotkeyManager.Current.Remove("HotkeyMainWindow"); + UpdateHotkeyLabel(Program.AppProgramSettings.HotkeyMainWindow, lbl_hotkey_main_window); + // Remove the Display Profile window + Program.AppProgramSettings.HotkeyDisplayProfileWindow = Keys.None; + HotkeyManager.Current.Remove("HotkeyDisplayProfileWindow"); + UpdateHotkeyLabel(Program.AppProgramSettings.HotkeyDisplayProfileWindow, lbl_hotkey_display_profile); + // Remove the Display Profile window + Program.AppProgramSettings.HotkeyShortcutLibraryWindow = Keys.None; + HotkeyManager.Current.Remove("HotkeyShortcutLibraryWindow"); + UpdateHotkeyLabel(Program.AppProgramSettings.HotkeyShortcutLibraryWindow, lbl_hotkey_shortcut_library); + } + } } } diff --git a/DisplayMagician/UIForms/ShortcutForm.cs b/DisplayMagician/UIForms/ShortcutForm.cs index 0d3c657..dd44f7d 100644 --- a/DisplayMagician/UIForms/ShortcutForm.cs +++ b/DisplayMagician/UIForms/ShortcutForm.cs @@ -629,8 +629,12 @@ namespace DisplayMagician.UIForms } - // Set the hokey if there is one - HotkeyManager.Current.AddOrReplace(_shortcutToEdit.UUID, _shortcutToEdit.Hotkey, OnWindowHotkeyPressed); + if (_hotkey == Keys.None) + // Remove the Hotkey if it needs to be removed + HotkeyManager.Current.Remove(_shortcutToEdit.UUID); + else + // Set the hokey if there is one + HotkeyManager.Current.AddOrReplace(_shortcutToEdit.UUID, _shortcutToEdit.Hotkey, OnWindowHotkeyPressed); // Refresh validity after these changes _shortcutToEdit.RefreshValidity();