Skip to content

Commit d971a26

Browse files
committed
Prep for 2.2.1.0 release
Added more capability around multiple-output remaps.
1 parent b0f7115 commit d971a26

File tree

6 files changed

+233
-22
lines changed

6 files changed

+233
-22
lines changed

Format/RemapEntry.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ public RemapEntry(InputConfig zInputConfig, OutputConfig zOutputConfig)
5656
m_nHash = CalculateHashCode(InputConfig);
5757
}
5858

59+
/// <summary>
60+
/// Constructor based on input/output definitions
61+
/// </summary>
62+
/// <param name="zInputConfig">the input definition</param>
63+
/// <param name="zOutputConfig">the output definition</param>
64+
public RemapEntry(InputConfig zInputConfig, List<OutputConfig> listOutputConfigs)
65+
{
66+
InputConfig = zInputConfig;
67+
OutputConfigs = listOutputConfigs;
68+
m_nHash = CalculateHashCode(InputConfig);
69+
}
70+
5971
/// <summary>
6072
/// Constructor based on an input stream
6173
/// </summary>
@@ -92,14 +104,37 @@ public RemapEntry(FileStream zFileStream)
92104
/// <summary>
93105
/// Appends an output definition
94106
/// </summary>
95-
/// <param name="zOutputConfig"></param>
107+
/// <param name="zOutputConfig">The output to append</param>
96108
/// <returns></returns>
97109
public bool AppendOutputConfig(OutputConfig zOutputConfig)
98110
{
99111
OutputConfigs.Add(zOutputConfig);
100112
return true;
101113
}
102114

