Skip to content

Commit

Permalink
Corect char comboBox behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
TBXin committed Mar 15, 2016
1 parent 1c6adc0 commit 2d2d237
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/NFirmwareEditor/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ private void RemoveStringEditControls()

private void CreateStringEditControls(byte[] firmwareString, IDictionary<int, Image> imageCache)
{
var nullByteFound = false;
for (var i = 0; i < firmwareString.Length; i++)
{
if (i == firmwareString.Length - 1 && firmwareString[i] == 0x00) continue;
Expand All @@ -526,8 +527,7 @@ private void CreateStringEditControls(byte[] firmwareString, IDictionary<int, Im
ForeColor = Color.White,
Tag = new Tuple<FirmwareStringMetadata, int>(LastSelectedStringMetadata, i)
};
icb.Items.Add(nullItem);

if (i > 0) icb.Items.Add(nullItem);
var selectedItem = nullItem;
foreach (var imageMetadata in CurrentImageBlockForStrings)
{
Expand All @@ -540,7 +540,9 @@ private void CreateStringEditControls(byte[] firmwareString, IDictionary<int, Im
}
icb.SelectedItem = selectedItem;
icb.SelectedValueChanged += Icb_SelectedValueChanged;
icb.Enabled = !nullByteFound;
CharLayoutPanel.Controls.Add(icb);
nullByteFound = (byte)selectedItem.Value == 0x00;
}
}

Expand All @@ -555,8 +557,33 @@ private void Icb_SelectedValueChanged(object sender, EventArgs e)
if (tag == null) return;
if (item == null) return;

m_firmware.WriteChar((byte)item.Value, tag.Item2, tag.Item1);
var value = (byte)item.Value;
var idx = CharLayoutPanel.Controls.IndexOf(icb);

m_firmware.WriteChar(value, tag.Item2, tag.Item1);
UpdateStringPreview();

if (value == 0x00)
{
for (var i = idx + 1; i < CharLayoutPanel.Controls.Count; i++)
{
var relatedIcb = CharLayoutPanel.Controls[i] as ImagedComboBox;
if (relatedIcb == null) continue;

relatedIcb.SelectedIndex = 0;
relatedIcb.Enabled = false;
}
}
else if (idx + 1 < CharLayoutPanel.Controls.Count)
{
var relatedIcb = CharLayoutPanel.Controls[idx + 1] as ImagedComboBox;
if (relatedIcb == null) return;

if (relatedIcb.SelectedIndex == 0 && !relatedIcb.Enabled)
{
relatedIcb.Enabled = true;
}
}
}

private void UpdateStringPreview()
Expand Down

0 comments on commit 2d2d237

Please sign in to comment.