This commit is contained in:
@@ -109,6 +109,8 @@ public partial class DesignerViewModel : ObservableObject
|
||||
issues.Add(new(ValidationSeverity.Error, $"Platzhalter „{used}“ ist nicht deklariert."));
|
||||
foreach (var path in layout.Elements.Select(x => x switch { BackgroundElement b => b.Path, ImageElement i => i.Path, _ => null }).Where(x => x is not null))
|
||||
if (!Assets.ContainsKey(path!)) issues.Add(new(ValidationSeverity.Error, $"Asset „{path}“ fehlt."));
|
||||
foreach (var issue in TemplateDataResolver.ValidateConstants(manifest))
|
||||
issues.Add(new(ValidationSeverity.Error, issue));
|
||||
if (issues.Count > 0) throw new TemplateValidationException(new(issues));
|
||||
return new(manifest, layout, new Dictionary<string, byte[]>(Assets));
|
||||
}
|
||||
@@ -145,7 +147,9 @@ public partial class DesignerViewModel : ObservableObject
|
||||
SelectedMetadata = null;
|
||||
Placeholders.Clear();
|
||||
foreach (var placeholder in template.Manifest.Placeholders)
|
||||
Placeholders.Add(new(placeholder.Name, placeholder.Type, placeholder.Required, DesignerPlaceholder.SampleFor(placeholder.Type)));
|
||||
Placeholders.Add(new(placeholder.Name, placeholder.Type, placeholder.Required,
|
||||
placeholder.IsConstant ? placeholder.ConstantValue ?? "" : DesignerPlaceholder.SampleFor(placeholder.Type),
|
||||
placeholder.IsConstant, placeholder.Bold, placeholder.Italic, placeholder.Underline));
|
||||
SelectedPlaceholder = Placeholders.FirstOrDefault();
|
||||
Assets.Clear(); AssetItems.Clear();
|
||||
foreach (var asset in template.Assets) AddOrReplaceAsset(asset.Key, asset.Value, keepName: true);
|
||||
@@ -201,7 +205,9 @@ public partial class DesignerViewModel : ObservableObject
|
||||
var name = placeholder.Name.Trim();
|
||||
if (name.Length == 0) throw new InvalidDataException("Ein Platzhaltername darf nicht leer sein.");
|
||||
if (!names.Add(name)) throw new InvalidDataException($"Platzhalter „{name}“ ist mehrfach definiert.");
|
||||
result.Add(new(name, placeholder.Type, placeholder.Required));
|
||||
result.Add(new(name, placeholder.Type, placeholder.Required, placeholder.IsConstant,
|
||||
placeholder.IsConstant ? placeholder.Sample : null,
|
||||
placeholder.Bold, placeholder.Italic, placeholder.Underline));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -439,8 +445,29 @@ public partial class DesignerPlaceholder : ObservableObject
|
||||
[ObservableProperty] private PlaceholderType _type;
|
||||
[ObservableProperty] private bool _required;
|
||||
[ObservableProperty] private string _sample;
|
||||
public DesignerPlaceholder(string name, PlaceholderType type, bool required, string sample)
|
||||
{ _name = name; _type = type; _required = required; _sample = sample; }
|
||||
[ObservableProperty] private bool _isConstant;
|
||||
[ObservableProperty] private bool _bold;
|
||||
[ObservableProperty] private bool _italic;
|
||||
[ObservableProperty] private bool _underline;
|
||||
public bool SupportsConstantValue => Type is PlaceholderType.Text or PlaceholderType.Multiline
|
||||
or PlaceholderType.Date or PlaceholderType.Number;
|
||||
public bool SupportsRichText => IsConstant && Type is PlaceholderType.Text or PlaceholderType.Multiline;
|
||||
|
||||
public DesignerPlaceholder(string name, PlaceholderType type, bool required, string sample,
|
||||
bool isConstant = false, bool bold = false, bool italic = false, bool underline = false)
|
||||
{
|
||||
_name = name; _type = type; _required = required; _sample = sample;
|
||||
_isConstant = isConstant; _bold = bold; _italic = italic; _underline = underline;
|
||||
}
|
||||
|
||||
partial void OnTypeChanged(PlaceholderType value)
|
||||
{
|
||||
OnPropertyChanged(nameof(SupportsConstantValue));
|
||||
OnPropertyChanged(nameof(SupportsRichText));
|
||||
if (!SupportsConstantValue) IsConstant = false;
|
||||
}
|
||||
|
||||
partial void OnIsConstantChanged(bool value) => OnPropertyChanged(nameof(SupportsRichText));
|
||||
|
||||
public PlaceholderValue ToValue() => Type switch
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user