diff --git a/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestMainBody.xaml b/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestMainBody.xaml index 458ff99..53c2379 100644 --- a/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestMainBody.xaml +++ b/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestMainBody.xaml @@ -63,7 +63,10 @@ IsEnabled="{x:Bind ViewModel.IsGenerating, Mode=OneWay, Converter={StaticResource ObjectToBoolReverseConverter}}" Visibility="{x:Bind ViewModel.IsVariableEmpty, Mode=OneWay, Converter={StaticResource BoolToVisibilityReverseConverter}}"> - + @@ -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" diff --git a/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestMainBody.xaml.cs b/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestMainBody.xaml.cs index 99fdb41..0be2637 100644 --- a/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestMainBody.xaml.cs +++ b/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestMainBody.xaml.cs @@ -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); } diff --git a/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestMainHeader.xaml b/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestMainHeader.xaml index b64887c..f32fcd2 100644 --- a/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestMainHeader.xaml +++ b/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestMainHeader.xaml @@ -27,21 +27,38 @@ Grid.Column="1" HorizontalAlignment="Center" SelectionChanged="OnPromptSelectionChanged" /> - + Orientation="Horizontal"> + + + diff --git a/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestMainHeader.xaml.cs b/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestMainHeader.xaml.cs index 1a1b608..b7c87ef 100644 --- a/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestMainHeader.xaml.cs +++ b/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestMainHeader.xaml.cs @@ -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) { diff --git a/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestSideBody.xaml b/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestSideBody.xaml index b71ba64..3c6d8e6 100644 --- a/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestSideBody.xaml +++ b/src/Desktop/RodelAgent.UI/Controls/Internal/PromptTestSideBody.xaml @@ -74,6 +74,7 @@ + + ToolTipService.ToolTip="{ext:Locale Name=OpenFile}" + Visibility="{x:Bind ViewModel.InputFilePath, Mode=OneWay, Converter={StaticResource ObjectToVisibilityConverter}}"> + @@ -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}}"> @@ -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}}"> diff --git a/src/Desktop/RodelAgent.UI/Resources/zh-Hans-CN/Resources.resw b/src/Desktop/RodelAgent.UI/Resources/zh-Hans-CN/Resources.resw index e2ceffd..b19724e 100644 --- a/src/Desktop/RodelAgent.UI/Resources/zh-Hans-CN/Resources.resw +++ b/src/Desktop/RodelAgent.UI/Resources/zh-Hans-CN/Resources.resw @@ -1259,4 +1259,7 @@ 关闭窗口时隐藏应用而非退出 + + 重新载入 + \ No newline at end of file diff --git a/src/Desktop/RodelAgent.UI/ViewModels/Items/VariableItemViewModel.cs b/src/Desktop/RodelAgent.UI/ViewModels/Items/VariableItemViewModel.cs index d54249e..9b139c9 100644 --- a/src/Desktop/RodelAgent.UI/ViewModels/Items/VariableItemViewModel.cs +++ b/src/Desktop/RodelAgent.UI/ViewModels/Items/VariableItemViewModel.cs @@ -16,6 +16,9 @@ public sealed partial class VariableItemViewModel : ViewModelBase [ObservableProperty] private List? _values; + [ObservableProperty] + private bool _isEnabled; + /// /// Initializes a new instance of the class. /// @@ -27,6 +30,7 @@ public VariableItemViewModel( Name = name; Values = selectValues; Value = defaultValue ?? Values?.FirstOrDefault() ?? string.Empty; + IsEnabled = true; } /// diff --git a/src/Desktop/RodelAgent.UI/ViewModels/Pages/PromptTestPageViewModel/PromptTestPageViewModel.Config.cs b/src/Desktop/RodelAgent.UI/ViewModels/Pages/PromptTestPageViewModel/PromptTestPageViewModel.Config.cs index 60d4917..4ef3192 100644 --- a/src/Desktop/RodelAgent.UI/ViewModels/Pages/PromptTestPageViewModel/PromptTestPageViewModel.Config.cs +++ b/src/Desktop/RodelAgent.UI/ViewModels/Pages/PromptTestPageViewModel/PromptTestPageViewModel.Config.cs @@ -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); } } @@ -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 diff --git a/src/Directory.Build.props b/src/Directory.Build.props index b661856..c4933d7 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -7,7 +7,7 @@ latest enable $(MSBuildThisFileDirectory)App.ruleset - $(NoWarn);NU1701;CS9057;MSB3277;NETSDK1206;NU1507;NU1008;CA2007;CS8622;SKEXP0010;SKEXP0001;CS1570 + $(NoWarn);NU1701;CS9057;MSB3277;NETSDK1206;NU1507;NU1008;CA2007;CS8622;SKEXP0010;SKEXP0001;CS1570;NU1900 true true true