Files
sbox-public/engine/Sandbox.Tools/Editor/ProgressPopup/Progress.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

79 lines
1.3 KiB
C#

using System;
using System.Threading;
namespace Editor;
public static class Progress
{
static ProgressWindow currentWindow;
static int Popups;
class ProgressSection : IDisposable
{
bool disposed;
string oldTitle;
public ProgressSection( string name )
{
currentWindow ??= new ProgressWindow();
Popups++;
// save state
oldTitle = currentWindow.Window.WindowTitle;
// new state
currentWindow.Window.WindowTitle = name;
currentWindow.Show();
}
public void Dispose()
{
if ( disposed ) return;
disposed = true;
Popups--;
if ( Popups <= 0 )
{
Popups = 0;
currentWindow.Window.Destroy();
currentWindow = null;
}
else
{
// restore state
currentWindow.Window.WindowTitle = oldTitle;
}
}
}
public static IDisposable Start( string name )
{
return new ProgressSection( name );
}
public static void Update( string title, float current = 0, float total = 0 )
{
if ( currentWindow == null )
return;
currentWindow.TaskTitle = title;
currentWindow.ProgressCurrent = current;
currentWindow.ProgressTotal = total;
currentWindow.Update();
Application.Spin();
}
public static CancellationToken GetCancel()
{
if ( currentWindow == null )
return CancellationToken.None;
return currentWindow.GetCancel();
}
}