diff options
Diffstat (limited to 'gui/internal/ui/history.go')
| -rw-r--r-- | gui/internal/ui/history.go | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/gui/internal/ui/history.go b/gui/internal/ui/history.go index f82f6e3..3a3166e 100644 --- a/gui/internal/ui/history.go +++ b/gui/internal/ui/history.go @@ -4,6 +4,7 @@ package ui import ( "context" + "errors" "fmt" "strings" @@ -36,6 +37,10 @@ type historyView struct { undo *gtk.Button cancel *gtk.Button + // applying is set while a reversal is in flight; the window refuses + // anything that would take its lock or its log away. + applying bool + tab *model.UndoTab cancelOp context.CancelFunc } @@ -349,6 +354,8 @@ func (h *historyView) onUndo() { return } n := h.tab.SelectedCount() + h.applying = true + h.w.setApplying(true) h.setBusy(true) h.w.setStatus("reversing %d file(s)...", n) var res *engine.ApplyResult @@ -357,6 +364,8 @@ func (h *historyView) onUndo() { res, err = h.tab.Apply(ctx) return err }, func(err error) { + h.applying = false + h.w.setApplying(false) h.setBusy(false) h.fillPlan() h.undo.SetSensitive(false) @@ -404,6 +413,9 @@ func (h *historyView) updateUndoButton() { } // setBusy turns the buttons on or off around a background operation. +// busyApplying reports whether an undo is in flight. +func (h *historyView) busyApplying() bool { return h.applying } + func (h *historyView) setBusy(busy bool) { h.reload.SetSensitive(!busy) h.more.SetSensitive(!busy && len(h.runRows) >= h.limit) @@ -419,15 +431,19 @@ func (h *historyView) setBusy(busy bool) { } // closeTab drops the open undo plan and releases its locks. -func (h *historyView) closeTab() { +func (h *historyView) closeTab() bool { if h.tab == nil { - return + return true } if err := h.tab.Close(); err != nil { h.w.setStatus("undo: %v", err) + if errors.Is(err, model.ErrApplying) { + return false + } } h.tab = nil h.clearPlan() + return true } // clearList removes every row of a ListBox. |
