Keep history tab selection and add clear all

This commit is contained in:
Stu Leak 2026-01-10 01:36:17 -05:00
parent 9922738f7c
commit c72443b3c6
2 changed files with 48 additions and 1 deletions

View File

@ -207,6 +207,9 @@ func BuildHistorySidebar(
activeJobs []HistoryEntry,
onEntryClick func(HistoryEntry),
onEntryDelete func(HistoryEntry),
onClearAll func(),
selectedTab int,
onTabChanged func(int),
titleColor, bgColor, textColor color.Color,
) fyne.CanvasObject {
// Filter by status
@ -231,14 +234,34 @@ func BuildHistorySidebar(
container.NewTabItem("Failed", container.NewVScroll(failedList)),
)
tabs.SetTabLocation(container.TabLocationTop)
if selectedTab >= 0 && selectedTab < len(tabs.Items) {
tabs.SelectIndex(selectedTab)
}
tabs.OnSelected = func(item *container.TabItem) {
if onTabChanged == nil {
return
}
for idx, tab := range tabs.Items {
if tab == item {
onTabChanged(idx)
return
}
}
}
// Header
title := canvas.NewText("HISTORY", titleColor)
title.TextStyle = fyne.TextStyle{Monospace: true, Bold: true}
title.TextSize = 18
clearBtn := widget.NewButton("Clear All", func() {
if onClearAll != nil {
onClearAll()
}
})
clearBtn.Importance = widget.LowImportance
header := container.NewVBox(
container.NewCenter(title),
container.NewBorder(nil, nil, title, clearBtn, nil),
widget.NewSeparator(),
)

24
main.go
View File

@ -1145,6 +1145,7 @@ type appState struct {
// History sidebar state
historyEntries []ui.HistoryEntry
sidebarVisible bool
historyTabIdx int
// Author module state
authorFile *videoSource
@ -1436,6 +1437,10 @@ func (s *appState) deleteHistoryEntry(entry ui.HistoryEntry) {
_ = s.jobQueue.Remove(entry.ID)
}
if entry.LogPath != "" {
_ = os.Remove(entry.LogPath)
}
// Remove entry from history
var updated []ui.HistoryEntry
for _, e := range s.historyEntries {
@ -1455,6 +1460,20 @@ 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)
}
}
s.historyEntries = nil
cfg := historyConfig{Entries: s.historyEntries}
if err := saveHistoryConfig(cfg); err != nil {
logging.Debug(logging.CatUI, "failed to save history after clear: %v", err)
}
s.refreshMainMenuThrottled()
}
func (s *appState) stopPreview() {
if s.anim != nil {
s.anim.Stop()
@ -1941,6 +1960,11 @@ func (s *appState) showMainMenu() {
activeJobs,
s.showHistoryDetails,
s.deleteHistoryEntry,
s.clearHistoryEntries,
s.historyTabIdx,
func(idx int) {
s.historyTabIdx = idx
},
titleColor,
utils.MustHex("#1A1F2E"),
textColor,