Skip to content

Commit

Permalink
Option to change selection to pasted rows after paste (#864)
Browse files Browse the repository at this point in the history
change selection to pasted rows
  • Loading branch information
Philiquaz authored Apr 23, 2024
1 parent 0ec34eb commit 65c82e1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/StudioCore/CFG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public class CFG
public bool Param_HideReferenceRows = false;
public bool Param_MakeMetaNamesPrimary = true;
public bool Param_PasteAfterSelection = false;
public bool Param_PasteThenSelect = true;
public bool Param_ShowFieldOffsets = false;
public bool Param_ShowHotkeysInContextMenu = true;
public bool Param_ShowSecondaryNames = true;
Expand Down
5 changes: 5 additions & 0 deletions src/StudioCore/Editor/Action.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ public override ActionEvent Undo()
Removed.Clear();
return ActionEvent.NoEvent;
}

public List<Param.Row> GetResultantRows()
{
return Clones;
}
}

public class DeleteParamsAction : EditorAction
Expand Down
31 changes: 26 additions & 5 deletions src/StudioCore/ParamEditor/ParamEditorScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,9 @@ public unsafe void OnGUI(string[] initcmd)
viewToModify._selection.SetActiveParam(initcmd[2]);
if (initcmd.Length > 3)
{
viewToModify._selection.SetActiveRow(null, doFocus);
bool onlyAddToSelection = initcmd.Length > 4 && initcmd[4] == "addOnly";
if (!onlyAddToSelection)
viewToModify._selection.SetActiveRow(null, doFocus);
Param p = ParamBank.PrimaryBank.Params[viewToModify._selection.GetActiveParam()];
int id;
var parsed = int.TryParse(initcmd[3], out id);
Expand All @@ -979,7 +981,10 @@ public unsafe void OnGUI(string[] initcmd)
Param.Row r = p.Rows.FirstOrDefault(r => r.ID == id);
if (r != null)
{
viewToModify._selection.SetActiveRow(r, doFocus);
if (onlyAddToSelection)
viewToModify._selection.AddRowToSelection(r);
else
viewToModify._selection.SetActiveRow(r, doFocus);
}
}
}
Expand Down Expand Up @@ -1904,6 +1909,7 @@ public void ShortcutPopups()
try
{
long offset = 0;
ImGui.Checkbox("Select new rows after paste", ref CFG.Current.Param_PasteThenSelect);
ImGui.Checkbox("Paste after selection", ref CFG.Current.Param_PasteAfterSelection);
var insertIndex = -1;
if (CFG.Current.Param_PasteAfterSelection)
Expand Down Expand Up @@ -1971,10 +1977,25 @@ public void ShortcutPopups()
// Do a clever thing by reversing order, making ID order incremental and resulting in row insertion being in the correct order because of the static index.
rowsToInsert.Reverse();
}

EditorActionManager.ExecuteAction(new AddParamsAction(
var paramAction = new AddParamsAction(
ParamBank.PrimaryBank.Params[ParamBank.ClipboardParam], "legacystring", rowsToInsert, false,
false, insertIndex));
false, insertIndex);
EditorActionManager.ExecuteAction(paramAction);

// Selection management
if (CFG.Current.Param_PasteThenSelect)
{
var res = paramAction.GetResultantRows();
if (res.Count > 0)
{
_activeView._selection.SetActiveRow(res[0], true);
foreach (Param.Row r in res)
{
_activeView._selection.AddRowToSelection(r);
}
EditorCommandQueue.AddCommand($@"param/select/-1/{_activeView._selection.GetActiveParam()}/{res[0].ID}/addOnly");
}
}
ImGui.CloseCurrentPopup();
}
}
Expand Down

0 comments on commit 65c82e1

Please sign in to comment.