This repository has been archived by the owner on Jul 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b3a2e1
commit 1c0439d
Showing
10 changed files
with
134 additions
and
16 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/OneWare.Essentials/Controls/DocumentUiExtensionCollection.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<Styles xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:controls="using:OneWare.Essentials.Controls" | ||
xmlns:converters="clr-namespace:OneWare.Essentials.Converters" | ||
xmlns:models="clr-namespace:OneWare.Essentials.Models"> | ||
<Design.PreviewWith> | ||
<controls:DocumentUiExtensionCollection /> | ||
</Design.PreviewWith> | ||
|
||
<Style Selector="controls|DocumentUiExtensionCollection"> | ||
<!-- Set Defaults --> | ||
<Setter Property="Template"> | ||
<ControlTemplate> | ||
<ItemsControl ItemsSource="{TemplateBinding Extensions}"> | ||
<ItemsControl.ItemsPanel> | ||
<ItemsPanelTemplate> | ||
<DockPanel HorizontalAlignment="{TemplateBinding HorizontalAlignment}"/> | ||
</ItemsPanelTemplate> | ||
</ItemsControl.ItemsPanel> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate x:DataType="models:DocumentUiExtension"> | ||
<ContentControl> | ||
<ContentControl.Content> | ||
<MultiBinding Converter="{x:Static converters:SharedConverters.DocumentUiExtensionConverter}"> | ||
<Binding Path="$parent[controls:DocumentUiExtensionCollection].File"/> | ||
<Binding Path="."/> | ||
</MultiBinding> | ||
</ContentControl.Content> | ||
</ContentControl> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
</ItemsControl> | ||
</ControlTemplate> | ||
</Setter> | ||
</Style> | ||
</Styles> |
40 changes: 40 additions & 0 deletions
40
src/OneWare.Essentials/Controls/DocumentUiExtensionCollection.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IFile?> FileProperty = | ||
AvaloniaProperty.Register<DocumentUiExtensionCollection, IFile?>(nameof(File)); | ||
|
||
public static readonly StyledProperty<ObservableCollection<DocumentUiExtension>?> ExtensionsProperty = | ||
AvaloniaProperty.Register<DocumentUiExtensionCollection, ObservableCollection<DocumentUiExtension>?>(nameof(Extensions)); | ||
|
||
public static readonly StyledProperty<Orientation> OrientationProperty = | ||
AvaloniaProperty.Register<DocumentUiExtensionCollection, Orientation>(nameof(Orientation)); | ||
|
||
protected override Type StyleKeyOverride => typeof(DocumentUiExtensionCollection); | ||
|
||
public IFile? File | ||
{ | ||
get => GetValue(FileProperty); | ||
set => SetValue(FileProperty, value); | ||
} | ||
|
||
public ObservableCollection<DocumentUiExtension>? Extensions | ||
{ | ||
get => GetValue(ExtensionsProperty); | ||
set => SetValue(ExtensionsProperty, value); | ||
} | ||
|
||
public Orientation Orientation | ||
{ | ||
get => GetValue(OrientationProperty); | ||
set => SetValue(OrientationProperty, value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/OneWare.Essentials/Converters/DocumentUiExtensionConverter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<object?> 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace OneWare.Essentials.Models; | ||
|
||
public class DocumentUiExtension(Type type, Func<IFile, object?> createDataContext) | ||
{ | ||
public Type Type { get; } = type; | ||
|
||
public Func<IFile, object?> CreateDataContext { get; } = createDataContext; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters