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

Added renaming undo/redo.

Fixed keyboard controls for renaming.
This commit is contained in:
Emre Dogan 2023-10-06 01:47:49 +01:00
parent 5ec46e53a1
commit 6e579667b2
2 changed files with 15 additions and 15 deletions

View File

@ -435,7 +435,6 @@ namespace XNodeEditor
if (isDoubleClick)
{
RenameSelectedNodeTextField();
currentActivity = NodeActivity.Renaming;
// Vector2 nodeDimension = nodeSizes.ContainsKey(hoveredNode)
// ? nodeSizes[hoveredNode] / 2
// : Vector2.zero;
@ -517,7 +516,7 @@ namespace XNodeEditor
isDoubleClick = false;
break;
case EventType.KeyDown:
if (EditorGUIUtility.editingTextField || GUIUtility.keyboardControl != 0)
if (EditorGUIUtility.editingTextField)
{
break;
}
@ -531,14 +530,14 @@ namespace XNodeEditor
{
if (e.keyCode == KeyCode.Return)
{
RenameSelectedNode();
RenameSelectedNodeTextField();
}
}
else
{
if (e.keyCode == KeyCode.F2)
{
RenameSelectedNode();
RenameSelectedNodeTextField();
}
}
@ -721,16 +720,8 @@ namespace XNodeEditor
{
if (Selection.objects.Length == 1 && Selection.activeObject is Node)
{
Node node = Selection.activeObject as Node;
Vector2 size;
if (nodeSizes.TryGetValue(node, out size))
{
RenameTextField.Show(Selection.activeObject, size.x);
}
else
{
RenameTextField.Show(Selection.activeObject);
}
currentActivity = NodeActivity.Renaming;
RenameTextField.Show(Selection.activeObject);
}
}

View File

@ -17,7 +17,7 @@ namespace XNodeEditor
private bool firstFrame = true;
/// <summary> Show a rename text field for an asset in the node header. Will trigger reimport of the asset on apply.
public static RenameTextField Show(Object target, float width = 200)
public static RenameTextField Show(Object target)
{
RenameTextField textField = new RenameTextField();
if (current != null)
@ -38,6 +38,7 @@ namespace XNodeEditor
input = GUILayout.TextField(input, NodeEditorResources.styles.nodeHeaderRename);
EditorGUI.FocusTextInControl(inputControlName);
// Fixes textfield not being fully selected on multiple consecutive rename activates.
if (firstFrame)
{
TextEditor textEditor =
@ -72,6 +73,9 @@ namespace XNodeEditor
public void SaveAndClose()
{
// Enabled undoing of renaming.
Undo.RecordObject(target, $"Renamed Node: [{target.name}] -> [{input}]");
target.name = input;
NodeEditor.GetEditor((Node)target, NodeEditorWindow.current).OnRename();
if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(target)))
@ -88,7 +92,12 @@ namespace XNodeEditor
{
firstFrame = true;
current = null;
EditorGUIUtility.editingTextField = false;
NodeEditorWindow.current.Repaint();
// If another action has not taken precedence, then just return to an idle state.
// E.g Would not run if another action was taken such as clicking another node or clicking the empty graph.
if (NodeEditorWindow.currentActivity == NodeEditorWindow.NodeActivity.Renaming)
{
NodeEditorWindow.currentActivity = NodeEditorWindow.NodeActivity.Idle;