Skip to content

Commit c7b056a

Browse files
Merge pull request #294 from PaperPrototype/saving-new-project-untitled-scene
CTRL + S prompts saving default Untitled Scene in blank project
2 parents 038e451 + 5641cf3 commit c7b056a

2 files changed

Lines changed: 20 additions & 28 deletions

File tree

Prowl.Editor/Core/EditorApplication.cs

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,10 @@ public override void Initialize()
249249
}
250250
if (EditorSceneManager.Save())
251251
return Loc.Get("save.scene", new { name = Runtime.Resources.Scene.Current?.Name ?? "Untitled" });
252+
253+
// No path yet - prompt for one, but never interrupt an unattended auto-save.
254+
if (!SaveManager.IsAutoSave)
255+
PromptSaveAs();
252256
return null;
253257
};
254258
SaveManager.OnSave += () =>
@@ -1308,6 +1312,7 @@ public void OpenPanelInstance(DockPanel panel, float width = 800, float height =
13081312
/// </summary>
13091313
public bool IsPanelOpen(Type panelType) => FindOpenPanel(panelType) != null;
13101314

1315+
/// <summary>Prompt for a scene file path and save the current scene there.</summary>
13111316
private void PromptSaveAs()
13121317
{
13131318
if (Project.Current == null) return;
@@ -1317,9 +1322,12 @@ private void PromptSaveAs()
13171322
string rel = EditorAssetDatabase.NormalizePath(
13181323
System.IO.Path.GetRelativePath(Project.Current.AssetsPath, path));
13191324
if (!rel.EndsWith(".scene")) rel += ".scene";
1320-
EditorSceneManager.SaveAs(rel);
1325+
1326+
if (EditorSceneManager.SaveAs(rel))
1327+
Toasts.Success(Loc.Get("save.saved"),
1328+
Loc.Get("save.scene", new { name = Runtime.Resources.Scene.Current?.Name ?? "Untitled" }));
13211329
}, Project.Current.AssetsPath,
1322-
new[] { "*.scene" }, new[] { "Scene Files (*.scene)" });
1330+
new[] { "*.scene" }, new[] { Loc.Get("editor.filter_scene") });
13231331
}
13241332

13251333
// ================================================================
@@ -1348,33 +1356,9 @@ private void RegisterMenus()
13481356
MenuRegistry.Register($"{file}/{Loc.Get("menu.file.save_scene")}", () =>
13491357
{
13501358
if (!EditorSceneManager.Save())
1351-
{
1352-
// No path yet prompt Save As
1353-
if (Project.Current == null) return;
1354-
EditorApplication.OpenFileDialog(FileDialogMode.Save, path =>
1355-
{
1356-
if (path == null || Project.Current == null) return;
1357-
string rel = EditorAssetDatabase.NormalizePath(
1358-
System.IO.Path.GetRelativePath(Project.Current.AssetsPath, path));
1359-
if (!rel.EndsWith(".scene")) rel += ".scene";
1360-
EditorSceneManager.SaveAs(rel);
1361-
}, Project.Current.AssetsPath,
1362-
new[] { "*.scene" }, new[] { Loc.Get("editor.filter_scene") });
1363-
}
1364-
});
1365-
MenuRegistry.Register($"{file}/{Loc.Get("menu.file.save_scene_as")}", () =>
1366-
{
1367-
if (Project.Current == null) return;
1368-
EditorApplication.OpenFileDialog(FileDialogMode.Save, path =>
1369-
{
1370-
if (path == null || Project.Current == null) return;
1371-
string rel = EditorAssetDatabase.NormalizePath(
1372-
System.IO.Path.GetRelativePath(Project.Current.AssetsPath, path));
1373-
if (!rel.EndsWith(".scene")) rel += ".scene";
1374-
EditorSceneManager.SaveAs(rel);
1375-
}, Project.Current.AssetsPath,
1376-
new[] { "*.scene" }, new[] { Loc.Get("editor.filter_scene") });
1359+
PromptSaveAs();
13771360
});
1361+
MenuRegistry.Register($"{file}/{Loc.Get("menu.file.save_scene_as")}", () => PromptSaveAs());
13781362
MenuRegistry.RegisterSeparator(file);
13791363
MenuRegistry.Register($"{file}/{Loc.Get("menu.file.open_project")}", () => ReturnToLauncher());
13801364
MenuRegistry.RegisterSeparator(file);

Prowl.Editor/Projects/SaveManager.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ public static class SaveManager
3838
/// <summary>Whether auto-save is enabled.</summary>
3939
public static bool AutoSaveEnabled = true;
4040

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

@@ -82,6 +89,7 @@ public static void RequestSave(bool isAutoSave = false)
8289
if (_saveRequestedThisFrame) return;
8390
_saveRequestedThisFrame = true;
8491
_timeSinceLastSave = 0;
92+
IsAutoSave = isAutoSave;
8593

8694
if (OnSave == null) return;
8795

0 commit comments

Comments
 (0)