Skip to content

Commit

Permalink
Prep for 2.2.1.0 release
Browse files Browse the repository at this point in the history
Added more capability around multiple-output remaps.
  • Loading branch information
nhmkdev committed May 21, 2023
1 parent b0f7115 commit d971a26
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 22 deletions.
37 changes: 36 additions & 1 deletion Format/RemapEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ public RemapEntry(InputConfig zInputConfig, OutputConfig zOutputConfig)
m_nHash = CalculateHashCode(InputConfig);
}

/// <summary>
/// Constructor based on input/output definitions
/// </summary>
/// <param name="zInputConfig">the input definition</param>
/// <param name="zOutputConfig">the output definition</param>
public RemapEntry(InputConfig zInputConfig, List<OutputConfig> listOutputConfigs)
{
InputConfig = zInputConfig;
OutputConfigs = listOutputConfigs;
m_nHash = CalculateHashCode(InputConfig);
}

/// <summary>
/// Constructor based on an input stream
/// </summary>
Expand Down Expand Up @@ -92,14 +104,37 @@ public RemapEntry(FileStream zFileStream)
/// <summary>
/// Appends an output definition
/// </summary>
/// <param name="zOutputConfig"></param>
/// <param name="zOutputConfig">The output to append</param>
/// <returns></returns>
public bool AppendOutputConfig(OutputConfig zOutputConfig)
{
OutputConfigs.Add(zOutputConfig);
return true;
}

/// <summary>
/// Appends an output definition at a specific index
/// </summary>
/// <param name="zOutputConfig">The output to append</param>
/// <param name="nZeroBasedIndex">The index to append the output at</param>
/// <returns></returns>
public bool AppendOutputConfigAt(OutputConfig zOutputConfig, int nZeroBasedIndex)
{
OutputConfigs.Insert(nZeroBasedIndex, zOutputConfig);
return true;
}

/// <summary>
/// Removes an output definition
/// </summary>
/// <param name="nZeroBasedIndex">The index to remove the output at</param>
/// <returns></returns>
public bool RemoveOutputConfigAt(int nZeroBasedIndex)
{
OutputConfigs.RemoveAt(nZeroBasedIndex);
return true;
}

