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
73 changes: 69 additions & 4 deletions schema/v1/ScriptRunnerSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,32 @@
"type": "object",
"properties": {
"options": {
"type": "string"
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "array",
"items": {
"type": "object",
"required": ["label", "value"],
"properties": {
"label": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
}
]
},
"searchable": {
"type": "boolean"
Expand All @@ -212,7 +237,32 @@
"type": "object",
"properties": {
"options": {
"type": "string"
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
},
{
"type": "array",
"items": {
"type": "object",
"required": ["label", "value"],
"properties": {
"label": {
"type": "string"
},
"value": {
"type": "string"
}
}
}
}
]
},
"delimiter": {
"type": "string"
Expand Down Expand Up @@ -282,12 +332,27 @@
},
"required": ["prompt"]
},
{
"properties": {
"prompt": {
"const": "multilineText"
},
"promptSettings": {
"type": "object",
"properties": {
"syntax": {
"type": "string"
}
}
}
},
"required": ["prompt"]
},
{
"properties": {
"prompt": {
"enum": [
"text",
"multilineText",
"text",
"password",
"filePicker",
"directoryPicker"
Expand Down
2 changes: 1 addition & 1 deletion src/ScriptRunner/ScriptRunner.GUI/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<FluentTheme />
<StyleInclude Source="/Themes/DarkTheme.xaml" />
<StyleInclude Source="/Themes/StyleClasses.axaml" />

<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
</Application.Styles>
<Application.Resources>
<ResourceDictionary>
Expand Down
10 changes: 10 additions & 0 deletions src/ScriptRunner/ScriptRunner.GUI/CheckBoxListBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,15 @@ public CheckBoxListBox()
}
};
this.Styles.Add(style);

// Style for selected items
var selectedStyle = new Style(x => x.OfType<ListBoxItem>().Class(":selected").Template().OfType<ContentPresenter>())
{
Setters =
{
new Setter(ContentPresenter.BackgroundProperty, Avalonia.Media.Brushes.Transparent)
}
};
this.Styles.Add(selectedStyle);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Globalization;
using Avalonia.Data.Converters;
using Avalonia.Media;

namespace ScriptRunner.GUI.Converters;

public class CategoryToColorConverter : IValueConverter
{
private static readonly Color[] PredefinedColors = new[]
{
Color.FromRgb(70, 100, 180), // Darker Blue
Color.FromRgb(200, 90, 70), // Darker Coral
Color.FromRgb(80, 150, 80), // Darker Green
Color.FromRgb(150, 100, 150), // Darker Plum
Color.FromRgb(180, 140, 0), // Darker Gold
Color.FromRgb(85, 130, 160), // Darker Sky Blue
Color.FromRgb(180, 100, 120), // Darker Pink
Color.FromRgb(90, 160, 90), // Darker Pale Green
Color.FromRgb(180, 100, 80), // Darker Salmon
Color.FromRgb(110, 130, 150), // Darker Steel Blue
Color.FromRgb(160, 80, 160), // Darker Violet
Color.FromRgb(180, 130, 100), // Darker Peach
Color.FromRgb(100, 140, 170), // Darker Light Blue
Color.FromRgb(170, 80, 80), // Darker Coral Red
Color.FromRgb(120, 140, 70), // Olive Green
};

public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is string category)
{
// Generate deterministic hash from category name
int hash = GetDeterministicHashCode(category);
int colorIndex = Math.Abs(hash) % PredefinedColors.Length;
return new SolidColorBrush(PredefinedColors[colorIndex]);
}

return new SolidColorBrush(Colors.Gray);
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}

private static int GetDeterministicHashCode(string str)
{
unchecked
{
int hash1 = 5381;
int hash2 = hash1;

for (int i = 0; i < str.Length && str[i] != '\0'; i += 2)
{
hash1 = ((hash1 << 5) + hash1) ^ str[i];
if (i == str.Length - 1 || str[i + 1] == '\0')
break;
hash2 = ((hash2 << 5) + hash2) ^ str[i + 1];
}

return hash1 + (hash2 * 1566083941);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Globalization;
using Avalonia.Data.Converters;

namespace ScriptRunner.GUI.Converters;

public class StringEmptyToVisibilityConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is string str)
{
return !string.IsNullOrEmpty(str);
}
return false;
}

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

31 changes: 26 additions & 5 deletions src/ScriptRunner/ScriptRunner.GUI/Parameters/DropdownControl.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Avalonia.Controls;
using System.Collections.ObjectModel;
using System.Linq;
using Avalonia.Controls;
using ScriptRunner.GUI.ScriptConfigs;
using ScriptRunner.GUI.Views;

namespace ScriptRunner.GUI;
Expand All @@ -7,15 +10,33 @@ public class DropdownControl : IControlRecord
{
public Control Control { get; set; }
public Control InputControl { get; set; }
public ObservableCollection<DropdownOption> DropdownOptions { get; set; }

public string GetFormattedValue()
{
return InputControl switch
var selectedItem = InputControl switch
{
ComboBox cb => cb.SelectedItem?.ToString(),
ComboBox cb => cb.SelectedItem,
SearchableComboBox acb => acb.SelectedItem,
_ => ""
} ?? string.Empty;
_ => null
};

if (selectedItem is DropdownOption option)
{
return option.Value;
}

// For SearchableComboBox, we need to map the label back to value
if (selectedItem is string label && DropdownOptions != null)
{
var matchingOption = DropdownOptions.FirstOrDefault(opt => opt.Label == label);
if (matchingOption != null)
{
return matchingOption.Value;
}
}

return selectedItem?.ToString() ?? string.Empty;
}

public string Name { get; set; }
Expand Down
8 changes: 7 additions & 1 deletion src/ScriptRunner/ScriptRunner.GUI/Parameters/FileContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Security.Cryptography;
using System.Text;
using Avalonia.Controls;
using AvaloniaEdit;

namespace ScriptRunner.GUI;

Expand All @@ -20,7 +21,12 @@ public FileContent(string extension)

public string GetFormattedValue()
{
var fileContent = ((TextBox)Control).Text;
var fileContent = Control switch
{
TextBox textBox => textBox.Text,
TextEditor textEditor => textEditor.Text,
_ => ((TextBox)Control).Text
};
var hash = string.IsNullOrWhiteSpace(fileContent)? "EMPTY" : ComputeSHA256(fileContent).Substring(0,10);
FileName = Path.Combine(Path.GetTempPath(), hash + "." + _extension);
File.WriteAllText(FileName, fileContent, Encoding.UTF8);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using Avalonia.Controls;
using ScriptRunner.GUI.ScriptConfigs;

namespace ScriptRunner.GUI;

Expand All @@ -13,7 +14,11 @@ public string GetFormattedValue()
var copy = new List<string>();
foreach (var item in selectedItems)
{
if (item.ToString() is { } nonNullItem)
if (item is DropdownOption option)
{
copy.Add(option.Value);
}
else if (item?.ToString() is { } nonNullItem)
{
copy.Add(nonNullItem);
}
Expand Down
Loading
Loading