Scope history clear to active tab

This commit is contained in:
Stu Leak 2026-01-10 01:39:57 -05:00
parent c72443b3c6
commit fbf93fc9a3
2 changed files with 28 additions and 9 deletions

View File

@ -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

23
main.go
View File

@ -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)