Skip to content

Commit

Permalink
Fix changing search scopes and add up/down buttons to the scenario ed…
Browse files Browse the repository at this point in the history
…itor (#290)

Co-authored-by: William <[email protected]>
  • Loading branch information
jonko0493 and WiIIiam278 authored Jun 25, 2023
1 parent c366679 commit 7f28815
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/SerialLoops/Dialogs/SearchDialog.eto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ private void Search(bool force = false)
_resultsLabel.Visible = false;
if (!query.QuickSearch && !force)
{
_results.Items = Enumerable.Empty<ItemDescription>().ToList();
return;
}
if (string.IsNullOrWhiteSpace(query.Term))
Expand Down
53 changes: 52 additions & 1 deletion src/SerialLoops/Editors/ScenarioEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class ScenarioEditor : Editor
private Button _addButton;
private Button _deleteButton;
private Button _clearButton;
private Button _upButton;
private Button _downButton;

private bool _triggerRefresh = true;

Expand Down Expand Up @@ -86,14 +88,33 @@ private StackLayout GetEditorButtons()
};
_clearButton.Click += ClearButton_Click;

_upButton = new()
{
Image = ControlGenerator.GetIcon("Move_Up", _log),
ToolTip = "Move Command Up",
Width = 22,
Enabled = _commandsPanel.SelectedCommand is not null
};
_upButton.Click += UpButton_Click;

_downButton = new()
{
Image = ControlGenerator.GetIcon("Move_Down", _log),
ToolTip = "Move Command Down",
Width = 22,
Enabled = _commandsPanel.SelectedCommand is not null
};
_downButton.Click += DownButton_Click;


return new()
{
Orientation = Orientation.Horizontal,
HorizontalContentAlignment = HorizontalAlignment.Right,
Width = _commandsPanel.Width,
Spacing = 5,
Padding = 5,
Items = { _addButton, _deleteButton, _clearButton }
Items = { _addButton, _deleteButton, _clearButton, _upButton, _downButton }
};
}

Expand All @@ -114,6 +135,8 @@ private void CommandsPanel_SelectedItemChanged(object sender, EventArgs e)

_addButton.Enabled = true;
_deleteButton.Enabled = true;
_upButton.Enabled = true;
_downButton.Enabled = true;

if (command is null)
{
Expand Down Expand Up @@ -302,10 +325,38 @@ private void ClearButton_Click(object sender, EventArgs e)
UpdateTabTitle(false);
}

private void UpButton_Click(object sender, EventArgs e)
{
int selectedIndex = _commandsPanel.Viewer.SelectedIndex;
if (selectedIndex <= 0 || selectedIndex >= _scenario.Scenario.Commands.Count) return;

_scenario.Scenario.Commands.Swap(selectedIndex, selectedIndex - 1);
_scenario.ScenarioCommands.Swap(selectedIndex, selectedIndex - 1);
_commandsPanel.Viewer.SelectedIndex--;

RefreshCommands();
UpdateTabTitle(false);
}

private void DownButton_Click(object sender, EventArgs e)
{
int selectedIndex = _commandsPanel.Viewer.SelectedIndex;
if (selectedIndex < 0 || selectedIndex >= _scenario.Scenario.Commands.Count - 1) return;

_scenario.Scenario.Commands.Swap(selectedIndex, selectedIndex + 1);
_scenario.ScenarioCommands.Swap(selectedIndex, selectedIndex + 1);
_commandsPanel.Viewer.SelectedIndex++;

RefreshCommands();
UpdateTabTitle(false);
}

private void RefreshCommands()
{
_commandsPanel.Commands = _scenario.ScenarioCommands;
_deleteButton.Enabled = _commandsPanel.SelectedCommand is not null;
_upButton.Enabled = _commandsPanel.SelectedCommand is not null;
_downButton.Enabled = _commandsPanel.SelectedCommand is not null;
}
}
}
Binary file added src/SerialLoops/Icons/Move_Down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/SerialLoops/Icons/Move_Up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7f28815

Please sign in to comment.