RynthChat: pinned tab bookkeeping
ChatPins: pure Toggle/Rename/Remove/Visible over the pinned-tab list (OrdinalIgnoreCase, order = button order). A pin on a hidden tab is kept but not returned by Visible. Tests in tools/ChatFilterTests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0eec23f6fd
commit
6f26d3f80b
3 changed files with 96 additions and 0 deletions
57
src/RynthCore.Engine/UI/Data/ChatPins.cs
Normal file
57
src/RynthCore.Engine/UI/Data/ChatPins.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
// ============================================================================
|
||||
// RynthCore.Engine - UI/Data/ChatPins.cs
|
||||
// Pinned chat tabs (2026-11-15): which tabs sit in the main chat window's top
|
||||
// bar. Pure list bookkeeping (no ChatModel or ImGui) so tools/ChatFilterTests
|
||||
// compiles it as is. Names compare OrdinalIgnoreCase, every function returns a
|
||||
// new array, and the order of the array is the order of the buttons.
|
||||
//
|
||||
// A pin on a tab that is not there (a server tab while its server is not
|
||||
// active) is kept but not drawn: Visible filters, nothing removes.
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace RynthCore.Engine.UI.Data;
|
||||
|
||||
internal static class ChatPins
|
||||
{
|
||||
private static bool Same(string a, string b) => string.Equals(a, b, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>Pins <paramref name="tab"/> at the end, or unpins it when it is pinned. A blank name changes nothing.</summary>
|
||||
internal static string[] Toggle(string[] pins, string tab)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(tab)) return pins.ToArray();
|
||||
tab = tab.Trim();
|
||||
if (pins.Any(p => Same(p, tab))) return Remove(pins, tab);
|
||||
return pins.Append(tab).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>The pin follows a renamed tab and keeps its place. If <paramref name="to"/> is already pinned, one pin remains.</summary>
|
||||
internal static string[] Rename(string[] pins, string from, string to)
|
||||
{
|
||||
var result = new List<string>(pins.Length);
|
||||
foreach (string p in pins)
|
||||
{
|
||||
string name = Same(p, from) ? to : p;
|
||||
if (!result.Any(r => Same(r, name))) result.Add(name);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>Drops the pin of a deleted tab.</summary>
|
||||
internal static string[] Remove(string[] pins, string tab) => pins.Where(p => !Same(p, tab)).ToArray();
|
||||
|
||||
/// <summary>The pins that have a tab now, in pin order, spelled as the tab is.</summary>
|
||||
internal static string[] Visible(string[] pins, string[] allTabs)
|
||||
{
|
||||
var result = new List<string>(pins.Length);
|
||||
foreach (string p in pins)
|
||||
{
|
||||
string? tab = allTabs.FirstOrDefault(t => Same(t, p));
|
||||
if (tab != null && !result.Any(r => Same(r, tab))) result.Add(tab);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue