Skip to content

Commit

Permalink
Update to latest Modern.WindowKit changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpobst committed Jul 28, 2023
1 parent ab48667 commit 9489248
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 17 deletions.
6 changes: 6 additions & 0 deletions Modern.Forms.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{8A64
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Outlaw", "samples\Outlaw\Outlaw.csproj", "{A297D354-FD20-43CD-9858-81B8794A6C3B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Modern.WindowKit", "..\Modern.WindowKit\src\Modern.WindowKit\Modern.WindowKit.csproj", "{D13DF7AB-FA51-4FC9-AA95-E4FA0402799C}"
EndProject
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -49,6 +51,10 @@ Global
{A297D354-FD20-43CD-9858-81B8794A6C3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A297D354-FD20-43CD-9858-81B8794A6C3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A297D354-FD20-43CD-9858-81B8794A6C3B}.Release|Any CPU.Build.0 = Release|Any CPU
{D13DF7AB-FA51-4FC9-AA95-E4FA0402799C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D13DF7AB-FA51-4FC9-AA95-E4FA0402799C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D13DF7AB-FA51-4FC9-AA95-E4FA0402799C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D13DF7AB-FA51-4FC9-AA95-E4FA0402799C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
9 changes: 5 additions & 4 deletions src/Modern.Forms/Extensions/WindowKitExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using Modern.WindowKit.Input;
using Modern.WindowKit.Platform.Storage;
using Modern.WindowKit.Platform.Storage.FileIO;

namespace Modern.Forms
{
Expand All @@ -25,16 +26,16 @@ public static Keys AddModifiers (Keys keys, RawInputModifiers modifiers)

public static string? GetFullPath (this IStorageFile file)
{
if (file.TryGetUri (out var uri))
return Path.GetFullPath (uri.LocalPath);
if (file is BclStorageFile path)
return path.FileInfo.FullName;

return null;
}

public static string? GetFullPath (this IStorageFolder file)
{
if (file.TryGetUri (out var uri))
return Path.GetFullPath (uri.LocalPath);
if (file is BclStorageFolder path)
return path.DirectoryInfo.FullName;

return null;
}
Expand Down
14 changes: 14 additions & 0 deletions src/Modern.Forms/FileSystemDialog.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.IO;
using Modern.WindowKit.Platform.Storage.FileIO;

namespace Modern.Forms
{
Expand All @@ -16,5 +18,17 @@ public abstract class FileSystemDialog
/// Gets or sets the title for the dialog.
/// </summary>
public string Title { get; set; } = string.Empty;

internal BclStorageFolder? GetInitialDirectory ()
{
if (InitialDirectory is not null) {
var dir_info = new DirectoryInfo (InitialDirectory);

if (dir_info.Exists)
return new BclStorageFolder (dir_info);
}

return null;
}
}
}
9 changes: 5 additions & 4 deletions src/Modern.Forms/FolderBrowserDialog.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Modern.WindowKit.Controls.Platform;
Expand All @@ -24,16 +25,16 @@ public class FolderBrowserDialog : FileSystemDialog
/// <param name="owner">The window that owns this dialog.</param>
public async Task<DialogResult> ShowDialog (Form owner)
{
if (owner.window is ITopLevelImplWithStorageProvider parent) {
if (owner.window.TryGetFeature (typeof (IStorageProvider)) is IStorageProvider parent) {
var options = new FolderPickerOpenOptions {
AllowMultiple = false,
SuggestedStartLocation = InitialDirectory is not null ? new BclStorageFolder (InitialDirectory) : null,
SuggestedStartLocation = GetInitialDirectory (),
Title = Title
};

var result = await parent.StorageProvider.OpenFolderPickerAsync (options);
var result = await parent.OpenFolderPickerAsync (options);

var paths = result.Select (f => f.GetFullPath ()).WhereNotNull ();
var paths = result.Select (f => f.GetFullPath ()).WhereNotNull ();

SelectedPath = paths?.FirstOrDefault ();

Expand Down
2 changes: 1 addition & 1 deletion src/Modern.Forms/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Form () : base (AvaloniaGlobals.GetRequiredService<IWindowingPlatform> ()
Window.SetSystemDecorations (SystemDecorations.None);
Window.SetExtendClientAreaToDecorationsHint (true);

Window.Closing = () => {
Window.Closing = (e) => {
var args = new CancelEventArgs ();
OnClosing (args);
Expand Down
5 changes: 4 additions & 1 deletion src/Modern.Forms/Modern.Forms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
<PackageReference Include="HarfBuzzSharp" Version="2.8.2.1" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="2.8.2.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Modern.WindowKit" Version="[0.4.0-alpha01]" />
<PackageReference Include="Topten.RichTextKit" Version="0.4.151" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Modern.WindowKit\src\Modern.WindowKit\Modern.WindowKit.csproj" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions src/Modern.Forms/OpenFileDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public class OpenFileDialog : FileDialog
/// <param name="owner">The window that owns this dialog.</param>
public async Task<DialogResult> ShowDialog (Form owner)
{
if (owner.window is ITopLevelImplWithStorageProvider parent) {
if (owner.window.TryGetFeature (typeof (IStorageProvider)) is IStorageProvider parent) {
var options = new FilePickerOpenOptions {
AllowMultiple = AllowMultiple,
SuggestedStartLocation = InitialDirectory is not null ? new BclStorageFolder (InitialDirectory) : null,
SuggestedStartLocation = GetInitialDirectory (),
Title = Title,
FileTypeFilter = filters
};

var result = await parent.StorageProvider.OpenFilePickerAsync (options);
var result = await parent.OpenFilePickerAsync (options);

FileNames.Clear ();

Expand Down
6 changes: 3 additions & 3 deletions src/Modern.Forms/SaveFileDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ public class SaveFileDialog : FileDialog
/// <param name="owner">The window that owns this dialog.</param>
public async Task<DialogResult> ShowDialog (Form owner)
{
if (owner.window is ITopLevelImplWithStorageProvider parent) {
if (owner.window.TryGetFeature (typeof (IStorageProvider)) is IStorageProvider parent) {
var options = new FilePickerSaveOptions {
DefaultExtension= DefaultExtension,
SuggestedStartLocation = InitialDirectory is not null ? new BclStorageFolder (InitialDirectory) : null,
SuggestedStartLocation = GetInitialDirectory (),
SuggestedFileName = FileName,
Title = Title,
FileTypeChoices = filters
};

var result = await parent.StorageProvider.SaveFilePickerAsync (options);
var result = await parent.SaveFilePickerAsync (options);

FileNames.Clear ();

Expand Down
2 changes: 1 addition & 1 deletion src/Modern.Forms/WindowBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ protected virtual void OnPaintBackground (PaintEventArgs e)
e.Canvas.DrawBackground (Bounds, CurrentStyle);
}

private void OnResize (Size size, PlatformResizeReason reason)
private void OnResize (Size size, WindowResizeReason reason)
{
adapter.SetBounds (DisplayRectangle.Left, DisplayRectangle.Top, Size.Width, Size.Height);
}
Expand Down

0 comments on commit 9489248

Please sign in to comment.