From b06ad897970ee543bcf6a276a64aca4c2115528d Mon Sep 17 00:00:00 2001 From: ahmdkaml Date: Sun, 11 Oct 2026 19:50:10 +0300 Subject: [PATCH] refactor: apply latest desktop UI changes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../ViewModels/MainViewModel.cs | 58 ++++- .../Views/Components/ModuleEditorView.axaml | 11 +- .../Components/ModuleEditorView.axaml.cs | 36 ++- .../Components/PropertiesToolbarView.axaml | 6 +- src/TextForge.Desktop/Views/MainWindow.axaml | 23 +- .../Views/MainWindow.axaml.cs | 238 ++---------------- 6 files changed, 125 insertions(+), 247 deletions(-) diff --git a/src/TextForge.Desktop/ViewModels/MainViewModel.cs b/src/TextForge.Desktop/ViewModels/MainViewModel.cs index a80d545..0d1cba7 100644 --- a/src/TextForge.Desktop/ViewModels/MainViewModel.cs +++ b/src/TextForge.Desktop/ViewModels/MainViewModel.cs @@ -1,7 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using TextForge.Core; using TextForge.Core.Documents; using TextForge.Core.Engine; +using TextForge.Core.Modules; using TextForge.Core.Templates; namespace TextForge.Desktop.ViewModels; @@ -16,7 +21,7 @@ public partial class MainViewModel : ObservableObject // --- NEW DRAWER STATE --- [ObservableProperty] - public partial string ActiveTab { get; set; } = string.Empty; + private partial string ActiveTab { get; set; } = string.Empty; // Derived flags for XAML IsVisible bindings public bool IsDrawerOpen => !string.IsNullOrEmpty(ActiveTab); @@ -37,14 +42,61 @@ partial void OnActiveTabChanged(string value) } [RelayCommand] - public void ToggleTab(string tabName) + private void ToggleTab(string tabName) { ActiveTab = (ActiveTab == tabName) ? string.Empty : tabName; } [RelayCommand] - public void CloseDrawer() + private void CloseDrawer() { ActiveTab = string.Empty; } + + public IReadOnlyList AvailableModules { get; } = ModuleRegistry.GetAvailableModules(); + [RelayCommand] + private void ClearAllModules() + { + CurrentDocument.ClearModules(); + } + + [ObservableProperty] + public partial string ExportStatusMessage { get; set; } = "Status: Ready"; + + [ObservableProperty] + [NotifyCanExecuteChangedFor(nameof(ExportPdfCommand))] + public partial bool IsExporting { get; set; } + + private bool CanExportPdf() => !IsExporting && CurrentDocument is not null; + + [RelayCommand(CanExecute = nameof(CanExportPdf))] + private async Task ExportPdfAsync() + { + try + { + IsExporting = true; + ExportStatusMessage = "Status: Exporting PDF..."; + + await PdfService.CreatePdfAsync(CurrentDocument, Template, "output.pdf"); + + ExportStatusMessage = "Status: PDF Exported successfully!"; + } + catch (Exception ex) + { + ExportStatusMessage = $"Status: Export failed ({ex.Message})"; + } + finally + { + IsExporting = false; + } + } + [RelayCommand] + private void AddModule(ModuleDefinition definition) + { + var newModule = definition.Create(); + var targetParent = CurrentDocument.IsRootSelected ? null : CurrentDocument.SelectedModule; + + CurrentDocument.AddModule(newModule, parent: targetParent); + } + } \ No newline at end of file diff --git a/src/TextForge.Desktop/Views/Components/ModuleEditorView.axaml b/src/TextForge.Desktop/Views/Components/ModuleEditorView.axaml index b404b23..9a7e54b 100644 --- a/src/TextForge.Desktop/Views/Components/ModuleEditorView.axaml +++ b/src/TextForge.Desktop/Views/Components/ModuleEditorView.axaml @@ -1,7 +1,9 @@ + xmlns:vm="using:TextForge.Desktop.ViewModels" + x:Class="TextForge.Desktop.Views.Components.ModuleEditorView" + x:DataType="vm:MainViewModel">