Skip to content

Commit

Permalink
Enable Tab navigation in vault and action parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarypiatek committed Aug 7, 2022
1 parent b756c1f commit 3d203cd
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 19 deletions.
57 changes: 42 additions & 15 deletions src/ScriptRunner/ScriptRunner.GUI/ParamsPanelFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Avalonia.Collections;
using Avalonia.Controls;
Expand All @@ -21,10 +22,10 @@ public ParamsPanel Create(IEnumerable<ScriptParam> parameters, Dictionary<string

var controlRecords = new List<IControlRecord>();

foreach (var param in parameters)
foreach (var (param,i) in parameters.Select((x,i)=>(x,i)))
{
values.TryGetValue(param.Name, out var value);
var controlRecord = CreateControlRecord(param, value);
var controlRecord = CreateControlRecord(param, value, i);
controlRecord.Name = param.Name;
var actionPanel = new StackPanel
{
Expand All @@ -50,7 +51,7 @@ public ParamsPanel Create(IEnumerable<ScriptParam> parameters, Dictionary<string
};
}

private static IControlRecord CreateControlRecord(ScriptParam p, string? value)
private static IControlRecord CreateControlRecord(ScriptParam p, string? value, int index)
{
switch (p.Prompt)
{
Expand All @@ -59,15 +60,19 @@ private static IControlRecord CreateControlRecord(ScriptParam p, string? value)
{
Control = new TextBox
{
Text = value
Text = value,
TabIndex = index,
IsTabStop = true
}
};
case PromptType.Password:
return new PasswordControl
{
Control = new PasswordBox()
{
Password = value
Password = value,
TabIndex = index,
IsTabStop = true
},
MaskingRequired = true
};
Expand All @@ -77,7 +82,9 @@ private static IControlRecord CreateControlRecord(ScriptParam p, string? value)
Control = new ComboBox
{
Items = p.GetPromptSettings("options", out var options) ? options.Split(","):Array.Empty<string>(),
SelectedItem = value
SelectedItem = value,
TabIndex = index,
IsTabStop = true
}
};
case PromptType.Multiselect:
Expand All @@ -88,7 +95,9 @@ private static IControlRecord CreateControlRecord(ScriptParam p, string? value)
{
SelectionMode = SelectionMode.Multiple,
Items = p.GetPromptSettings("options", out var multiSelectOptions) ? multiSelectOptions.Split(delimiter) : Array.Empty<string>(),
SelectedItems = new AvaloniaList<string>((value ?? string.Empty).Split(delimiter))
SelectedItems = new AvaloniaList<string>((value ?? string.Empty).Split(delimiter)),
TabIndex = index,
IsTabStop = true
},
Delimiter = delimiter
};
Expand All @@ -103,15 +112,19 @@ private static IControlRecord CreateControlRecord(ScriptParam p, string? value)
new CalendarDatePicker
{
SelectedDate = selectedDate?.Date,
IsTodayHighlighted = true
IsTodayHighlighted = true,
TabIndex = index,
IsTabStop = true
}
: new DatePicker
{
SelectedDate = selectedDate,
YearVisible = yearVisible,
MonthVisible = monthVisible,
DayVisible = dayVisible,

TabIndex = index,
IsTabStop = true

},
Format = p.GetPromptSettings("format", out var format) ? format : null,
};
Expand All @@ -121,7 +134,9 @@ private static IControlRecord CreateControlRecord(ScriptParam p, string? value)
Control = new TimePicker
{
SelectedTime = string.IsNullOrWhiteSpace(value)?null: TimeSpan.Parse(value),
ClockIdentifier = "24HourClock"
ClockIdentifier = "24HourClock",
TabIndex = index,
IsTabStop = true
},
Format = p.GetPromptSettings("format", out var timeFormat) ? timeFormat : null,
};
Expand All @@ -131,7 +146,9 @@ private static IControlRecord CreateControlRecord(ScriptParam p, string? value)
{
Control = new CheckBox
{
IsChecked = string.IsNullOrWhiteSpace(value) == false && value == checkedValueText
IsChecked = string.IsNullOrWhiteSpace(value) == false && value == checkedValueText,
TabIndex = index,
IsTabStop = true
},
CheckedValue = checkedValueText,
UncheckedValue = p.GetPromptSettings("uncheckedValue", out var uncheckedValue)? uncheckedValue: "false",
Expand All @@ -144,7 +161,9 @@ private static IControlRecord CreateControlRecord(ScriptParam p, string? value)
TextWrapping = TextWrapping.Wrap,
AcceptsReturn = true,
Height = 100,
Text = value
Text = value,
TabIndex = index,
IsTabStop = true
}
};
case PromptType.FileContent:
Expand All @@ -155,23 +174,29 @@ private static IControlRecord CreateControlRecord(ScriptParam p, string? value)
TextWrapping = TextWrapping.Wrap,
AcceptsReturn = true,
Height = 100,
Text = File.Exists(value)? File.ReadAllText(value): string.Empty
Text = File.Exists(value)? File.ReadAllText(value): string.Empty,
TabIndex = index,
IsTabStop = true
}
};
case PromptType.FilePicker:
return new FilePickerControl
{
Control = new FilePicker
{
FilePath = value
FilePath = value,
TabIndex = index,
IsTabStop = true
}
};
case PromptType.DirectoryPicker:
return new DirectoryPickerControl
{
Control = new DirectoryPicker
{
DirPath = value
DirPath = value,
TabIndex = index,
IsTabStop = true
}
};
case PromptType.Numeric:
Expand All @@ -182,6 +207,8 @@ private static IControlRecord CreateControlRecord(ScriptParam p, string? value)
Minimum = p.GetPromptSettings("min", out var minValue) && double.TryParse(minValue, out var mindDouble)? mindDouble : double.MinValue,
Maximum = p.GetPromptSettings("max", out var maxValue) && double.TryParse(maxValue, out var maxDouble)? maxDouble: double.MaxValue,
Increment = p.GetPromptSettings("step", out var stepValue) && double.TryParse(stepValue, out var stepDouble)? stepDouble: 1.0,
TabIndex = index,
IsTabStop = true
}
};
default:
Expand Down
12 changes: 9 additions & 3 deletions src/ScriptRunner/ScriptRunner.GUI/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<Button i:Attached.Icon="fas fa-lock" Height="35" Width="50" FontSize="18" Command="{Binding OpenVaultWindow}" ToolTip.Tip="Open Vault" />
</StackPanel>
</Grid>
<GridSplitter Grid.Column="1" Grid.Row="1" ResizeDirection="Columns"></GridSplitter>
<GridSplitter Grid.Column="1" Grid.Row="1" ResizeDirection="Columns" IsTabStop="False"></GridSplitter>
<!-- Below instead of stack panel will be Reactive UI View Host displaying current action props-->
<ScrollViewer Grid.Column="2" Grid.Row="1">
<StackPanel Margin="20, 10" IsVisible="{Binding IsActionSelected, Mode=OneWay}">
Expand Down Expand Up @@ -101,7 +101,13 @@
</ComboBox.DataTemplates>
</ComboBox>
</StackPanel>
<ItemsControl Items="{Binding ActionParametersPanel}"></ItemsControl>
<ItemsControl Items="{Binding ActionParametersPanel}">
<ItemsControl.Styles>
<Style Selector="ItemsPresenter">
<Setter Property="(KeyboardNavigation.TabNavigation)" Value="Continue" />
</Style>
</ItemsControl.Styles>
</ItemsControl>
</StackPanel>

