# Conflicts: # LehrerApp.TemplateDesigner.Tests/ProjectLifecycleTests.cs # LehrerApp.TemplateDesigner/DesignerViewModel.cs # LehrerApp.TemplateDesigner/MainWindow.axaml # LehrerApp.Templating/LayoutParser.cs # LehrerApp.Templating/QuestTemplateRenderer.cs
This commit is contained in:
@@ -107,6 +107,22 @@ public partial class MainWindow : Window
|
||||
catch (Exception ex) { _viewModel.SetStatus($"Bildimport fehlgeschlagen: {ex.Message}", true); }
|
||||
}
|
||||
|
||||
[SupportedOSPlatform("windows")]
|
||||
[SupportedOSPlatform("linux")]
|
||||
[SupportedOSPlatform("macos")]
|
||||
private async void OnImportPdfTemplate(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var dialog = new PdfImportDialog();
|
||||
var accepted = await dialog.ShowDialog<bool>(this);
|
||||
if (!accepted || dialog.Result is null) return;
|
||||
try
|
||||
{
|
||||
_viewModel.ApplyPdfImport(dialog.Result);
|
||||
_currentPackagePath = null; UpdateDocumentTitle(); OnPreview(sender, e);
|
||||
}
|
||||
catch (Exception ex) { _viewModel.SetStatus($"PDF-Vorschlag konnte nicht übernommen werden: {ex.Message}", true); }
|
||||
}
|
||||
|
||||
private async void OnReplaceSelectedAsset(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_viewModel.SelectedAsset is null) { _viewModel.SetStatus("Bitte zuerst ein Asset auswählen.", true); return; }
|
||||
@@ -143,8 +159,8 @@ public partial class MainWindow : Window
|
||||
{ _viewModel.SetStatus("Bitte zuerst eine Ausgangsvorlage auswählen.", true); return; }
|
||||
try
|
||||
{
|
||||
var (template, layout) = _starterTemplates.Load(selected);
|
||||
_viewModel.Load(template, layout); _currentPackagePath = null; UpdateDocumentTitle(); OnPreview(sender, e);
|
||||
var (template, layout, continuationLayout) = _starterTemplates.LoadWithContinuation(selected);
|
||||
_viewModel.Load(template, layout, continuationLayout); _currentPackagePath = null; UpdateDocumentTitle(); OnPreview(sender, e);
|
||||
}
|
||||
catch (Exception ex) { _viewModel.SetStatus($"Öffnen fehlgeschlagen: {ex.Message}", true); }
|
||||
}
|
||||
@@ -155,9 +171,9 @@ public partial class MainWindow : Window
|
||||
{ _viewModel.SetStatus("Bitte zuerst eine Ausgangsvorlage auswählen.", true); return; }
|
||||
try
|
||||
{
|
||||
var (template, layout) = _starterTemplates.Load(selected);
|
||||
var (template, layout, continuationLayout) = _starterTemplates.LoadWithContinuation(selected);
|
||||
var projectId = _starterTemplates.CreateUniqueId(template.Manifest.Id + "-neu");
|
||||
_viewModel.LoadAsNewProject(template, layout, projectId);
|
||||
_viewModel.LoadAsNewProject(template, layout, continuationLayout, projectId);
|
||||
_currentPackagePath = null; UpdateDocumentTitle(); OnPreview(sender, e);
|
||||
}
|
||||
catch (Exception ex) { _viewModel.SetStatus($"Klonen fehlgeschlagen: {ex.Message}", true); }
|
||||
@@ -168,7 +184,8 @@ public partial class MainWindow : Window
|
||||
try
|
||||
{
|
||||
_viewModel.BuildLoaded();
|
||||
var saved = _starterTemplates.Save(_viewModel.BuildManifest(), _viewModel.LayoutSource, _viewModel.Assets);
|
||||
var saved = _starterTemplates.Save(_viewModel.BuildManifest(), _viewModel.LayoutSource, _viewModel.Assets,
|
||||
_viewModel.UseContinuationLayout ? _viewModel.ContinuationLayoutSource : null);
|
||||
RefreshStarterTemplates(saved.Id);
|
||||
_viewModel.SetStatus($"Ausgangsvorlage „{saved.Name}“ lokal gespeichert/aktualisiert.", false);
|
||||
}
|
||||
@@ -238,8 +255,16 @@ public partial class MainWindow : Window
|
||||
try
|
||||
{
|
||||
var path = files[0].Path.LocalPath; var loaded = new TemplateLoader().LoadFromPackage(path);
|
||||
using var archive = ZipFile.OpenRead(path); using var reader = new StreamReader(archive.GetEntry(loaded.Manifest.LayoutFile)!.Open());
|
||||
_viewModel.Load(loaded, reader.ReadToEnd()); _currentPackagePath = Path.GetFullPath(path);
|
||||
using var archive = ZipFile.OpenRead(path);
|
||||
string layoutSource;
|
||||
using (var reader = new StreamReader(archive.GetEntry(loaded.Manifest.LayoutFile)!.Open())) layoutSource = reader.ReadToEnd();
|
||||
string? continuationLayoutSource = null;
|
||||
if (loaded.Manifest.ContinuationLayoutFile is { } continuationPath)
|
||||
{
|
||||
using var reader = new StreamReader(archive.GetEntry(continuationPath)!.Open());
|
||||
continuationLayoutSource = reader.ReadToEnd();
|
||||
}
|
||||
_viewModel.Load(loaded, layoutSource, continuationLayoutSource); _currentPackagePath = Path.GetFullPath(path);
|
||||
UpdateDocumentTitle(); OnPreview(sender, e);
|
||||
}
|
||||
catch (Exception ex) { _viewModel.SetStatus($"Öffnen fehlgeschlagen: {ex.Message}", true); }
|
||||
@@ -253,6 +278,40 @@ public partial class MainWindow : Window
|
||||
|
||||
private async void OnSaveAs(object? sender, RoutedEventArgs e) => await SaveAsAsync();
|
||||
|
||||
private async void OnExportCurrentPdf(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
byte[] pdf;
|
||||
try
|
||||
{
|
||||
pdf = _viewModel.RenderCurrentPdf();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_viewModel.SetStatus($"PDF-Export fehlgeschlagen: {ex.Message}", true);
|
||||
return;
|
||||
}
|
||||
|
||||
var file = await StorageProvider.SaveFilePickerAsync(new()
|
||||
{
|
||||
Title = "Aktuelle Vorlagenansicht als PDF exportieren",
|
||||
SuggestedFileName = _viewModel.TemplateId + "-vorschau.pdf",
|
||||
DefaultExtension = "pdf",
|
||||
FileTypeChoices = [new("PDF-Dateien") { Patterns = ["*.pdf"] }],
|
||||
});
|
||||
if (file is null) return;
|
||||
|
||||
try
|
||||
{
|
||||
var destination = EnsurePdfExtension(file.Path.LocalPath);
|
||||
await File.WriteAllBytesAsync(destination, pdf);
|
||||
_viewModel.SetStatus($"PDF-Vorschau exportiert: {Path.GetFileName(destination)}", false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_viewModel.SetStatus($"PDF-Export fehlgeschlagen: {ex.Message}", true);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveAsAsync()
|
||||
{
|
||||
try { _viewModel.BuildLoaded(); }
|
||||
@@ -274,7 +333,8 @@ public partial class MainWindow : Window
|
||||
try
|
||||
{
|
||||
_viewModel.BuildLoaded();
|
||||
TemplatePackage.Create(path, _viewModel.BuildManifest(), _viewModel.LayoutSource, _viewModel.Assets);
|
||||
TemplatePackage.Create(path, _viewModel.BuildManifest(), _viewModel.LayoutSource, _viewModel.Assets,
|
||||
_viewModel.UseContinuationLayout ? _viewModel.ContinuationLayoutSource : null);
|
||||
_viewModel.CanExport = true;
|
||||
_viewModel.SetStatus($"Gespeichert: {Path.GetFileName(path)}", false);
|
||||
return true;
|
||||
@@ -317,6 +377,9 @@ public partial class MainWindow : Window
|
||||
private static string EnsurePackageExtension(string path) =>
|
||||
string.Equals(Path.GetExtension(path), TemplatePackage.Extension, StringComparison.OrdinalIgnoreCase)
|
||||
? path : path + TemplatePackage.Extension;
|
||||
private static string EnsurePdfExtension(string path) =>
|
||||
string.Equals(Path.GetExtension(path), ".pdf", StringComparison.OrdinalIgnoreCase)
|
||||
? path : path + ".pdf";
|
||||
private void RefreshStarterTemplates(string? selectedId = null) =>
|
||||
_viewModel.SetStarterTemplates(_starterTemplates.GetAll(), selectedId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user