feat: add simple delete and move tools for tabs

This commit is contained in:
Anna 2022-01-14 15:40:31 -05:00
parent fdabb821c7
commit 1ef91b81f3
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0
4 changed files with 40 additions and 10 deletions

View File

@ -40,7 +40,7 @@ internal class Tab {
return this.ChatCodes.TryGetValue(message.Code.Type, out var sources) && (message.Code.Source is 0 or (ChatSource) 1 || sources.HasFlag(message.Code.Source));
}
internal void AddMessage(Message message) {
internal void AddMessage(Message message, bool unread = true) {
this.MessagesMutex.WaitOne();
this.Messages.Add(message);
if (this.Messages.Count > 1000) {
@ -49,7 +49,9 @@ internal class Tab {
this.MessagesMutex.ReleaseMutex();
this.Unread += 1;
if (unread) {
this.Unread += 1;
}
}
internal Tab Clone() {

View File

@ -75,17 +75,17 @@ internal class Store : IDisposable {
}
}
internal void FilterAllTabs() {
internal void FilterAllTabs(bool unread = true) {
foreach (var tab in this.Plugin.Config.Tabs) {
this.FilterTab(tab);
this.FilterTab(tab, unread);
}
}
internal void FilterTab(Tab tab) {
internal void FilterTab(Tab tab, bool unread) {
using var messages = this.GetMessages();
foreach (var message in messages.Messages) {
if (tab.Matches(message)) {
tab.AddMessage(message);
tab.AddMessage(message, unread);
}
}
}

View File

@ -2,6 +2,7 @@
using ChatTwo.Code;
using ChatTwo.Util;
using Dalamud.Game.Command;
using Dalamud.Interface;
using ImGuiNET;
namespace ChatTwo.Ui;
@ -86,16 +87,33 @@ internal sealed class Settings : IUiComponent {
}
if (ImGui.TreeNodeEx("Tabs")) {
if (ImGui.Button("Add")) {
if (ImGuiUtil.IconButton(FontAwesomeIcon.Plus, tooltip: "Add")) {
this._tabs.Add(new Tab());
}
var toRemove = -1;
for (var i = 0; i < this._tabs.Count; i++) {
var tab = this._tabs[i];
if (ImGui.TreeNodeEx($"{tab.Name}###tab-{i}")) {
ImGui.PushID($"tab-{i}");
if (ImGuiUtil.IconButton(FontAwesomeIcon.TrashAlt, tooltip: "Delete")) {
toRemove = i;
}
ImGui.SameLine();
if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowUp, tooltip: "Move up") && i > 0) {
(this._tabs[i - 1], this._tabs[i]) = (this._tabs[i], this._tabs[i - 1]);
}
ImGui.SameLine();
if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowDown, tooltip: "Move down") && i < this._tabs.Count - 1) {
(this._tabs[i + 1], this._tabs[i]) = (this._tabs[i], this._tabs[i + 1]);
}
ImGui.InputText("Name", ref tab.Name, 512, ImGuiInputTextFlags.EnterReturnsTrue);
ImGui.Checkbox("Show unread count", ref tab.DisplayUnread);
ImGui.Checkbox("Show timestamps", ref tab.DisplayTimestamp);
@ -107,7 +125,7 @@ internal sealed class Settings : IUiComponent {
}
foreach (var channel in Enum.GetValues<InputChannel>()) {
if (ImGui.Selectable(channel.ToChatType().Name() ?? "???", tab.Channel == channel)) {
if (ImGui.Selectable(channel.ToChatType().Name(), tab.Channel == channel)) {
tab.Channel = channel;
}
}
@ -151,6 +169,10 @@ internal sealed class Settings : IUiComponent {
ImGui.PopID();
}
}
if (toRemove > -1) {
this._tabs.RemoveAt(toRemove);
}
}
ImGui.EndChild();
@ -190,7 +212,7 @@ internal sealed class Settings : IUiComponent {
this.Ui.Plugin.SaveConfig();
this.Ui.Plugin.Store.FilterAllTabs();
this.Ui.Plugin.Store.FilterAllTabs(false);
if (fontSizeChanged) {
this.Ui.Plugin.Interface.UiBuilder.RebuildFonts();

View File

@ -81,7 +81,7 @@ internal static class ImGuiUtil {
}
}
internal static bool IconButton(FontAwesomeIcon icon, string? id = null) {
internal static bool IconButton(FontAwesomeIcon icon, string? id = null, string? tooltip = null) {
ImGui.PushFont(UiBuilder.IconFont);
var label = icon.ToIconString();
@ -93,6 +93,12 @@ internal static class ImGuiUtil {
ImGui.PopFont();
if (tooltip != null && ImGui.IsItemHovered()) {
ImGui.BeginTooltip();
ImGui.TextUnformatted(tooltip);
ImGui.EndTooltip();
}
return ret;
}
}