Skip to content

Commit

Permalink
refactor: don't directly call the win32 open/savedialog impls.
Browse files Browse the repository at this point in the history
instead call them through a "cross-platform" wrapper.
  • Loading branch information
purifetchi committed Dec 13, 2022
1 parent 024c82e commit e2039b3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
38 changes: 38 additions & 0 deletions VTTiny/Editor/Native/FileDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace VTTiny.Editor.Native
{
/// <summary>
/// This is the multiplatform wrapper for the open/save file dialog functionality.
/// It just calls back into the platform-specific implementations.
///
/// NOTE: So far the only FileDialog implementation we have is for Win32.
/// PRs to improve that are welcome.
/// </summary>
public static class FileDialog
{
/// <summary>
/// Show an open file dialog.
/// </summary>
/// <returns>The path to the opened file, or nothing.</returns>
public static string OpenFile()
{
#if ARCH_WINDOWS
return Win32.FileDialog.OpenFile();
#else
throw new System.NotImplementedException($"OpenFile() is not yet supported on {System.Runtime.InteropServices.RuntimeInformation.OSDescription}!");
#endif
}

/// <summary>
/// Show a save file dialog.
/// </summary>
/// <returns>The path to the saved file, or nothing.</returns>
public static string SaveFile()
{
#if ARCH_WINDOWS
return Win32.FileDialog.SaveFile();
#else
throw new System.NotImplementedException($"SaveFile() is not yet supported on {System.Runtime.InteropServices.RuntimeInformation.OSDescription}!");
#endif
}
}
}
5 changes: 1 addition & 4 deletions VTTiny/Editor/Native/Win32/FileDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ namespace VTTiny.Editor.Native.Win32
{
/// <summary>
/// This class wraps the Win32 methods for opening open/save file dialog boxes.
///
/// NOTE: So far this is the only FileDialog implementation we have, it'd be nice to have more cross platform solutions.
/// PRs welcome.
/// </summary>
public static class FileDialog
internal static class FileDialog
{
private const string COMDLG_LIBRARY_NAME = "comdlg32";

Expand Down
2 changes: 1 addition & 1 deletion VTTiny/Editor/UI/Menu/FileMenuCategory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using VTTiny.Editor.Native.Win32;
using VTTiny.Editor.Native;
using VTTiny.Scenery;

namespace VTTiny.Editor.UI
Expand Down
13 changes: 13 additions & 0 deletions VTTiny/VTTiny.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
<TargetFramework>net6.0</TargetFramework>
<Authors>prefetcher</Authors>
<Product />
<IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindows>
<IsMacOS Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsMacOS>
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
</PropertyGroup>

<PropertyGroup Condition="'$(IsWindows)'=='true'">
<DefineConstants>ARCH_WINDOWS</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(IsMacOS)'=='true'">
<DefineConstants>ARCH_MACOS</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(IsLinux)'=='true'">
<DefineConstants>ARCH_LINUX</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down

0 comments on commit e2039b3

Please sign in to comment.