diff --git a/src/OneWare.Essentials/Controls/DocumentUiExtensionCollection.axaml b/src/OneWare.Essentials/Controls/DocumentUiExtensionCollection.axaml new file mode 100644 index 0000000..175b480 --- /dev/null +++ b/src/OneWare.Essentials/Controls/DocumentUiExtensionCollection.axaml @@ -0,0 +1,36 @@ + + + + + + + diff --git a/src/OneWare.Essentials/Controls/DocumentUiExtensionCollection.axaml.cs b/src/OneWare.Essentials/Controls/DocumentUiExtensionCollection.axaml.cs new file mode 100644 index 0000000..fde9e0c --- /dev/null +++ b/src/OneWare.Essentials/Controls/DocumentUiExtensionCollection.axaml.cs @@ -0,0 +1,40 @@ +using System.Collections.ObjectModel; +using System.Collections.Specialized; +using Avalonia; +using Avalonia.Controls.Primitives; +using Avalonia.Layout; +using OneWare.Essentials.Models; + +namespace OneWare.Essentials.Controls; + +public class DocumentUiExtensionCollection : TemplatedControl +{ + public static readonly StyledProperty FileProperty = + AvaloniaProperty.Register(nameof(File)); + + public static readonly StyledProperty?> ExtensionsProperty = + AvaloniaProperty.Register?>(nameof(Extensions)); + + public static readonly StyledProperty OrientationProperty = + AvaloniaProperty.Register(nameof(Orientation)); + + protected override Type StyleKeyOverride => typeof(DocumentUiExtensionCollection); + + public IFile? File + { + get => GetValue(FileProperty); + set => SetValue(FileProperty, value); + } + + public ObservableCollection? Extensions + { + get => GetValue(ExtensionsProperty); + set => SetValue(ExtensionsProperty, value); + } + + public Orientation Orientation + { + get => GetValue(OrientationProperty); + set => SetValue(OrientationProperty, value); + } +} \ No newline at end of file diff --git a/src/OneWare.Essentials/Controls/SharedControls.axaml b/src/OneWare.Essentials/Controls/SharedControls.axaml index f0436f8..fabbd55 100644 --- a/src/OneWare.Essentials/Controls/SharedControls.axaml +++ b/src/OneWare.Essentials/Controls/SharedControls.axaml @@ -5,4 +5,5 @@ + \ No newline at end of file diff --git a/src/OneWare.Essentials/Controls/UiExtensionCollection.axaml b/src/OneWare.Essentials/Controls/UiExtensionCollection.axaml index 5f0835b..70502d4 100644 --- a/src/OneWare.Essentials/Controls/UiExtensionCollection.axaml +++ b/src/OneWare.Essentials/Controls/UiExtensionCollection.axaml @@ -14,7 +14,7 @@ - + diff --git a/src/OneWare.Essentials/Controls/UiExtensionCollection.axaml.cs b/src/OneWare.Essentials/Controls/UiExtensionCollection.axaml.cs index 122ea2c..68711f7 100644 --- a/src/OneWare.Essentials/Controls/UiExtensionCollection.axaml.cs +++ b/src/OneWare.Essentials/Controls/UiExtensionCollection.axaml.cs @@ -2,6 +2,7 @@ using System.Collections.Specialized; using Avalonia; using Avalonia.Controls.Primitives; +using Avalonia.Layout; using OneWare.Essentials.Models; namespace OneWare.Essentials.Controls; @@ -9,29 +10,22 @@ namespace OneWare.Essentials.Controls; public class UiExtensionCollection : TemplatedControl { public static readonly StyledProperty?> ExtensionsProperty = - AvaloniaProperty.Register?>(nameof(UiExtensionCollection)); + AvaloniaProperty.Register?>(nameof(Extensions)); + + public static readonly StyledProperty OrientationProperty = + AvaloniaProperty.Register(nameof(Orientation)); protected override Type StyleKeyOverride => typeof(UiExtensionCollection); public ObservableCollection? Extensions { get => GetValue(ExtensionsProperty); - set - { - if(Extensions != null) - Extensions.CollectionChanged -= OnExtensionsChanged; - - SetValue(ExtensionsProperty, value); - - if (value == null) - return; - - value.CollectionChanged += OnExtensionsChanged; - } + set => SetValue(ExtensionsProperty, value); } - private void OnExtensionsChanged(object? sender, NotifyCollectionChangedEventArgs e) + public Orientation Orientation { - + get => GetValue(OrientationProperty); + set => SetValue(OrientationProperty, value); } } \ No newline at end of file diff --git a/src/OneWare.Essentials/Converters/DocumentUiExtensionConverter.cs b/src/OneWare.Essentials/Converters/DocumentUiExtensionConverter.cs new file mode 100644 index 0000000..430c65c --- /dev/null +++ b/src/OneWare.Essentials/Converters/DocumentUiExtensionConverter.cs @@ -0,0 +1,26 @@ +using System.Globalization; +using Avalonia.Controls; +using Avalonia.Data.Converters; +using OneWare.Essentials.Models; + +namespace OneWare.Essentials.Converters; + +public class DocumentUiExtensionConverter : IMultiValueConverter +{ + public object? Convert(IList values, Type targetType, object? parameter, CultureInfo culture) + { + if (values.Count != 2) return null; + + var file = values[0] as IFile; + var uiExtension = values[1] as DocumentUiExtension; + + if(file == null || uiExtension == null) return null; + + if (Activator.CreateInstance(uiExtension.Type) is Control control) + { + control.DataContext = uiExtension.CreateDataContext(file); + return control; + } + return null; + } +} \ No newline at end of file diff --git a/src/OneWare.Essentials/Converters/SharedConverters.cs b/src/OneWare.Essentials/Converters/SharedConverters.cs index 9718493..5da8481 100644 --- a/src/OneWare.Essentials/Converters/SharedConverters.cs +++ b/src/OneWare.Essentials/Converters/SharedConverters.cs @@ -9,6 +9,7 @@ public static readonly IValueConverter public static readonly IValueConverter BoolToScrollBarVisibilityConverter = new BoolToScrollBarVisibilityConverter(); public static readonly IValueConverter UiExtensionToControlConverter = new UiExtensionToControlConverter(); + public static readonly IMultiValueConverter DocumentUiExtensionConverter = new DocumentUiExtensionConverter(); public static readonly IValueConverter ComparisonConverter = new ComparisonConverter(); public static readonly IValueConverter EnumToStringConverter = new EnumToStringConverter(); public static readonly IValueConverter FileOpacityConverter = new FileOpacityConverter(); diff --git a/src/OneWare.Essentials/Models/DocumentUiExtension.cs b/src/OneWare.Essentials/Models/DocumentUiExtension.cs new file mode 100644 index 0000000..1bb769f --- /dev/null +++ b/src/OneWare.Essentials/Models/DocumentUiExtension.cs @@ -0,0 +1,8 @@ +namespace OneWare.Essentials.Models; + +public class DocumentUiExtension(Type type, Func createDataContext) +{ + public Type Type { get; } = type; + + public Func CreateDataContext { get; } = createDataContext; +} \ No newline at end of file diff --git a/src/OneWare.Essentials/OneWare.Essentials.csproj b/src/OneWare.Essentials/OneWare.Essentials.csproj index 455bf28..28a4113 100644 --- a/src/OneWare.Essentials/OneWare.Essentials.csproj +++ b/src/OneWare.Essentials/OneWare.Essentials.csproj @@ -36,5 +36,12 @@ + + + + DocumentUiExtensionCollection.axaml + Code + + diff --git a/src/OneWare.Essentials/Services/IDockService.cs b/src/OneWare.Essentials/Services/IDockService.cs index 197d227..d82ccfa 100644 --- a/src/OneWare.Essentials/Services/IDockService.cs +++ b/src/OneWare.Essentials/Services/IDockService.cs @@ -1,3 +1,4 @@ +using System.Collections.ObjectModel; using System.ComponentModel; using Avalonia.Controls; using Dock.Model.Core; @@ -18,6 +19,10 @@ public interface IDockService : INotifyPropertyChanged public void RegisterDocumentView(params string[] extensions) where T : IExtendedDocument; + public ObservableCollection GetDocumentViewExtensions(string key); + + public void RegisterDocumentViewExtension(string key, Func createDataContext); + public void RegisterLayoutExtension(DockShowLocation location); public void Show(DockShowLocation location = DockShowLocation.Window) where T : IDockable;