public byte[] SerializeToBytes()
{
var zStream = new MemoryStream();
Expand Down
131 changes: 123 additions & 8 deletions Forms/KeyCaptureConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
Expand Down Expand Up @@ -547,9 +548,7 @@ private void recentConfiguration_Click(object sender, EventArgs e)

private void listViewKeys_SelectedIndexChanged(object sender, EventArgs e)
{
btnAppend.Enabled = (1 == listViewKeys.SelectedIndices.Count);
btnUpdate.Enabled = (1 == listViewKeys.SelectedIndices.Count);
btnRemove.Enabled = (0 < listViewKeys.SelectedIndices.Count);
UpdateActionEnableStates();
}

private void listViewKeys_Resize(object sender, EventArgs e)
Expand Down Expand Up @@ -646,12 +645,46 @@ private void btnUpdate_Click(object sender, EventArgs e)
{
if (listViewKeys.SelectedItems.Count == 1)
{
var zSelectedEntry = (RemapEntry)listViewKeys.SelectedItems[0].Tag;
if (zSelectedEntry.OutputConfigCount > 1)
{
switch (MessageBox.Show(this, "This entry has multiple outputs. Do you want to overwrite the outputs?" +
"\nYES - overwrite input & outputs." +
"\nNO - overwrite input only.", "Remap has multiple outputs", MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1))
{
case DialogResult.Yes:
// nothing
break;
case DialogResult.No:
btnUpdateInput_Click(sender, e);
return;
case DialogResult.Cancel:
return;
}
}
RemapEntry zRemapEntry = null;
if (!CreateRemapEntryFromActiveConfigs(ref zRemapEntry, (RemapEntry)listViewKeys.SelectedItems[0].Tag)) return;
if (!CreateRemapEntryFromActiveConfigs(ref zRemapEntry, (RemapEntry)listViewKeys.SelectedItems[0].Tag))
{
MessageBox.Show("Unable to determine remap from configuration.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
AddRemapEntryToListView(zRemapEntry, true, listViewKeys.SelectedItems[0]);
}
}

private void btnUpdateInput_Click(object sender, EventArgs e)
{
RemapEntry zRemapEntry = null;
if (!CreateRemapEntryFromActiveConfigs(ref zRemapEntry, (RemapEntry)listViewKeys.SelectedItems[0].Tag,
true))
{
MessageBox.Show("Unable to determine remap from configuration.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
AddRemapEntryToListView(zRemapEntry, true, listViewKeys.SelectedItems[0]);
}

private void btnAppend_Click(object sender, EventArgs e)
{
if (1 != listViewKeys.SelectedItems.Count)
Expand All @@ -662,12 +695,84 @@ private void btnAppend_Click(object sender, EventArgs e)
var zItem = listViewKeys.SelectedItems[0];
var zRemapEntry = (RemapEntry)zItem.Tag;
OutputConfig zOutputConfig = null;
if (!RetrieveOutputConfigForAppend(zRemapEntry, ref zOutputConfig)) return;
if (!RetrieveOutputConfigForAppend(zRemapEntry, ref zOutputConfig))
{
MessageBox.Show("Unable to determine remap from configuration.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

zRemapEntry.AppendOutputConfig(zOutputConfig);
zItem.SubItems[1].Text = zRemapEntry.GetOutputString();
MarkDirty();
txtKeyOut.Focus(); // restore focus to the output
UpdateActionEnableStates();
}

private void btnAppendAt_Click(object sender, EventArgs e)
{
if (1 != listViewKeys.SelectedItems.Count)
{
return;
}

var zItem = listViewKeys.SelectedItems[0];
var zRemapEntry = (RemapEntry)zItem.Tag;
OutputConfig zOutputConfig = null;
if (!RetrieveOutputConfigForAppend(zRemapEntry, ref zOutputConfig))
{
MessageBox.Show("Unable to determine remap from configuration.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

const string IDX_QUERY_KEY = "idx";
var zQuery = new QueryPanelDialog("Append output config", 450, false);
zQuery.SetIcon(Icon);
zQuery.AddLabel("Select the index to append the output at (the selected output will be pushed forward to insert the new output).", 48);
var arrayOutputs = zRemapEntry.OutputConfigs.Select((zOutput, nIdx) => $"{nIdx}:{zOutput.GetDescription()}").ToArray();
zQuery.AddPullDownBox("Output To Append At", arrayOutputs, 0, IDX_QUERY_KEY);
if(DialogResult.Cancel == zQuery.ShowDialog(this))
{
return;
}

zRemapEntry.AppendOutputConfigAt(zOutputConfig, zQuery.GetIndex(IDX_QUERY_KEY));
zItem.SubItems[1].Text = zRemapEntry.GetOutputString();
MarkDirty();
txtKeyOut.Focus(); // restore focus to the output
UpdateActionEnableStates();
}

private void btnRemoveAt_Click(object sender, EventArgs e)
{
if (1 != listViewKeys.SelectedItems.Count)
{
return;
}

var zItem = listViewKeys.SelectedItems[0];
var zRemapEntry = (RemapEntry)zItem.Tag;
OutputConfig zOutputConfig = null;
if (!RetrieveOutputConfigForAppend(zRemapEntry, ref zOutputConfig))
{
MessageBox.Show("Unable to determine remap from configuration.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

const string IDX_QUERY_KEY = "idx";
var zQuery = new QueryPanelDialog("Remove output config at index", 450, false);
zQuery.SetIcon(Icon);
zQuery.AddLabel("Select the output to remove.", 24);
var arrayOutputs = zRemapEntry.OutputConfigs.Select((zOutput, nIdx) => $"{nIdx}:{zOutput.GetDescription()}").ToArray();
zQuery.AddPullDownBox("Output To Remove", arrayOutputs, 0, IDX_QUERY_KEY);
if (DialogResult.Cancel == zQuery.ShowDialog(this))
{
return;
}

zRemapEntry.RemoveOutputConfigAt(zQuery.GetIndex(IDX_QUERY_KEY));
zItem.SubItems[1].Text = zRemapEntry.GetOutputString();
MarkDirty();
UpdateActionEnableStates();
}

private void btnRemove_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -722,6 +827,16 @@ private void numericUpDownOutputParameter_ValueChanged(object sender, EventArgs

#region Support Methods

private void UpdateActionEnableStates()
{
btnAppend.Enabled = (1 == listViewKeys.SelectedIndices.Count);
btnAppendAt.Enabled = (1 == listViewKeys.SelectedIndices.Count);
btnUpdate.Enabled = (1 == listViewKeys.SelectedIndices.Count);
btnUpdateInput.Enabled = (1 == listViewKeys.SelectedIndices.Count);
btnRemoveAt.Enabled = (listViewKeys.SelectedItems.Count == 1) &&
(((RemapEntry)listViewKeys.SelectedItems[0].Tag).OutputConfigCount > 1);
}

private void ResetInputOutputUI()
{
m_zActiveInputConfig.Reset();
Expand Down Expand Up @@ -897,7 +1012,7 @@ private void FlushIniSettings()
m_zIniManager.FlushIniSettings();
}

private bool CreateRemapEntryFromActiveConfigs(ref RemapEntry zRemapEntry, RemapEntry updateEntry = null)
private bool CreateRemapEntryFromActiveConfigs(ref RemapEntry zRemapEntry, RemapEntry updateEntry = null, bool bKeepOutputs = false)
{
var zCurrentInputConfig = CreateInputConfigFromUI();
var zCurrentOutputConfig = CreateOutputConfigFromUI();
Expand All @@ -906,7 +1021,8 @@ private bool CreateRemapEntryFromActiveConfigs(ref RemapEntry zRemapEntry, Remap
return false;
}

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

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

#endregion

}
}
Loading

0 comments on commit d971a26

Please sign in to comment.