115+
/// <summary>
116+
/// Appends an output definition at a specific index
117+
/// </summary>
118+
/// <param name="zOutputConfig">The output to append</param>
119+
/// <param name="nZeroBasedIndex">The index to append the output at</param>
120+
/// <returns></returns>
121+
public bool AppendOutputConfigAt(OutputConfig zOutputConfig, int nZeroBasedIndex)
122+
{
123+
OutputConfigs.Insert(nZeroBasedIndex, zOutputConfig);
124+
return true;
125+
}
126+
127+
/// <summary>
128+
/// Removes an output definition
129+
/// </summary>
130+
/// <param name="nZeroBasedIndex">The index to remove the output at</param>
131+
/// <returns></returns>
132+
public bool RemoveOutputConfigAt(int nZeroBasedIndex)
133+
{
134+
OutputConfigs.RemoveAt(nZeroBasedIndex);
135+
return true;
136+
}
137+
103138
public byte[] SerializeToBytes()
104139
{
105140
var zStream = new MemoryStream();

Forms/KeyCaptureConfig.cs

Lines changed: 123 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
using System.Collections.Generic;
2929
using System.ComponentModel;
3030
using System.Drawing;
31+
using System.Linq;
3132
using System.Text;
3233
using System.Threading;
3334
using System.Windows.Forms;
@@ -547,9 +548,7 @@ private void recentConfiguration_Click(object sender, EventArgs e)
547548

548549
private void listViewKeys_SelectedIndexChanged(object sender, EventArgs e)
549550
{
550-
btnAppend.Enabled = (1 == listViewKeys.SelectedIndices.Count);
551-
btnUpdate.Enabled = (1 == listViewKeys.SelectedIndices.Count);
552-
btnRemove.Enabled = (0 < listViewKeys.SelectedIndices.Count);
551+
UpdateActionEnableStates();
553552
}
554553

555554
private void listViewKeys_Resize(object sender, EventArgs e)
@@ -646,12 +645,46 @@ private void btnUpdate_Click(object sender, EventArgs e)
646645
{
647646
if (listViewKeys.SelectedItems.Count == 1)
648647
{
648+
var zSelectedEntry = (RemapEntry)listViewKeys.SelectedItems[0].Tag;
649+
if (zSelectedEntry.OutputConfigCount > 1)
650+
{
651+
switch (MessageBox.Show(this, "This entry has multiple outputs. Do you want to overwrite the outputs?" +
652+
"\nYES - overwrite input & outputs." +
653+
"\nNO - overwrite input only.", "Remap has multiple outputs", MessageBoxButtons.YesNoCancel,
654+
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1))
655+
{
656+
case DialogResult.Yes:
657+
// nothing
658+
break;
659+
case DialogResult.No:
660+
btnUpdateInput_Click(sender, e);
661+
return;
662+
case DialogResult.Cancel:
663+
return;
664+
}
665+
}
649666
RemapEntry zRemapEntry = null;
650-
if (!CreateRemapEntryFromActiveConfigs(ref zRemapEntry, (RemapEntry)listViewKeys.SelectedItems[0].Tag)) return;
667+
if (!CreateRemapEntryFromActiveConfigs(ref zRemapEntry, (RemapEntry)listViewKeys.SelectedItems[0].Tag))
668+
{
669+
MessageBox.Show("Unable to determine remap from configuration.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
670+
return;
671+
}
651672
AddRemapEntryToListView(zRemapEntry, true, listViewKeys.SelectedItems[0]);
652673
}
653674
}
654675

676+
private void btnUpdateInput_Click(object sender, EventArgs e)
677+
{
678+
RemapEntry zRemapEntry = null;
679+
if (!CreateRemapEntryFromActiveConfigs(ref zRemapEntry, (RemapEntry)listViewKeys.SelectedItems[0].Tag,
680+
true))
681+
{
682+
MessageBox.Show("Unable to determine remap from configuration.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
683+
return;
684+
}
685+
AddRemapEntryToListView(zRemapEntry, true, listViewKeys.SelectedItems[0]);
686+
}
687+
655688
private void btnAppend_Click(object sender, EventArgs e)
656689
{
657690
if (1 != listViewKeys.SelectedItems.Count)
@@ -662,12 +695,84 @@ private void btnAppend_Click(object sender, EventArgs e)
662695
var zItem = listViewKeys.SelectedItems[0];
663696
var zRemapEntry = (RemapEntry)zItem.Tag;
664697
OutputConfig zOutputConfig = null;
665-
if (!RetrieveOutputConfigForAppend(zRemapEntry, ref zOutputConfig)) return;
698+
if (!RetrieveOutputConfigForAppend(zRemapEntry, ref zOutputConfig))
699+
{
700+
MessageBox.Show("Unable to determine remap from configuration.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
701+
return;
702+
}
666703

667704
zRemapEntry.AppendOutputConfig(zOutputConfig);
668705
zItem.SubItems[1].Text = zRemapEntry.GetOutputString();
669706
MarkDirty();
670707
txtKeyOut.Focus(); // restore focus to the output
708+
UpdateActionEnableStates();
709+
}
710+
711+
private void btnAppendAt_Click(object sender, EventArgs e)
712+
{
713+
if (1 != listViewKeys.SelectedItems.Count)
714+
{
715+
return;
716+
}
717+
718+
var zItem = listViewKeys.SelectedItems[0];
719+
var zRemapEntry = (RemapEntry)zItem.Tag;
720+
OutputConfig zOutputConfig = null;
721+
if (!RetrieveOutputConfigForAppend(zRemapEntry, ref zOutputConfig))
722+
{
723+
MessageBox.Show("Unable to determine remap from configuration.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
724+
return;
725+
}
726+
727+
const string IDX_QUERY_KEY = "idx";
728+
var zQuery = new QueryPanelDialog("Append output config", 450, false);
729+
zQuery.SetIcon(Icon);
730+
zQuery.AddLabel("Select the index to append the output at (the selected output will be pushed forward to insert the new output).", 48);
731+
var arrayOutputs = zRemapEntry.OutputConfigs.Select((zOutput, nIdx) => $"{nIdx}:{zOutput.GetDescription()}").ToArray();
732+
zQuery.AddPullDownBox("Output To Append At", arrayOutputs, 0, IDX_QUERY_KEY);
733+
if(DialogResult.Cancel == zQuery.ShowDialog(this))
734+
{
735+
return;
736+
}
737+
738+
zRemapEntry.AppendOutputConfigAt(zOutputConfig, zQuery.GetIndex(IDX_QUERY_KEY));
739+
zItem.SubItems[1].Text = zRemapEntry.GetOutputString();
740+
MarkDirty();
741+
txtKeyOut.Focus(); // restore focus to the output
742+
UpdateActionEnableStates();
743+
}
744+
745+
private void btnRemoveAt_Click(object sender, EventArgs e)
746+
{
747+
if (1 != listViewKeys.SelectedItems.Count)
748+
{
749+
return;
750+
}
751+
752+
var zItem = listViewKeys.SelectedItems[0];
753+
var zRemapEntry = (RemapEntry)zItem.Tag;
754+
OutputConfig zOutputConfig = null;
755+
if (!RetrieveOutputConfigForAppend(zRemapEntry, ref zOutputConfig))
756+
{
757+
MessageBox.Show("Unable to determine remap from configuration.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
758+
return;
759+
}
760+
761+
const string IDX_QUERY_KEY = "idx";
762+
var zQuery = new QueryPanelDialog("Remove output config at index", 450, false);
763+
zQuery.SetIcon(Icon);
764+
zQuery.AddLabel("Select the output to remove.", 24);
765+
var arrayOutputs = zRemapEntry.OutputConfigs.Select((zOutput, nIdx) => $"{nIdx}:{zOutput.GetDescription()}").ToArray();
766+
zQuery.AddPullDownBox("Output To Remove", arrayOutputs, 0, IDX_QUERY_KEY);
767+
if (DialogResult.Cancel == zQuery.ShowDialog(this))
768+
{
769+
return;
770+
}
771+
772+
zRemapEntry.RemoveOutputConfigAt(zQuery.GetIndex(IDX_QUERY_KEY));
773+
zItem.SubItems[1].Text = zRemapEntry.GetOutputString();
774+
MarkDirty();
775+
UpdateActionEnableStates();
671776
}
672777

673778
private void btnRemove_Click(object sender, EventArgs e)
@@ -722,6 +827,16 @@ private void numericUpDownOutputParameter_ValueChanged(object sender, EventArgs
722827

723828
#region Support Methods
724829

830+
private void UpdateActionEnableStates()
831+
{
832+
btnAppend.Enabled = (1 == listViewKeys.SelectedIndices.Count);
833+
btnAppendAt.Enabled = (1 == listViewKeys.SelectedIndices.Count);
834+
btnUpdate.Enabled = (1 == listViewKeys.SelectedIndices.Count);
835+
btnUpdateInput.Enabled = (1 == listViewKeys.SelectedIndices.Count);
836+
btnRemoveAt.Enabled = (listViewKeys.SelectedItems.Count == 1) &&
837+
(((RemapEntry)listViewKeys.SelectedItems[0].Tag).OutputConfigCount > 1);
838+
}
839+
725840
private void ResetInputOutputUI()
726841
{
727842
m_zActiveInputConfig.Reset();
@@ -897,7 +1012,7 @@ private void FlushIniSettings()
8971012
m_zIniManager.FlushIniSettings();
8981013
}
8991014

900-
private bool CreateRemapEntryFromActiveConfigs(ref RemapEntry zRemapEntry, RemapEntry updateEntry = null)
1015+
private bool CreateRemapEntryFromActiveConfigs(ref RemapEntry zRemapEntry, RemapEntry updateEntry = null, bool bKeepOutputs = false)
9011016
{
9021017
var zCurrentInputConfig = CreateInputConfigFromUI();
9031018
var zCurrentOutputConfig = CreateOutputConfigFromUI();
@@ -906,7 +1021,8 @@ private bool CreateRemapEntryFromActiveConfigs(ref RemapEntry zRemapEntry, Remap
9061021
return false;
9071022
}
9081023

909-
zRemapEntry = new RemapEntry(new InputConfig(zCurrentInputConfig), new OutputConfig(zCurrentOutputConfig));
1024+
zRemapEntry = new RemapEntry(new InputConfig(zCurrentInputConfig),
1025+
(bKeepOutputs && updateEntry != null) ? updateEntry.OutputConfigs : new List<OutputConfig> {new OutputConfig(zCurrentOutputConfig)});
9101026

9111027
// flip this result for indicator of a good remap entry
9121028
return !IsInputAlreadyDefined(zRemapEntry, updateEntry);
@@ -1018,6 +1134,5 @@ public override void Reset()
10181134
}
10191135

10201136
#endregion
1021-
10221137
}
10231138
}

0 commit comments

Comments
 (0)