mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
[WIP] Shortcut and Profile hotkey UI
Completed the Shortcut and Display Profile hotkey UI interface to a satisfactory level. The hotkey settings are stored with the profile JSON for profiles, and with the shortcut JSON for shortcuts. This means they load correctly and are remembered between runs of DisplayMagician. Next step is to actually register the Hotkeys so they work, and then allow them to be replaced or removed when they are changed.
This commit is contained in:
parent
a5f74576ba
commit
023a1a8862
@ -15,6 +15,7 @@ using System.Text.RegularExpressions;
|
||||
using IWshRuntimeLibrary;
|
||||
using AudioSwitcher.AudioApi.CoreAudio;
|
||||
using AudioSwitcher.AudioApi;
|
||||
using WK.Libraries.HotkeyListenerNS;
|
||||
|
||||
namespace DisplayMagician
|
||||
{
|
||||
@ -110,6 +111,7 @@ namespace DisplayMagician
|
||||
private ShortcutPermanence _displayPermanence = ShortcutPermanence.Temporary;
|
||||
private ShortcutPermanence _audioPermanence = ShortcutPermanence.Temporary;
|
||||
private ShortcutPermanence _capturePermanence = ShortcutPermanence.Temporary;
|
||||
private Hotkey _hotkey = null;
|
||||
private bool _autoName = true;
|
||||
private ShortcutValidity _isValid;
|
||||
private List<ShortcutError> _shortcutErrors = new List<ShortcutError>();
|
||||
@ -964,6 +966,19 @@ namespace DisplayMagician
|
||||
}
|
||||
}
|
||||
|
||||
public Hotkey Hotkey
|
||||
{
|
||||
get
|
||||
{
|
||||
return _hotkey;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value is Hotkey)
|
||||
_hotkey = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int StartTimeout
|
||||
{
|
||||
get
|
||||
|
@ -352,7 +352,7 @@ namespace DisplayMagician.UIForms
|
||||
this.lbl_hotkey_assigned.BackColor = System.Drawing.Color.Transparent;
|
||||
this.lbl_hotkey_assigned.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.lbl_hotkey_assigned.ForeColor = System.Drawing.Color.White;
|
||||
this.lbl_hotkey_assigned.Location = new System.Drawing.Point(20, 785);
|
||||
this.lbl_hotkey_assigned.Location = new System.Drawing.Point(20, 782);
|
||||
this.lbl_hotkey_assigned.Name = "lbl_hotkey_assigned";
|
||||
this.lbl_hotkey_assigned.Size = new System.Drawing.Size(57, 16);
|
||||
this.lbl_hotkey_assigned.TabIndex = 36;
|
||||
|
@ -294,6 +294,9 @@ namespace DisplayMagician.UIForms
|
||||
lbl_save_profile.Visible = true;
|
||||
}
|
||||
|
||||
// Update the Hotkey Label text
|
||||
UpdateHotkeyLabel(_selectedProfile.Hotkey);
|
||||
|
||||
// Refresh the image list view
|
||||
//RefreshImageListView(profile);
|
||||
|
||||
@ -301,6 +304,7 @@ namespace DisplayMagician.UIForms
|
||||
dv_profile.Profile = profile;
|
||||
dv_profile.Refresh();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void btn_save_as_Click(object sender, EventArgs e)
|
||||
@ -462,7 +466,11 @@ namespace DisplayMagician.UIForms
|
||||
|
||||
private void btn_hotkey_Click(object sender, EventArgs e)
|
||||
{
|
||||
Hotkey testHotkey = new Hotkey();
|
||||
Hotkey testHotkey = null;
|
||||
if (_selectedProfile.Hotkey is Hotkey)
|
||||
testHotkey = _selectedProfile.Hotkey;
|
||||
else
|
||||
testHotkey = new Hotkey();
|
||||
string hotkeyHeading = $"Choose a '{_selectedProfile.Name}' Display Profile Hotkey";
|
||||
string hotkeyDescription = $"Choose a Hotkey (a keyboard shortcut) so that you can apply to this" + Environment.NewLine +
|
||||
"screen using your keyboard. This must be a Hotkey that" + Environment.NewLine +
|
||||
@ -473,9 +481,12 @@ namespace DisplayMagician.UIForms
|
||||
displayHotkeyForm.ShowDialog(this);
|
||||
if (displayHotkeyForm.DialogResult == DialogResult.OK)
|
||||
{
|
||||
MessageBox.Show($"We got the hotkey {displayHotkeyForm.Hotkey}", "results", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
// As this is an edit, we need to manually force saving the shortcut library
|
||||
//ShortcutRepository.SaveShortcuts();
|
||||
// now we save the Hotkey
|
||||
_selectedProfile.Hotkey = displayHotkeyForm.Hotkey;
|
||||
// And cause this has changed within a Profile we need to save all the profiles
|
||||
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);
|
||||
}
|
||||
}
|
||||
private void lbl_hotkey_assigned_Click(object sender, EventArgs e)
|
||||
@ -483,5 +494,21 @@ namespace DisplayMagician.UIForms
|
||||
btn_hotkey.PerformClick();
|
||||
}
|
||||
|
||||
private void UpdateHotkeyLabel (Hotkey myHotkey)
|
||||
{
|
||||
// And if we get back and this is a Hotkey with a value, we need to show that in the UI
|
||||
if (myHotkey is Hotkey && !(myHotkey.KeyCode == Keys.None && myHotkey.Modifiers == Keys.None))
|
||||
{
|
||||
lbl_hotkey_assigned.Text = "Hotkey: " + HotkeyListener.Convert(myHotkey);
|
||||
lbl_hotkey_assigned.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
lbl_hotkey_assigned.Text = "Hotkey: None";
|
||||
lbl_hotkey_assigned.Visible = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -86,21 +86,33 @@ namespace DisplayMagician.UIForms
|
||||
{
|
||||
this.DialogResult = DialogResult.None;
|
||||
hks.Clear(txt_hotkey);
|
||||
myHotkey.KeyCode = Keys.None;
|
||||
myHotkey.Modifiers = Keys.None;
|
||||
this.ActiveControl = txt_hotkey;
|
||||
}
|
||||
|
||||
private void btn_save_Click(object sender, EventArgs e)
|
||||
{
|
||||
Program.HotkeyListener.Update
|
||||
(
|
||||
// Reference the current clipping hotkey for directly updating
|
||||
// the hotkey without a need for restarting your application.
|
||||
ref myHotkey,
|
||||
{
|
||||
|
||||
// Convert the selected hotkey's text representation
|
||||
// to a Hotkey object and update it.
|
||||
HotkeyListener.Convert(txt_hotkey.Text)
|
||||
);
|
||||
if (!String.IsNullOrWhiteSpace(txt_hotkey.Text))
|
||||
{
|
||||
Program.HotkeyListener.Update
|
||||
(
|
||||
// Reference the current clipping hotkey for directly updating
|
||||
// the hotkey without a need for restarting your application.
|
||||
ref myHotkey,
|
||||
|
||||
// Convert the selected hotkey's text representation
|
||||
// to a Hotkey object and update it.
|
||||
HotkeyListener.Convert(txt_hotkey.Text)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
myHotkey.KeyCode = Keys.None;
|
||||
myHotkey.Modifiers = Keys.None;
|
||||
}
|
||||
|
||||
this.Hotkey = myHotkey;
|
||||
this.DialogResult = DialogResult.OK;
|
||||
this.Close();
|
||||
|
@ -1432,7 +1432,8 @@ namespace DisplayMagician.UIForms
|
||||
// Restart updating the saved_profiles listview
|
||||
ilv_saved_profiles.ResumeLayout();
|
||||
}
|
||||
|
||||
|
||||
UpdateHotkeyLabel(_shortcutToEdit.Hotkey);
|
||||
EnableSaveButtonIfValid();
|
||||
}
|
||||
|
||||
@ -2229,7 +2230,11 @@ namespace DisplayMagician.UIForms
|
||||
|
||||
private void btn_hotkey_Click(object sender, EventArgs e)
|
||||
{
|
||||
Hotkey testHotkey = new Hotkey();
|
||||
Hotkey testHotkey = null;
|
||||
if (_shortcutToEdit.Hotkey is Hotkey)
|
||||
testHotkey = _shortcutToEdit.Hotkey;
|
||||
else
|
||||
testHotkey = new Hotkey();
|
||||
string hotkeyHeading = $"Choose a '{_shortcutToEdit.Name}' Shortcut Hotkey";
|
||||
string hotkeyDescription = $"Choose a Hotkey (a keyboard shortcut) so that you can start this" + Environment.NewLine +
|
||||
"game shortcut using your keyboard. This must be a Hotkey that" + Environment.NewLine +
|
||||
@ -2240,9 +2245,10 @@ namespace DisplayMagician.UIForms
|
||||
displayHotkeyForm.ShowDialog(this);
|
||||
if (displayHotkeyForm.DialogResult == DialogResult.OK)
|
||||
{
|
||||
MessageBox.Show($"We got the hotkey {displayHotkeyForm.Hotkey}", "results", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
// As this is an edit, we need to manually force saving the shortcut library
|
||||
//ShortcutRepository.SaveShortcuts();
|
||||
// now we save the Hotkey
|
||||
_shortcutToEdit.Hotkey = displayHotkeyForm.Hotkey;
|
||||
// And if we get back and this is a Hotkey with a value, we need to show that in the UI
|
||||
UpdateHotkeyLabel(_shortcutToEdit.Hotkey);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2250,5 +2256,21 @@ namespace DisplayMagician.UIForms
|
||||
{
|
||||
btn_hotkey.PerformClick();
|
||||
}
|
||||
|
||||
private void UpdateHotkeyLabel(Hotkey myHotkey)
|
||||
{
|
||||
// And if we get back and this is a Hotkey with a value, we need to show that in the UI
|
||||
if (myHotkey is Hotkey && !(myHotkey.KeyCode == Keys.None && myHotkey.Modifiers == Keys.None))
|
||||
{
|
||||
lbl_hotkey_assigned.Text = "Hotkey: " + HotkeyListener.Convert(myHotkey);
|
||||
lbl_hotkey_assigned.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
lbl_hotkey_assigned.Text = "Hotkey: None";
|
||||
lbl_hotkey_assigned.Visible = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -104,6 +104,9 @@
|
||||
<PackageReference Include="EDIDParser">
|
||||
<Version>1.2.0.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="HotkeyListener">
|
||||
<Version>1.9.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="IconExtractor.dll">
|
||||
<Version>1.0.2.1-beta</Version>
|
||||
</PackageReference>
|
||||
|
@ -9,6 +9,7 @@ using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Text.RegularExpressions;
|
||||
using IWshRuntimeLibrary;
|
||||
using WK.Libraries.HotkeyListenerNS;
|
||||
|
||||
namespace DisplayMagicianShared
|
||||
{
|
||||
@ -24,6 +25,7 @@ namespace DisplayMagicianShared
|
||||
|
||||
private string _uuid = "";
|
||||
private bool _isPossible = false;
|
||||
private Hotkey _hotkey = null;
|
||||
|
||||
|
||||
#region JsonConverterBitmap
|
||||
@ -150,6 +152,18 @@ namespace DisplayMagicianShared
|
||||
}
|
||||
}
|
||||
|
||||
public Hotkey Hotkey {
|
||||
get
|
||||
{
|
||||
return _hotkey;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value is Hotkey)
|
||||
_hotkey = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public Topology.Path[] Paths { get; set; } = new Topology.Path[0];
|
||||
|
Loading…
Reference in New Issue
Block a user