Skip to content

Commit

Permalink
Fix scenario editor crash on Linux and duplicate scenario entries bugs (
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 authored Jun 23, 2023
1 parent 484041f commit 1a0f43e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/SerialLoops/Controls/ScenarioCommandListPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@ namespace SerialLoops.Controls
{
public class ScenarioCommandListPanel : Panel
{
private bool _alreadySetting = false;
public List<(ScenarioVerb Verb, string Parameter)> Commands
{
get => _commands;
set
{
// Prevents duplicate commands from being added
if (_alreadySetting)
{
return;
}

_alreadySetting = true;
_commands = value;
int selectedIndex = -1;
if (Viewer is not null)
{
selectedIndex = Viewer.SelectedIndex;
int selectedIndex = Viewer.SelectedIndex;
Viewer.Items.Clear();
Viewer.Items.AddRange(_commands.Select(c => new ListItem { Text = $"{c.Verb} {c.Parameter}" }));
if (selectedIndex < 0)
Expand All @@ -30,7 +37,12 @@ public class ScenarioCommandListPanel : Panel
Viewer.SelectedIndex = selectedIndex;
Viewer.Focus();
}
else
{
Viewer.SelectedIndex = -1;
}
}
_alreadySetting = false;
}
}
public ListBox Viewer { get; private set; }
Expand Down

0 comments on commit 1a0f43e

Please sign in to comment.