Skip to content

Commit

Permalink
修复测试工具的问题 (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
Richasy authored Sep 25, 2024
1 parent 397cf7a commit 3e99772
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@
IsEnabled="{x:Bind ViewModel.IsGenerating, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
Visibility="{x:Bind ViewModel.IsVariableEmpty, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}">
<Button.Flyout>
<Flyout Placement="Top" ShouldConstrainToRootBounds="False">
<Flyout
Opened="OnVariableFlyoutOpened"
Placement="Top"
ShouldConstrainToRootBounds="False">
<Grid Width="380">
<ItemsRepeater ItemsSource="{x:Bind ViewModel.Variables}">
<ItemsRepeater.ItemTemplate>
Expand All @@ -88,7 +91,9 @@
HorizontalAlignment="Stretch"
x:Load="{x:Bind Values, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
AcceptsReturn="True"
AllowFocusOnInteraction="True"
Header="{x:Bind Name}"
IsEnabled="{x:Bind IsEnabled, Mode=OneWay}"
PlaceholderText="{x:Bind Name}"
Text="{x:Bind Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public sealed partial class PromptTestMainBody : PromptTestPageControlBase
public PromptTestMainBody() => InitializeComponent();

private void OnTextBoxLostFocus(object sender, RoutedEventArgs e)
{
ViewModel?.UpdatePromptVariablesCommand.Execute(default);
}
=> ViewModel?.UpdatePromptVariablesCommand.Execute(default);

private void OnVariableFlyoutOpened(object sender, object e)
=> ViewModel?.CheckDefaultInputVariableCommand.Execute(default);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,38 @@
Grid.Column="1"
HorizontalAlignment="Center"
SelectionChanged="OnPromptSelectionChanged" />
<Button
<StackPanel
Grid.Column="2"
VerticalAlignment="Center"
Command="{x:Bind ViewModel.SaveHistoryJsonCommand}"
IsEnabled="{x:Bind ViewModel.IsGenerating, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
Style="{StaticResource IconButtonStyle}"
ToolTipService.ToolTip="{ext:Locale Name=SaveAs}"
Visibility="{x:Bind ViewModel.CurrentSystemPrompt, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
<ic:SymbolIcon FontSize="14" Symbol="Save" />
<Button.KeyboardAccelerators>
<KeyboardAccelerator
Key="S"
IsEnabled="True"
Modifiers="Control" />
</Button.KeyboardAccelerators>
</Button>
Orientation="Horizontal">
<Button
Command="{x:Bind ViewModel.ReloadMessagesCommand}"
IsEnabled="{x:Bind ViewModel.IsGenerating, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
Style="{StaticResource IconButtonStyle}"
ToolTipService.ToolTip="{ext:Locale Name=Reload}"
Visibility="{x:Bind ViewModel.CurrentSystemPrompt, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
<ic:SymbolIcon FontSize="14" Symbol="ArrowClockwise" />
<Button.KeyboardAccelerators>
<KeyboardAccelerator
Key="R"
IsEnabled="True"
Modifiers="Control" />
</Button.KeyboardAccelerators>
</Button>
<Button
Command="{x:Bind ViewModel.SaveHistoryJsonCommand}"
IsEnabled="{x:Bind ViewModel.IsGenerating, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}"
Style="{StaticResource IconButtonStyle}"
ToolTipService.ToolTip="{ext:Locale Name=SaveAs}"
Visibility="{x:Bind ViewModel.CurrentSystemPrompt, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
<ic:SymbolIcon FontSize="14" Symbol="Save" />
<Button.KeyboardAccelerators>
<KeyboardAccelerator
Key="S"
IsEnabled="True"
Modifiers="Control" />
</Button.KeyboardAccelerators>
</Button>
</StackPanel>
</Grid>
</local:PromptTestPageControlBase>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ private void OnSystemPromptInitialized(object? sender, EventArgs e)

private void OnPromptSelectionChanged(SelectorBar sender, SelectorBarSelectionChangedEventArgs args)
{
if (sender.SelectedItem is null)
{
return;
}

var item = sender.SelectedItem.Tag as PromptTestSystemPromptItemViewModel;
if (ViewModel.CurrentSystemPrompt == item)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock
HorizontalAlignment="Left"
Expand All @@ -87,9 +88,22 @@
VerticalAlignment="Center"
Command="{x:Bind ViewModel.OpenInputFileCommand}"
Style="{StaticResource SmallIconButtonStyle}"
ToolTipService.ToolTip="{ext:Locale Name=OpenFile}">
ToolTipService.ToolTip="{ext:Locale Name=OpenFile}"
Visibility="{x:Bind ViewModel.InputFilePath, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
<ic:SymbolIcon FontSize="14" Symbol="Open" />
</Button>
<Button
Grid.Column="2"
VerticalAlignment="Center"
Command="{x:Bind ViewModel.RemoveInputCommand}"
Style="{StaticResource SmallIconButtonStyle}"
ToolTipService.ToolTip="{ext:Locale Name=Delete}"
Visibility="{x:Bind ViewModel.InputFilePath, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
<ic:SymbolIcon
FontSize="14"
Foreground="{ThemeResource SystemFillColorCriticalBrush}"
Symbol="Delete" />
</Button>
</Grid>
</base:SettingsExpander.ItemsFooter>
</base:SettingsExpander>
Expand Down Expand Up @@ -124,7 +138,8 @@
VerticalAlignment="Center"
Command="{x:Bind ViewModel.OpenHistoryFileCommand}"
Style="{StaticResource SmallIconButtonStyle}"
ToolTipService.ToolTip="{ext:Locale Name=OpenFile}">
ToolTipService.ToolTip="{ext:Locale Name=OpenFile}"
Visibility="{x:Bind ViewModel.MessageJsonFilePath, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
<ic:SymbolIcon FontSize="14" Symbol="Open" />
</Button>
</Grid>
Expand Down Expand Up @@ -161,7 +176,8 @@
VerticalAlignment="Center"
Command="{x:Bind ViewModel.OpenVariablesFileCommand}"
Style="{StaticResource SmallIconButtonStyle}"
ToolTipService.ToolTip="{ext:Locale Name=OpenFile}">
ToolTipService.ToolTip="{ext:Locale Name=OpenFile}"
Visibility="{x:Bind ViewModel.PresetVariablesFilePath, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}">
<ic:SymbolIcon FontSize="14" Symbol="Open" />
</Button>
</Grid>
Expand Down
3 changes: 3 additions & 0 deletions src/Desktop/RodelAgent.UI/Resources/zh-Hans-CN/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -1259,4 +1259,7 @@
<data name="HideWhenCloseDescription" xml:space="preserve">
<value>关闭窗口时隐藏应用而非退出</value>
</data>
<data name="Reload" xml:space="preserve">
<value>重新载入</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public sealed partial class VariableItemViewModel : ViewModelBase
[ObservableProperty]
private List<string>? _values;

[ObservableProperty]
private bool _isEnabled;

/// <summary>
/// Initializes a new instance of the <see cref="VariableItemViewModel"/> class.
/// </summary>
Expand All @@ -27,6 +30,7 @@ public VariableItemViewModel(
Name = name;
Values = selectValues;
Value = defaultValue ?? Values?.FirstOrDefault() ?? string.Empty;
IsEnabled = true;
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private async Task ImportVariablesAsync()
PresetVariablesFilePath = file.Path;
SettingsToolkit.WriteLocalSetting(SettingNames.PromptTestPresetVariablesFilePath, PresetVariablesFilePath);
Variables.Clear();
_variables.Clear();
_variables?.Clear();
await ParsePresetVariablesAsync(PresetVariablesFilePath);
}
}
Expand Down Expand Up @@ -201,6 +201,35 @@ private async Task OpenVariablesFileAsync()
private async Task OpenHistoryFileAsync()
=> await Launcher.LaunchFileAsync(await StorageFile.GetFileFromPathAsync(MessageJsonFilePath));

[RelayCommand]
private void RemoveInput()
{
InputFilePath = string.Empty;
SettingsToolkit.WriteLocalSetting(SettingNames.PromptTestInputFilePath, InputFilePath);
_inputs.Clear();
InputsCount = 0;
}

[RelayCommand]
private void CheckDefaultInputVariable()
{
if (string.IsNullOrEmpty(_defaultInputVariable))
{
return;
}

var shouldDisableDefaultInputVariable = _inputs?.Count > 0;
var defaultInputVariable = Variables.FirstOrDefault(p => p.Name == _defaultInputVariable);
if (defaultInputVariable is not null)
{
defaultInputVariable.IsEnabled = !shouldDisableDefaultInputVariable;
}
}

[RelayCommand]
private Task ReloadMessagesAsync()
=> ParseHistoryAsync(MessageJsonFilePath, true);

private async Task ParseInputAsync(string filePath, bool showTip = true)
{
try
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)App.ruleset</CodeAnalysisRuleSet>
<NoWarn>$(NoWarn);NU1701;CS9057;MSB3277;NETSDK1206;NU1507;NU1008;CA2007;CS8622;SKEXP0010;SKEXP0001;CS1570</NoWarn>
<NoWarn>$(NoWarn);NU1701;CS9057;MSB3277;NETSDK1206;NU1507;NU1008;CA2007;CS8622;SKEXP0010;SKEXP0001;CS1570;NU1900</NoWarn>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
Expand Down

0 comments on commit 3e99772

Please sign in to comment.