Files
2026-10-20 22:36:19 +02:00

67 lines
2.2 KiB
Go

package ui
import (
"context"
"github.com/rivo/tview"
)
// confirmDelete asks before removing a title from the library. Deleting the
// files is a separate, unticked choice: by default only the library entry goes.
func (a *App) confirmDelete(label, summary string, onDelete func(deleteFiles, exclude bool)) {
box, _ := a.newDeleteDialog(label, summary, onDelete)
a.openModal(box, 66, 14)
}
func (a *App) newDeleteDialog(label, summary string, onDelete func(deleteFiles, exclude bool)) (*tview.Flex, *tview.Form) {
const (
lFiles = "Delete files from disk"
lExclude = "Don't let import lists re-add it"
)
text := tview.NewTextView().SetDynamicColors(true).SetWordWrap(true).
SetText("[::b]" + label + "[::-]\n" + summary)
form := tview.NewForm()
form.AddCheckbox(lFiles, false, nil)
form.AddCheckbox(lExclude, false, nil)
files := form.GetFormItemByLabel(lFiles).(*tview.Checkbox)
exclude := form.GetFormItemByLabel(lExclude).(*tview.Checkbox)
// Cancel first so a stray Enter is safe.
form.AddButton("Cancel", a.closeModal)
form.AddButton("Delete", func() {
a.closeModal()
onDelete(files.IsChecked(), exclude.IsChecked())
})
form.SetFocus(form.GetFormItemCount()) // the Cancel button
arrowNavigation(form, a.closeModal, nil)
box := tview.NewFlex().SetDirection(tview.FlexRow).
AddItem(text, 4, 0, false).
AddItem(form, 0, 1, true)
box.SetBorder(true).SetTitle(" Remove from library ")
return box, form
}
// remove asks to delete the selected library item.
func (v *libraryView) remove() {
it, ok := v.selected()
if !ok {
return
}
summary := "[gray]Untick “Delete files” to keep the files on disk.[-]"
if it.have {
summary = "[yellow]" + it.size + " on disk.[-] Files are kept unless you tick “Delete files”."
}
v.app.confirmDelete(it.label, summary, func(deleteFiles, exclude bool) {
what := "Removed " + it.label
if deleteFiles {
what = "Removed " + it.label + " and its files"
}
v.run("Removing "+it.label, what, func(ctx context.Context) error {
if it.movie != nil {
return v.radarr.DeleteMovie(ctx, it.id, deleteFiles, exclude)
}
return v.sonarr.DeleteSeries(ctx, it.id, deleteFiles, exclude)
}, v.reload)
})
}