add appstate
This commit is contained in:
19
src/SharpIDE.Godot/Features/IdeSettings/AppState.cs
Normal file
19
src/SharpIDE.Godot/Features/IdeSettings/AppState.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
namespace SharpIDE.Godot.Features.IdeSettings;
|
||||||
|
|
||||||
|
public class AppState
|
||||||
|
{
|
||||||
|
public string? LastOpenSolutionFilePath { get; set; }
|
||||||
|
public IdeSettings IdeSettings { get; set; } = new IdeSettings();
|
||||||
|
public List<PreviouslyOpenedSln> PreviouslyOpenedSolutions { get; set; } = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public class IdeSettings
|
||||||
|
{
|
||||||
|
public bool AutoOpenLastSolution { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PreviouslyOpenedSln
|
||||||
|
{
|
||||||
|
public required string Name { get; set; }
|
||||||
|
public required string FilePath { get; set; }
|
||||||
|
}
|
||||||
1
src/SharpIDE.Godot/Features/IdeSettings/AppState.cs.uid
Normal file
1
src/SharpIDE.Godot/Features/IdeSettings/AppState.cs.uid
Normal file
@@ -0,0 +1 @@
|
|||||||
|
uid://ccsfv10f1lhxd
|
||||||
39
src/SharpIDE.Godot/Features/IdeSettings/AppStateLoader.cs
Normal file
39
src/SharpIDE.Godot/Features/IdeSettings/AppStateLoader.cs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using Ardalis.GuardClauses;
|
||||||
|
|
||||||
|
namespace SharpIDE.Godot.Features.IdeSettings;
|
||||||
|
|
||||||
|
public static class AppStateLoader
|
||||||
|
{
|
||||||
|
private static string GetConfigFilePath()
|
||||||
|
{
|
||||||
|
var folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
||||||
|
var configFolder = Path.Combine(folder, "SharpIDE");
|
||||||
|
Directory.CreateDirectory(configFolder);
|
||||||
|
var configFilePath = Path.Combine(configFolder, "sharpIde.json");
|
||||||
|
return configFilePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AppState LoadAppStateFromConfigFile()
|
||||||
|
{
|
||||||
|
var configFilePath = GetConfigFilePath();
|
||||||
|
if (File.Exists(configFilePath) is false)
|
||||||
|
{
|
||||||
|
File.WriteAllText(configFilePath, "{}");
|
||||||
|
}
|
||||||
|
|
||||||
|
using var stream = File.OpenRead(configFilePath);
|
||||||
|
var deserializedAppState = JsonSerializer.Deserialize<AppState>(stream);
|
||||||
|
Guard.Against.Null(deserializedAppState, nameof(deserializedAppState));
|
||||||
|
|
||||||
|
return deserializedAppState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SaveAppStateToConfigFile(AppState appState)
|
||||||
|
{
|
||||||
|
var configFilePath = GetConfigFilePath();
|
||||||
|
using var stream = File.Create(configFilePath);
|
||||||
|
JsonSerializer.Serialize(stream, appState);
|
||||||
|
stream.Flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://dnu6x5m37dapi
|
||||||
@@ -2,6 +2,7 @@ using Godot;
|
|||||||
using Microsoft.Build.Locator;
|
using Microsoft.Build.Locator;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using SharpIDE.Application.Features.Events;
|
using SharpIDE.Application.Features.Events;
|
||||||
|
using SharpIDE.Godot.Features.IdeSettings;
|
||||||
using SharpIDE.Godot.Features.SlnPicker;
|
using SharpIDE.Godot.Features.SlnPicker;
|
||||||
|
|
||||||
namespace SharpIDE.Godot;
|
namespace SharpIDE.Godot;
|
||||||
@@ -25,19 +26,21 @@ public partial class IdeWindow : Control
|
|||||||
ResourceLoader.LoadThreadedRequest(IdeRootScenePath);
|
ResourceLoader.LoadThreadedRequest(IdeRootScenePath);
|
||||||
MSBuildLocator.RegisterDefaults();
|
MSBuildLocator.RegisterDefaults();
|
||||||
GodotServiceDefaults.AddServiceDefaults();
|
GodotServiceDefaults.AddServiceDefaults();
|
||||||
|
Singletons.AppState = AppStateLoader.LoadAppStateFromConfigFile();
|
||||||
//GetWindow().SetMinSize(new Vector2I(1152, 648));
|
//GetWindow().SetMinSize(new Vector2I(1152, 648));
|
||||||
Callable.From(() => PickSolution(true)).CallDeferred();
|
Callable.From(() => PickSolution(true)).CallDeferred();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public override void _ExitTree()
|
public override void _ExitTree()
|
||||||
// {
|
{
|
||||||
// GodotGlobalEvents.Instance = null!;
|
AppStateLoader.SaveAppStateToConfigFile(Singletons.AppState);
|
||||||
// GlobalEvents.Instance = null!;
|
// GodotGlobalEvents.Instance = null!;
|
||||||
// GC.Collect();
|
// GlobalEvents.Instance = null!;
|
||||||
// GC.WaitForPendingFinalizers();
|
// GC.Collect();
|
||||||
// GC.Collect();
|
// GC.WaitForPendingFinalizers();
|
||||||
// PrintOrphanNodes();
|
// GC.Collect();
|
||||||
// }
|
// PrintOrphanNodes();
|
||||||
|
}
|
||||||
|
|
||||||
public void PickSolution(bool fullscreen = false)
|
public void PickSolution(bool fullscreen = false)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using SharpIDE.Application.Features.Build;
|
using SharpIDE.Application.Features.Build;
|
||||||
using SharpIDE.Application.Features.Run;
|
using SharpIDE.Application.Features.Run;
|
||||||
|
using SharpIDE.Godot.Features.IdeSettings;
|
||||||
|
|
||||||
namespace SharpIDE.Godot;
|
namespace SharpIDE.Godot;
|
||||||
|
|
||||||
@@ -7,4 +8,5 @@ public static class Singletons
|
|||||||
{
|
{
|
||||||
public static RunService RunService { get; } = new RunService();
|
public static RunService RunService { get; } = new RunService();
|
||||||
public static BuildService BuildService { get; } = new BuildService();
|
public static BuildService BuildService { get; } = new BuildService();
|
||||||
|
public static AppState AppState { get; set; } = null!;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user