-
Notifications
You must be signed in to change notification settings - Fork 332
FIX: Editor closes when clicking cancel in a save dialog prompt (UUM-134748) #2366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
8e497fb
06864e1
c27e8ca
e0c04bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |||||||||
|
|
||||||||||
| private string m_AssetJson; | ||||||||||
| private bool m_IsDirty; | ||||||||||
| private bool m_IsEditorQuitting; | ||||||||||
|
|
||||||||||
| private StateContainer m_StateContainer; | ||||||||||
| private InputActionsEditorView m_View; | ||||||||||
|
|
@@ -316,11 +317,21 @@ | |||||||||
| private void OnEnable() | ||||||||||
| { | ||||||||||
| analytics.Begin(); | ||||||||||
| EditorApplication.wantsToQuit += OnWantsToQuit; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private void OnDisable() | ||||||||||
| { | ||||||||||
| analytics.End(); | ||||||||||
| EditorApplication.wantsToQuit -= OnWantsToQuit; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private bool OnWantsToQuit() | ||||||||||
| { | ||||||||||
|
Check warning on line 330 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs
|
||||||||||
| // Here the user will be prompted | ||||||||||
| bool isAllowedToQuit = HandleOnDestroyIfApplicationIsAllowedToQuit(false); | ||||||||||
| m_IsEditorQuitting = isAllowedToQuit; | ||||||||||
| return m_IsEditorQuitting; | ||||||||||
|
Check warning on line 334 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs
|
||||||||||
| } | ||||||||||
|
|
||||||||||
| private void OnFocus() | ||||||||||
|
|
@@ -345,39 +356,52 @@ | |||||||||
| analytics.RegisterEditorFocusOut(); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| private void HandleOnDestroy() | ||||||||||
| /// <summary> | ||||||||||
| /// Shows a dialog when trying to close an input asset without saving changes. | ||||||||||
| /// </summary> | ||||||||||
| /// <returns> Returns true if you should allow the Unity Editor to close. </returns> | ||||||||||
| private bool HandleOnDestroyIfApplicationIsAllowedToQuit(bool rebuildUIOnCancel) | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm having issue with the semantic mismatch of what the method is doing versus what it is returning. What about a change of signature:
Suggested change
Or
Suggested change
|
||||||||||
| { | ||||||||||
| // Do we have unsaved changes that we need to ask the user to save or discard? | ||||||||||
| if (!m_IsDirty) | ||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code could be simplify.
Suggested change
|
||||||||||
| return; | ||||||||||
| return true; | ||||||||||
|
|
||||||||||
| // Get target asset path from GUID, if this fails file no longer exists and we need to abort. | ||||||||||
| var assetPath = AssetDatabase.GUIDToAssetPath(m_AssetGUID); | ||||||||||
| if (string.IsNullOrEmpty(assetPath)) | ||||||||||
| return; | ||||||||||
| return true; | ||||||||||
|
Check warning on line 372 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs
|
||||||||||
|
|
||||||||||
| // Prompt user with a dialog | ||||||||||
| var result = Dialog.InputActionAsset.ShowSaveChanges(assetPath); | ||||||||||
| switch (result) | ||||||||||
| if (!m_IsEditorQuitting) | ||||||||||
| { | ||||||||||
| case Dialog.Result.Save: | ||||||||||
| Save(isAutoSave: false); | ||||||||||
| break; | ||||||||||
| case Dialog.Result.Cancel: | ||||||||||
| // Cancel editor quit. (open new editor window with the edited asset) | ||||||||||
| ReshowEditorWindowWithUnsavedChanges(); | ||||||||||
| break; | ||||||||||
| case Dialog.Result.Discard: | ||||||||||
| // Don't save, quit - reload the old asset from the json to prevent the asset from being dirtied | ||||||||||
| break; | ||||||||||
| default: | ||||||||||
| throw new ArgumentOutOfRangeException(nameof(result)); | ||||||||||
| // Prompt user with a dialog | ||||||||||
| var result = Dialog.InputActionAsset.ShowSaveChanges(assetPath); | ||||||||||
| switch (result) | ||||||||||
| { | ||||||||||
| case Dialog.Result.Save: | ||||||||||
| Save(isAutoSave: false); | ||||||||||
| return true; | ||||||||||
|
Check warning on line 382 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs
|
||||||||||
| case Dialog.Result.Cancel: | ||||||||||
| if (rebuildUIOnCancel) | ||||||||||
| { | ||||||||||
|
Check warning on line 385 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs
|
||||||||||
| // Cancel editor quit. (open new editor window with the edited asset) | ||||||||||
| ReshowEditorWindowWithUnsavedChanges(); | ||||||||||
| } | ||||||||||
|
Check warning on line 388 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs
|
||||||||||
|
|
||||||||||
| return false; | ||||||||||
|
Check warning on line 390 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs
|
||||||||||
| case Dialog.Result.Discard: | ||||||||||
| // Don't save, quit - reload the old asset from the json to prevent the asset from being dirtied | ||||||||||
| return true; | ||||||||||
| default: | ||||||||||
| throw new ArgumentOutOfRangeException(nameof(result)); | ||||||||||
|
Check warning on line 395 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs
|
||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return true; | ||||||||||
|
Check warning on line 399 in Packages/com.unity.inputsystem/InputSystem/Editor/UITKAssetEditor/InputActionsEditorWindow.cs
|
||||||||||
| } | ||||||||||
|
|
||||||||||
| private void OnDestroy() | ||||||||||
| { | ||||||||||
| HandleOnDestroy(); | ||||||||||
| HandleOnDestroyIfApplicationIsAllowedToQuit(true); | ||||||||||
|
|
||||||||||
| // Clean-up | ||||||||||
| CleanupStateContainer(); | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.