Add option to expand or collapse all sub-folders in the right-click context for mod folders.

This commit is contained in:
Ottermandias 2022-03-08 10:09:34 +01:00
parent 6df82fdf18
commit bf40c2a3cb

View file

@ -14,8 +14,8 @@ using Penumbra.Mods;
using Penumbra.UI.Custom;
using Penumbra.Util;
namespace Penumbra.UI
{
namespace Penumbra.UI;
public partial class SettingsInterface
{
// Constants
@ -501,6 +501,9 @@ namespace Penumbra.UI
// === Folder ===
private string _newFolderName = string.Empty;
private int _expandIndex = -1;
private bool _expandCollapse;
private bool _currentlyExpanding;
private void ChangeStatusOfChildren( ModFolder folder, int currentIdx, bool toWhat )
{
@ -563,6 +566,18 @@ namespace Penumbra.UI
using var raii = ImGuiRaii.DeferredEnd( ImGui.EndPopup );
if( ImGui.MenuItem( "Expand All Descendants" ) )
{
_expandIndex = currentIdx;
_expandCollapse = false;
}
if( ImGui.MenuItem( "Collapse All Descendants" ) )
{
_expandIndex = currentIdx;
_expandCollapse = true;
}
if( ImGui.MenuItem( "Enable All Descendants" ) )
{
ChangeStatusOfChildren( folder, currentIdx, true );
@ -674,6 +689,17 @@ namespace Penumbra.UI
var treeName = $"{folder.Name}##{folder.FullName}";
var open = ImGui.TreeNodeEx( treeName );
using var raii = ImGuiRaii.DeferredEnd( ImGui.TreePop, open );
if( idx == _expandIndex )
{
_currentlyExpanding = true;
}
if( _currentlyExpanding )
{
ImGui.SetNextItemOpen( !_expandCollapse );
}
if( ImGui.IsItemClicked( ImGuiMouseButton.Right ) )
{
_newFolderName = string.Empty;
@ -692,6 +718,12 @@ namespace Penumbra.UI
{
idx += folder.TotalDescendantMods();
}
if( idx == _expandIndex )
{
_currentlyExpanding = false;
_expandIndex = -1;
}
}
private void DrawMod( Mod.Mod mod, int modIndex, uint color )
@ -768,4 +800,3 @@ namespace Penumbra.UI
}
}
}
}