Skip to content

Commit

Permalink
fix: Text Editor Selection Context
Browse files Browse the repository at this point in the history
- Changed how the selection context is handled so Select-All from the FMG Entry context should never be accidently invoked
  • Loading branch information
vawser committed Oct 29, 2024
1 parent 6c43c75 commit d259266
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 26 deletions.
3 changes: 3 additions & 0 deletions src/StudioCore/Editors/TextEditor/Core/TextFileView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ public void Display()
{
if (ImGui.Begin("Files##FmgContainerFileList"))
{
Selection.SwitchWindowContext(TextSelectionContext.File);

if (TextBank.PrimaryBankLoaded)
{
Filters.DisplayFileFilterSearch();

int index = 0;

ImGui.BeginChild("CategoryList");
Selection.SwitchWindowContext(TextSelectionContext.File);

// Categories
foreach (TextContainerCategory category in Enum.GetValues(typeof(TextContainerCategory)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public void Display()
{
if (ImGui.Begin("Contents##fmgEntryContents"))
{
Selection.SwitchWindowContext(TextSelectionContext.FmgEntryContents);

ImGui.BeginChild("FmgEntryContents");
Selection.SwitchWindowContext(TextSelectionContext.FmgEntryContents);

if (Selection._selectedFmgEntry != null)
{
Expand Down Expand Up @@ -157,7 +160,7 @@ public void DisplayGroupedTextInput(FMG.Entry entry, FmgEntryGroup fmgEntryGroup
if (ImGui.InputInt($"##fmgEntryIdInputGrouped", ref curId))
{
_idCache = curId;
Selection.CurrentSelectionContext = TextSelectionContext.FmgEntryContents;
Selection.CurrentWindowContext = TextSelectionContext.FmgEntryContents;
}

var idCommit = ImGui.IsItemDeactivatedAfterEdit();
Expand Down Expand Up @@ -228,7 +231,7 @@ public void DisplayGroupedTextInput(FMG.Entry entry, FmgEntryGroup fmgEntryGroup
if (ImGui.InputTextMultiline($"##fmgTextInput_Title", ref curText, 2000, new Vector2(-1, height)))
{
_textCache = curText;
Selection.CurrentSelectionContext = TextSelectionContext.FmgEntryContents;
Selection.CurrentWindowContext = TextSelectionContext.FmgEntryContents;
}

var titleTextCommit = ImGui.IsItemDeactivatedAfterEdit();
Expand Down Expand Up @@ -261,7 +264,7 @@ public void DisplayGroupedTextInput(FMG.Entry entry, FmgEntryGroup fmgEntryGroup
if (ImGui.InputTextMultiline($"##fmgTextInput_Summary", ref curText, 2000, new Vector2(-1, height)))
{
_textCache = curText;
Selection.CurrentSelectionContext = TextSelectionContext.FmgEntryContents;
Selection.CurrentWindowContext = TextSelectionContext.FmgEntryContents;
}

var summaryTextCommit = ImGui.IsItemDeactivatedAfterEdit();
Expand Down Expand Up @@ -293,7 +296,7 @@ public void DisplayGroupedTextInput(FMG.Entry entry, FmgEntryGroup fmgEntryGroup
if (ImGui.InputTextMultiline($"##fmgTextInput_Description", ref curText, 2000, new Vector2(-1, height)))
{
_textCache = curText;
Selection.CurrentSelectionContext = TextSelectionContext.FmgEntryContents;
Selection.CurrentWindowContext = TextSelectionContext.FmgEntryContents;
}

var descriptionTextCommit = ImGui.IsItemDeactivatedAfterEdit();
Expand Down Expand Up @@ -325,7 +328,7 @@ public void DisplayGroupedTextInput(FMG.Entry entry, FmgEntryGroup fmgEntryGroup
if (ImGui.InputTextMultiline($"##fmgTextInput_Effect", ref curText, 2000, new Vector2(-1, height)))
{
_textCache = curText;
Selection.CurrentSelectionContext = TextSelectionContext.FmgEntryContents;
Selection.CurrentWindowContext = TextSelectionContext.FmgEntryContents;
}

var effectTextCommit = ImGui.IsItemDeactivatedAfterEdit();
Expand Down Expand Up @@ -369,7 +372,7 @@ public void DisplayBasicTextInput(FMG.Entry entry)
if(ImGui.InputInt($"##fmgEntryIdInputBasic", ref curId))
{
_idCache = curId;
Selection.CurrentSelectionContext = TextSelectionContext.FmgEntryContents;
Selection.CurrentWindowContext = TextSelectionContext.FmgEntryContents;
}

var idCommit = ImGui.IsItemDeactivatedAfterEdit();
Expand Down Expand Up @@ -400,7 +403,7 @@ public void DisplayBasicTextInput(FMG.Entry entry)
if (ImGui.InputTextMultiline($"##fmgTextInputBasic", ref curText, 2000, new Vector2(-1, height)))
{
_textCache = curText;
Selection.CurrentSelectionContext = TextSelectionContext.FmgEntryContents;
Selection.CurrentWindowContext = TextSelectionContext.FmgEntryContents;
}

var textCommit = ImGui.IsItemDeactivatedAfterEdit();
Expand Down
3 changes: 3 additions & 0 deletions src/StudioCore/Editors/TextEditor/Core/TextFmgEntryView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ public void Display()
{
if (ImGui.Begin("Text Entries##fmgEntryList"))
{
Selection.SwitchWindowContext(TextSelectionContext.FmgEntry);

Filters.DisplayFmgEntryFilterSearch();

ImGui.BeginChild("FmgEntriesList");
Selection.SwitchWindowContext(TextSelectionContext.FmgEntry);

if (Selection.SelectedFmgWrapper != null && Selection.SelectedFmgWrapper.File != null)
{
Expand Down
3 changes: 3 additions & 0 deletions src/StudioCore/Editors/TextEditor/Core/TextFmgView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ public void Display()
{
if (ImGui.Begin("Text Files##fmgList"))
{
Selection.SwitchWindowContext(TextSelectionContext.Fmg);

Filters.DisplayFmgFilterSearch();

ImGui.BeginChild("FmgFileList");
Selection.SwitchWindowContext(TextSelectionContext.Fmg);

if (Selection.SelectedContainerWrapper != null && Selection.SelectedContainerWrapper.FmgWrappers != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void AddEffectEntry(TextFmgWrapper curFmgWrapper, FMG.Entry curEntry)
/// </summary>
public void DuplicateEntries()
{
if (Screen.Selection.CurrentSelectionContext is not TextSelectionContext.FmgEntry)
if (Screen.Selection.CurrentWindowContext is not TextSelectionContext.FmgEntry)
return;

if (Screen.Selection._selectedFmgEntry == null)
Expand Down Expand Up @@ -223,7 +223,7 @@ private List<EditorAction> ProcessDuplicate(FMG.Entry curEntry, int newId)
/// </summary>
public void DeleteEntries()
{
if(Screen.Selection.CurrentSelectionContext is not TextSelectionContext.FmgEntry)
if(Screen.Selection.CurrentWindowContext is not TextSelectionContext.FmgEntry)
return;

if (Screen.Selection._selectedFmgEntry == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void Parse(string[] initcmd)
if(fmg.Name == fmgName)
{
Screen.Selection.FocusFmgSelection = true;
Screen.Selection.SelectFmg(fmg, false);
Screen.Selection.SelectFmg(fmg);

var entryIndex = 0;

Expand All @@ -54,7 +54,7 @@ public void Parse(string[] initcmd)
if($"{entry.ID}" == fmgEntryId)
{
Screen.Selection.FocusFmgEntrySelection = true;
Screen.Selection.SelectFmgEntry(entryIndex, entry, false);
Screen.Selection.SelectFmgEntry(entryIndex, entry);
}

entryIndex++;
Expand Down
33 changes: 20 additions & 13 deletions src/StudioCore/Editors/TextEditor/Framework/TextSelectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Threading.Tasks;
using SoulsFormats;
using HKLib.hk2018.hkaiCollisionAvoidance;
using ImGuiNET;
using StudioCore.Utilities;

namespace StudioCore.Editors.TextEditor;

Expand Down Expand Up @@ -36,7 +38,7 @@ public class TextSelectionManager

private KeyBind MultiSelectKey = KeyBindings.Current.TEXT_Multiselect;

public TextSelectionContext CurrentSelectionContext;
public TextSelectionContext CurrentWindowContext;

public TextSelectionManager(TextEditorScreen screen)
{
Expand Down Expand Up @@ -72,8 +74,6 @@ public void OnProjectChanged()
/// </summary>>
public void SelectFileContainer(TextContainerWrapper info, int index)
{
CurrentSelectionContext = TextSelectionContext.File;

SelectedContainerKey = index;
SelectedContainerWrapper = info;

Expand All @@ -92,9 +92,6 @@ public void SelectFileContainer(TextContainerWrapper info, int index)
/// </summary>
public void SelectFmg(TextFmgWrapper fmgInfo, bool changeContext = true)
{
if(changeContext)
CurrentSelectionContext = TextSelectionContext.Fmg;

SelectedFmgWrapper = fmgInfo;
SelectedFmgKey = fmgInfo.ID;

Expand Down Expand Up @@ -122,7 +119,7 @@ private void AutoSelectFirstValidFmg()

if (Screen.Filters.IsFmgFilterMatch(fmgName, displayName, id))
{
SelectFmg(fmgInfo, false);
SelectFmg(fmgInfo);
break;
}
}
Expand All @@ -131,12 +128,9 @@ private void AutoSelectFirstValidFmg()
/// <summary>
/// Set current FMG Entry selection
/// </summary>
public void SelectFmgEntry(int index, FMG.Entry entry, bool changeContext = true)
public void SelectFmgEntry(int index, FMG.Entry entry)
{
if(changeContext)
CurrentSelectionContext = TextSelectionContext.FmgEntry;

if (CurrentSelectionContext == TextSelectionContext.FmgEntry)
if (CurrentWindowContext == TextSelectionContext.FmgEntry)
{
FmgEntryMultiselect.HandleMultiselect(_selectedFmgEntryIndex, index);
}
Expand All @@ -156,7 +150,7 @@ public void AutoSelectFmgEntry()

if (Screen.Filters.IsFmgEntryFilterMatch(entry))
{
SelectFmgEntry(i, entry, false);
SelectFmgEntry(i, entry);
break;
}
}
Expand All @@ -174,4 +168,17 @@ public bool IsFmgEntrySelected(int index)

return false;
}

/// <summary>
/// Switches the focus context to the passed value.
/// Use this on all windows (e.g. both Begin and BeginChild)
/// </summary>
public void SwitchWindowContext(TextSelectionContext newContext)
{
if (ImGui.IsWindowHovered())
{
CurrentWindowContext = newContext;
//TaskLogs.AddLog($"Context: {newContext.GetDisplayName()}");
}
}
}
4 changes: 2 additions & 2 deletions src/StudioCore/Editors/TextEditor/Framework/TextShortcuts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void Monitor()
public void HandleSelectAll()
{
var editor = Smithbox.EditorHandler.TextEditor;
var selectionContext = Selection.CurrentSelectionContext;
var selectionContext = Selection.CurrentWindowContext;
var multiselect = Selection.FmgEntryMultiselect;
var fmg = Selection.SelectedFmgWrapper.File;

Expand Down Expand Up @@ -109,7 +109,7 @@ public void HandleSelectAll()
/// </summary>
public void HandleCopyEntryText()
{
var selectionContext = Selection.CurrentSelectionContext;
var selectionContext = Selection.CurrentWindowContext;

// Copy Entry Contents
if (selectionContext is TextSelectionContext.FmgEntry)
Expand Down

0 comments on commit d259266

Please sign in to comment.