1
0
mirror of https://github.com/Siccity/xNode.git synced 2026-02-07 07:44:53 +08:00

Reformat RenamePopup.cs

Was inconsistently formatted as tabs instead of spaces
This commit is contained in:
Thor Brigsted 2019-06-26 10:13:12 +02:00
parent 55dddf8142
commit 4e1d9b6721

View File

@ -2,65 +2,65 @@
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 {
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;
private bool firstFrame = true; private bool firstFrame = true;
/// <summary> Show a rename popup for an asset at mouse position. Will trigger reimport of the asset on apply. /// <summary> Show a rename popup for an asset at mouse position. Will trigger reimport of the asset on apply.
public static RenamePopup Show(Object target, float width = 200) { public static RenamePopup Show(Object target, float width = 200) {
RenamePopup window = EditorWindow.GetWindow<RenamePopup>(true, "Rename " + target.name, true); RenamePopup window = EditorWindow.GetWindow<RenamePopup>(true, "Rename " + target.name, true);
if (current != null) current.Close(); if (current != null) current.Close();
current = window; current = window;
window.target = target; window.target = target;
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"); GUI.FocusControl("ClearAllFocus");
window.UpdatePositionToMouse(); window.UpdatePositionToMouse();
return window; return window;
} }
private void UpdatePositionToMouse() { private void UpdatePositionToMouse() {
if (Event.current == null) return; if (Event.current == null) return;
Vector3 mousePoint = GUIUtility.GUIToScreenPoint(Event.current.mousePosition); Vector3 mousePoint = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);
Rect pos = position; Rect pos = position;
pos.x = mousePoint.x - position.width * 0.5f; pos.x = mousePoint.x - position.width * 0.5f;
pos.y = mousePoint.y - 10; pos.y = mousePoint.y - 10;
position = pos; position = pos;
} }
private void OnLostFocus() { private void OnLostFocus() {
// Make the popup close on lose focus // Make the popup close on lose focus
Close(); Close();
} }
private void OnGUI() { private void OnGUI() {
if (firstFrame) { if (firstFrame) {
UpdatePositionToMouse(); UpdatePositionToMouse();
firstFrame = false; firstFrame = false;
} }
input = EditorGUILayout.TextField(input); input = EditorGUILayout.TextField(input);
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() == "") {
if (GUILayout.Button("Revert to default") || (e.isKey && e.keyCode == KeyCode.Return)) { if (GUILayout.Button("Revert to default") || (e.isKey && e.keyCode == KeyCode.Return)) {
target.name = NodeEditorUtilities.NodeDefaultName(target.GetType()); target.name = NodeEditorUtilities.NodeDefaultName(target.GetType());
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target)); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
Close(); Close();
} }
} }
// Rename asset to input text // Rename asset to input text
else { else {
if (GUILayout.Button("Apply") || (e.isKey && e.keyCode == KeyCode.Return)) { if (GUILayout.Button("Apply") || (e.isKey && e.keyCode == KeyCode.Return)) {
target.name = input; target.name = input;
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target)); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
Close(); Close();
} }
} }
} }
} }
} }