Files
sbox-public/engine/Sandbox.Tools/Qt/Window.Cookies.cs
Matt Stevens 18da35110c Qt Advanced Docking System (#4041)
* Add Qt-Advanced-Docking-System 5.0
* Bind new CDockManager, dock areas
* Use Valve's CSS & images for ADS as a baseline, load stuff from disk instead of embedded in c++
* dockmanager.css in tool styles, auto loads and hotloads
* Rewrite DockManager
* delete toolwindowmanager
* Delete the 50 different ways to create/add/register a dock, you just add a dock, that's all u need
* More dockmanager rejigging
* restore all editor dock layouts and asset browser on the new docking system
* remove last toolwindowmanager remnants, add ADS to third party legal notice
* build classic default layout in code for main editor reset/first-run, add relative area AddDock overload
* relativeTo placement API, restore correct default layouts for all tool windows, register [Dock] types closed instead of eagerly docking
* styling pass
* disable ADS built-in stylesheet load, styling comes from editor stylesheet
* lock picker browser tabs against closing/dragging, make ActionGraph reset layout actually reposition docks
* add DockManager.OpenDock, dedupe layout code in EditorMainWindow/ActionGraph
* CloseDockWidget internal
* add "Close Tabs to the Left/Right" to dock tab context menu
* expose dock MinimumSizeFromContent
* only offer close left/right tab options when open tabs exist on that side
* move "Close Tabs to the Left/Right" out of the ADS lib into a components factory
* guard dock tab context menu against pinned docks with no dock area
* fix crash when pinned tab is destroyed before delayed auto hide timer fires
* recreate scene widget swapchains when Qt recreates their native window on dock reparent
*  wrap all sbox changes to the dock lib in #ifdef SBOX
* save a plain window rect as fallback for when Qt rejects saved geometry on mixed-DPI monitors
* expose DockWidget Float/IsFloating
* always restore window geometry from a plain saved rect instead of Qt's DPI fragile geometry blob
* route all window centering through one screen aware helper that handles mixed DPI monitors
* restore window geometry onto the screen it was saved on
* don't close live docks when a dock type unregisters, hotload substitutes them in place

---------

Co-authored-by: Layla <1667289+aylaylay@users.noreply.github.com>
2026-07-12 12:41:08 +01:00

75 lines
2.2 KiB
C#

using Sandbox;
namespace Editor
{
public partial class Window
{
string _stateCookie;
/// <summary>
/// A unique identifier for this window, to store the window state across sessions using the <see cref="Cookie">Cookie</see> library.
/// </summary>
public string StateCookie
{
get => _stateCookie;
set
{
if ( _stateCookie == value ) return;
_stateCookie = value;
RestoreFromStateCookie();
}
}
/// <summary>
/// Called whenever the window should restore its state via the <see cref="EditorCookie">EditorCookie</see> library,
/// that was previously saved in <see cref="SaveToStateCookie"/>.<br/>
/// You should use <see cref="StateCookie"/> in the cookie name.
/// </summary>
public virtual void RestoreFromStateCookie()
{
if ( string.IsNullOrWhiteSpace( StateCookie ) )
return;
// We restore geometry from a plain rect we save ourselves - Qt's saved
// geometry blob rescales unpredictably across monitors with different DPI
if ( !EditorCookie.TryGet( $"Window.{StateCookie}.Rect", out Rect rect ) || !_widget.tryRestoreGeometry( rect ) )
{
Center();
}
if ( EditorCookie.Get( $"Window.{StateCookie}.Maximized", false ) )
SetMaximized( true );
var state = EditorCookie.GetString( $"Window.{StateCookie}.State", null );
if ( state != null ) RestoreState( state );
}
/// <summary>
/// Called whenever the window should save its state via the <see cref="EditorCookie">EditorCookie</see> library,
/// to be later restored in <see cref="RestoreFromStateCookie"/>. This is useful to carry data across game sessions.<br/>
/// You should use <see cref="StateCookie"/> in the cookie name.
/// </summary>
[Event( "app.exit" )]
public virtual void SaveToStateCookie()
{
if ( string.IsNullOrWhiteSpace( StateCookie ) )
return;
if ( !this.IsValid() )
return;
var state = SaveState();
EditorCookie.SetString( $"Window.{StateCookie}.State", state );
EditorCookie.Set( $"Window.{StateCookie}.Maximized", IsMaximized );
// Only when plain windowed, so the rect always holds the last normal geometry
if ( !IsMinimized && !IsMaximized )
{
EditorCookie.Set( $"Window.{StateCookie}.Rect", _widget.windowGeometry().Rect );
}
}
}
}