Merge branch 'auto-rename-new-param' of https://github.com/TyGrze/FlaxEngine into TyGrze-auto-rename-new-param

This commit is contained in:
2026-07-13 17:58:47 +02:00
3 changed files with 34 additions and 0 deletions
@@ -42,6 +42,12 @@ namespace FlaxEditor.Surface
/// </summary>
IEnumerable<ScriptType> NewParameterTypes { get; }
/// <summary>
/// Index of the parameter to start renaming once the properties panel is next rebuilt, or -1 if none.
/// Used to auto-start renaming of a freshly added parameter.
/// </summary>
int ParamToRename { get; set; }
/// <summary>
/// Event called when surface gets loaded (eg. after opening the window).
/// </summary>
@@ -589,6 +595,7 @@ namespace FlaxEditor.Surface
if (Utilities.Utils.OnAssetProperties(layout, asset))
return;
var parameters = window.VisjectSurface.Parameters;
ParameterPropertyNameLabel labelToRename = null;
CustomEditors.Editors.GenericEditor.OnGroupsBegin();
for (int i = 0; i < parameters.Count; i++)
{
@@ -643,6 +650,8 @@ namespace FlaxEditor.Surface
tooltipText += '\n' + tooltip.Text;
propertyLabel.MouseLeftDoubleClick += (label, location) => StartParameterRenaming(pIndex, label);
propertyLabel.SetupContextMenu += OnPropertyLabelSetupContextMenu;
if (pIndex == window.ParamToRename)
labelToRename = propertyLabel;
var property = itemLayout.AddPropertyItem(propertyLabel, tooltipText);
property.Property("Value", propertyValue);
}
@@ -657,6 +666,21 @@ namespace FlaxEditor.Surface
newParam.Button.ButtonClicked += OnAddParameterButtonClicked;
layout.Space(10);
}
// Defer renaming a newly added param once its label is built and laid out
// Adding a param can rebuild the panel more than once (disposing earlier labels)
// Because of this every rebuild recaptures the current label, only the surviving one actually calls StartParameterRenaming
if (labelToRename != null)
{
var index = window.ParamToRename;
var label = labelToRename;
FlaxEngine.Scripting.InvokeOnUpdate(() =>
{
if (label.IsDisposing)
return; // A latter rebuild replaced this label, its own callback will handle it
window.ParamToRename = -1;
StartParameterRenaming(index, label);
});
}
}
private void OnAddParameterButtonClicked(Button button)
@@ -695,6 +719,7 @@ namespace FlaxEditor.Surface
};
window.VisjectSurface.Undo.AddAction(action);
action.Do();
window.ParamToRename = action.Index;
}
private DragData OnDragParameter(DraggablePropertyNameLabel label)
@@ -1276,6 +1301,9 @@ namespace FlaxEditor.Surface
/// <inheritdoc />
public abstract IEnumerable<ScriptType> NewParameterTypes { get; }
/// <inheritdoc />
public int ParamToRename { get; set; } = -1;
/// <inheritdoc />
public event Action SurfaceLoaded;
@@ -602,6 +602,9 @@ namespace FlaxEditor.Windows.Assets
/// <inheritdoc />
public IEnumerable<ScriptType> NewParameterTypes => Editor.CodeEditing.VisualScriptPropertyTypes.Get();
/// <inheritdoc />
public int ParamToRename { get; set; } = -1;
/// <inheritdoc />
public event Action SurfaceLoaded;
@@ -1398,6 +1398,9 @@ namespace FlaxEditor.Windows.Assets
/// <inheritdoc />
public IEnumerable<ScriptType> NewParameterTypes => Editor.CodeEditing.VisualScriptPropertyTypes.Get();
/// <inheritdoc />
public int ParamToRename { get; set; } = -1;
/// <inheritdoc />
public event Action SurfaceLoaded;