<StackPanel Orientation="Horizontal" Margin="0, 20, 0 , 5">
Expand All @@ -111,7 +117,7 @@

</StackPanel>
</ScrollViewer>
<GridSplitter Grid.Row="2" Grid.Column="0" ResizeDirection="Rows" Grid.ColumnSpan="3" BorderThickness="0,1,0,0" BorderBrush="#828282" ></GridSplitter>
<GridSplitter IsTabStop="False" Grid.Row="2" Grid.Column="0" ResizeDirection="Rows" Grid.ColumnSpan="3" BorderThickness="0,1,0,0" BorderBrush="#828282" ></GridSplitter>
<TabControl x:Name="RunningJobsPanel" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3" Items="{Binding RunningJobs}" SelectedItem="{Binding SelectedRunningJob, Mode=TwoWay}">
<TabControl.ItemTemplate>
<DataTemplate>
Expand Down
7 changes: 6 additions & 1 deletion src/ScriptRunner/ScriptRunner.GUI/Views/Vault.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@
<Label Margin="0,0,10,0" VerticalAlignment="Center">Key</Label>
<TextBox Grid.Column="1" Text="{Binding Name, Mode=TwoWay}"></TextBox>
<Label Grid.Column="2" Margin="10,0,10,0" VerticalAlignment="Center">Value</Label>
<TextBox PasswordChar="*" Grid.Column="3" Text="{Binding Secret, Mode=TwoWay}"></TextBox>
<TextBox PasswordChar="*" Grid.Column="3" Text="{Binding Secret, Mode=TwoWay}" ></TextBox>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.Styles>
<Style Selector="ItemsPresenter">
<Setter Property="(KeyboardNavigation.TabNavigation)" Value="Continue" />
</Style>
</ItemsControl.Styles>
</ItemsControl>
<Button Command="{Binding AddNewVaultEntry}" Margin="20">
<StackPanel Orientation="Horizontal">
Expand Down

0 comments on commit 3d203cd

Please sign in to comment.