mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-05 04:48:19 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
using System.IO;
|
|
namespace Editor;
|
|
|
|
public static partial class EditorUtility
|
|
{
|
|
/// <summary>
|
|
/// Open a file save dialog. Returns null on cancel, else the absolute path of the target file.
|
|
/// </summary>
|
|
public static string SaveFileDialog( string title, string extension, string defaultPath )
|
|
{
|
|
extension = extension.Trim( '.' );
|
|
|
|
var path = defaultPath;
|
|
if ( path.Contains( "." ) ) path = Path.GetDirectoryName( path );
|
|
|
|
var fd = new FileDialog( null );
|
|
fd.Title = title;
|
|
fd.Directory = path;
|
|
fd.DefaultSuffix = $".{extension}";
|
|
fd.SelectFile( Path.GetFileName( defaultPath ) );
|
|
fd.SetFindFile();
|
|
fd.SetModeSave();
|
|
fd.SetNameFilter( $"{extension} (*.{extension})" );
|
|
|
|
if ( !fd.Execute() )
|
|
return null;
|
|
|
|
return fd.SelectedFile;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Open a file open dialog. Returns null on cancel, else the absolute path of the target file.
|
|
/// </summary>
|
|
public static string OpenFileDialog( string title, string extension, string defaultPath )
|
|
{
|
|
extension = extension.Trim( '.' );
|
|
|
|
var fd = new FileDialog( null );
|
|
fd.Title = title;
|
|
fd.Directory = Path.GetDirectoryName( defaultPath );
|
|
fd.DefaultSuffix = $".{extension}";
|
|
fd.SelectFile( Path.GetFileName( defaultPath ) );
|
|
fd.SetFindFile();
|
|
fd.SetModeOpen();
|
|
fd.SetNameFilter( $"{extension} (*.{extension})" );
|
|
|
|
if ( !fd.Execute() )
|
|
return null;
|
|
|
|
return fd.SelectedFile;
|
|
}
|
|
}
|