mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-20 09:16:01 +08:00
Improve rename popup (#256)
This commit is contained in:
parent
a1cf78d3fb
commit
4c6d22a152
@ -1,9 +1,11 @@
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace XNodeEditor {
|
namespace XNodeEditor {
|
||||||
/// <summary> Utility for renaming assets </summary>
|
/// <summary> Utility for renaming assets </summary>
|
||||||
public class RenamePopup : EditorWindow {
|
public class RenamePopup : EditorWindow {
|
||||||
|
private const string inputControlName = "nameInput";
|
||||||
|
|
||||||
public static RenamePopup current { get; private set; }
|
public static RenamePopup current { get; private set; }
|
||||||
public Object target;
|
public Object target;
|
||||||
public string input;
|
public string input;
|
||||||
@ -19,7 +21,6 @@ namespace XNodeEditor {
|
|||||||
window.input = target.name;
|
window.input = target.name;
|
||||||
window.minSize = new Vector2(100, 44);
|
window.minSize = new Vector2(100, 44);
|
||||||
window.position = new Rect(0, 0, width, 44);
|
window.position = new Rect(0, 0, width, 44);
|
||||||
GUI.FocusControl("ClearAllFocus");
|
|
||||||
window.UpdatePositionToMouse();
|
window.UpdatePositionToMouse();
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
@ -43,7 +44,9 @@ namespace XNodeEditor {
|
|||||||
UpdatePositionToMouse();
|
UpdatePositionToMouse();
|
||||||
firstFrame = false;
|
firstFrame = false;
|
||||||
}
|
}
|
||||||
|
GUI.SetNextControlName(inputControlName);
|
||||||
input = EditorGUILayout.TextField(input);
|
input = EditorGUILayout.TextField(input);
|
||||||
|
EditorGUI.FocusTextInControl(inputControlName);
|
||||||
Event e = Event.current;
|
Event e = Event.current;
|
||||||
// If input is empty, revert name to default instead
|
// If input is empty, revert name to default instead
|
||||||
if (input == null || input.Trim() == "") {
|
if (input == null || input.Trim() == "") {
|
||||||
@ -67,6 +70,14 @@ namespace XNodeEditor {
|
|||||||
target.TriggerOnValidate();
|
target.TriggerOnValidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.isKey && e.keyCode == KeyCode.Escape) {
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDestroy() {
|
||||||
|
EditorGUIUtility.editingTextField = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user