Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 12 additions & 28 deletions Prowl.Editor/Core/EditorApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ public override void Initialize()
}
if (EditorSceneManager.Save())
return Loc.Get("save.scene", new { name = Runtime.Resources.Scene.Current?.Name ?? "Untitled" });

// No path yet - prompt for one, but never interrupt an unattended auto-save.
if (!SaveManager.IsAutoSave)
PromptSaveAs();
return null;
};
SaveManager.OnSave += () =>
Expand Down Expand Up @@ -1308,6 +1312,7 @@ public void OpenPanelInstance(DockPanel panel, float width = 800, float height =
/// </summary>
public bool IsPanelOpen(Type panelType) => FindOpenPanel(panelType) != null;

/// <summary>Prompt for a scene file path and save the current scene there.</summary>
private void PromptSaveAs()
{
if (Project.Current == null) return;
Expand All @@ -1317,9 +1322,12 @@ private void PromptSaveAs()
string rel = EditorAssetDatabase.NormalizePath(
System.IO.Path.GetRelativePath(Project.Current.AssetsPath, path));
if (!rel.EndsWith(".scene")) rel += ".scene";
EditorSceneManager.SaveAs(rel);

if (EditorSceneManager.SaveAs(rel))
Toasts.Success(Loc.Get("save.saved"),
Loc.Get("save.scene", new { name = Runtime.Resources.Scene.Current?.Name ?? "Untitled" }));
}, Project.Current.AssetsPath,
new[] { "*.scene" }, new[] { "Scene Files (*.scene)" });
new[] { "*.scene" }, new[] { Loc.Get("editor.filter_scene") });
}

// ================================================================
Expand Down Expand Up @@ -1348,33 +1356,9 @@ private void RegisterMenus()
MenuRegistry.Register($"{file}/{Loc.Get("menu.file.save_scene")}", () =>
{
if (!EditorSceneManager.Save())
{
// No path yet prompt Save As
if (Project.Current == null) return;
EditorApplication.OpenFileDialog(FileDialogMode.Save, path =>
{
if (path == null || Project.Current == null) return;
string rel = EditorAssetDatabase.NormalizePath(
System.IO.Path.GetRelativePath(Project.Current.AssetsPath, path));
if (!rel.EndsWith(".scene")) rel += ".scene";
EditorSceneManager.SaveAs(rel);
}, Project.Current.AssetsPath,
new[] { "*.scene" }, new[] { Loc.Get("editor.filter_scene") });
}
});
MenuRegistry.Register($"{file}/{Loc.Get("menu.file.save_scene_as")}", () =>
{
if (Project.Current == null) return;
EditorApplication.OpenFileDialog(FileDialogMode.Save, path =>
{
if (path == null || Project.Current == null) return;
string rel = EditorAssetDatabase.NormalizePath(
System.IO.Path.GetRelativePath(Project.Current.AssetsPath, path));
if (!rel.EndsWith(".scene")) rel += ".scene";
EditorSceneManager.SaveAs(rel);
}, Project.Current.AssetsPath,
new[] { "*.scene" }, new[] { Loc.Get("editor.filter_scene") });
PromptSaveAs();
});
MenuRegistry.Register($"{file}/{Loc.Get("menu.file.save_scene_as")}", () => PromptSaveAs());
MenuRegistry.RegisterSeparator(file);
MenuRegistry.Register($"{file}/{Loc.Get("menu.file.open_project")}", () => ReturnToLauncher());
MenuRegistry.RegisterSeparator(file);
Expand Down
8 changes: 8 additions & 0 deletions Prowl.Editor/Projects/SaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public static class SaveManager
/// <summary>Whether auto-save is enabled.</summary>
public static bool AutoSaveEnabled = true;

/// <summary>
/// True while <see cref="OnSave"/> handlers are running as part of an auto-save rather than a
/// manual Ctrl+S. Handlers should check this before showing user-facing prompts (e.g. a Save As
/// dialog for a never-saved scene) - auto-save must never interrupt the user unattended.
/// </summary>
public static bool IsAutoSave { get; private set; }

private static double _timeSinceLastSave;
private static bool _saveRequestedThisFrame;

Expand Down Expand Up @@ -82,6 +89,7 @@ public static void RequestSave(bool isAutoSave = false)
if (_saveRequestedThisFrame) return;
_saveRequestedThisFrame = true;
_timeSinceLastSave = 0;
IsAutoSave = isAutoSave;

if (OnSave == null) return;

Expand Down
Loading