1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 01:06:01 +08:00

Improve rename popup (#256)

This commit is contained in:
Romain Théry 2020-05-07 10:21:39 +02:00 committed by GitHub
parent a1cf78d3fb
commit 4c6d22a152
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,11 @@
using UnityEditor;
using UnityEditor;
using UnityEngine;
namespace XNodeEditor {
/// <summary> Utility for renaming assets </summary>
public class RenamePopup : EditorWindow {
private const string inputControlName = "nameInput";
public static RenamePopup current { get; private set; }
public Object target;
public string input;
@ -19,7 +21,6 @@ namespace XNodeEditor {
window.input = target.name;
window.minSize = new Vector2(100, 44);
window.position = new Rect(0, 0, width, 44);
GUI.FocusControl("ClearAllFocus");
window.UpdatePositionToMouse();
return window;
}
@ -43,7 +44,9 @@ namespace XNodeEditor {
UpdatePositionToMouse();
firstFrame = false;
}
GUI.SetNextControlName(inputControlName);
input = EditorGUILayout.TextField(input);
EditorGUI.FocusTextInControl(inputControlName);
Event e = Event.current;
// If input is empty, revert name to default instead
if (input == null || input.Trim() == "") {
@ -67,6 +70,14 @@ namespace XNodeEditor {
target.TriggerOnValidate();
}
}
if (e.isKey && e.keyCode == KeyCode.Escape) {
Close();
}
}
private void OnDestroy() {
EditorGUIUtility.editingTextField = false;
}
}
}