Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions schema/v1/ScriptRunnerSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@
"type": "boolean"
},
"optionsGeneratorCommand":
{
"type": "string"
},
"delimiter":
{
"type": "string"
}
Expand Down
25 changes: 22 additions & 3 deletions src/ScriptRunner/ScriptRunner.GUI/Parameters/ParamsPanelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Avalonia.Controls;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Threading;
Expand Down Expand Up @@ -239,7 +240,8 @@ private IControlRecord CreateControlRecord(ScriptParam p, string? value, int ind
MaskingRequired = true,
};
case PromptType.Dropdown:
var initialOptions = p.GetPromptSettings("options", out var options) ? options.Split(","):Array.Empty<string>();
var delimiterForOptions = p.GetPromptSettings("delimiter", x => x, ",");
var initialOptions = p.GetPromptSettings("options", out var options) ? options.Split(delimiterForOptions):Array.Empty<string>();
var observableOptions = new ObservableCollection<string>(initialOptions);
var searchable = p.GetPromptSettings("searchable", bool.Parse, false);
var optionsGeneratorCommand = p.GetPromptSettings("optionsGeneratorCommand", out var optionsGeneratorCommandText) ? optionsGeneratorCommandText : null;
Expand Down Expand Up @@ -283,22 +285,39 @@ private IControlRecord CreateControlRecord(ScriptParam p, string? value, int ind
VerticalAlignment = VerticalAlignment.Stretch,
HorizontalContentAlignment = HorizontalAlignment.Center
};
generateButton.Click += async(sender, args) =>
bool wasGenerated = false;
EventHandler<RoutedEventArgs> generate = async(sender, args) =>
{
generateButton.IsEnabled = false;
generateButton.Classes.Add("spinning");
var result = await commandExecutor($"Generate options for '{p.Name}'", optionsGeneratorCommand) ?? "";
Dispatcher.UIThread.Post(() =>
{
observableOptions.Clear();
foreach (var option in result.Split(new[]{'\r', '\n',','}, StringSplitOptions.RemoveEmptyEntries).Distinct().OrderBy(x=>x))
foreach (var option in result.Split(new[]{"\r", "\n",delimiterForOptions}, StringSplitOptions.RemoveEmptyEntries).Distinct().OrderBy(x=>x))
{
observableOptions.Add(option);
}
generateButton.Classes.Remove("spinning");
generateButton.IsEnabled = true;
wasGenerated = true;
if (inputControl is SearchableComboBox scb)
{
scb.ShowAll();
}
});
};
generateButton.Click += generate;
if(inputControl is SearchableComboBox scb)
{
scb.GotFocus += (sender, args) =>
{
if (wasGenerated == false)
{
generate(sender, args);
}
};
}
Attached.SetIcon(generateButton, "fas fa-sync");
ToolTip.SetTip(generateButton, "Refresh available options");
actionPanel.Children.Add(generateButton);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;

namespace ScriptRunner.GUI.Views;

Expand Down Expand Up @@ -72,29 +74,51 @@ private void InitializeComponent()
_autoCompleteBox.ItemsSource = Items;
_autoCompleteBox.SelectedItem = SelectedItem;
//_autoCompleteBox.TextChanged += AutoCompleteBox_TextChanged;
_autoCompleteBox.GotFocus += (sender, args) =>
{
_autoCompleteBox.IsDropDownOpen = true;
};
_autoCompleteBox.LostFocus += (sender, args) =>
{
if(_autoCompleteBox.SelectedItem == null)
Task.Run(async () =>
{
_autoCompleteBox.Text = "";
}
await Task.Delay(TimeSpan.FromSeconds(1));
Dispatcher.UIThread.InvokeAsync(() =>
{
if(_autoCompleteBox.SelectedItem == null)
{
_autoCompleteBox.Text = "";
}
});
});
};

_autoCompleteBox.SelectionChanged += AutoCompleteBox_SelectionChanged;
}
}


private string previousValue = "";
private void AutoCompleteBox_SelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (_autoCompleteBox?.SelectedItem is string selected)
if (_autoCompleteBox?.SelectedItem is string selected && selected != previousValue)
{
SelectedItem = selected;
previousValue = selected;
}
}

private void ShowAllOptions_Click(object? sender, RoutedEventArgs e)
{
ShowAll();
}

public void ShowAll()
{
if (_autoCompleteBox != null)
{
_autoCompleteBox.Text = "";
_autoCompleteBox.Focus();
_autoCompleteBox.ItemsSource = new ObservableCollection<string>(Items);
_autoCompleteBox.IsDropDownOpen = true;
}
Expand Down
Loading