diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a5befe4..ebb9cd33 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1153,7 +1153,7 @@ jobs: # in somebody else's file. run: | set -euo pipefail - watched='internal/format/registry.go internal/damage/damage.go cmd/tfg/main.go internal/gui/window/run.go internal/gui/run_cgo.go internal/gui/window/tidy.go internal/audit/parallel.go internal/engine/parallel.go internal/tool/tool.go internal/gui/window/tools.go internal/gui/window/work.go internal/gui/window/closing.go internal/gui/window/dropping.go internal/format/video/ahead.go go.mod .github/workflows/ci.yml .github/build-tags .github/race-weights .github/scripts/race_parts.py .github/scripts/guard_part.sh internal/guard/guardpart_test.go' + watched='internal/format/registry.go internal/damage/damage.go cmd/tfg/main.go internal/gui/window/run.go internal/gui/run_cgo.go internal/gui/window/tidy.go internal/audit/parallel.go internal/engine/parallel.go internal/tool/tool.go internal/gui/window/tools.go internal/gui/window/work.go internal/gui/window/closing.go internal/gui/window/dropping.go internal/gui/window/copycommand.go internal/format/video/ahead.go go.mod .github/workflows/ci.yml .github/build-tags .github/race-weights .github/scripts/race_parts.py .github/scripts/guard_part.sh internal/guard/guardpart_test.go' # On a pull request there is no "before" - the field belongs to a push # - so this asked for something empty and every pull request answered # "touched". That quietly undid the decision of 2026-08-20, because diff --git a/CHANGELOG.md b/CHANGELOG.md index c4c2a4a0..f5adb6b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,10 @@ because it turns other people's test suites red. install commands. - **The README says what the tool can do in full**: presets, damaged files, a name no disk stores, the tools, and the packages for pytest and Node. +- **After a run, Open folder, Open manifest and Open instructions get a line of + their own** under Preview and Generate in the window, when they do not fit + beside them. Preview and Generate stay where they were, and the next run + starts without the form moving. ### Fixed diff --git a/internal/engine/engine.go b/internal/engine/engine.go index 78b16c52..429239e7 100644 --- a/internal/engine/engine.go +++ b/internal/engine/engine.go @@ -272,10 +272,8 @@ func (f PlannedFile) Damaged() bool { // the run rather than about one entry, and run is what the memory setting lets // the run hold, which the draw of a range is kept inside (planstretch.go). func settleTarget(ctx context.Context, t *Target, opt Options, seen map[string]bool, run int64) (format.Descriptor, error) { - if t.ID == "" { - return format.Descriptor{}, &RecipeError{Setting: SettingID, - Detail: core.Says("engine.NoID", "a target has no id"), - Because: core.Says("engine.NoIDWhy", "every target needs a stable id, it anchors the seed and links to the manifest")} + if err := MissingID(t.ID); err != nil { + return format.Descriptor{}, err } if seen[t.ID] { return format.Descriptor{}, &RecipeError{Setting: SettingID, diff --git a/internal/engine/errors.go b/internal/engine/errors.go index a972b3bc..bbe29aae 100644 --- a/internal/engine/errors.go +++ b/internal/engine/errors.go @@ -312,3 +312,18 @@ func (e *CollisionError) Said() core.Said { "%s already exists and this run will not write over it. Generate into an empty directory, or remove the file first", core.A("Path", core.Shown(e.Path))) } + +// MissingID is the refusal of a target with no id, or nil when it has one. +// +// Exported for the window, which asks it before it writes a command line as +// well as before a run: a line with --id left out runs under the id the command +// line fills in, so without this the copy of a form that Generate refuses would +// run. +func MissingID(id string) error { + if id != "" { + return nil + } + return &RecipeError{Setting: SettingID, + Detail: core.Says("engine.NoID", "a target has no id"), + Because: core.Says("engine.NoIDWhy", "every target needs a stable id, it anchors the seed and links to the manifest")} +} diff --git a/internal/guard/barbuttons_test.go b/internal/guard/barbuttons_test.go new file mode 100644 index 00000000..81f580ae --- /dev/null +++ b/internal/guard/barbuttons_test.go @@ -0,0 +1,216 @@ +package guard + +import ( + "fmt" + "os" + "testing" + + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/test" + "fyne.io/fyne/v2/theme" + + "github.com/donislawdev/TestingFilesGenerator/internal/gui/parts" + "github.com/donislawdev/TestingFilesGenerator/internal/gui/text" + "github.com/donislawdev/TestingFilesGenerator/internal/gui/window" +) + +// barButtonsChild runs the bar guard in a process of its own, because the +// language a window speaks is the whole process's. +const barButtonsChild = "TFG_BAR_BUTTONS_CHILD" + +// TestTheBarsButtonsNeverStandOverOneAnother asks the bar at the foot of each +// work screen after a run has finished, in every language of the build and in +// the pseudo language that makes every word longer, in the window as it opens and in the +// narrowest one it allows: no button of the bar may stand over another, and +// none may reach past the window's edge. +// +// Measured on 2026-11-26 with guirender after the review of #264 +// (docs/REVIEW-264-2026-11-25.md, remark 6): Copy command, at the bar's right +// end, stood over the offers of a finished run - over Open manifest of the +// batch screen entirely, in English - at every width, because the bar is never +// wider than the readable column. No guard looked at the bar after a run. +func TestTheBarsButtonsNeverStandOverOneAnother(t *testing.T) { + if os.Getenv(barButtonsChild) != "1" { + t.Run("canary: a row that cannot wrap is caught", canaryBarThatCannotWrap) + runChild(t, "TestTheBarsButtonsNeverStandOverOneAnother", barButtonsChild) + return + } + // Every language the build carries, read from the build, and the pseudo + // one, whose longer words stand for the language nobody has written yet. + var languages []string + for _, l := range text.Languages() { + languages = append(languages, l.Tag) + } + for _, language := range append(languages, text.Pseudo) { + if err := text.LoadBuiltIn(language); err != nil { + t.Fatalf("the window would not speak %s: %v", language, err) + } + for _, tab := range []string{text.TabOneTarget(), text.TabPresets(), text.TabRecipe()} { + t.Run(language+"/"+tab, func(t *testing.T) { barAfterARun(t, tab) }) + } + } +} + +// barAfterARun finishes a small run on a screen and asks the bar about it, at +// the size the window opens at and at the narrowest. +func barAfterARun(t *testing.T, tab string) { + content, w, host := screenInAWindowWithHost(t, tab) + if tab != text.TabPresets() { + chooser, ok := controlUnder(content, text.FieldFormat()).(*parts.Chooser) + if !ok { + t.Fatalf("the %s screen has no format menu, so this guard read the wrong tree", tab) + } + chooser.SetSelected("txt") + fill(t, content, text.FieldSize(), "1kb") + fill(t, content, text.FieldCount(), "3") + } + fill(t, content, text.FieldOutputDir(), t.TempDir()) + press(t, content, text.ButtonGenerate()) + join(host) + settle(content, w) + + // The state this guard is about, asserted rather than assumed: a run that + // failed offers nothing, and a bar with nothing offered has nothing to + // stand over. + for _, offer := range []string{text.ButtonOpenFolder(), text.ButtonOpenManifest()} { + if b := buttonNamed(content, offer); b == nil || !b.Visible() { + t.Fatalf("after the run the %s screen offers no %q - the run did not finish. The screen says: %s", + tab, offer, textIn(content)) + } + } + noButtonOverAnother(t, content, w, "the window as it opens") + + width := w.Content().MinSize().Width + if w.Padded() { + width += 2 * theme.Padding() + } + narrowest := fyne.NewSize(width, window.LargestOpening.Height) + opening := w.Canvas().Size().Width + settleAt(content, w, narrowest) + // settle lays the window out at the size it opens at, which is the size + // asked about above - so the narrow state is asserted, not assumed. Until + // the review of this guard (#266) it went through settle and asked the + // opening width twice. + if now := w.Canvas().Size().Width; now >= opening { + t.Fatalf("the window was to be narrowed to %.0f px and is %.0f px wide, as wide as it opened, so the "+ + "narrowest window is not what is asked about", narrowest.Width, now) + } + noButtonOverAnother(t, content, w, "the narrowest window") +} + +// settleAt is settle at a size of the guard's choosing: laid out again at +// another size and back, so every container asks its children again. +func settleAt(content fyne.CanvasObject, w fyne.Window, size fyne.Size) { + content.Refresh() + w.Resize(fyne.NewSize(size.Width, size.Height-1)) + content.Refresh() + w.Resize(size) +} + +// TestAnOfferWiderThanTheRunButtonsStaysInsideTheBar lays out a bar whose one +// offer is wider than the button that runs something, in the narrowest window +// the bar allows, and asks that the offer ends inside it. The row's minimum was +// the run buttons alone until the review of #266, so a window that narrow put +// the offer on a line of its own and let it run past the edge. +func TestAnOfferWiderThanTheRunButtonsStaysInsideTheBar(t *testing.T) { + newTestApp() + t.Cleanup(func() { newTestApp() }) + offer := parts.NewButton(parts.Secondary, "Open the instructions this run wrote beside its files", func() {}).InTheBar() + bar := parts.ActionBar(nil, parts.ActionRow( + []fyne.CanvasObject{parts.NewButton(parts.Primary, "Go", func() {}).InTheBar()}, offer)) + w := test.NewWindow(bar) + t.Cleanup(w.Close) + narrowest := bar.MinSize() + settleAt(bar, w, narrowest) + settleAt(bar, w, narrowest) + drv := fyne.CurrentApp().Driver() + ends := drv.AbsolutePositionForObject(offer).X + offer.Size().Width + if width := w.Canvas().Size().Width; ends > width+0.5 { + t.Errorf("in a window %.0f px wide, the narrowest the bar allows, the offer ends at x=%.1f - past the edge", + width, ends) + } +} + +// barButtonNames are the buttons that stand in the bar at the foot: the rail, +// the buttons that run something, what a finished run offers and Copy command. +func barButtonNames() []string { + return []string{text.ButtonDonate(), text.ButtonGitHub(), text.ButtonAddBatch(), + text.ButtonPreview(), text.ButtonGenerate(), text.ButtonCancel(), + text.ButtonOpenFolder(), text.ButtonOpenManifest(), text.ButtonOpenInstructions(), + text.ButtonCopyCommand()} +} + +// noButtonOverAnother reports every pair of the bar's shown buttons that share +// a pixel, and every one past the window's edge. +func noButtonOverAnother(t *testing.T, content fyne.CanvasObject, w fyne.Window, where string) { + t.Helper() + for _, problem := range barOverlaps(content, w.Canvas().Size().Width) { + t.Errorf("in %s, %s", where, problem) + } +} + +// barOverlaps is what noButtonOverAnother reports, as sentences, so the canary +// can ask it the same question. +func barOverlaps(content fyne.CanvasObject, windowWidth float32) []string { + drv := fyne.CurrentApp().Driver() + type placed struct { + name string + pos fyne.Position + size fyne.Size + } + var shown []placed + for _, name := range barButtonNames() { + b := buttonNamed(content, name) + if b == nil || !b.Visible() { + continue + } + shown = append(shown, placed{name, drv.AbsolutePositionForObject(b), b.Size()}) + } + var problems []string + for i, a := range shown { + if a.pos.X < 0 || a.pos.X+a.size.Width > windowWidth+0.5 { + problems = append(problems, fmt.Sprintf("%q runs from x=%.1f to x=%.1f, past the window's edge at %.0f", + a.name, a.pos.X, a.pos.X+a.size.Width, windowWidth)) + } + for _, b := range shown[i+1:] { + apart := a.pos.X+a.size.Width <= b.pos.X+0.5 || b.pos.X+b.size.Width <= a.pos.X+0.5 || + a.pos.Y+a.size.Height <= b.pos.Y+0.5 || b.pos.Y+b.size.Height <= a.pos.Y+0.5 + if !apart { + problems = append(problems, fmt.Sprintf("%q (x %.1f-%.1f, y %.1f) and %q (x %.1f-%.1f, y %.1f) stand over one another", + a.name, a.pos.X, a.pos.X+a.size.Width, a.pos.Y, b.name, b.pos.X, b.pos.X+b.size.Width, b.pos.Y)) + } + } + } + return problems +} + +// canaryBarThatCannotWrap builds the bar the way the work screens built it +// before 2026-11-26 - the offers in a row that has one line - in a window as +// narrow as the readable column leaves it, and asks that the check above finds +// the buttons over one another. A check that passes this bar would pass the +// bug. +func canaryBarThatCannotWrap(t *testing.T) { + newTestApp() + t.Cleanup(func() { newTestApp() }) + bar := parts.ActionBarEnds( + container.NewHBox(parts.NewButton(parts.Quiet, text.ButtonDonate(), func() {}).InTheBar(), + parts.NewButton(parts.Quiet, text.ButtonGitHub(), func() {}).InTheBar()), + parts.NewButton(parts.Secondary, text.ButtonCopyCommand(), func() {}).InTheBar(), + parts.ButtonRow( + parts.NewButton(parts.Secondary, text.ButtonPreview(), func() {}).InTheBar(), + parts.NewButton(parts.Primary, text.ButtonGenerate(), func() {}).InTheBar(), + parts.NewButton(parts.Secondary, text.ButtonOpenFolder(), func() {}).InTheBar(), + parts.NewButton(parts.Secondary, text.ButtonOpenManifest(), func() {}).InTheBar(), + parts.NewButton(parts.Secondary, text.ButtonOpenInstructions(), func() {}).InTheBar())) + w := test.NewWindow(bar) + t.Cleanup(w.Close) + size := fyne.NewSize(parts.ColumnWidth, 200) + w.Resize(size) + bar.Refresh() + w.Resize(size) + if len(barOverlaps(bar, size.Width)) == 0 { + t.Fatal("five buttons, a rail and Copy command on one line of a column as wide as the window allows, " + + "and the check found nothing over anything - it would pass the bar of #264 as well") + } +} diff --git a/internal/guard/barheld_test.go b/internal/guard/barheld_test.go new file mode 100644 index 00000000..264218d9 --- /dev/null +++ b/internal/guard/barheld_test.go @@ -0,0 +1,208 @@ +package guard + +import ( + "strings" + "sync" + "sync/atomic" + "testing" + "time" + + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/test" + + "github.com/donislawdev/TestingFilesGenerator/internal/engine" + "github.com/donislawdev/TestingFilesGenerator/internal/gui/parts" + "github.com/donislawdev/TestingFilesGenerator/internal/gui/text" + "github.com/donislawdev/TestingFilesGenerator/internal/gui/window" +) + +// TestTheFormDoesNotMoveWhenARunStartsAfterOneThatOfferedSomething is the run +// after a run whose offers stood on a line of their own under the buttons. +// +// The offers are taken away the moment the next run starts, and until +// 2026-11-26 they could not be on a line of their own. Since then they can +// (parts.ActionRow), and their line going with them would move the form at the +// press of Generate - the movement TestTheFormDoesNotMoveWhenARunStarts was +// written against, by a way into it that guard does not take. The batch screen, +// because there the offers do not fit beside the buttons in English, which is +// asserted rather than assumed. +func TestTheFormDoesNotMoveWhenARunStartsAfterOneThatOfferedSomething(t *testing.T) { + newTestApp().Settings().SetTheme(parts.Theme()) + t.Cleanup(func() { newTestApp() }) + host := newFakeHost(t) + screen := window.NewRecipe(host) + hold := newHold() + screen.HoldBeforeFinishing(hold.enter) + t.Cleanup(screen.Settled) + t.Cleanup(hold.free) + + content := screen.Object() + w := test.NewWindow(content) + t.Cleanup(w.Close) + w.Resize(window.LargestOpening) + settle(content, w) + + chooser, ok := controlUnder(content, text.FieldFormat()).(*parts.Chooser) + if !ok { + t.Fatal("the batch screen has no format menu, so this guard read the wrong tree") + } + chooser.SetSelected("txt") + fill(t, content, text.FieldSize(), "1kb") + fill(t, content, text.FieldOutputDir(), t.TempDir()) + press(t, content, text.ButtonGenerate()) + hold.look(func() {}) + screen.Settled() + settle(content, w) + + preview, folder := buttonNamed(content, text.ButtonPreview()), buttonNamed(content, text.ButtonOpenFolder()) + if preview == nil || folder == nil || !folder.Visible() { + t.Fatalf("after the first run the screen offers no %q, so there is no line of offers to lose. It says: %s", + text.ButtonOpenFolder(), textIn(content)) + } + drv := fyne.CurrentApp().Driver() + if drv.AbsolutePositionForObject(folder).Y <= drv.AbsolutePositionForObject(preview).Y { + t.Fatalf("%q stands on the line of %q, so the offers have no line of their own here and this guard "+ + "asks nothing - a longer offer or a narrower bar is what puts them under it", text.ButtonOpenFolder(), text.ButtonPreview()) + } + scroll := scrollIn(content) + if scroll == nil { + t.Fatal("the batch screen has no scrolling area, so this guard read the wrong tree") + } + atRest := scroll.Size().Height + previewAt := drv.AbsolutePositionForObject(preview) + + hold.again() + press(t, content, text.ButtonGenerate()) + hold.look(func() { + settle(content, w) + if during := scroll.Size().Height; during != atRest { + t.Errorf("after a run whose offers stood under the buttons the form has %.0f px, and once the next run "+ + "starts it has %.0f px - it moves %.0f px under the pointer that pressed Generate.\n"+ + "What to do: the run holds the row of buttons at its height until it is over (parts.HoldRows, "+ + "busy.keepRowHeight), before the offers are taken away.", atRest, during, during-atRest) + } + if at := drv.AbsolutePositionForObject(preview); at != previewAt { + t.Errorf("%q stood at %v and moved to %v when the next run started", text.ButtonPreview(), previewAt, at) + } + }) + screen.Settled() +} + +// searchHeld is a hold for the search behind Copy command: the first search to +// reach it waits there until the guard lets it go, and every search that +// reaches it is counted. A second one passes straight through, so a build that +// starts a search per press is counted rather than hung. +type searchHeld struct { + entered atomic.Int32 + reached chan struct{} + release chan struct{} + freed sync.Once +} + +func newSearchHeld() *searchHeld { + return &searchHeld{reached: make(chan struct{}, 1), release: make(chan struct{})} +} + +func (h *searchHeld) enter() { + if h.entered.Add(1) != 1 { + return + } + h.reached <- struct{}{} + <-h.release +} + +func (h *searchHeld) free() { h.freed.Do(func() { close(h.release) }) } + +// copyScreenHeld is the Single batch screen with the search behind its Copy +// command held, and the press that started it already returned - or the guard +// failed saying the press waited. +func copyScreenHeld(t *testing.T) (*window.Generate, *fakeHost, *searchHeld, *parts.Button) { + t.Helper() + host := newFakeHost(t) + gen := window.NewGenerate(host) + held := newSearchHeld() + gen.HoldBeforeFinishing(held.enter) + t.Cleanup(gen.Settled) + t.Cleanup(held.free) + content := gen.Object() + entryUnder(t, content, text.FieldOutputDir()).SetText(t.TempDir()) + copyBtn := buttonNamed(content, text.ButtonCopyCommand()) + if copyBtn == nil { + t.Fatalf("the Single batch screen has no %q button", text.ButtonCopyCommand()) + } + pressed := make(chan struct{}) + go func() { + copyBtn.OnTapped() + close(pressed) + }() + select { + case <-pressed: + case <-time.After(10 * time.Second): + t.Fatal("Copy command has not returned while the search for tfg is held inside its first look at the " + + "disk - the press waits for the search, so a folder on PATH that does not answer stops the window " + + "for as long as it takes") + } + select { + case <-held.reached: + case <-time.After(10 * time.Second): + t.Fatal("the press returned and no search for tfg ever reached its first look at the disk") + } + return gen, host, held, copyBtn +} + +// TestCopyCommandLeavesTheWindowFreeWhileItLooksForTfg holds the search for tfg +// behind Copy command inside its first look at the disk, and asks that the +// press has returned all the same - and that pressing again meanwhile neither +// starts a second search nor loses what was pressed last. +// +// The search looks at every folder on PATH, and a folder on a network host that +// does not answer took 21.0 s on 2026-11-26 (docs/REVIEW-264-2026-11-25.md, +// remark 4) - on the thread that draws the window, which stood still for all of +// it. Held inside the search rather than after it since the review of #266: a +// hold after the search let a search moved back onto the press pass, as long as +// it finished inside the time this guard waits. +func TestCopyCommandLeavesTheWindowFreeWhileItLooksForTfg(t *testing.T) { + gen, host, held, copyBtn := copyScreenHeld(t) + fields := gen.Fields() + setBox(t, fields, "size", "2kb") + copyBtn.OnTapped() + setBox(t, fields, "size", "3kb") + copyBtn.OnTapped() + if host.copied != "" { + t.Errorf("the clipboard holds %q while the search for tfg is still held - something other than "+ + "the search wrote it", host.copied) + } + held.free() + gen.Settled() + if n := held.entered.Load(); n != 1 { + t.Errorf("three presses while one search was under way started %d searches - each press at a folder "+ + "that does not answer would leave another worker waiting on it", n) + } + if !strings.Contains(host.copied, "3kb") { + t.Fatalf("after the search the clipboard holds %q, which is not the line of the last press, with 3kb", host.copied) + } +} + +// TestARefusedPressCopiesNothingWhileAnEarlierSearchAnswers presses Copy +// command on a form it takes, empties the batch name while the search is held, +// presses again and lets the search go: the refusal is the answer to the +// newest press, so nothing may reach the clipboard. Found by the review of +// #266 - the earlier search answered, copied the line from before the name was +// emptied, and said so under the refusal. +func TestARefusedPressCopiesNothingWhileAnEarlierSearchAnswers(t *testing.T) { + gen, host, held, copyBtn := copyScreenHeld(t) + fields := gen.Fields() + setBox(t, fields, engine.SettingID, "") + copyBtn.OnTapped() + if findField(fields, engine.SettingID).Saying() == "" { + t.Fatal("the emptied batch name was not refused, so there is no refusal for the earlier search to answer over") + } + held.free() + gen.Settled() + if host.copied != "" { + t.Errorf("the newest press was refused and the clipboard holds %q, the line of the press before it", host.copied) + } + if findField(fields, engine.SettingID).Saying() == "" { + t.Error("the refusal under the batch name went when the earlier search answered") + } +} diff --git a/internal/guard/codeshape_test.go b/internal/guard/codeshape_test.go index dc57ef58..9d4f8ce6 100644 --- a/internal/guard/codeshape_test.go +++ b/internal/guard/codeshape_test.go @@ -85,7 +85,10 @@ const ( // directory moved out of engine/engine.go into errors.go, so the window's // Copy command gives it in the same words. engine/engine.go is still the // longest. - longestFile = 384 + // Lowered from 384 on 2026-11-26: the refusal of a target with no id moved + // out of engine/engine.go into errors.go the same way, for the same + // button. engine/engine.go is still the longest. + longestFile = 382 // Depth answers a different question than length, and it is the better // question of the two. A hundred line function that is flat reads top to diff --git a/internal/guard/concurrency_test.go b/internal/guard/concurrency_test.go index aa7525c4..5ad22db9 100644 --- a/internal/guard/concurrency_test.go +++ b/internal/guard/concurrency_test.go @@ -48,6 +48,11 @@ var mayBeConcurrent = map[string]string{ // os.Stat on a worker, the answer back through fyne.Do, nothing shared but // a count read on the interface thread. "internal/gui/window/dropping.go": "what a dropped path is gets asked beside the window, so a network path that does not answer cannot freeze it", + // The same reason for the same kind of question: Copy command asks every + // folder on PATH whether tfg is in it, and one on a network host that does + // not answer took 21.0 s on 2026-11-26. The newest press wins, counted on + // the interface thread, and a guard waits on the group. + "internal/gui/window/copycommand.go": "where tfg is gets asked beside the window, so a folder on PATH that does not answer cannot freeze it", // Signals arrive on a channel by definition, and the handler has to run // beside the work it interrupts. "cmd/tfg/main.go": "the interrupt handler has to run beside the work it stops", diff --git a/internal/guard/copycommand_test.go b/internal/guard/copycommand_test.go index e48fc130..ad8b4ed8 100644 --- a/internal/guard/copycommand_test.go +++ b/internal/guard/copycommand_test.go @@ -64,7 +64,7 @@ func TestACommandCopiedFromSingleBatchMakesTheFilesTheWindowMakes(t *testing.T) fromLine := t.TempDir() entryUnder(t, content, text.FieldOutputDir()).SetText(fromLine) - line := copiedFrom(t, host, content) + line := copiedFrom(t, host, content, gen.Settled) for _, flag := range []string{commandline.Format, commandline.Set, commandline.Count, commandline.ID, commandline.NameTemplate, commandline.Seed, commandline.Damage, commandline.Clean, commandline.Out} { if !strings.Contains(line, flag) { @@ -96,7 +96,7 @@ func TestACommandCopiedFromPresetsMakesTheFilesTheWindowMakes(t *testing.T) { fromLine := t.TempDir() entryUnder(t, content, text.FieldOutputDir()).SetText(fromLine) - line := copiedFrom(t, host, content) + line := copiedFrom(t, host, content, screen.Settled) for _, flag := range []string{commandline.Preset, "--limit", "--spread", commandline.Format, commandline.Seed} { if !strings.Contains(line, flag) { t.Fatalf("the copied line has no %s:\n%s", flag, line) @@ -133,7 +133,7 @@ func TestACommandCopiedFromToolsReadsTheFileTheBoxNames(t *testing.T) { setBox(t, fields, "file", file) setBox(t, fields, "algorithm", "sha256") - line := copiedFrom(t, host, content) + line := copiedFrom(t, host, content, screen.Settled) out := runCopied(t, line) sum := sha256.Sum256(body) if !strings.Contains(out, hex.EncodeToString(sum[:])) { @@ -158,6 +158,10 @@ func TestCopyCommandRefusesWhatGenerateRefusesAndCopiesNothing(t *testing.T) { {"a size that is not a size", "", "size", "ten", "10kb", ""}, {"a name template with a tab in it", "", "name", "a\tb_{index}.txt", "ab_{index}.txt", text.CommandControlCharacter()}, {"a damage setting with a comma in it", damage.ZeroHead, damage.SettingBytes, "1,6", "16", text.CommandCommaInDamage()}, + // The line leaves an empty flag out, and without --id the command + // runs under the name it fills in itself - so until 2026-11-26 the copy + // of this form ran where Generate refused (review of #264, remark 7). + {"a batch name left empty", "", engine.SettingID, "", "files", ""}, // The command does not refuse this one itself: without --out it writes // into the folder the terminal is in, where the window refuses. {"an output folder left empty", "", engine.SettingOutDir, "", os.TempDir(), ""}, @@ -183,6 +187,7 @@ func TestCopyCommandRefusesWhatGenerateRefusesAndCopiesNothing(t *testing.T) { t.Fatalf("the box holds %q rather than %q, so there is nothing to refuse", got, c.bad) } press(t, content, text.ButtonCopyCommand()) + gen.Settled() if host.copied != "" { t.Errorf("a refused form put %q on the clipboard", host.copied) } @@ -193,6 +198,7 @@ func TestCopyCommandRefusesWhatGenerateRefusesAndCopiesNothing(t *testing.T) { setBox(t, fields, c.box, c.good) press(t, content, text.ButtonCopyCommand()) + gen.Settled() if host.copied == "" { t.Fatalf("the form put right copied nothing either, so the refusal above proves nothing") } @@ -205,10 +211,12 @@ func TestCopyCommandRefusesWhatGenerateRefusesAndCopiesNothing(t *testing.T) { // copiedFrom presses Copy command and answers the line, after asking that the // status line says which shell it was written for. -func copiedFrom(t *testing.T, host *fakeHost, o fyne.CanvasObject) string { +func copiedFrom(t *testing.T, host *fakeHost, o fyne.CanvasObject, settled func()) string { t.Helper() host.copied = "" press(t, o, text.ButtonCopyCommand()) + // Where tfg is, is asked on a worker - the copy lands when it answers. + settled() if host.copied == "" { t.Fatalf("Copy command put nothing on the clipboard. The screen says: %s", textIn(o)) } diff --git a/internal/guard/copyrecipe_test.go b/internal/guard/copyrecipe_test.go index 6c05a99e..76e08f4c 100644 --- a/internal/guard/copyrecipe_test.go +++ b/internal/guard/copyrecipe_test.go @@ -66,6 +66,7 @@ func TestACommandCopiedFromSeveralBatchesMakesTheFilesTheWindowMakes(t *testing. // folder the terminal is in, where Generate refuses. setBox(t, fields, recipe.KeyOutputDir, "") press(t, body, text.ButtonCopyCommand()) + screen.Settled() if host.copied != "" || findField(fields, recipe.KeyOutputDir).Saying() == "" { t.Errorf("with the output folder emptied the clipboard holds %q and the box says %q", host.copied, findField(fields, recipe.KeyOutputDir).Saying()) } @@ -79,7 +80,7 @@ func TestACommandCopiedFromSeveralBatchesMakesTheFilesTheWindowMakes(t *testing. t.Run(filepath.Base(shell), func(t *testing.T) { fromScript := t.TempDir() setBox(t, fields, recipe.KeyOutputDir, fromScript) - script := copiedFrom(t, host, body) + script := copiedFrom(t, host, body, screen.Settled) last := script[strings.LastIndex(script, "\n")+1:] if !strings.HasPrefix(last, commandline.Name+" ") { t.Fatalf("the last command does not start tfg by its name, so the stand in put first on PATH is not what runs:\n%s", script) diff --git a/internal/guard/provenbyprobe_test.go b/internal/guard/provenbyprobe_test.go index 7ec47192..54392c4c 100644 --- a/internal/guard/provenbyprobe_test.go +++ b/internal/guard/provenbyprobe_test.go @@ -492,4 +492,23 @@ var provenByProbe = map[string]string{ "TestAValueNoLineCanCarryIsRefusedUnderItsSetting": "every row requires a refusal of one kind under one setting, so a " + "writer that refused nothing, or refused under another name, fails every row. The rows of a saved text were red on " + "2026-11-25 with the check of the line that ends it switched off.", + // The review of #264, 2026-11-26 (docs/REVIEW-264-2026-11-25.md). Each was + // broken once through go test -overlay, the tree untouched, and the row + // for an emptied batch name of the guard above was red the same way with + // the window no longer asking engine.MissingID. + "TestTheBarsButtonsNeverStandOverOneAnother": "its own canary - a bar whose offers stand in a row that cannot wrap, in " + + "a column as wide as the window allows, must be found with buttons over one another - and broken on 2026-11-26 by " + + "building the work screens' row with ButtonRow again: red.", + "TestTheFormDoesNotMoveWhenARunStartsAfterOneThatOfferedSomething": "broken on 2026-11-26 by no longer holding the row " + + "before the offers are taken away: red, the form grew 41 px at the press of Generate. It asserts that the offers " + + "stood on a line of their own first, or it asks nothing.", + "TestCopyCommandLeavesTheWindowFreeWhileItLooksForTfg": "broken on 2026-11-26, after the review of #266 moved the " + + "hold inside the search, by searching on the thread of the press: red, the press had not returned. And by " + + "starting a search per press: red, three searches for three presses. It asks that the line of the last press " + + "reaches the clipboard once the search is let go, so a press that copied nothing does not pass.", + "TestARefusedPressCopiesNothingWhileAnEarlierSearchAnswers": "broken on 2026-11-26 by forgetting the earlier " + + "press only after the form was taken: red, the earlier search copied its line over the refusal. It asserts " + + "the refusal first.", + "TestAnOfferWiderThanTheRunButtonsStaysInsideTheBar": "broken on 2026-11-26 by leaving the widest offer out of " + + "the row's minimum: red, the offer ended at 423 px in a window 107 px wide.", } diff --git a/internal/guard/testdata/screens/catalogue.png b/internal/guard/testdata/screens/catalogue.png index a653caef..0c75c149 100644 Binary files a/internal/guard/testdata/screens/catalogue.png and b/internal/guard/testdata/screens/catalogue.png differ diff --git a/internal/guard/testdata/screens/catalogue.xml b/internal/guard/testdata/screens/catalogue.xml index 277ac99a..492c5050 100644 --- a/internal/guard/testdata/screens/catalogue.xml +++ b/internal/guard/testdata/screens/catalogue.xml @@ -1,7 +1,7 @@ - + - - + + @@ -4445,12 +4445,12 @@ - - - - + + + + Section - + @@ -4686,7 +4686,76 @@ - + + + + + the bar after a run, its offers on a line of their own + + + + + + + + + + + + + + + Preview + + + + + Generate + + + + + Open folder + + + + + Open manifest + + + + + Open instructions with a much longer name + + + + + + + + + + Donate + + + + + + + + + + Copy command + + + + + + + + + + @@ -4824,7 +4893,7 @@ - + @@ -4939,7 +5008,7 @@ - + @@ -5010,7 +5079,7 @@ - + @@ -5080,7 +5149,7 @@ - + @@ -5702,7 +5771,7 @@ - + @@ -6324,7 +6393,7 @@ - + @@ -6489,7 +6558,7 @@ - + diff --git a/internal/gui/catalogue/words.go b/internal/gui/catalogue/words.go index 72efed51..6158e8bb 100644 --- a/internal/gui/catalogue/words.go +++ b/internal/gui/catalogue/words.go @@ -74,6 +74,20 @@ func textRanks() Entry { }} } +// barAfterARun is the bar the way a finished run leaves it when what the run +// offers has no room beside the buttons that run something: the offers on a +// line of their own under them (parts.ActionRow). +func barAfterARun() fyne.CanvasObject { + return parts.ActionBarEnds(container.NewHBox(parts.NewButton(parts.Quiet, "Donate", func() {}).InTheBar()), + parts.NewButton(parts.Secondary, "Copy command", func() {}).InTheBar(), + parts.ActionRow([]fyne.CanvasObject{ + parts.NewButton(parts.Secondary, "Preview", func() {}).InTheBar(), + parts.NewButton(parts.Primary, "Generate", func() {}).InTheBar()}, + parts.NewButton(parts.Secondary, "Open folder", func() {}).InTheBar(), + parts.NewButton(parts.Secondary, "Open manifest", func() {}).InTheBar(), + parts.NewButton(parts.Secondary, "Open instructions with a much longer name", func() {}).InTheBar())) +} + // What a screen is built from besides its fields: the panel a section is, // the line between two things, and the bar a run is started from. func structure() Entry { @@ -83,7 +97,7 @@ func structure() Entry { two := s.Add("count", "How many files", "1", parts.NoDetail, parts.NewEntry()) return []fyne.CanvasObject{one, two} } - return Entry{Name: "Section", Covers: []string{"Divider", "ActionBar", "ActionBarEnds"}, States: []State{ + return Entry{Name: "Section", Covers: []string{"Divider", "ActionBar", "ActionBarEnds", "ActionRow"}, States: []State{ {"a section of two rows", func() fyne.CanvasObject { return parts.Section("File configuration", twoRows()...) }}, @@ -108,6 +122,7 @@ func structure() Entry { parts.NewButton(parts.Secondary, "Preview", func() {}).InTheBar(), parts.NewButton(parts.Primary, "Generate", func() {}).InTheBar())) }}, + {"the bar after a run, its offers on a line of their own", barAfterARun}, {"fields in columns, each as wide as its value needs", func() fyne.CanvasObject { s := form() return parts.Section("File configuration", diff --git a/internal/gui/parts/buttonrow.go b/internal/gui/parts/buttonrow.go index c93317e5..3ae028d7 100644 --- a/internal/gui/parts/buttonrow.go +++ b/internal/gui/parts/buttonrow.go @@ -15,50 +15,200 @@ import ( // read as one control. What is hidden takes no room and no gap, so Cancel and // the two offers after a run come and go without leaving a hole. func ButtonRow(items ...fyne.CanvasObject) *fyne.Container { - return container.New(&buttonRow{}, items...) + return container.New(&buttonRow{lead: len(items)}, items...) } -// buttonRow is the layout behind ButtonRow. clearLeft and clearRight are room -// at either end the row keeps free of buttons - the rails laid over the action -// bar, see railOver - and nought everywhere else. Fields of the layout rather -// than a move made from outside, because the row lays itself out again whenever -// a button in it comes or goes, and a move made once would be undone by the -// next of those. -type buttonRow struct{ clearLeft, clearRight float32 } +// ActionRow is the ButtonRow of the bar at the foot of a work screen: the +// buttons that run something, then the ones a finished run offers. The offers +// stand beside the others while there is room for them between the rails, and +// on a line of their own under the others when there is not. +// +// Measured on 2026-11-26 with guirender after the review of #264 +// (docs/REVIEW-264-2026-11-25.md): one line was all the row had, and once Copy +// command stood at the right end, the offers of a finished run ran under it - +// Open manifest of the batch screen entirely, in English. The bar is never +// wider than the readable column, so no window was wide enough to undo it, and +// a translation or a third offer brings it back at any width. A second line is +// the answer that holds for all three. +func ActionRow(run []fyne.CanvasObject, offers ...fyne.CanvasObject) *fyne.Container { + items := append(append([]fyne.CanvasObject{}, run...), offers...) + return container.New(&buttonRow{lead: len(run), wraps: true}, items...) +} -func (*buttonRow) MinSize(objects []fyne.CanvasObject) fyne.Size { - size := fyne.NewSize(0, 0) - shown := 0 - for _, o := range objects { - if !o.Visible() { - continue +// HoldRows keeps an ActionRow at the height it has now, or lets it go. A run +// holds it from the press to its last word, so the offers of the run before, +// taken away when the next one starts, do not take their line with them and +// move the form under the pointer that has just pressed Generate - the +// movement TestTheFormDoesNotMoveWhenARunStarts was written against. Any other +// row is left as it is. +func HoldRows(row *fyne.Container, hold bool) { + b, ok := row.Layout.(*buttonRow) + if !ok { + return + } + b.held = 0 + if hold { + b.held = row.MinSize().Height + } +} + +// buttonRow is the layout behind ButtonRow and ActionRow. clearLeft and +// clearRight are room at either end of the first line the row keeps free of +// buttons - the rails laid over the action bar, see railOver - and nought +// everywhere else. Fields of the layout rather than a move made from outside, +// because the row lays itself out again whenever a button in it comes or goes, +// and a move made once would be undone by the next of those. +type buttonRow struct { + clearLeft, clearRight float32 + // lead is how many of the buttons run something. wraps says whether the + // ones after them may go to a line of their own - ActionRow. + lead int + wraps bool + // width is the width the row was last laid out at. How many lines it + // takes depends on it, which a toolkit minimum cannot say directly - + // remembered for the reason formGrid remembers its own. + width float32 + // held is a height the row keeps while a run owns the screen - HoldRows. + held float32 +} + +// MinSize is as wide as the buttons that run something, or the widest offer if +// that is wider - the offers can always go under them, one to a line at the +// least - and as tall as the lines the row takes at the width it was last +// given, or as it is held. +func (b *buttonRow) MinSize(objects []fyne.CanvasObject) fyne.Size { + width := lineWidth(shown(objects)) + if b.wraps { + lead := min(b.lead, len(objects)) + width = lineWidth(shown(objects[:lead])) + for _, o := range shown(objects[lead:]) { + width = fyne.Max(width, o.MinSize().Width) } - min := o.MinSize() - size.Width += min.Width - size.Height = fyne.Max(size.Height, min.Height) - shown++ } - if shown > 1 { - size.Width += GapButtons * float32(shown-1) + size := fyne.NewSize(width, 0) + tallest := lineHeight(shown(objects)) + for i, line := range b.lines(objects, b.width) { + if i > 0 { + size.Height += GapButtonRows + } + size.Height += heightOf(line, tallest) } + size.Height = fyne.Max(size.Height, b.held) return size } func (b *buttonRow) Layout(objects []fyne.CanvasObject, size fyne.Size) { - // Centred, and moved off centre only as far as the room kept clear asks - - // so in a wide window nothing changes, and a narrow one does not have to be - // wide enough to centre the row clear of both rails. The left rail wins - // when both ask, and the bar is never narrower than both need (railOver). - width := b.MinSize(objects).Width - x := fyne.Min((size.Width-width)/2, size.Width-b.clearRight-width) - x = fyne.Max(x, b.clearLeft) + b.width = size.Width + lines := b.lines(objects, size.Width) + tallest := lineHeight(shown(objects)) + var top float32 + for i, line := range lines { + width, height := lineWidth(line), heightOf(line, tallest) + // The first line is centred, and moved off centre only as far as the + // room kept clear asks - so in a wide window nothing changes, and a + // narrow one does not have to be wide enough to centre the row clear + // of both rails. The left rail wins when both ask, and the bar is + // never narrower than both need (railOver). The rails are one line + // tall, so the lines under them are centred in the whole width. + x := fyne.Max((size.Width-width)/2, 0) + if i == 0 { + x = fyne.Min((size.Width-width)/2, size.Width-b.clearRight-width) + x = fyne.Max(x, b.clearLeft) + } + // One line stands in the middle of the height it is given, which is + // the head of a batch taller than its buttons. Lines under one another, + // or a row held taller than its one line, start at the top, so the + // buttons that run something stay where the pointer left them. + if len(lines) == 1 && b.held == 0 { + top = (size.Height - height) / 2 + } + for _, o := range line { + min := o.MinSize() + o.Resize(min) + o.Move(fyne.NewPos(x, top+(height-min.Height)/2)) + x += min.Width + GapButtons + } + top += height + GapButtonRows + } +} + +// lines is how the shown buttons stand at a width: all on one line while they +// fit between the rails, and otherwise the buttons that run something on the +// first line and the offers under them, as many to a line as the whole width +// takes. When not even the buttons that run something fit between the rails - +// longer words in a column that cannot grow, which the pseudo language shows on +// the batch screen - the first line is left to the rails and every button goes +// under them. A row that does not wrap, or a width not known yet, is one line. +func (b *buttonRow) lines(objects []fyne.CanvasObject, width float32) [][]fyne.CanvasObject { + lead := min(b.lead, len(objects)) + run, offers := shown(objects[:lead]), shown(objects[lead:]) + all := append(append([]fyne.CanvasObject{}, run...), offers...) + between := width - b.clearLeft - b.clearRight + if !b.wraps || width <= 0 || lineWidth(all) <= between { + return [][]fyne.CanvasObject{all} + } + lines := [][]fyne.CanvasObject{run} + under := offers + if lineWidth(run) > between { + lines, under = [][]fyne.CanvasObject{nil}, all + } + var line []fyne.CanvasObject + var taken float32 + for _, o := range under { + w := o.MinSize().Width + if len(line) > 0 && taken+GapButtons+w > width { + lines = append(lines, line) + line, taken = nil, 0 + } + if len(line) > 0 { + taken += GapButtons + } + line = append(line, o) + taken += w + } + if len(line) > 0 { + lines = append(lines, line) + } + return lines +} + +// heightOf is the height of a line: its tallest button, or for the first line +// left to the rails, the height of the bar's buttons, which is the rails'. +func heightOf(line []fyne.CanvasObject, tallest float32) float32 { + if len(line) == 0 { + return tallest + } + return lineHeight(line) +} + +// shown is the buttons that are not hidden, in their order. +func shown(objects []fyne.CanvasObject) []fyne.CanvasObject { + var out []fyne.CanvasObject for _, o := range objects { - if !o.Visible() { - continue + if o.Visible() { + out = append(out, o) + } + } + return out +} + +// lineWidth is how wide buttons stand side by side, GapButtons apart. +func lineWidth(line []fyne.CanvasObject) float32 { + var width float32 + for i, o := range line { + if i > 0 { + width += GapButtons } - min := o.MinSize() - o.Resize(min) - o.Move(fyne.NewPos(x, (size.Height-min.Height)/2)) - x += min.Width + GapButtons + width += o.MinSize().Width + } + return width +} + +// lineHeight is the height of the tallest button on a line. +func lineHeight(line []fyne.CanvasObject) float32 { + var height float32 + for _, o := range line { + height = fyne.Max(height, o.MinSize().Height) } + return height } diff --git a/internal/gui/parts/tokens.go b/internal/gui/parts/tokens.go index 5ead2bd9..98c4445b 100644 --- a/internal/gui/parts/tokens.go +++ b/internal/gui/parts/tokens.go @@ -215,6 +215,11 @@ const ( // about 4 px, so Preview and Generate, and Duplicate and Remove, each read // as one control with two words in it. GapButtons = space3 + // GapButtonRows is the space between two lines of buttons in that bar, + // when what a finished run offers goes under the buttons that run + // something (ActionRow). The same as between two buttons side by side, so + // the two lines read as one group rather than as a second bar. + GapButtonRows = GapButtons // GlyphButton is the side of the small square button that holds one // glyph - the mark beside a field's name that opens its explanation. The // glyph itself is the toolkit's inline icon, 20, and the square keeps two diff --git a/internal/gui/window/copycommand.go b/internal/gui/window/copycommand.go index 1f64a982..d67196e1 100644 --- a/internal/gui/window/copycommand.go +++ b/internal/gui/window/copycommand.go @@ -7,6 +7,9 @@ import ( "runtime" "strconv" "strings" + "sync" + + "fyne.io/fyne/v2" "github.com/donislawdev/TestingFilesGenerator/internal/commandline" "github.com/donislawdev/TestingFilesGenerator/internal/core" @@ -44,6 +47,18 @@ type copying struct { // fields gives a setting the label its box shows, for the line that // names boxes. fields *parts.Fields + // looking is the search for tfg on a worker, waited for by a guard. + // searching says one is under way, and waiting is the line of the newest + // press for its answer, or nil when that press was refused. Both are read + // and written on the interface thread only. + looking sync.WaitGroup + searching bool + waiting commandline.Command + // hold is the screen's busy.holdBeforeFinishing, passed through inside + // the search, at its first look at the disk - so a guard can hold the + // search itself and see the window answer meanwhile. Nothing in the + // shipped program. + hold func() } // newCopying builds the button. The screen hands over where its words go, @@ -59,16 +74,76 @@ func newCopying(host Host, fields *parts.Fields, line func() (commandline.Comman // // A refusal from putting the line together goes through unwritable as well as // one from writing it, because a damage setting with a comma is refused there, -// and it belongs under its box in the words of this window. +// and it belongs under its box in the words of this window. Both are asked on +// this thread, at the press, so a refusal lands under the box the moment the +// button is pressed - and a search still under way for an earlier press then +// copies nothing, since the newest press is the one that counts. +// +// Where tfg is, is asked on a worker. It looks at every folder on PATH, and a +// folder on a network host that does not answer took 21.0 s on 2026-11-26 +// (docs/REVIEW-264-2026-11-25.md, remark 4) - the window stood still for all of +// it. On this machine's own PATH it is 561 looks and 16 ms. One search at a +// time: a press while one is under way leaves its line for that search's answer +// instead of starting another, so pressing again and again at a folder that +// does not answer adds no worker. func (c *copying) press() { + c.waiting = nil c.clear() l, err := c.line() + if err == nil { + _, err = l.Write(commandline.Program{Where: commandline.Missing}, commandline.ShellFor(runtime.GOOS)) + } if err != nil { c.refuse(unwritable(err)) return } + c.waiting = l + if c.searching { + return + } + c.searching = true + c.looking.Add(1) + go c.lookFor() +} + +// lookFor asks where tfg is, on the worker, and hands the answer to the +// interface thread. +func (c *copying) lookFor() { + defer c.looking.Done() + program := commandline.Locate(c.system()) + fyne.Do(func() { c.answer(program) }) +} + +// system is this computer as the search reads it, with the guard's hold, when +// there is one, in front of its first look at the disk. +func (c *copying) system() commandline.System { + sys := thisSystem() + if c.hold == nil { + return sys + } + stat, held := sys.Stat, false + sys.Stat = func(name string) (os.FileInfo, error) { + if !held { + held = true + c.hold() + } + return stat(name) + } + return sys +} + +// answer copies the line of the newest press with the word that starts tfg on +// this computer, on the interface thread - or nothing, when that press was +// refused. +func (c *copying) answer(program commandline.Program) { + c.searching = false + l := c.waiting + c.waiting = nil + if l == nil { + return + } shell := commandline.ShellFor(runtime.GOOS) - written, err := l.Write(commandline.Locate(thisSystem()), shell) + written, err := l.Write(program, shell) if err != nil { c.refuse(unwritable(err)) return @@ -164,6 +239,8 @@ func offerCopy(r *runner, host Host, line func() (commandline.Command, error)) * c.clear = r.clearProblems c.refuse = r.refuse r.busy.also = append(r.busy.also, c.btn) + r.busy.lookups = append(r.busy.lookups, c.looking.Wait) + c.hold = r.busy.holdBeforeFinishing return c.btn } diff --git a/internal/gui/window/generate.go b/internal/gui/window/generate.go index 4444c9fb..f6e60f31 100644 --- a/internal/gui/window/generate.go +++ b/internal/gui/window/generate.go @@ -698,6 +698,12 @@ func (g *Generate) settle() ([]engine.Target, engine.Options, error) { if err != nil { bad = append(bad, err) } + // Asked here and not left to the run, because Copy command settles the + // form too and leaves an empty flag out - the copy of an emptied name + // would run under the command line's own, where Generate refuses. + if err := engine.MissingID(g.id.Text); err != nil { + bad = append(bad, err) + } if len(bad) > 0 { return nil, none, errors.Join(bad...) diff --git a/internal/gui/window/run.go b/internal/gui/window/run.go index 1627346a..f6f916ba 100644 --- a/internal/gui/window/run.go +++ b/internal/gui/window/run.go @@ -595,7 +595,9 @@ func (r *runner) onGenerate() { // Remembered here rather than read back afterwards, because the box on the // screen can be edited while a run is going and the button has to open // where the files ACTUALLY went. Hidden first, so a run that produces - // nothing does not leave the offer from the run before it standing. + // nothing does not leave the offer from the run before it standing - with + // the row held at its height, so their line does not go with them. + r.busy.keepRowHeight() r.offer.forget() r.offer.wroteInto = opt.OutDir r.startRun(targets, opt) @@ -824,8 +826,12 @@ func (r *runner) HoldWhileWriting(fn func(ctx context.Context)) { r.busy.writing // that distinction disappears, because there fyne.Do runs on the calling // goroutine, so the callback has already run by the time the channel closes - // which is why a guard may read the screen the moment this returns, and why the -// limit is a production one rather than a test one. -func (r *runner) Settled() { r.work.settled() } +// limit is a production one rather than a test one. The search behind Copy +// command is waited for the same way, with the same limit. +func (r *runner) Settled() { + r.work.settled() + r.busy.settledLookups() +} // wholeNumber reads a plain count out of a box. // diff --git a/internal/gui/window/runactions.go b/internal/gui/window/runactions.go index e6e7aede..1e60a27c 100644 --- a/internal/gui/window/runactions.go +++ b/internal/gui/window/runactions.go @@ -77,8 +77,10 @@ func (r *runner) actions() fyne.CanvasObject { // row out again when a button in it is hidden - see busy.relay. // // A row of ours with a wider gap since the prototype of 2026-09-23 - see - // parts.ButtonRow. - r.busy.row = parts.ButtonRow(r.previewBtn, r.generateBtn, r.busy.cancel, + // parts.ButtonRow. The offers of a finished run go to a line of their own + // when they do not fit beside the buttons, since 2026-11-26 - see + // parts.ActionRow. + r.busy.row = parts.ActionRow([]fyne.CanvasObject{r.previewBtn, r.generateBtn, r.busy.cancel}, r.offer.folderBtn, r.offer.manifest.btn, r.offer.instructions.btn) return r.busy.row } diff --git a/internal/gui/window/runbusy.go b/internal/gui/window/runbusy.go index c884a10b..1b24a2bd 100644 --- a/internal/gui/window/runbusy.go +++ b/internal/gui/window/runbusy.go @@ -72,6 +72,10 @@ type busy struct { // have no business being pressed while work is going. The batch screen's // "add a batch" is one: pressing it rebuilds the form under a run. also []fyne.Disableable + // lookups wait for what the screen's buttons ask on a worker without + // owning the screen - the search for tfg behind Copy command - so a guard + // can wait for their answers as it waits for work. See settledLookups. + lookups []func() // row is the row the buttons stand in, laid out again whenever one of // them comes or goes - see relay. row *fyne.Container @@ -95,6 +99,8 @@ type busy struct { // screen is told the work has ended. Nil in the shipped program - see // runner.HoldBeforeFinishing for what it is for. Here rather than on the // screens since 2026-11-03, when the Tools tab came to need it as well. + // The search for tfg behind Copy command passes through it too, inside the + // search, at its first look at the disk - see copying.system. hold func() // writing, when a guard supplies one, is run on a writer each time a run @@ -187,9 +193,30 @@ func (b *busy) undress() { b.cancel.Disable() b.cancel.Hide() b.bar.Hide() + if b.row != nil { + parts.HoldRows(b.row, false) + } b.relay() } +// settledLookups waits for every lookup a button started, for a guard. +func (b *busy) settledLookups() { + for _, wait := range b.lookups { + wait() + } +} + +// keepRowHeight holds the row of buttons at the height it has now until the +// work is over - undress lets it go. Asked for before the offers of the run +// before are taken away, because those can stand on a line of their own and +// the line would go with them, moving the form at the press of Generate. See +// parts.HoldRows. +func (b *busy) keepRowHeight() { + if b.row != nil { + parts.HoldRows(b.row, true) + } +} + // halt asks the work wearing this face to stop, and turns the face to // stopping - Cancel and Escape on every screen that does work. // diff --git a/internal/gui/window/tools.go b/internal/gui/window/tools.go index 552aaa9b..29c80fd7 100644 --- a/internal/gui/window/tools.go +++ b/internal/gui/window/tools.go @@ -155,9 +155,11 @@ func NewTools(host Host) *Tools { t.status = widget.NewLabel("") t.status.Wrapping = fyne.TextWrapWord t.fault = parts.NewErrorArea() - copyBtn := toolCopying(host, t).btn + copying := toolCopying(host, t) + copyBtn := copying.btn t.busy = &busy{fields: t.fields, starters: []*parts.Button{run}, cancel: cancel, bar: bar, later: host.Later, - also: []fyne.Disableable{copyBtn}} + also: []fyne.Disableable{copyBtn}, lookups: []func(){copying.looking.Wait}} + copying.hold = t.busy.holdBeforeFinishing t.busy.row = parts.ButtonRow(run, cancel, t.offer.btn) t.view.scroll = parts.VScroll(parts.Screen( @@ -215,8 +217,12 @@ func (t *Tools) onCancel() { t.busy.halt(t.job, t.status) } // It waits, so it is called off the interface thread - see closing.go. func (t *Tools) Stop() { t.job.stop() } -// Settled waits for the tool that is running to finish, for a guard. -func (t *Tools) Settled() { t.job.settled() } +// Settled waits for the tool that is running to finish, and for the search +// behind Copy command, for a guard. +func (t *Tools) Settled() { + t.job.settled() + t.busy.settledLookups() +} // HoldBeforeFinishing sets a hold the tool passes through on its way to // reporting, for a guard - see runner.HoldBeforeFinishing.