Skip to content

Commit

Permalink
Fix the LoopyLogger crashing (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonko0493 authored Apr 4, 2023
1 parent 141e9c8 commit c627489
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
37 changes: 32 additions & 5 deletions src/SerialLoops/Controls/ScriptCommandSectionTree.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Eto.Drawing;
using Eto;
using Eto.Drawing;
using Eto.Forms;
using HaruhiChokuretsuLib.Archive.Event;
using SerialLoops.Lib.Script;
Expand Down Expand Up @@ -253,8 +254,21 @@ internal void AddItem(ScriptCommandSectionTreeItem item)
}

AddCommand?.Invoke(this, new(item.Command));
_treeView.DataStore = _treeView.DataStore;
_treeView.SelectedItem = item;

// https://github.com/haroohie-club/SerialLoops/issues/109
// In WPF, the selection of the tree item happens automatically, so doing it this way
// ends up doubling the selection it seems causing multiple invocations in case of an error
// which crashes the LoopyLogger. Wild, I know.
if (!Platform.Instance.IsWpf)
{
_treeView.DataStore = _treeView.DataStore;
_treeView.SelectedItem = item;
}
else
{
_treeView.SelectedItem = item;
_treeView.DataStore = _treeView.DataStore;
}
}

internal void AddSection(ScriptCommandSectionTreeItem section)
Expand All @@ -265,8 +279,21 @@ internal void AddSection(ScriptCommandSectionTreeItem section)
section.Parent = rootNode;

AddCommand?.Invoke(this, new(section.Text));
_treeView.DataStore = rootNode;
_treeView.SelectedItem = section;

// https://github.com/haroohie-club/SerialLoops/issues/109
// In WPF, the selection of the tree item happens automatically, so doing it this way
// ends up doubling the selection it seems causing multiple invocations in case of an error
// which crashes the LoopyLogger. Wild, I know.
if (!Platform.Instance.IsWpf)
{
_treeView.DataStore = rootNode;
_treeView.SelectedItem = section;
}
else
{
_treeView.SelectedItem = section;
_treeView.DataStore = rootNode;
}
}

public void SetContents(IEnumerable<ScriptCommandSectionEntry> topNodes, bool expanded)
Expand Down
7 changes: 4 additions & 3 deletions src/SerialLoops/Editors/ScriptEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private StackLayout GetEditorButtons(ScriptCommandSectionTreeGridView treeGridVi
Image = ControlGenerator.GetIcon("Add", _log),
ToolTip = "New Command",
Width = 22,
Enabled = treeGridView.SelectedCommandTreeItem is not null
Enabled = treeGridView.SelectedCommandTreeItem is not null,
};
_addCommandButton.Click += (sender, args) =>
{
Expand Down Expand Up @@ -276,7 +276,7 @@ private StackLayout GetEditorButtons(ScriptCommandSectionTreeGridView treeGridVi
Image = ControlGenerator.GetIcon("Add_Section", _log),
ToolTip = "New Section",
Width = 22,
Enabled = true
Enabled = treeGridView.SelectedCommandTreeItem is not null,
};
_addSectionButton.Click += (sender, args) =>
{
Expand Down Expand Up @@ -330,7 +330,7 @@ private StackLayout GetEditorButtons(ScriptCommandSectionTreeGridView treeGridVi
Image = ControlGenerator.GetIcon("Remove", _log),
ToolTip = "Remove Command/Section",
Width = 22,
Enabled = treeGridView.SelectedCommandTreeItem is not null
Enabled = treeGridView.SelectedCommandTreeItem is not null,
};
_deleteButton.Click += (sender, args) =>
{
Expand Down Expand Up @@ -843,6 +843,7 @@ private void CommandsPanel_SelectedItemChanged(object sender, EventArgs e)
_editorControls.Items.Clear();

_addCommandButton.Enabled = true;
_addSectionButton.Enabled = true;
_deleteButton.Enabled = true;

// if we've selected a script section header
Expand Down

0 comments on commit c627489

Please sign in to comment.