Merge Common to Desktop
This commit is contained in:
parent
26915defe1
commit
e9c6e14965
40 changed files with 447 additions and 282 deletions
13
app/InkForge.Desktop/Services/DialogHelper.cs
Normal file
13
app/InkForge.Desktop/Services/DialogHelper.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using Avalonia.Platform.Storage;
|
||||
|
||||
namespace InkForge.Desktop.Services;
|
||||
|
||||
public static class StorageProviderExtensions
|
||||
{
|
||||
public static IStorageProvider? GetStorageProvider(this object? context)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
|
||||
return TopLevels.GetTopLevelForContext(context)?.StorageProvider;
|
||||
}
|
||||
}
|
||||
54
app/InkForge.Desktop/Services/TopLevels.cs
Normal file
54
app/InkForge.Desktop/Services/TopLevels.cs
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
|
||||
namespace InkForge.Desktop.Services;
|
||||
|
||||
public class TopLevels
|
||||
{
|
||||
public static readonly AttachedProperty<object?> RegisterProperty
|
||||
= AvaloniaProperty.RegisterAttached<TopLevels, Visual, object?>("Register");
|
||||
|
||||
private static readonly Dictionary<object, Visual> RegistrationMapper = [];
|
||||
|
||||
static TopLevels()
|
||||
{
|
||||
RegisterProperty.Changed.AddClassHandler<Visual>(RegisterChanged);
|
||||
}
|
||||
|
||||
public static object? GetRegister(AvaloniaObject element)
|
||||
{
|
||||
return element.GetValue(RegisterProperty);
|
||||
}
|
||||
|
||||
public static TopLevel? GetTopLevelForContext(object context)
|
||||
{
|
||||
return TopLevel.GetTopLevel(GetVisualForContext(context));
|
||||
}
|
||||
|
||||
public static Visual? GetVisualForContext(object context)
|
||||
{
|
||||
return RegistrationMapper.TryGetValue(context, out var result) ? result : null;
|
||||
}
|
||||
|
||||
public static void SetRegister(AvaloniaObject element, object value)
|
||||
{
|
||||
element.SetValue(RegisterProperty, value);
|
||||
}
|
||||
|
||||
private static void RegisterChanged(Visual sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(sender);
|
||||
|
||||
// Unregister any old registered context
|
||||
if (e.OldValue != null)
|
||||
{
|
||||
RegistrationMapper.Remove(e.OldValue);
|
||||
}
|
||||
|
||||
// Register any new context
|
||||
if (e.NewValue != null)
|
||||
{
|
||||
RegistrationMapper.Add(e.NewValue, sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
6
app/InkForge.Desktop/Services/WorkspaceContext.cs
Normal file
6
app/InkForge.Desktop/Services/WorkspaceContext.cs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
namespace InkForge.Desktop.Services;
|
||||
|
||||
public class WorkspaceContext
|
||||
{
|
||||
public string DbPath { get; set; }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue