From fbf93fc9a35248d38811cee8de446432d5458827 Mon Sep 17 00:00:00 2001 From: Stu Leak Date: Sat, 10 Jan 2026 01:39:57 -0500 Subject: [PATCH] Scope history clear to active tab --- internal/ui/mainmenu.go | 14 +++++++++++--- main.go | 23 +++++++++++++++++------ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/internal/ui/mainmenu.go b/internal/ui/mainmenu.go index 8766677..5d3f7bd 100644 --- a/internal/ui/mainmenu.go +++ b/internal/ui/mainmenu.go @@ -207,7 +207,7 @@ func BuildHistorySidebar( activeJobs []HistoryEntry, onEntryClick func(HistoryEntry), onEntryDelete func(HistoryEntry), - onClearAll func(), + onClearAll func(int), selectedTab int, onTabChanged func(int), titleColor, bgColor, textColor color.Color, @@ -254,9 +254,17 @@ func BuildHistorySidebar( title.TextStyle = fyne.TextStyle{Monospace: true, Bold: true} title.TextSize = 18 clearBtn := widget.NewButton("Clear All", func() { - if onClearAll != nil { - onClearAll() + if onClearAll == nil { + return } + idx := 0 + for i, tab := range tabs.Items { + if tab == tabs.Selected() { + idx = i + break + } + } + onClearAll(idx) }) clearBtn.Importance = widget.LowImportance diff --git a/main.go b/main.go index bb5e22f..3fe69c9 100644 --- a/main.go +++ b/main.go @@ -1460,13 +1460,24 @@ func (s *appState) deleteHistoryEntry(entry ui.HistoryEntry) { s.refreshMainMenuThrottled() } -func (s *appState) clearHistoryEntries() { - for _, entry := range s.historyEntries { - if entry.LogPath != "" { - _ = os.Remove(entry.LogPath) - } +func (s *appState) clearHistoryEntries(tabIndex int) { + if tabIndex == 0 { + return } - s.historyEntries = nil + keep := s.historyEntries[:0] + for _, entry := range s.historyEntries { + isCompleted := entry.Status == queue.JobStatusCompleted + isFailed := entry.Status != queue.JobStatusCompleted + shouldClear := (tabIndex == 1 && isCompleted) || (tabIndex == 2 && isFailed) + if shouldClear { + if entry.LogPath != "" { + _ = os.Remove(entry.LogPath) + } + continue + } + keep = append(keep, entry) + } + s.historyEntries = keep cfg := historyConfig{Entries: s.historyEntries} if err := saveHistoryConfig(cfg); err != nil { logging.Debug(logging.CatUI, "failed to save history after clear: %v", err)