Keep history tab selection and add clear all

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

View File

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

24
main.go
View File

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