Implement migration plan: models, service, MVVM, XAML layout, icons\n\n- Add Models: HistoryItem, VariableItem, FunctionDefinitionItem, IconFont\n- Add Services: ICalculatorService, CalculatorService wrapping interpreter\n- Update MainViewModel: properties and Submit/ToggleFunctions commands\n- Rebuild Views/MainView.axaml with variables, history, input, functions panel\n- Add BoolToGridLengthConverter for panel toggle\n- Wire Material Design Icons font as Avalonia resource in App.axaml/csproj

This commit is contained in:
Codex CLI 2025-08-26 01:45:05 -05:00
commit 7b1912579f
11 changed files with 342 additions and 9 deletions

View file

@ -1,6 +1,64 @@
namespace AdvancedCalculator.ViewModels;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using AdvancedCalculator.Models;
using AdvancedCalculator.Services;
namespace AdvancedCalculator.ViewModels;
public partial class MainViewModel : ViewModelBase
{
public string Greeting => "Welcome to Avalonia!";
private readonly ICalculatorService _calculatorService;
public MainViewModel()
: this(new CalculatorService())
{
}
public MainViewModel(ICalculatorService calculatorService)
{
_calculatorService = calculatorService;
History = new ObservableCollection<HistoryItem>();
Variables = new ObservableCollection<VariableItem>();
}
[ObservableProperty]
private string _inputText = string.Empty;
[ObservableProperty]
private bool _isFunctionsPanelOpen;
[ObservableProperty]
private int _selectedHistoryIndex = -1;
public ObservableCollection<HistoryItem> History { get; }
public ObservableCollection<VariableItem> Variables { get; }
[RelayCommand]
private void ToggleFunctions()
{
IsFunctionsPanelOpen = !IsFunctionsPanelOpen;
}
[RelayCommand(AllowConcurrentExecutions = false)]
private async Task Submit()
{
var text = InputText?.Trim();
if (string.IsNullOrEmpty(text))
return;
var result = await _calculatorService.InterpretAsync(text);
History.Add(new HistoryItem { Input = text, Output = result.Output });
Variables.Clear();
foreach (var v in result.Variables)
{
Variables.Add(v);
}
InputText = string.Empty;
SelectedHistoryIndex = History.Count - 1;
}
}