diff --git a/.github/ci/install-git.sh b/.github/ci/install-git.sh index 756c7702..2f057672 100644 --- a/.github/ci/install-git.sh +++ b/.github/ci/install-git.sh @@ -4,6 +4,15 @@ set -euo pipefail version="$1" prefix="$HOME/gits/$version" +# fetch saves a download to a file, so a retry starts the file afresh +# instead of feeding a second copy into a pipe that already holds part +# of the first. github.com answers 503 and 504 now and then, and one such +# answer used to fail the whole job. +fetch() { + curl -sSfL --connect-timeout 30 --retry 5 --retry-delay 10 --retry-all-errors \ + -o "$2" "$1" +} + install_linux() { if [ ! -x "$prefix/bin/git" ]; then { @@ -11,7 +20,12 @@ install_linux() { sudo apt-get install -y --no-install-recommends \ libcurl4-openssl-dev zlib1g-dev libexpat1-dev libssl-dev work=$(mktemp -d) - curl -sSfL "https://github.com/git/git/archive/refs/tags/v$version.tar.gz" | tar xz -C "$work" + archive="$work/git-$version.tar.gz" + # kernel.org carries the release tarballs too, and they unpack to the + # same git-$version directory, so it stands in when github.com is down. + fetch "https://github.com/git/git/archive/refs/tags/v$version.tar.gz" "$archive" || + fetch "https://mirrors.edge.kernel.org/pub/software/scm/git/git-$version.tar.gz" "$archive" + tar xzf "$archive" -C "$work" make -C "$work/git-$version" -j"$(nproc)" prefix="$prefix" NO_TCLTK=1 NO_GETTEXT=1 install rm -rf "$work" } >&2 @@ -27,8 +41,8 @@ install_windows() { if [ ! -x "$prefix/cmd/git.exe" ]; then { mkdir -p "$prefix" - curl -sSfL -o "$HOME/portable-git.exe" \ - "https://github.com/git-for-windows/git/releases/download/v$version.windows.1/PortableGit-$version-64-bit.7z.exe" + fetch "https://github.com/git-for-windows/git/releases/download/v$version.windows.1/PortableGit-$version-64-bit.7z.exe" \ + "$HOME/portable-git.exe" "$HOME/portable-git.exe" -y "-o$(cygpath -w "$prefix")" rm -f "$HOME/portable-git.exe" } >&2 diff --git a/.github/workflows/gitmatrix.yml b/.github/workflows/gitmatrix.yml index 57017a54..39bac3fa 100644 --- a/.github/workflows/gitmatrix.yml +++ b/.github/workflows/gitmatrix.yml @@ -28,7 +28,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest] + os: [ubuntu-24.04, windows-latest] git: ["2.30.2", "2.39.2", "2.47.1"] suite: [oracle-ops-git, oracle-rest] defaults: diff --git a/CHANGELOG.md b/CHANGELOG.md index 539ca871..93b39117 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,50 @@ # Изменения +## 1.7.2 — 2026-11-11 + +Новый движок, текст как в Windows, окна сравнения и разрешения конфликтов +сворачиваются по сторонам и запоминают вид, ветки main и develop стоят первыми. + +### Текст + +- Движок headless-gui обновлён до v4.5.0 (с v3.43.0). Текст рисуется так, как + настроен в системе: при включённом ClearType — субпиксельным сглаживанием (по + цифрам — как у самой Windows на том же шрифте) с порядком подпикселей монитора, + в удалённом сеансе (RDP) и при сером сглаживании — серым. Переключение + ClearType или вход по RDP меняют вид сразу, без перезапуска. +- Шрифт интерфейса на Windows — Verdana: на мелком кегле она читается чётче + прежнего Go Regular. На Linux шрифт прежний. +- Диалоги и плавающие панели в собственных окнах рисуют текст тем же шрифтом и + тем же сглаживанием, что главное окно. +- На Windows 11 у окна и диалогов на скруглённых углах больше нет второй дуги + рамки: рамку рисует сама система, цвет акцента — тоже она. + +### Сравнение и конфликты + +- В окне сравнения можно свернуть левую или правую сторону и двигать границу + между ними; у окна есть кнопки «развернуть» и «свернуть». +- В окне разрешения конфликтов сворачиваются «Наша», «База» и «Их», итог или + исходные панели разворачиваются на всю высоту, границу между верхом и итогом + можно двигать. Появились «Повторить», меню «Все конфликты» (взять нашу или их + во всех нерешённых, снова отметить все нерешёнными) и раздельная прокрутка. +- Оба окна открываются такими, какими их закрыли: размер, свёрнутые стороны, + граница, база и совместная прокрутка хранятся в `config.toml`. + +### Ветки + +- develop и master git-flow, ветка по умолчанию каждого сервера и обычные main, + master и develop стоят первыми в группе «Основные» со своим значком, и на + каждом сервере тоже первыми. Группу можно выключить в меню панели, выбор + устаревших веток основные не трогает. Ветка по умолчанию сервера вроде + `release/current` больше не повторяется в разделе релизов. + +### Исправления + +- Установщик снова показывает текст лицензии: с 1.6.1 окно лицензии было пустым. +- Ошибка в виджете или обработчике больше не роняет приложение: движок её + перехватывает, Go.Git пишет в журнал один раз на место, без секретов. +- Раскладка окна, закрытого дважды (из окна и из движка), сохраняется один раз. + ## 1.7.1 — 2026-10-25 Мелкий текст стал чётче, статус больших рабочих папок считается вдвое быстрее, а diff --git a/README.en.md b/README.en.md index cd8bf2ff..fb060c50 100644 --- a/README.en.md +++ b/README.en.md @@ -10,14 +10,14 @@ interface. An alternative to the paid SmartGit. - Its own implementation of git in pure Go: no installed git is required. - `CGO_ENABLED=0`, a single executable with all resources built in. -- Graphics engine [headless-gui/v3](https://github.com/oops1/headless-gui): +- Graphics engine [headless-gui/v4](https://github.com/oops1/headless-gui): the interface is described in XAML, the logic in Go, Windows 11 themes (dark and light, matching the system by default). - Dock panels: repositories, branches, files, diff, commit log — any of them can be hidden, dragged to another edge, or torn off into a separate system window; the layout is remembered. - Localization: Russian and English out of the box, any other language is a single JSON file. -## What 1.7.1 can already do +## What 1.7.2 can already do **Interface.** The menu and toolbar mirror SmartGit; the toolbar is configured in a separate window and stored in `config.toml`. Dock panels: diff --git a/README.md b/README.md index d9d65801..5c858dff 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,14 @@ - Собственная реализация git на чистом Go: установленный git не нужен. - `CGO_ENABLED=0`, один исполняемый файл со всеми ресурсами внутри. -- Графический движок [headless-gui/v3](https://github.com/oops1/headless-gui): +- Графический движок [headless-gui/v4](https://github.com/oops1/headless-gui): интерфейс описан в XAML, логика на Go, темы Windows 11 (тёмная и светлая, по умолчанию как в системе). - Док-панели: репозитории, ветки, файлы, diff, журнал коммитов — любую можно скрыть, перетащить к другой стенке или оторвать в отдельное окно системы; раскладка запоминается. - Локализация: русский и английский из коробки, любой другой язык — один JSON-файл. -## Что уже умеет 1.7.1 +## Что уже умеет 1.7.2 **Интерфейс.** Меню и панель инструментов повторяют SmartGit; панель настраивается в отдельном окне и хранится в `config.toml`. Док-панели: diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index a394e68d..4bd34707 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,44 +1,47 @@ -# Go.Git 1.7.1 — Sharper text, faster big working trees - -Small text is sharper, the status of a big working tree takes half the time, and -opening a repository no longer holds up the interface. - -All numbers below were measured on Windows with a 20-thread processor. - -## Sharper text - -- Small text is drawn with vertical hinting and a contrast boost for thin strokes: - the heights of lowercase and capital letters land on whole pixels, and dark text - on a light background looks denser. Line widths and layout do not change. - Subpixel smoothing stays off because it is useless in a remote session. The - headless-gui engine is updated to v3.43.0 for this. - -## Big working trees - -- Status of a working tree with 50 thousand files, unchanged files included (the - way the Files pane asks for it), takes 53 ms instead of 103 ms and 41 MB instead - of 122 MB. File attributes come from the cache without rebuilding the rule stack, - and for every file only the question of whether it needs an external filter is - asked. -- A directory with tracked files is read once per scan: the search for untracked - files reuses the listing that was already read. Status of 50 thousand files takes - 30 ms instead of 44 ms. -- Opening a repository with 80 thousand files holds up the interface for 19 ms - instead of 250–440 ms. The working tree watcher takes its first snapshot in the - background, and the status scan waits for it so that no change made right after - opening is lost. A new set of ignored directories reaches the running watcher - instead of restarting it with a full walk of the tree. +# Go.Git 1.7.2 — Text as in Windows, collapsible compare and conflict windows + +A new engine, text drawn the way Windows is set up, compare and conflict-resolution +windows that collapse their sides and remember how they were left, and main +branches first in the Branches pane. + +## Text + +- The headless-gui engine is updated to v4.5.0 (from v3.43.0). Text follows the + system setting: with ClearType on it uses subpixel smoothing (measured the same as + Windows itself on the same font) with the monitor's subpixel order; in a remote + session (RDP) and with greyscale smoothing it is grey. Turning ClearType on or off + or connecting over RDP changes it at once, without a restart. +- The interface font on Windows is Verdana: at small sizes it reads more clearly + than the former Go Regular. Linux keeps the old font. +- Dialogs and floating panes in their own windows draw text with the same font and + smoothing as the main window. +- On Windows 11 the window and the dialogs no longer show a second frame arc at the + rounded corners: the system draws the frame, accent color included. + +## Compare and conflicts + +- The compare window collapses its left or right side, the border between them can + be dragged, and the window has maximize and minimize buttons. +- The conflict-resolution window collapses Ours, Base and Theirs, shows the result + or the sources at full height, and the border between the top and the result can + be dragged. New: Redo, the All conflicts menu (take ours or theirs in every + unresolved conflict, mark every conflict unresolved again) and separate scrolling. +- Both windows reopen the way they were closed: size, collapsed sides, border, base + pane and joint scrolling are kept in `config.toml`. + +## Branches + +- git-flow develop and master, every server's default branch and the usual main, + master and develop come first in a Main group with their own icon, and first on + every server. The pane menu turns the group off, and selecting obsolete branches + leaves main branches alone. A server default branch such as `release/current` no + longer appears again under Releases. ## Fixes -- Loading the next page of the journal no longer drops the selected commit or - rebuilds the whole table. -- In Blame a commit opens with a single click on its link, and the cursor turns - into a hand over it. -- A secure connection over a slow network waits a minute instead of 15 seconds, and - the server response timer starts only after the request is sent. When the - connection never comes up, Go.Git says so instead of "context deadline exceeded". -- On Windows a commit made right after git or a virus scanner let go of - `packed-refs.lock` no longer fails with "Access is denied": while the system is - still closing the old file, Go.Git waits up to a second, as it does for a busy - lock. +- The installer shows the license text again: since 1.6.1 the license dialog was + empty. +- A failure in a widget or a handler no longer brings the app down: the engine + catches it, and Go.Git logs it once per place, with secrets redacted. +- The layout of a window closed twice (by the window and by the engine) is saved + once. diff --git a/USER_GUIDE.md b/USER_GUIDE.md index 866c7ad3..9da2b9e6 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -110,7 +110,10 @@ обратным порядком чисел, по времени коммита), группировкой веток по пути (`foo/bar`, с вариантами «После последнего слэша» и «Кроме одиночных»), показом внешних веток в разделах Git-Flow и выбором устаревших локальных -веток (тех, чей upstream исчез на сервере). +веток (тех, чей upstream исчез на сервере). Основные ветки — develop и master +git-flow, ветка по умолчанию сервера, main, master, develop — стоят первыми в +группе «Основные»; её можно выключить в том же меню, а выбор устаревших веток +основные не трогает. ### Файлы @@ -197,8 +200,16 @@ Shift; правый щелчок по выделению открывает «П (**Разрешить конфликт...**). Окно показывает три панели только для чтения — «Наша», «База» (можно скрыть) и «Их» — и снизу редактируемый итог. Кнопки «Взять нашу», «Взять их», «Взять обе», переходы между конфликтами и счётчик -нерешённых. «Сохранить» пишет итог в рабочую копию и, если конфликтов не -осталось, отмечает файл решённым и закрывает окно. +нерешённых, «Отменить» и «Повторить», меню «Все конфликты» — взять нашу или их +во всех нерешённых сразу либо снова отметить все нерешёнными. «Наша», «База» и +«Их» сворачиваются шевронами в заголовках, итог или исходные панели +разворачиваются на всю высоту кнопками справа в заголовке итога, границу между +верхом и итогом можно тянуть (двойной щелчок возвращает её на место). +«Сохранить» пишет итог в рабочую копию и, если конфликтов не осталось, отмечает +файл решённым и закрывает окно. Окно сравнения так же сворачивает левую или +правую сторону. Оба окна открываются такими, какими их закрыли: размер, +свёрнутые стороны, граница, база и совместная прокрутка хранятся в +`config.toml`. ### Stash diff --git a/cmd/gogit/installerlicense_test.go b/cmd/gogit/installerlicense_test.go new file mode 100644 index 00000000..b209272e --- /dev/null +++ b/cmd/gogit/installerlicense_test.go @@ -0,0 +1,73 @@ +package main + +import ( + "fmt" + "os" + "path/filepath" + "strings" + "testing" +) + +const installerLicenseHeader = `{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fswiss Segoe UI;}}\fs18` + +func readRepositoryFile(t *testing.T, rel string) string { + t.Helper() + data, err := os.ReadFile(filepath.Join("..", "..", filepath.FromSlash(rel))) + if err != nil { + t.Fatal(err) + } + return string(data) +} + +func TestTheInstallerLicenseIsAWellFormedRTFHeader(t *testing.T) { + rtf := readRepositoryFile(t, "packaging/windows/license.rtf") + + if !strings.HasPrefix(rtf, installerLicenseHeader+"\n") { + t.Fatalf("license.rtf starts with %q, want the RTF header %q", rtf[:min(len(rtf), 80)], installerLicenseHeader) + } + for at, b := range []byte(rtf) { + if b < 0x20 && b != '\n' { + t.Fatalf("license.rtf holds control byte %#02x at offset %d: a backslash sequence was turned into a control character", b, at) + } + } + if !strings.HasSuffix(rtf, "}\n") { + t.Fatal("license.rtf does not close its RTF group") + } +} + +func TestTheInstallerLicenseShowsTheTextOfLICENSE(t *testing.T) { + rtf := readRepositoryFile(t, "packaging/windows/license.rtf") + license := readRepositoryFile(t, "LICENSE") + + body := strings.TrimSuffix(strings.TrimPrefix(rtf, installerLicenseHeader+"\n"), "}\n") + unescape := strings.NewReplacer(`\\`, `\`, `\{`, `{`, `\}`, `}`) + var shown []string + for line := range strings.Lines(body) { + text, ok := strings.CutSuffix(strings.TrimSuffix(line, "\n"), `\par`) + if !ok { + t.Fatalf("line %q of license.rtf does not end a paragraph", line) + } + shown = append(shown, unescape.Replace(text)) + } + + if got, want := strings.Join(shown, "\n"), strings.TrimRight(license, "\n"); got != want { + t.Fatalf("the installer license differs from LICENSE:\n%s", firstDifference(got, want)) + } +} + +func firstDifference(got, want string) string { + gotLines, wantLines := strings.Split(got, "\n"), strings.Split(want, "\n") + for i := range max(len(gotLines), len(wantLines)) { + var g, w string + if i < len(gotLines) { + g = gotLines[i] + } + if i < len(wantLines) { + w = wantLines[i] + } + if g != w { + return fmt.Sprintf("line %d: got %q, want %q", i+1, g, w) + } + } + return "no differing line" +} diff --git a/cmd/gogit/main_test.go b/cmd/gogit/main_test.go index b170e2fc..093dc92b 100644 --- a/cmd/gogit/main_test.go +++ b/cmd/gogit/main_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" ) diff --git a/cmd/gogit/winres/winres.json b/cmd/gogit/winres/winres.json index def0c670..35ef0570 100644 --- a/cmd/gogit/winres/winres.json +++ b/cmd/gogit/winres/winres.json @@ -11,7 +11,7 @@ "0409": { "identity": { "name": "Go.Git", - "version": "1.7.1.0" + "version": "1.7.2.0" }, "description": "Go.Git git client", "minimum-os": "win7", @@ -35,8 +35,8 @@ "#1": { "0000": { "fixed": { - "file_version": "1.7.1.0", - "product_version": "1.7.1.0" + "file_version": "1.7.2.0", + "product_version": "1.7.2.0" }, "info": { "0409": { diff --git a/go.mod b/go.mod index 911ff399..9e93a6d5 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/BurntSushi/toml v1.6.0 github.com/godbus/dbus/v5 v5.2.2 github.com/jcmturner/gokrb5/v8 v8.4.4 - github.com/oops1/headless-gui/v3 v3.43.0 + github.com/oops1/headless-gui/v4 v4.5.0 golang.org/x/crypto v0.56.0 golang.org/x/sys v0.47.0 golang.org/x/text v0.41.0 diff --git a/go.sum b/go.sum index ee101645..6ceceab8 100644 --- a/go.sum +++ b/go.sum @@ -30,12 +30,8 @@ github.com/jcmturner/gokrb5/v8 v8.4.4 h1:x1Sv4HaTpepFkXbt2IkL29DXRf8sOfZXo8eRKh6 github.com/jcmturner/gokrb5/v8 v8.4.4/go.mod h1:1btQEpgT6k+unzCwX1KdWMEwPPkkgBtP+F6aCACiMrs= github.com/jcmturner/rpc/v2 v2.0.3 h1:7FXXj8Ti1IaVFpSAziCZWNzbNuZmnvw/i6CqLNdWfZY= github.com/jcmturner/rpc/v2 v2.0.3/go.mod h1:VUJYCIDm3PVOEHw8sgt091/20OJjskO/YJki3ELg/Hc= -github.com/oops1/headless-gui/v3 v3.39.0 h1:a7wJdqsR+yhjSJrSVgD9bWVchDa+oeu7LiP45eQUwrc= -github.com/oops1/headless-gui/v3 v3.39.0/go.mod h1:KfrQeckxm94JygZq21eM6fpaQCYhUkL1vrb71WY5to8= -github.com/oops1/headless-gui/v3 v3.42.0 h1:meVrKaf7DSzJA/HuyjN3KdKs6XenzOXARWqi5QWPPv8= -github.com/oops1/headless-gui/v3 v3.42.0/go.mod h1:KfrQeckxm94JygZq21eM6fpaQCYhUkL1vrb71WY5to8= -github.com/oops1/headless-gui/v3 v3.43.0 h1:qY/PhHjndWu4CMXCAcgqSrqVlQ0z7hV8FeC34jVhhXo= -github.com/oops1/headless-gui/v3 v3.43.0/go.mod h1:KfrQeckxm94JygZq21eM6fpaQCYhUkL1vrb71WY5to8= +github.com/oops1/headless-gui/v4 v4.5.0 h1:mCN4cpYzCX6xWOBhaER0Z7FIJzmuPYfJ1BgzRQwdDEw= +github.com/oops1/headless-gui/v4 v4.5.0/go.mod h1:F2VHnvyVf8UGe7I6OUwDGlEYV8zNi1mjkM1q1MbFcgg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/internal/app/app.go b/internal/app/app.go index 34d6cb11..ecbab38c 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -11,10 +11,10 @@ import ( "sync/atomic" "time" - "github.com/oops1/headless-gui/v3/engine" - "github.com/oops1/headless-gui/v3/widget" - "github.com/oops1/headless-gui/v3/widget/datagrid" - "github.com/oops1/headless-gui/v3/window" + "github.com/oops1/headless-gui/v4/engine" + "github.com/oops1/headless-gui/v4/widget" + "github.com/oops1/headless-gui/v4/widget/datagrid" + "github.com/oops1/headless-gui/v4/window" "github.com/oops1/gogit/internal/assets" "github.com/oops1/gogit/internal/config" @@ -70,6 +70,8 @@ type App struct { accentOf func() systheme.Accent log *slog.Logger + enginePanics enginePanicLog + layoutStore layout.Store defaultLayout []byte @@ -417,7 +419,9 @@ func NewFromXAML(cfg *config.Config, paths config.Paths, xaml []byte, log *slog. root.Title = i18n.T("App.Title") a.eng = engine.New(cfg.Window.Width, cfg.Window.Height, targetFPS) - a.eng.SetTextQuality(engine.TextQuality{Hinting: true, Contrast: engine.DefaultTextContrast}) + a.eng.SetTextQuality(style.TextQuality()) + useInterfaceFont(a.eng, systemInterfaceFont()) + a.eng.SetOnPanic(a.reportEnginePanic) a.eng.SetRoot(root) a.eng.SetOnModalClosed(func(widget.ModalWidget) { a.releaseClosedDialogs() }) a.startPostQueue() @@ -1173,6 +1177,7 @@ func (a *App) Run() error { a.scheduleUpdateCheck() go a.runWatchdog(ctx, a.watches()) win := window.New(a.eng, a.root.Title) + win.SetTextQualityFromSystem(true) a.applyWindowIcon(win) if a.OnExit == nil { a.OnExit = win.Close diff --git a/internal/app/app_test.go b/internal/app/app_test.go index 8e3a3d99..81af7519 100644 --- a/internal/app/app_test.go +++ b/internal/app/app_test.go @@ -9,8 +9,7 @@ import ( "strings" "testing" - "github.com/oops1/headless-gui/v3/engine" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/systheme" @@ -62,8 +61,8 @@ func TestNewLoadsMainWindow(t *testing.T) { func TestNewTurnsOnHintedHighContrastText(t *testing.T) { a := newTestApp(t) got := a.Engine().TextQuality() - if !got.Hinting || got.Contrast != engine.DefaultTextContrast || got.LCD { - t.Fatalf("text quality = %+v, want hinting with default contrast and no LCD", got) + if got != style.TextQuality() { + t.Fatalf("text quality = %+v, want %+v", got, style.TextQuality()) } } diff --git a/internal/app/branchespane.go b/internal/app/branchespane.go index a1390afb..14bd3849 100644 --- a/internal/app/branchespane.go +++ b/internal/app/branchespane.go @@ -1,7 +1,7 @@ package app import ( - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/i18n" @@ -49,6 +49,7 @@ var branchGroupToggles = []struct { func branchesPaneOptions(pane config.BranchesPane) branches.Options { options := branches.Options{ FlowSections: pane.FlowSections, + MainSection: pane.MainSection, Grouping: branches.Grouping{ ByPath: pane.GroupByPath, ExceptSingles: pane.GroupExceptSingles, @@ -83,6 +84,9 @@ func (a *App) branchesPaneMenuItems() []widget.MenuItem { a.branchesToggleItem("Menu.Branches.FlowSections", pane.FlowSections, true, func(p *config.BranchesPane) { p.FlowSections = !p.FlowSections }), + a.branchesToggleItem("Menu.Branches.MainSection", pane.MainSection, true, func(p *config.BranchesPane) { + p.MainSection = !p.MainSection + }), menuSeparator(), a.branchesToggleItem("Menu.Branches.Group", pane.GroupByPath, true, func(p *config.BranchesPane) { p.GroupByPath = !p.GroupByPath diff --git a/internal/app/branchespane_test.go b/internal/app/branchespane_test.go index 03757356..78d952c4 100644 --- a/internal/app/branchespane_test.go +++ b/internal/app/branchespane_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" gitconfig "github.com/oops1/gogit/internal/gitcore/config" @@ -57,6 +57,7 @@ func TestTheViewMenuKeepsItsOrderAndTheStoredChoices(t *testing.T) { i18n.T("Menu.Branches.Sort"), "-", i18n.T("Menu.Branches.FlowSections"), + i18n.T("Menu.Branches.MainSection"), "-", i18n.T("Menu.Branches.Group"), i18n.T("Menu.Branches.Group.ExceptSingles"), @@ -81,10 +82,13 @@ func TestTheViewMenuKeepsItsOrderAndTheStoredChoices(t *testing.T) { t.Fatalf("sort item %q checked = %v, want the stored sort by name", item.Text, item.Checked) } } - if !items[4].Checked { + if !items[3].Checked { + t.Fatal("main branches must start in a group of their own") + } + if !items[5].Checked { t.Fatal("grouping by path must start checked") } - if items[5].Disabled || items[6].Disabled || items[7].Disabled { + if items[6].Disabled || items[7].Disabled || items[8].Disabled { t.Fatal("the grouping sub-options must be reachable while grouping is on") } if !items[len(items)-1].Disabled { @@ -97,10 +101,10 @@ func TestTurningGroupingOffGreysItsSubOptions(t *testing.T) { clickViewMenuItem(t, a, branchesPaneMenu(t, a), "Menu.Branches.Group") items := branchesPaneMenu(t, a) - if items[4].Checked { + if items[5].Checked { t.Fatal("grouping by path must be off now") } - if !items[5].Disabled || !items[6].Disabled || !items[7].Disabled { + if !items[6].Disabled || !items[7].Disabled || !items[8].Disabled { t.Fatal("the grouping sub-options must be greyed out while grouping is off") } if readOnDispatcher(t, a, a.branchesView.Options).Grouping.ByPath { @@ -119,6 +123,7 @@ func TestEveryViewMenuToggleSurvivesARestart(t *testing.T) { a, paths := newTestAppWithPaths(t) for _, key := range []string{ "Menu.Branches.FlowSections", + "Menu.Branches.MainSection", "Menu.Branches.Group.ExceptSingles", "Menu.Branches.Group.GroupsFirst", "Menu.Branches.Group.AfterLastSlash", @@ -148,7 +153,7 @@ func TestEveryViewMenuToggleSurvivesARestart(t *testing.T) { if options != branchesPaneOptions(want) { t.Fatalf("options after restart = %+v, want %+v", options, branchesPaneOptions(want)) } - if options.Sort != branches.SortByCommitTime || !options.FlowSections { + if options.Sort != branches.SortByCommitTime || !options.FlowSections || options.MainSection { t.Fatalf("options after restart = %+v", options) } } diff --git a/internal/app/branchmenu.go b/internal/app/branchmenu.go index 42d71b32..7c1538e4 100644 --- a/internal/app/branchmenu.go +++ b/internal/app/branchmenu.go @@ -3,7 +3,7 @@ package app import ( "context" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/ops" "github.com/oops1/gogit/internal/gitcore/refs" diff --git a/internal/app/branchmenu_test.go b/internal/app/branchmenu_test.go index c67bb140..129bb344 100644 --- a/internal/app/branchmenu_test.go +++ b/internal/app/branchmenu_test.go @@ -6,7 +6,7 @@ import ( "slices" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/refs" gitrepo "github.com/oops1/gogit/internal/gitcore/repo" diff --git a/internal/app/busy_test.go b/internal/app/busy_test.go index 34072a4b..b6db65b5 100644 --- a/internal/app/busy_test.go +++ b/internal/app/busy_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/gitcore/remote" diff --git a/internal/app/changes.go b/internal/app/changes.go index 65b816f7..5f7df69f 100644 --- a/internal/app/changes.go +++ b/internal/app/changes.go @@ -6,7 +6,7 @@ import ( "errors" "fmt" - "github.com/oops1/headless-gui/v3/widget/datagrid" + "github.com/oops1/headless-gui/v4/widget/datagrid" "github.com/oops1/gogit/internal/gitcore/diff" "github.com/oops1/gogit/internal/gitcore/hash" diff --git a/internal/app/changes_test.go b/internal/app/changes_test.go index c820625b..45291523 100644 --- a/internal/app/changes_test.go +++ b/internal/app/changes_test.go @@ -13,8 +13,8 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" - "github.com/oops1/headless-gui/v3/widget/datagrid" + "github.com/oops1/headless-gui/v4/widget" + "github.com/oops1/headless-gui/v4/widget/datagrid" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/gitcore/diff" diff --git a/internal/app/commands.go b/internal/app/commands.go index 0072d10b..50bcd78c 100644 --- a/internal/app/commands.go +++ b/internal/app/commands.go @@ -3,7 +3,7 @@ package app import ( "strings" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/gitcore/ops" diff --git a/internal/app/compare.go b/internal/app/compare.go index 8c1e3b82..d659e613 100644 --- a/internal/app/compare.go +++ b/internal/app/compare.go @@ -5,7 +5,7 @@ import ( "context" "path/filepath" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/diff" gitrepo "github.com/oops1/gogit/internal/gitcore/repo" @@ -161,6 +161,7 @@ func (a *App) openCompareSides(left, right compareSide) { view.OnPick = func(side widget.DiffSide) { a.pickCompareFile(view, side) } view.OnSaveAs = func(side widget.DiffSide) { a.saveCompareAs(view, side) } view.OnClose = func() { a.closeCompare(view) } + a.restoreCompareWindow(view) if bounds := a.root.Bounds(); !bounds.Empty() { view.FitWithin(bounds.Dx(), bounds.Dy()) } diff --git a/internal/app/compare_activate_test.go b/internal/app/compare_activate_test.go index 6aa09e3a..c59925e7 100644 --- a/internal/app/compare_activate_test.go +++ b/internal/app/compare_activate_test.go @@ -7,7 +7,7 @@ import ( "path/filepath" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/diff" "github.com/oops1/gogit/internal/gitcore/hash" diff --git a/internal/app/compare_test.go b/internal/app/compare_test.go index 1b79de6e..e1b0aa6b 100644 --- a/internal/app/compare_test.go +++ b/internal/app/compare_test.go @@ -7,7 +7,7 @@ import ( "strings" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/ui/compare" ) diff --git a/internal/app/comparecmd.go b/internal/app/comparecmd.go index 6e45d611..71ec4e68 100644 --- a/internal/app/comparecmd.go +++ b/internal/app/comparecmd.go @@ -3,7 +3,7 @@ package app import ( "context" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/diff" "github.com/oops1/gogit/internal/gitcore/ops" diff --git a/internal/app/comparecmd_test.go b/internal/app/comparecmd_test.go index 9b1083f8..83c65133 100644 --- a/internal/app/comparecmd_test.go +++ b/internal/app/comparecmd_test.go @@ -5,7 +5,7 @@ import ( "errors" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/diff" "github.com/oops1/gogit/internal/gitcore/ops" diff --git a/internal/app/conflictcmd.go b/internal/app/conflictcmd.go index 36b77b09..1e56da15 100644 --- a/internal/app/conflictcmd.go +++ b/internal/app/conflictcmd.go @@ -4,7 +4,7 @@ import ( "context" "strings" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/ops" gitrepo "github.com/oops1/gogit/internal/gitcore/repo" @@ -57,6 +57,7 @@ func (a *App) showConflictEditor(file ops.ConflictFile) { Style: file.Style, FinalNewline: endsWithNewline(file), }) + a.restoreConflictWindow(view) if bounds := a.root.Bounds(); !bounds.Empty() { view.FitWithin(bounds.Dx(), bounds.Dy()) } diff --git a/internal/app/conflictcmd_test.go b/internal/app/conflictcmd_test.go index 705b8e6d..cb8a7189 100644 --- a/internal/app/conflictcmd_test.go +++ b/internal/app/conflictcmd_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/merge" "github.com/oops1/gogit/internal/gitcore/ops" diff --git a/internal/app/consolecmd_test.go b/internal/app/consolecmd_test.go index 0480a680..5c324352 100644 --- a/internal/app/consolecmd_test.go +++ b/internal/app/consolecmd_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" gitrepo "github.com/oops1/gogit/internal/gitcore/repo" diff --git a/internal/app/contextmenu.go b/internal/app/contextmenu.go index 40673d36..5e3ccb1f 100644 --- a/internal/app/contextmenu.go +++ b/internal/app/contextmenu.go @@ -3,7 +3,7 @@ package app import ( "path/filepath" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/i18n" "github.com/oops1/gogit/internal/repo" diff --git a/internal/app/contextmenu_test.go b/internal/app/contextmenu_test.go index a6260cd3..387d7090 100644 --- a/internal/app/contextmenu_test.go +++ b/internal/app/contextmenu_test.go @@ -6,7 +6,7 @@ import ( "path/filepath" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/hash" "github.com/oops1/gogit/internal/i18n" diff --git a/internal/app/credentials_test.go b/internal/app/credentials_test.go index def73123..2bbaf88a 100644 --- a/internal/app/credentials_test.go +++ b/internal/app/credentials_test.go @@ -11,7 +11,7 @@ import ( "slices" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" gitconfig "github.com/oops1/gogit/internal/gitcore/config" diff --git a/internal/app/detailsparent_test.go b/internal/app/detailsparent_test.go index 6022a8b4..3914059a 100644 --- a/internal/app/detailsparent_test.go +++ b/internal/app/detailsparent_test.go @@ -3,7 +3,7 @@ package app import ( "testing" - "github.com/oops1/headless-gui/v3/widget/datagrid" + "github.com/oops1/headless-gui/v4/widget/datagrid" "github.com/oops1/gogit/internal/gitcore/hash" "github.com/oops1/gogit/internal/ui/journal" diff --git a/internal/app/detailswidth.go b/internal/app/detailswidth.go index 5b709e93..938ba950 100644 --- a/internal/app/detailswidth.go +++ b/internal/app/detailswidth.go @@ -1,7 +1,7 @@ package app import ( - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" ) const detailsTabsMargin = 12 diff --git a/internal/app/detailswidth_test.go b/internal/app/detailswidth_test.go index 15039217..eef03928 100644 --- a/internal/app/detailswidth_test.go +++ b/internal/app/detailswidth_test.go @@ -3,7 +3,7 @@ package app import ( "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" ) diff --git a/internal/app/diffsides_test.go b/internal/app/diffsides_test.go index ef3dbf45..5b06f5a3 100644 --- a/internal/app/diffsides_test.go +++ b/internal/app/diffsides_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/diff" "github.com/oops1/gogit/internal/gitcore/object" diff --git a/internal/app/edit_test.go b/internal/app/edit_test.go index b11de0de..4654fa12 100644 --- a/internal/app/edit_test.go +++ b/internal/app/edit_test.go @@ -11,8 +11,8 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" - "github.com/oops1/headless-gui/v3/widget/datagrid" + "github.com/oops1/headless-gui/v4/widget" + "github.com/oops1/headless-gui/v4/widget/datagrid" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/gitcore/hash" diff --git a/internal/app/enginepanic.go b/internal/app/enginepanic.go new file mode 100644 index 00000000..92221eb3 --- /dev/null +++ b/internal/app/enginepanic.go @@ -0,0 +1,55 @@ +package app + +import ( + "fmt" + "reflect" + "sync" + + "github.com/oops1/headless-gui/v4/engine" + "github.com/oops1/headless-gui/v4/widget" + + "github.com/oops1/gogit/internal/logx" +) + +type enginePanicSite struct { + where string + widget string +} + +type enginePanicLog struct { + mu sync.Mutex + seen map[enginePanicSite]bool +} + +func (l *enginePanicLog) firstAt(site enginePanicSite) bool { + l.mu.Lock() + defer l.mu.Unlock() + if l.seen[site] { + return false + } + if l.seen == nil { + l.seen = map[enginePanicSite]bool{} + } + l.seen[site] = true + return true +} + +func (a *App) reportEnginePanic(info engine.PanicInfo) { + site := enginePanicSite{where: info.Where, widget: widgetTypeName(info.Widget)} + if !a.enginePanics.firstAt(site) { + return + } + a.log.Error("engine caught a panic", + "where", info.Where, + "widget", site.widget, + "path", info.Path, + "value", logx.RedactText(fmt.Sprint(info.Value)), + "stack", logx.RedactText(string(info.Stack))) +} + +func widgetTypeName(w widget.Widget) string { + if w == nil { + return "" + } + return reflect.TypeOf(w).String() +} diff --git a/internal/app/enginepanic_test.go b/internal/app/enginepanic_test.go new file mode 100644 index 00000000..757fbea5 --- /dev/null +++ b/internal/app/enginepanic_test.go @@ -0,0 +1,101 @@ +package app + +import ( + "bytes" + "image/color" + "log/slog" + "net/url" + "strings" + "testing" + + "github.com/oops1/headless-gui/v4/engine" + "github.com/oops1/headless-gui/v4/widget" + + "github.com/oops1/gogit/internal/config" +) + +func newPanicLoggingApp(t *testing.T) (*App, *bytes.Buffer) { + t.Helper() + widget.ClearStrings() + t.Cleanup(widget.ClearStrings) + var buf bytes.Buffer + logger := slog.New(slog.NewTextHandler(&buf, &slog.HandlerOptions{Level: slog.LevelWarn})) + a, err := New(config.Default(), config.Paths{Dir: t.TempDir()}, logger) + if err != nil { + t.Fatal(err) + } + t.Cleanup(a.Close) + a.stopPostDriver() + a.stopPostDriver = func() {} + return a, &buf +} + +func TestAPanicTheEngineIsolatesIsWrittenToTheLog(t *testing.T) { + a, buf := newPanicLoggingApp(t) + a.Engine().SetFailurePolicy(engine.FailureIsolate) + + a.Post(func() { panic("broken callback") }) + a.Engine().Flush() + + out := buf.String() + for _, want := range []string{"engine caught a panic", "where=Post", "broken callback", "stack="} { + if !strings.Contains(out, want) { + t.Fatalf("log lacks %q: %s", want, out) + } + } +} + +func TestTheSamePanicSiteIsLoggedOnce(t *testing.T) { + a, buf := newPanicLoggingApp(t) + a.Engine().SetFailurePolicy(engine.FailureIsolate) + + a.Post(func() { panic("first") }) + a.Post(func() { panic("second") }) + a.Engine().Flush() + + if got := strings.Count(buf.String(), "engine caught a panic"); got != 1 { + t.Fatalf("logged %d times, want once: %s", got, buf.String()) + } +} + +func TestPanicsOfDifferentWidgetsAreLoggedApart(t *testing.T) { + a, buf := newPanicLoggingApp(t) + + a.reportEnginePanic(engine.PanicInfo{Where: "Draw", Widget: widget.NewLabel("a", color.RGBA{}), Path: "Window > Label", Value: "x"}) + a.reportEnginePanic(engine.PanicInfo{Where: "Draw", Widget: widget.NewButton("b"), Path: "Window > Button", Value: "y"}) + a.reportEnginePanic(engine.PanicInfo{Where: "Draw", Widget: widget.NewButton("c"), Path: "Window > Button", Value: "z"}) + + out := buf.String() + if got := strings.Count(out, "engine caught a panic"); got != 2 { + t.Fatalf("logged %d times, want 2: %s", got, out) + } + for _, want := range []string{"*base.Label", "*base.Button", "path=\"Window > Button\""} { + if !strings.Contains(out, want) { + t.Fatalf("log lacks %q: %s", want, out) + } + } +} + +func TestAPanicValueDoesNotLeakASecret(t *testing.T) { + a, buf := newPanicLoggingApp(t) + remote := url.URL{Scheme: "https", User: url.UserPassword("user", "hunter2"), Host: "host", Path: "/r.git"} + + a.reportEnginePanic(engine.PanicInfo{ + Where: "Post", + Value: "fetch " + remote.String() + " failed", + Stack: []byte("Authorization: Bearer abc"), + }) + + out := buf.String() + for _, secret := range []string{"hunter2", "Bearer abc"} { + if strings.Contains(out, secret) { + t.Fatalf("log leaks %q: %s", secret, out) + } + } +} + +func TestAWidgetlessPanicHasNoTypeName(t *testing.T) { + if got := widgetTypeName(nil); got != "" { + t.Fatalf("widgetTypeName(nil) = %q", got) + } +} diff --git a/internal/app/filesfilter_test.go b/internal/app/filesfilter_test.go index f8c682c5..06c36ffe 100644 --- a/internal/app/filesfilter_test.go +++ b/internal/app/filesfilter_test.go @@ -4,7 +4,7 @@ import ( "path/filepath" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/ui/changes" ) diff --git a/internal/app/filesstatusfilter.go b/internal/app/filesstatusfilter.go index 357801c0..08a4dbe1 100644 --- a/internal/app/filesstatusfilter.go +++ b/internal/app/filesstatusfilter.go @@ -3,7 +3,7 @@ package app import ( "image/color" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/i18n" "github.com/oops1/gogit/internal/ui/changes" diff --git a/internal/app/filesstatusfilter_test.go b/internal/app/filesstatusfilter_test.go index c2030196..ca9ac25a 100644 --- a/internal/app/filesstatusfilter_test.go +++ b/internal/app/filesstatusfilter_test.go @@ -10,7 +10,7 @@ import ( "strings" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/ui/changes" diff --git a/internal/app/filessubdirs.go b/internal/app/filessubdirs.go index 17012cdc..656f798a 100644 --- a/internal/app/filessubdirs.go +++ b/internal/app/filessubdirs.go @@ -3,7 +3,7 @@ package app import ( "image/color" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/i18n" "github.com/oops1/gogit/internal/ui/icons" diff --git a/internal/app/flowbutton.go b/internal/app/flowbutton.go index b8bb69e2..eeac5fcb 100644 --- a/internal/app/flowbutton.go +++ b/internal/app/flowbutton.go @@ -3,7 +3,7 @@ package app import ( "slices" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/i18n" ) diff --git a/internal/app/flowcmd_test.go b/internal/app/flowcmd_test.go index 47868eca..edbc9fcd 100644 --- a/internal/app/flowcmd_test.go +++ b/internal/app/flowcmd_test.go @@ -12,7 +12,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/hash" gitmerge "github.com/oops1/gogit/internal/gitcore/merge" diff --git a/internal/app/font.go b/internal/app/font.go new file mode 100644 index 00000000..6f13d0ac --- /dev/null +++ b/internal/app/font.go @@ -0,0 +1,45 @@ +package app + +import ( + "path/filepath" + + "github.com/oops1/headless-gui/v4/widget" +) + +const ( + interfaceFontName = "GoGitUI" + interfaceFontBoldName = "GoGitUI-Bold" +) + +var systemInterfaceFont = platformInterfaceFont + +type fontRegistrar interface { + RegisterFontFile(name, path string) error + SetDefaultFont(name string) bool +} + +type interfaceFontFiles struct { + dir string + regular string + bold string +} + +func useInterfaceFont(eng fontRegistrar, files interfaceFontFiles) bool { + if files.dir == "" || files.regular == "" { + return false + } + if eng.RegisterFontFile(interfaceFontName, filepath.Join(files.dir, files.regular)) != nil { + return false + } + if !eng.SetDefaultFont(interfaceFontName) { + return false + } + if files.bold == "" { + return true + } + bold := filepath.Join(files.dir, files.bold) + if eng.RegisterFontFile(interfaceFontBoldName, bold) == nil { + _ = eng.RegisterFontFile(widget.BuiltinFontBold, bold) + } + return true +} diff --git a/internal/app/font_other.go b/internal/app/font_other.go new file mode 100644 index 00000000..9d54f00c --- /dev/null +++ b/internal/app/font_other.go @@ -0,0 +1,7 @@ +//go:build !windows + +package app + +func platformInterfaceFont() interfaceFontFiles { + return interfaceFontFiles{} +} diff --git a/internal/app/font_other_test.go b/internal/app/font_other_test.go new file mode 100644 index 00000000..8edb2216 --- /dev/null +++ b/internal/app/font_other_test.go @@ -0,0 +1,11 @@ +//go:build !windows + +package app + +import "testing" + +func TestSystemInterfaceFontIsNoneOutsideWindows(t *testing.T) { + if got := platformInterfaceFont(); got != (interfaceFontFiles{}) { + t.Errorf("platformInterfaceFont = %+v, want none", got) + } +} diff --git a/internal/app/font_test.go b/internal/app/font_test.go new file mode 100644 index 00000000..80d79024 --- /dev/null +++ b/internal/app/font_test.go @@ -0,0 +1,120 @@ +package app + +import ( + "errors" + "path/filepath" + "slices" + "testing" + + "github.com/oops1/headless-gui/v4/engine" + "github.com/oops1/headless-gui/v4/widget" +) + +type recordingFontRegistrar struct { + failPaths map[string]bool + refuseDef bool + registered []string + defaultFont string +} + +func (r *recordingFontRegistrar) RegisterFontFile(name, path string) error { + if r.failPaths[filepath.Base(path)] { + return errors.New("unreadable font") + } + r.registered = append(r.registered, name+"="+filepath.Base(path)) + return nil +} + +func (r *recordingFontRegistrar) SetDefaultFont(name string) bool { + if r.refuseDef { + return false + } + r.defaultFont = name + return true +} + +func TestUseInterfaceFontRegistersRegularAndBold(t *testing.T) { + files := interfaceFontFiles{dir: "fonts", regular: "ui.ttf", bold: "uib.ttf"} + tests := []struct { + name string + files interfaceFontFiles + reg recordingFontRegistrar + wantOK bool + wantDefault string + wantFonts []string + }{ + { + name: "regular and bold", + files: files, + wantOK: true, + wantDefault: interfaceFontName, + wantFonts: []string{interfaceFontName + "=ui.ttf", interfaceFontBoldName + "=uib.ttf", widget.BuiltinFontBold + "=uib.ttf"}, + }, + { + name: "no bold file configured", + files: interfaceFontFiles{dir: "fonts", regular: "ui.ttf"}, + wantOK: true, + wantDefault: interfaceFontName, + wantFonts: []string{interfaceFontName + "=ui.ttf"}, + }, + { + name: "unreadable bold keeps the regular font", + files: files, + reg: recordingFontRegistrar{failPaths: map[string]bool{"uib.ttf": true}}, + wantOK: true, + wantDefault: interfaceFontName, + wantFonts: []string{interfaceFontName + "=ui.ttf"}, + }, + { + name: "no font directory", + files: interfaceFontFiles{regular: "ui.ttf"}, + }, + { + name: "no regular file", + files: interfaceFontFiles{dir: "fonts"}, + }, + { + name: "unreadable regular font", + files: files, + reg: recordingFontRegistrar{failPaths: map[string]bool{"ui.ttf": true}}, + }, + { + name: "engine refuses the default font", + files: files, + reg: recordingFontRegistrar{refuseDef: true}, + wantFonts: []string{interfaceFontName + "=ui.ttf"}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + reg := tt.reg + if got := useInterfaceFont(®, tt.files); got != tt.wantOK { + t.Fatalf("useInterfaceFont = %v, want %v", got, tt.wantOK) + } + if reg.defaultFont != tt.wantDefault { + t.Errorf("default font %q, want %q", reg.defaultFont, tt.wantDefault) + } + if !slices.Equal(reg.registered, tt.wantFonts) { + t.Errorf("registered %v, want %v", reg.registered, tt.wantFonts) + } + }) + } +} + +func TestUseInterfaceFontWithSystemFontOnRealEngine(t *testing.T) { + files := platformInterfaceFont() + if files.dir == "" { + t.Skip("this platform has no interface font") + } + eng := engine.New(100, 80, 30) + defer eng.Stop() + if !useInterfaceFont(eng, files) { + t.Skipf("interface font %s is not installed", filepath.Join(files.dir, files.regular)) + } + fonts := eng.AvailableFonts() + for _, name := range []string{interfaceFontName, interfaceFontBoldName, widget.BuiltinFontBold} { + if !slices.Contains(fonts, name) { + t.Errorf("font %q not registered: %v", name, fonts) + } + } +} diff --git a/internal/app/font_windows.go b/internal/app/font_windows.go new file mode 100644 index 00000000..5a2ae167 --- /dev/null +++ b/internal/app/font_windows.go @@ -0,0 +1,16 @@ +//go:build windows + +package app + +import ( + "os" + "path/filepath" +) + +func platformInterfaceFont() interfaceFontFiles { + windir := os.Getenv("WINDIR") + if windir == "" { + return interfaceFontFiles{} + } + return interfaceFontFiles{dir: filepath.Join(windir, "Fonts"), regular: "verdana.ttf", bold: "verdanab.ttf"} +} diff --git a/internal/app/font_windows_test.go b/internal/app/font_windows_test.go new file mode 100644 index 00000000..5363b976 --- /dev/null +++ b/internal/app/font_windows_test.go @@ -0,0 +1,24 @@ +//go:build windows + +package app + +import ( + "path/filepath" + "testing" +) + +func TestSystemInterfaceFontIsVerdanaFromWindowsFonts(t *testing.T) { + t.Setenv("WINDIR", `C:\Windows`) + got := platformInterfaceFont() + want := interfaceFontFiles{dir: filepath.Join(`C:\Windows`, "Fonts"), regular: "verdana.ttf", bold: "verdanab.ttf"} + if got != want { + t.Errorf("platformInterfaceFont = %+v, want %+v", got, want) + } +} + +func TestSystemInterfaceFontWithoutWindowsDirectory(t *testing.T) { + t.Setenv("WINDIR", "") + if got := platformInterfaceFont(); got != (interfaceFontFiles{}) { + t.Errorf("platformInterfaceFont = %+v, want none", got) + } +} diff --git a/internal/app/helpers_test.go b/internal/app/helpers_test.go index 9febdb53..f9d8a41c 100644 --- a/internal/app/helpers_test.go +++ b/internal/app/helpers_test.go @@ -5,7 +5,7 @@ import ( "path/filepath" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" ) diff --git a/internal/app/historycmd.go b/internal/app/historycmd.go index 8f527808..ff527a78 100644 --- a/internal/app/historycmd.go +++ b/internal/app/historycmd.go @@ -3,7 +3,7 @@ package app import ( "context" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/blame" "github.com/oops1/gogit/internal/gitcore/hash" diff --git a/internal/app/historycmd_test.go b/internal/app/historycmd_test.go index 8b69776c..7e8154aa 100644 --- a/internal/app/historycmd_test.go +++ b/internal/app/historycmd_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/blame" "github.com/oops1/gogit/internal/gitcore/ops" diff --git a/internal/app/hostkeys_test.go b/internal/app/hostkeys_test.go index d7f62628..7c0ee952 100644 --- a/internal/app/hostkeys_test.go +++ b/internal/app/hostkeys_test.go @@ -8,7 +8,7 @@ import ( "os" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "golang.org/x/crypto/ssh" "github.com/oops1/gogit/internal/gitcore/transport" diff --git a/internal/app/icons_test.go b/internal/app/icons_test.go index 828775bd..36f52a32 100644 --- a/internal/app/icons_test.go +++ b/internal/app/icons_test.go @@ -4,7 +4,7 @@ import ( "path/filepath" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/ui/icons" diff --git a/internal/app/indexeditorcmd.go b/internal/app/indexeditorcmd.go index bef65c44..e7d1d74b 100644 --- a/internal/app/indexeditorcmd.go +++ b/internal/app/indexeditorcmd.go @@ -3,7 +3,7 @@ package app import ( "context" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/ops" gitrepo "github.com/oops1/gogit/internal/gitcore/repo" diff --git a/internal/app/indexeditorcmd_test.go b/internal/app/indexeditorcmd_test.go index 8834b012..4c303fb4 100644 --- a/internal/app/indexeditorcmd_test.go +++ b/internal/app/indexeditorcmd_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/ops" gitrepo "github.com/oops1/gogit/internal/gitcore/repo" diff --git a/internal/app/investigatecmd.go b/internal/app/investigatecmd.go index 82edc960..e63d7e0c 100644 --- a/internal/app/investigatecmd.go +++ b/internal/app/investigatecmd.go @@ -4,7 +4,7 @@ import ( "cmp" "context" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/linelog" "github.com/oops1/gogit/internal/gitcore/ops" diff --git a/internal/app/investigatecmd_test.go b/internal/app/investigatecmd_test.go index 85b80597..48b7dc98 100644 --- a/internal/app/investigatecmd_test.go +++ b/internal/app/investigatecmd_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/diff" "github.com/oops1/gogit/internal/gitcore/hash" diff --git a/internal/app/journal_test.go b/internal/app/journal_test.go index 62b4b428..a02dfed6 100644 --- a/internal/app/journal_test.go +++ b/internal/app/journal_test.go @@ -13,8 +13,8 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" - "github.com/oops1/headless-gui/v3/widget/datagrid" + "github.com/oops1/headless-gui/v4/widget" + "github.com/oops1/headless-gui/v4/widget/datagrid" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/gitcore/hash" diff --git a/internal/app/layout.go b/internal/app/layout.go index 4e57b168..cd657404 100644 --- a/internal/app/layout.go +++ b/internal/app/layout.go @@ -5,7 +5,7 @@ import ( "io/fs" "os" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" ) func (a *App) RestoreLayout() error { diff --git a/internal/app/layout_test.go b/internal/app/layout_test.go index 8386a6a6..09855cb7 100644 --- a/internal/app/layout_test.go +++ b/internal/app/layout_test.go @@ -5,7 +5,7 @@ import ( "os" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" ) diff --git a/internal/app/layoutmode.go b/internal/app/layoutmode.go index ca35a67f..0c01d0b5 100644 --- a/internal/app/layoutmode.go +++ b/internal/app/layoutmode.go @@ -1,7 +1,7 @@ package app import ( - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/ui/branches" diff --git a/internal/app/layoutmode_test.go b/internal/app/layoutmode_test.go index 5e389e22..3573245f 100644 --- a/internal/app/layoutmode_test.go +++ b/internal/app/layoutmode_test.go @@ -4,7 +4,7 @@ import ( "image/color" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/ui/branches" diff --git a/internal/app/main_test.go b/internal/app/main_test.go new file mode 100644 index 00000000..bb0e67db --- /dev/null +++ b/internal/app/main_test.go @@ -0,0 +1,11 @@ +package app + +import ( + "os" + "testing" +) + +func TestMain(m *testing.M) { + systemInterfaceFont = func() interfaceFontFiles { return interfaceFontFiles{} } + os.Exit(m.Run()) +} diff --git a/internal/app/mainmenu_test.go b/internal/app/mainmenu_test.go index bcb43da7..c4dc8102 100644 --- a/internal/app/mainmenu_test.go +++ b/internal/app/mainmenu_test.go @@ -6,7 +6,7 @@ import ( "strings" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/i18n" diff --git a/internal/app/menu.go b/internal/app/menu.go index 70bb4735..bb5a215e 100644 --- a/internal/app/menu.go +++ b/internal/app/menu.go @@ -1,8 +1,8 @@ package app import ( - "github.com/oops1/headless-gui/v3/widget" - "github.com/oops1/headless-gui/v3/widget/datagrid" + "github.com/oops1/headless-gui/v4/widget" + "github.com/oops1/headless-gui/v4/widget/datagrid" "github.com/oops1/gogit/internal/i18n" ) diff --git a/internal/app/menu_test.go b/internal/app/menu_test.go index d93e3125..f18a637c 100644 --- a/internal/app/menu_test.go +++ b/internal/app/menu_test.go @@ -8,7 +8,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/gitcore/refs" diff --git a/internal/app/menuicons.go b/internal/app/menuicons.go index 6d7e25d1..3b6e099f 100644 --- a/internal/app/menuicons.go +++ b/internal/app/menuicons.go @@ -4,7 +4,7 @@ import ( "image" "image/color" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/ui/icons" ) diff --git a/internal/app/menuicons_test.go b/internal/app/menuicons_test.go index 7e1765fc..5f2c9ef5 100644 --- a/internal/app/menuicons_test.go +++ b/internal/app/menuicons_test.go @@ -4,7 +4,7 @@ import ( "image" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/assets" "github.com/oops1/gogit/internal/ui/repos" diff --git a/internal/app/mergecmd.go b/internal/app/mergecmd.go index 47266205..f1c173ab 100644 --- a/internal/app/mergecmd.go +++ b/internal/app/mergecmd.go @@ -6,7 +6,7 @@ import ( "fmt" "strings" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/hash" gitmerge "github.com/oops1/gogit/internal/gitcore/merge" diff --git a/internal/app/mergecmd_test.go b/internal/app/mergecmd_test.go index 541dfb38..1b469b3b 100644 --- a/internal/app/mergecmd_test.go +++ b/internal/app/mergecmd_test.go @@ -11,7 +11,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/hash" gitmerge "github.com/oops1/gogit/internal/gitcore/merge" diff --git a/internal/app/modals.go b/internal/app/modals.go index c1e510df..61423917 100644 --- a/internal/app/modals.go +++ b/internal/app/modals.go @@ -1,7 +1,9 @@ package app import ( - "github.com/oops1/headless-gui/v3/widget" + "image" + + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/ui/dialogs" ) @@ -22,10 +24,27 @@ type shownDialog struct { func (a *App) showModal(modal widget.ModalWidget, view styledView) { a.releaseClosedDialogs() a.trackDialog(modal, view) + if dlg, ok := modal.(*widget.Dialog); ok && dlg.HasWindowButtons() { + dlg.OnMaximizeRestore = a.maximizeInsideMainWindow(dlg) + } a.eng.ShowModal(modal) view.Restyle(a.theme()) } +func (a *App) maximizeInsideMainWindow(dlg *widget.Dialog) func() { + var restored image.Rectangle + return func() { + if dlg.IsMaximized() { + dlg.SetBounds(restored) + dlg.SetMaximized(false) + return + } + restored = dlg.Bounds() + dlg.SetBounds(a.root.Bounds()) + dlg.SetMaximized(true) + } +} + func (a *App) trackDialog(modal widget.ModalWidget, view styledView) { shown := shownDialog{modal: modal, trees: []widget.Widget{modal}} if owner, ok := view.(dialogOwner); ok { diff --git a/internal/app/modals_test.go b/internal/app/modals_test.go index a9a7d28f..9c9af0a9 100644 --- a/internal/app/modals_test.go +++ b/internal/app/modals_test.go @@ -3,7 +3,7 @@ package app import ( "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/i18n" @@ -100,3 +100,49 @@ func TestClosingTheAppReleasesTheDialogsStillOpen(t *testing.T) { t.Fatal("the app still tracks dialogs after closing") } } + +func windowedDialog(t *testing.T) *widget.Dialog { + t.Helper() + dlg := widget.NewDialog("Title", 400, 300) + dlg.SetResizable(true) + dlg.SetMinSize(200, 150) + dlg.SetWindowButtons(true) + return dlg +} + +func TestADialogDrawnInsideTheMainWindowMaximizesToIt(t *testing.T) { + a := newTestApp(t) + dlg := windowedDialog(t) + runOnDispatcher(t, a, func() { a.showModal(dlg, dialogOwnerView{}) }) + shown := readOnDispatcher(t, a, dlg.Bounds) + + runOnDispatcher(t, a, func() { dlg.OnMaximizeRestore() }) + + if got, want := readOnDispatcher(t, a, dlg.Bounds), readOnDispatcher(t, a, a.root.Bounds); got != want { + t.Fatalf("maximized bounds = %v, want the main window %v", got, want) + } + if !readOnDispatcher(t, a, dlg.IsMaximized) { + t.Fatal("the dialog does not know it is maximized") + } + + runOnDispatcher(t, a, func() { dlg.OnMaximizeRestore() }) + + if got := readOnDispatcher(t, a, dlg.Bounds); got != shown { + t.Fatalf("restored bounds = %v, want %v", got, shown) + } + if readOnDispatcher(t, a, dlg.IsMaximized) { + t.Fatal("the restored dialog still counts as maximized") + } + runOnDispatcher(t, a, func() { a.eng.CloseModal(dlg) }) +} + +func TestADialogWithoutWindowButtonsGetsNoMaximize(t *testing.T) { + a := newTestApp(t) + dlg := widget.NewDialog("Title", 400, 300) + runOnDispatcher(t, a, func() { a.showModal(dlg, dialogOwnerView{}) }) + + if readOnDispatcher(t, a, func() bool { return dlg.OnMaximizeRestore != nil }) { + t.Fatal("a dialog without window buttons got a maximize action") + } + runOnDispatcher(t, a, func() { a.eng.CloseModal(dlg) }) +} diff --git a/internal/app/operation_test.go b/internal/app/operation_test.go index d181a38e..ddba65c4 100644 --- a/internal/app/operation_test.go +++ b/internal/app/operation_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/progress" "github.com/oops1/gogit/internal/i18n" diff --git a/internal/app/patchcmd.go b/internal/app/patchcmd.go index 10d00d5e..fd382980 100644 --- a/internal/app/patchcmd.go +++ b/internal/app/patchcmd.go @@ -4,7 +4,7 @@ import ( "context" "errors" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/diff" "github.com/oops1/gogit/internal/gitcore/ops" diff --git a/internal/app/patchcmd_test.go b/internal/app/patchcmd_test.go index 9d1a6618..490dd2d5 100644 --- a/internal/app/patchcmd_test.go +++ b/internal/app/patchcmd_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/diff" "github.com/oops1/gogit/internal/gitcore/index" diff --git a/internal/app/pickcmd.go b/internal/app/pickcmd.go index e4246398..1618d5e4 100644 --- a/internal/app/pickcmd.go +++ b/internal/app/pickcmd.go @@ -3,7 +3,7 @@ package app import ( "context" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/hash" "github.com/oops1/gogit/internal/gitcore/ops" diff --git a/internal/app/pickcmd_test.go b/internal/app/pickcmd_test.go index 5537b5c1..6808e490 100644 --- a/internal/app/pickcmd_test.go +++ b/internal/app/pickcmd_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/hash" "github.com/oops1/gogit/internal/gitcore/ops" diff --git a/internal/app/preview_test.go b/internal/app/preview_test.go index 3c09b994..88fb2196 100644 --- a/internal/app/preview_test.go +++ b/internal/app/preview_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/gitcore/hash" diff --git a/internal/app/reflogcmd.go b/internal/app/reflogcmd.go index d346e073..46570b81 100644 --- a/internal/app/reflogcmd.go +++ b/internal/app/reflogcmd.go @@ -3,7 +3,7 @@ package app import ( "context" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/ops" "github.com/oops1/gogit/internal/gitcore/refs" diff --git a/internal/app/reflogcmd_test.go b/internal/app/reflogcmd_test.go index 15b6bad8..bab6f05d 100644 --- a/internal/app/reflogcmd_test.go +++ b/internal/app/reflogcmd_test.go @@ -5,7 +5,7 @@ import ( "errors" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/ops" "github.com/oops1/gogit/internal/gitcore/refs" diff --git a/internal/app/remote_test.go b/internal/app/remote_test.go index 0d0d131a..08d95eaa 100644 --- a/internal/app/remote_test.go +++ b/internal/app/remote_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/hash" "github.com/oops1/gogit/internal/gitcore/odb" diff --git a/internal/app/repos_test.go b/internal/app/repos_test.go index 2453d7b0..14c5084c 100644 --- a/internal/app/repos_test.go +++ b/internal/app/repos_test.go @@ -10,8 +10,8 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" - "github.com/oops1/headless-gui/v3/widget/treeview" + "github.com/oops1/headless-gui/v4/widget" + "github.com/oops1/headless-gui/v4/widget/treeview" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/gitcore/hash" diff --git a/internal/app/repotree_test.go b/internal/app/repotree_test.go index 3851a14b..dac598c7 100644 --- a/internal/app/repotree_test.go +++ b/internal/app/repotree_test.go @@ -5,8 +5,8 @@ import ( "slices" "testing" - "github.com/oops1/headless-gui/v3/widget" - "github.com/oops1/headless-gui/v3/widget/treeview" + "github.com/oops1/headless-gui/v4/widget" + "github.com/oops1/headless-gui/v4/widget/treeview" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/gitcore/index" diff --git a/internal/app/resetcmd.go b/internal/app/resetcmd.go index c4c65b6c..54effe76 100644 --- a/internal/app/resetcmd.go +++ b/internal/app/resetcmd.go @@ -3,7 +3,7 @@ package app import ( "context" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/hash" "github.com/oops1/gogit/internal/gitcore/ops" diff --git a/internal/app/resetcmd_test.go b/internal/app/resetcmd_test.go index 63ed58f2..bce2fdec 100644 --- a/internal/app/resetcmd_test.go +++ b/internal/app/resetcmd_test.go @@ -7,7 +7,7 @@ import ( "path/filepath" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/hash" "github.com/oops1/gogit/internal/gitcore/ops" diff --git a/internal/app/reveal.go b/internal/app/reveal.go index d384a8d0..b5f1c719 100644 --- a/internal/app/reveal.go +++ b/internal/app/reveal.go @@ -4,7 +4,7 @@ import ( "os/exec" "path/filepath" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" ) var setClipboard = widget.ClipboardSetText diff --git a/internal/app/search.go b/internal/app/search.go index a31c5968..2ff40087 100644 --- a/internal/app/search.go +++ b/internal/app/search.go @@ -8,7 +8,7 @@ import ( "path/filepath" "sync" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/i18n" "github.com/oops1/gogit/internal/repo" diff --git a/internal/app/search_test.go b/internal/app/search_test.go index 7962ad82..1628e81c 100644 --- a/internal/app/search_test.go +++ b/internal/app/search_test.go @@ -10,7 +10,7 @@ import ( "strings" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/i18n" diff --git a/internal/app/secrets.go b/internal/app/secrets.go index 52769bef..00951c61 100644 --- a/internal/app/secrets.go +++ b/internal/app/secrets.go @@ -7,7 +7,7 @@ import ( "io/fs" "sync" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/i18n" "github.com/oops1/gogit/internal/ui/masterpassword" diff --git a/internal/app/secrets_flow_test.go b/internal/app/secrets_flow_test.go index 26873f00..1057b590 100644 --- a/internal/app/secrets_flow_test.go +++ b/internal/app/secrets_flow_test.go @@ -9,7 +9,7 @@ import ( "sync" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/i18n" "github.com/oops1/gogit/internal/ui/masterpassword" diff --git a/internal/app/secrets_test.go b/internal/app/secrets_test.go index 60095547..9a3a4977 100644 --- a/internal/app/secrets_test.go +++ b/internal/app/secrets_test.go @@ -10,7 +10,7 @@ import ( "path/filepath" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/i18n" diff --git a/internal/app/settings_test.go b/internal/app/settings_test.go index 11175ad3..b296d479 100644 --- a/internal/app/settings_test.go +++ b/internal/app/settings_test.go @@ -11,8 +11,8 @@ import ( "strings" "testing" - "github.com/oops1/headless-gui/v3/widget" - "github.com/oops1/headless-gui/v3/widget/datagrid" + "github.com/oops1/headless-gui/v4/widget" + "github.com/oops1/headless-gui/v4/widget/datagrid" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/ui/settings" diff --git a/internal/app/sshkeys_test.go b/internal/app/sshkeys_test.go index 073aef93..df3db799 100644 --- a/internal/app/sshkeys_test.go +++ b/internal/app/sshkeys_test.go @@ -16,7 +16,7 @@ import ( "sync" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "golang.org/x/crypto/ssh" "github.com/oops1/gogit/internal/gitcore/transport" diff --git a/internal/app/stashcmd.go b/internal/app/stashcmd.go index c16aa4a8..a9393834 100644 --- a/internal/app/stashcmd.go +++ b/internal/app/stashcmd.go @@ -5,7 +5,7 @@ import ( "errors" "slices" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/diff" "github.com/oops1/gogit/internal/gitcore/odb" diff --git a/internal/app/stashcmd_test.go b/internal/app/stashcmd_test.go index 3c267642..0b659688 100644 --- a/internal/app/stashcmd_test.go +++ b/internal/app/stashcmd_test.go @@ -7,7 +7,7 @@ import ( "reflect" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/hash" "github.com/oops1/gogit/internal/gitcore/ops" diff --git a/internal/app/stashui_test.go b/internal/app/stashui_test.go index 30446cf8..6ef09125 100644 --- a/internal/app/stashui_test.go +++ b/internal/app/stashui_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" - "github.com/oops1/headless-gui/v3/widget/datagrid" + "github.com/oops1/headless-gui/v4/widget" + "github.com/oops1/headless-gui/v4/widget/datagrid" "github.com/oops1/gogit/internal/gitcore/diff" "github.com/oops1/gogit/internal/gitcore/hash" diff --git a/internal/app/submodulecmd.go b/internal/app/submodulecmd.go index 4c802e64..a2733f91 100644 --- a/internal/app/submodulecmd.go +++ b/internal/app/submodulecmd.go @@ -6,7 +6,7 @@ import ( "log/slog" "path/filepath" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/ops" "github.com/oops1/gogit/internal/gitcore/progress" diff --git a/internal/app/submodulecmd_test.go b/internal/app/submodulecmd_test.go index c034ce27..9996309e 100644 --- a/internal/app/submodulecmd_test.go +++ b/internal/app/submodulecmd_test.go @@ -10,7 +10,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/gitcore/hash" diff --git a/internal/app/submoduleedit_test.go b/internal/app/submoduleedit_test.go index 2651f064..14c61677 100644 --- a/internal/app/submoduleedit_test.go +++ b/internal/app/submoduleedit_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/ops" gitrepo "github.com/oops1/gogit/internal/gitcore/repo" diff --git a/internal/app/switchcmd_test.go b/internal/app/switchcmd_test.go index 678d7026..18012ae1 100644 --- a/internal/app/switchcmd_test.go +++ b/internal/app/switchcmd_test.go @@ -5,7 +5,7 @@ import ( "errors" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/ops" "github.com/oops1/gogit/internal/gitcore/refs" diff --git a/internal/app/tagcmd.go b/internal/app/tagcmd.go index 0f9b467e..e140f75a 100644 --- a/internal/app/tagcmd.go +++ b/internal/app/tagcmd.go @@ -3,7 +3,7 @@ package app import ( "context" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/hash" "github.com/oops1/gogit/internal/gitcore/ops" diff --git a/internal/app/tagcmd_test.go b/internal/app/tagcmd_test.go index 92e5fa95..12f73911 100644 --- a/internal/app/tagcmd_test.go +++ b/internal/app/tagcmd_test.go @@ -5,7 +5,7 @@ import ( "errors" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/gitcore/hash" "github.com/oops1/gogit/internal/gitcore/ops" diff --git a/internal/app/testdata/golden/toolbar-dark.png b/internal/app/testdata/golden/toolbar-dark.png index 16b98816..697d2c57 100644 Binary files a/internal/app/testdata/golden/toolbar-dark.png and b/internal/app/testdata/golden/toolbar-dark.png differ diff --git a/internal/app/testdata/golden/toolbar-light.png b/internal/app/testdata/golden/toolbar-light.png index 21fedf76..ba97dd4d 100644 Binary files a/internal/app/testdata/golden/toolbar-light.png and b/internal/app/testdata/golden/toolbar-light.png differ diff --git a/internal/app/toolbar.go b/internal/app/toolbar.go index 40abd3bc..be53da11 100644 --- a/internal/app/toolbar.go +++ b/internal/app/toolbar.go @@ -2,9 +2,8 @@ package app import ( "image" - "image/color" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/i18n" "github.com/oops1/gogit/internal/ui/dialogs/toolbar" @@ -19,30 +18,22 @@ const ( toolbarButtonHeight = 54 toolbarCompactWidth = 44 toolbarCompactHeight = 36 - toolbarSeparatorWidth = 9 + toolbarSeparatorPad = 6 + toolbarSeparatorInset = 4 toolbarMenuArrowWidth = 16 toolbarItemMargin = 2 ) const toolbarCaptionFontSize = 8.0 -type toolbarSeparator struct { - widget.Base - Color color.RGBA +func newToolbarSeparator() *widget.Separator { + separator := widget.NewVerticalSeparator() + separator.Color = widget.CurrentTheme().Border + separator.Margin = toolbarSeparatorInset + separator.SetMargin(widget.Margin{Left: toolbarSeparatorPad, Right: toolbarSeparatorPad}) + return separator } -func (s *toolbarSeparator) Draw(ctx widget.DrawContext) { - b := s.Bounds() - if b.Empty() || s.Color.A == 0 { - return - } - ctx.FillRect(b.Min.X+b.Dx()/2, b.Min.Y+4, 1, max(b.Dy()-8, 1), s.Color) -} - -func (s *toolbarSeparator) ApplyTheme(t *widget.Theme) { s.Color = t.Border } - -func (*toolbarSeparator) DesiredSize() (int, int) { return toolbarSeparatorWidth, 0 } - func toolbarItemSize(w widget.Widget) (int, int) { if sizer, ok := w.(widget.DesiredSizer); ok { if width, height := sizer.DesiredSize(); width > 0 { @@ -89,9 +80,7 @@ func (a *App) buildToolbar() { for _, id := range a.configuredToolbarItems() { switch id { case toolbar.SeparatorID: - separator := &toolbarSeparator{Color: widget.CurrentTheme().Border} - setToolbarMargin(separator) - panel.AddChild(separator) + panel.AddChild(newToolbarSeparator()) case toolbar.StretchID: stretch := panel.AddStretch() setToolbarMargin(stretch) diff --git a/internal/app/toolbar_test.go b/internal/app/toolbar_test.go index 795bb06e..a9aa7a9a 100644 --- a/internal/app/toolbar_test.go +++ b/internal/app/toolbar_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/i18n" @@ -34,7 +34,7 @@ func toolbarItemIDs(a *App) []string { ids := make([]string, 0, len(panel.Children())) for _, child := range panel.Children() { switch child.(type) { - case *toolbarSeparator: + case *widget.Separator: ids = append(ids, toolbar.SeparatorID) case *widget.Stretch: ids = append(ids, toolbar.StretchID) @@ -243,7 +243,8 @@ func TestTheStretchesShareWhateverTheButtonsLeaveOver(t *testing.T) { stretches := []*widget.Stretch{} fixed := panel.Padding * 2 for _, child := range panel.Children() { - fixed += toolbarItemMargin * 2 + margin := child.(interface{ GetMargin() widget.Margin }).GetMargin() + fixed += margin.Left + margin.Right if stretch, is := child.(*widget.Stretch); is { stretches = append(stretches, stretch) continue @@ -278,10 +279,6 @@ func TestTheToolbarSkipsItemsItDoesNotKnow(t *testing.T) { func TestASpacerDrawsNothingWhereThereIsNothingToDraw(t *testing.T) { (&widget.Stretch{}).Draw(nil) - (&toolbarSeparator{}).Draw(nil) - invisible := &toolbarSeparator{} - invisible.SetBounds(rectOfSize(0, 0, 9, 40)) - invisible.Draw(nil) } func TestAToolbarBuiltUnderATestedThemeWearsIt(t *testing.T) { @@ -309,7 +306,7 @@ func toolbarConfigurationOf(items []string, captions bool) toolbar.Result { } func TestTheSeparatorTakesItsColourFromTheTheme(t *testing.T) { - separator := &toolbarSeparator{} + separator := newToolbarSeparator() for _, theme := range []*widget.Theme{widget.Win11LightTheme(), widget.Win11DarkTheme()} { separator.ApplyTheme(theme) if separator.Color != theme.Border { diff --git a/internal/app/toolbarcmd_test.go b/internal/app/toolbarcmd_test.go index cd11464d..fd6ac5c6 100644 --- a/internal/app/toolbarcmd_test.go +++ b/internal/app/toolbarcmd_test.go @@ -11,7 +11,7 @@ import ( "strings" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/i18n" diff --git a/internal/app/toolbargolden_test.go b/internal/app/toolbargolden_test.go index d04626a1..c908c81a 100644 --- a/internal/app/toolbargolden_test.go +++ b/internal/app/toolbargolden_test.go @@ -9,10 +9,11 @@ import ( "runtime" "testing" - "github.com/oops1/headless-gui/v3/engine" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/engine" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" + "github.com/oops1/gogit/internal/ui/style" ) const ( @@ -46,6 +47,7 @@ func renderToolbarFrame(t *testing.T, theme string, captions bool) *image.RGBA { canvas := engine.New(config.MinWindowWidth, height, 30) t.Cleanup(canvas.Stop) + canvas.SetTextQuality(style.TextQuality()) canvas.SetTheme(a.theme()) widget.ApplyThemeTree(panel, a.theme()) a.applyToolbarIcons() diff --git a/internal/app/toolbaritems.go b/internal/app/toolbaritems.go index f53caeac..d747b1df 100644 --- a/internal/app/toolbaritems.go +++ b/internal/app/toolbaritems.go @@ -1,7 +1,7 @@ package app import ( - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/ui/dialogs/toolbar" ) diff --git a/internal/app/update_test.go b/internal/app/update_test.go index d79e06d2..ee3cb1df 100644 --- a/internal/app/update_test.go +++ b/internal/app/update_test.go @@ -13,7 +13,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/i18n" diff --git a/internal/app/watch_test.go b/internal/app/watch_test.go index a840b50b..90a8044f 100644 --- a/internal/app/watch_test.go +++ b/internal/app/watch_test.go @@ -11,7 +11,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/gitcore/ops" diff --git a/internal/app/windowicon.go b/internal/app/windowicon.go index 58e92bb3..0933d676 100644 --- a/internal/app/windowicon.go +++ b/internal/app/windowicon.go @@ -4,7 +4,7 @@ import ( "errors" "image" - "github.com/oops1/headless-gui/v3/window" + "github.com/oops1/headless-gui/v4/window" "github.com/oops1/gogit/internal/ui/icons" ) diff --git a/internal/app/windowicon_test.go b/internal/app/windowicon_test.go index e3f1a76c..8e2c38d3 100644 --- a/internal/app/windowicon_test.go +++ b/internal/app/windowicon_test.go @@ -3,8 +3,8 @@ package app import ( "testing" - "github.com/oops1/headless-gui/v3/engine" - "github.com/oops1/headless-gui/v3/window" + "github.com/oops1/headless-gui/v4/engine" + "github.com/oops1/headless-gui/v4/window" "github.com/oops1/gogit/internal/ui/icons" ) diff --git a/internal/app/windowmemory.go b/internal/app/windowmemory.go new file mode 100644 index 00000000..7aeea6d8 --- /dev/null +++ b/internal/app/windowmemory.go @@ -0,0 +1,71 @@ +package app + +import ( + "sync" + + "github.com/oops1/headless-gui/v4/widget" + + "github.com/oops1/gogit/internal/config" + "github.com/oops1/gogit/internal/ui/compare" + "github.com/oops1/gogit/internal/ui/conflict" + "github.com/oops1/gogit/internal/ui/dialogs" +) + +func (a *App) rememberOnClose(dlg *widget.Dialog, remember func()) { + closed := dlg.OnClosed + var once sync.Once + dlg.OnClosed = func() { + if closed != nil { + closed() + } + once.Do(func() { + a.Post(func() { + remember() + if err := a.cfg.Save(a.paths.ConfigFile()); err != nil { + a.log.Warn("save window size failed", "error", err) + } + }) + }) + } +} + +func rememberSize(dlg *widget.Dialog, target *config.WindowSize) { + if width, height, ok := dialogs.RememberedSize(dlg); ok { + *target = config.WindowSize{Width: width, Height: height} + } +} + +func (a *App) restoreCompareWindow(view *compare.View) { + saved := a.cfg.UI.CompareWindow + dialogs.RestoreSize(view.Dialog(), saved.Width, saved.Height) + view.SetLayout(compare.Layout{CollapseLeft: saved.CollapseLeft, CollapseRight: saved.CollapseRight, Split: saved.Split}) + a.rememberOnClose(view.Dialog(), func() { + target := &a.cfg.UI.CompareWindow + rememberSize(view.Dialog(), &target.WindowSize) + layout := view.Layout() + target.CollapseLeft, target.CollapseRight, target.Split = layout.CollapseLeft, layout.CollapseRight, layout.Split + }) +} + +func (a *App) restoreConflictWindow(view *conflict.View) { + saved := a.cfg.UI.ConflictWindow + dialogs.RestoreSize(view.Dialog(), saved.Width, saved.Height) + view.SetPanes(!saved.HideBase, !saved.SeparateScroll) + view.SetLayout(conflict.Layout{ + CollapseOurs: saved.CollapseOurs, + CollapseBase: saved.CollapseBase, + CollapseTheirs: saved.CollapseTheirs, + ResultMaximized: saved.ResultMaximized, + SourcesMaximized: saved.SourcesMaximized, + Split: saved.Split, + }) + a.rememberOnClose(view.Dialog(), func() { + target := &a.cfg.UI.ConflictWindow + rememberSize(view.Dialog(), &target.WindowSize) + target.HideBase = !view.ShowsBase() + target.SeparateScroll = !view.ScrollsTogether() + layout := view.Layout() + target.CollapseOurs, target.CollapseBase, target.CollapseTheirs = layout.CollapseOurs, layout.CollapseBase, layout.CollapseTheirs + target.ResultMaximized, target.SourcesMaximized, target.Split = layout.ResultMaximized, layout.SourcesMaximized, layout.Split + }) +} diff --git a/internal/app/windowmemory_test.go b/internal/app/windowmemory_test.go new file mode 100644 index 00000000..f7f82dd4 --- /dev/null +++ b/internal/app/windowmemory_test.go @@ -0,0 +1,233 @@ +package app + +import ( + "os" + "strings" + "testing" + + "github.com/oops1/headless-gui/v4/widget" + + "github.com/oops1/gogit/internal/config" + "github.com/oops1/gogit/internal/ui/conflict" +) + +func dialogSize(t *testing.T, a *App, size func() (int, int)) config.WindowSize { + t.Helper() + return readOnDispatcher(t, a, func() config.WindowSize { + w, h := size() + return config.WindowSize{Width: w, Height: h} + }) +} + +func TestTheCompareWindowReopensAtTheSizeItWasLeft(t *testing.T) { + a, paths := newTestAppWithPaths(t) + captured := captureCompareView(t) + a.openCompareFiles(textFile(t, "a.txt", "a\n"), textFile(t, "b.txt", "b\n")) + runOnDispatcher(t, a, func() { (*captured).Dialog().Resize(1000, 600) }) + + runOnDispatcher(t, a, func() { (*captured).OnClose() }) + waitForPostQueueDrain(t, a) + + want := config.WindowSize{Width: 1000, Height: 600} + if got := readOnDispatcher(t, a, func() config.WindowSize { return a.cfg.UI.CompareWindow.WindowSize }); got != want { + t.Fatalf("remembered = %+v, want %+v", got, want) + } + saved, err := config.Load(paths.ConfigFile()) + if err != nil { + t.Fatal(err) + } + if saved.UI.CompareWindow.WindowSize != want { + t.Fatalf("saved = %+v, want %+v", saved.UI.CompareWindow, want) + } + + a.openCompareFiles("", "") + reopened := dialogSize(t, a, func() (int, int) { + b := (*captured).Dialog().Bounds() + return b.Dx(), b.Dy() + }) + if reopened != want { + t.Fatalf("reopened at %+v, want %+v", reopened, want) + } + runOnDispatcher(t, a, func() { a.eng.CloseModal((*captured).Dialog()) }) +} + +func TestAMaximizedCompareWindowKeepsTheSizeToReturnTo(t *testing.T) { + a := newTestApp(t) + a.cfg.UI.CompareWindow.WindowSize = config.WindowSize{Width: 1000, Height: 600} + captured := captureCompareView(t) + a.openCompareFiles("", "") + + runOnDispatcher(t, a, func() { (*captured).Dialog().OnMaximizeRestore() }) + runOnDispatcher(t, a, func() { (*captured).OnClose() }) + waitForPostQueueDrain(t, a) + + want := config.WindowSize{Width: 1000, Height: 600} + if got := readOnDispatcher(t, a, func() config.WindowSize { return a.cfg.UI.CompareWindow.WindowSize }); got != want { + t.Fatalf("remembered = %+v, want the restored size %+v", got, want) + } +} + +func newConflictWindow(t *testing.T, a *App) *conflict.View { + t.Helper() + return readOnDispatcher(t, a, func() *conflict.View { + view, err := newConflictView() + if err != nil { + t.Error(err) + return nil + } + view.Show(conflict.File{Path: "f.txt"}) + return view + }) +} + +func TestTheConflictWindowOpensTheWayItWasLeft(t *testing.T) { + a := newTestApp(t) + a.cfg.UI.ConflictWindow = config.ConflictWindow{ + WindowSize: config.WindowSize{Width: 1180, Height: 700}, + HideBase: true, + SeparateScroll: true, + } + view := newConflictWindow(t, a) + + runOnDispatcher(t, a, func() { a.restoreConflictWindow(view) }) + + if readOnDispatcher(t, a, view.ShowsBase) || readOnDispatcher(t, a, view.ScrollsTogether) { + t.Fatal("the window must open with the base hidden and the sides scrolling apart") + } + size := dialogSize(t, a, func() (int, int) { b := view.Dialog().Bounds(); return b.Dx(), b.Dy() }) + if size != a.cfg.UI.ConflictWindow.WindowSize { + t.Fatalf("opened at %+v, want %+v", size, a.cfg.UI.ConflictWindow.WindowSize) + } +} + +func TestTheConflictWindowRemembersItsPanesWhenClosed(t *testing.T) { + a := newTestApp(t) + view := newConflictWindow(t, a) + runOnDispatcher(t, a, func() { + a.restoreConflictWindow(view) + a.showModal(view.Dialog(), view) + view.SetPanes(false, false) + view.Dialog().Resize(1200, 680) + }) + + runOnDispatcher(t, a, func() { a.eng.CloseModal(view.Dialog()) }) + waitForPostQueueDrain(t, a) + + want := config.ConflictWindow{WindowSize: config.WindowSize{Width: 1200, Height: 680}, HideBase: true, SeparateScroll: true, Split: 0.58} + if got := readOnDispatcher(t, a, func() config.ConflictWindow { return a.cfg.UI.ConflictWindow }); got != want { + t.Fatalf("remembered = %+v, want %+v", got, want) + } +} + +func TestAWindowSizeThatCannotBeSavedIsLogged(t *testing.T) { + a, buf := newPanicLoggingApp(t) + if err := os.Mkdir(a.paths.ConfigFile(), 0o700); err != nil { + t.Fatal(err) + } + view := newConflictWindowDirect(t) + a.restoreConflictWindow(view) + a.showModal(view.Dialog(), view) + + a.eng.CloseModal(view.Dialog()) + a.Engine().Flush() + + if !strings.Contains(buf.String(), "save window size failed") { + t.Fatalf("log = %s", buf.String()) + } +} + +func TestAnEarlierCloseListenerStillRuns(t *testing.T) { + a := newTestApp(t) + view := newConflictWindow(t, a) + called := false + runOnDispatcher(t, a, func() { + view.Dialog().OnClosed = func() { called = true } + a.restoreConflictWindow(view) + a.showModal(view.Dialog(), view) + }) + + runOnDispatcher(t, a, func() { a.eng.CloseModal(view.Dialog()) }) + waitForPostQueueDrain(t, a) + + if !readOnDispatcher(t, a, func() bool { return called }) { + t.Fatal("the listener set before the window was restored was dropped") + } +} + +func newConflictWindowDirect(t *testing.T) *conflict.View { + t.Helper() + view, err := newConflictView() + if err != nil { + t.Fatal(err) + } + view.Show(conflict.File{Path: "f.txt"}) + return view +} + +func TestTheCompareWindowReopensWithTheSideThatWasCollapsed(t *testing.T) { + a := newTestApp(t) + captured := captureCompareView(t) + a.openCompareFiles(textFile(t, "a.txt", "a\n"), textFile(t, "b.txt", "b\n")) + runOnDispatcher(t, a, func() { + (*captured).Diff().SetSplit(0.7) + (*captured).Diff().SetCollapsed(widget.DiffLeft, true) + }) + + runOnDispatcher(t, a, func() { (*captured).OnClose() }) + waitForPostQueueDrain(t, a) + + saved := readOnDispatcher(t, a, func() config.CompareWindow { return a.cfg.UI.CompareWindow }) + if !saved.CollapseLeft || saved.CollapseRight || saved.Split != 0.7 { + t.Fatalf("remembered = %+v, want the left side collapsed at 0.7", saved) + } + + a.openCompareFiles("", "") + if got := readOnDispatcher(t, a, (*captured).Layout); !got.CollapseLeft || got.Split != 0.7 { + t.Fatalf("reopened with %+v, want the left side collapsed at 0.7", got) + } + runOnDispatcher(t, a, func() { a.eng.CloseModal((*captured).Dialog()) }) +} + +func TestTheConflictWindowRemembersItsCollapsedPanes(t *testing.T) { + a := newTestApp(t) + view := newConflictWindow(t, a) + runOnDispatcher(t, a, func() { + a.restoreConflictWindow(view) + a.showModal(view.Dialog(), view) + view.Merge().SetSplit(0.4) + view.Merge().SetPaneCollapsed(widget.MergeTheirs, true) + view.Merge().SetResultMaximized(true) + }) + + runOnDispatcher(t, a, func() { a.eng.CloseModal(view.Dialog()) }) + waitForPostQueueDrain(t, a) + + saved := readOnDispatcher(t, a, func() config.ConflictWindow { return a.cfg.UI.ConflictWindow }) + if !saved.CollapseTheirs || saved.CollapseOurs || saved.CollapseBase || !saved.ResultMaximized || saved.Split != 0.4 { + t.Fatalf("remembered = %+v", saved) + } + + reopened := newConflictWindow(t, a) + runOnDispatcher(t, a, func() { a.restoreConflictWindow(reopened) }) + got := readOnDispatcher(t, a, reopened.Layout) + if !got.CollapseTheirs || !got.ResultMaximized || got.Split != 0.4 { + t.Fatalf("reopened with %+v", got) + } +} + +func TestAWindowClosedTwiceIsRememberedOnce(t *testing.T) { + a := newTestApp(t) + dlg := widget.NewDialog("Title", 400, 300) + remembered := 0 + runOnDispatcher(t, a, func() { a.rememberOnClose(dlg, func() { remembered++ }) }) + + runOnDispatcher(t, a, func() { + dlg.OnClosed() + dlg.OnClosed() + }) + waitForPostQueueDrain(t, a) + + if got := readOnDispatcher(t, a, func() int { return remembered }); got != 1 { + t.Fatalf("remembered %d times, want once", got) + } +} diff --git a/internal/app/working_diff_test.go b/internal/app/working_diff_test.go index f8070d07..4a35b425 100644 --- a/internal/app/working_diff_test.go +++ b/internal/app/working_diff_test.go @@ -12,9 +12,9 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget/datagrid" + "github.com/oops1/headless-gui/v4/widget/datagrid" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/gitcore/diff" diff --git a/internal/app/working_test.go b/internal/app/working_test.go index 69ac848d..2b588909 100644 --- a/internal/app/working_test.go +++ b/internal/app/working_test.go @@ -5,7 +5,7 @@ import ( "path/filepath" "testing" - "github.com/oops1/headless-gui/v3/widget/datagrid" + "github.com/oops1/headless-gui/v4/widget/datagrid" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/gitcore/diff" diff --git a/internal/app/worktreecmd_test.go b/internal/app/worktreecmd_test.go index e39d157c..5970de32 100644 --- a/internal/app/worktreecmd_test.go +++ b/internal/app/worktreecmd_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/gitcore/ops" diff --git a/internal/app/worktrees_test.go b/internal/app/worktrees_test.go index 68400ca6..cf49c63f 100644 --- a/internal/app/worktrees_test.go +++ b/internal/app/worktrees_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "github.com/oops1/headless-gui/v3/widget" + "github.com/oops1/headless-gui/v4/widget" "github.com/oops1/gogit/internal/config" "github.com/oops1/gogit/internal/gitcore/ops" diff --git a/internal/assets/assets_test.go b/internal/assets/assets_test.go index 534b5771..3e97d6c9 100644 --- a/internal/assets/assets_test.go +++ b/internal/assets/assets_test.go @@ -134,7 +134,7 @@ func TestTreeIcons(t *testing.T) { want := []string{ "group", "group_open", "repository", "repository_modified", "repository_ahead", "repository_missing", "worktree", - "branch", "branch_current", "branch_remote", "branch_head", "tag", "stash", + "branch", "branch_current", "branch_remote", "branch_head", "branch_main", "tag", "stash", "folder", "file", "directory", "directory_dim", "directory_muted", } names := TreeIconNames() diff --git a/internal/assets/i18n/en.json b/internal/assets/i18n/en.json index 24dff7b6..8f7b7038 100644 --- a/internal/assets/i18n/en.json +++ b/internal/assets/i18n/en.json @@ -231,6 +231,11 @@ "Dialog.CompareRefs.Sides": "%s compared with %s", "Dialog.CompareRefs.SidesLabel": "Two places to compare:", "Dialog.CompareRefs.Title": "Compare Branches", + "Dialog.Conflict.AllConflicts": "All conflicts", + "Dialog.Conflict.AllConflicts.Ours": "Take ours in the remaining conflicts", + "Dialog.Conflict.AllConflicts.Reset": "Mark every conflict unresolved again", + "Dialog.Conflict.AllConflicts.Theirs": "Take theirs in the remaining conflicts", + "Dialog.Conflict.AllConflicts.Tip": "Resolve every conflict of the file at once", "Dialog.Conflict.Close": "Close", "Dialog.Conflict.Next.Tip": "Next conflict", "Dialog.Conflict.Note.Base": "the file in the last commit both branches share", @@ -238,6 +243,8 @@ "Dialog.Conflict.Note.Theirs": "the branch you are merging in", "Dialog.Conflict.Position": "Line %d, column %d", "Dialog.Conflict.Prev.Tip": "Previous conflict", + "Dialog.Conflict.Redo": "Redo", + "Dialog.Conflict.Redo.Tip": "Redo the choice or edit that was undone", "Dialog.Conflict.Save": "Save", "Dialog.Conflict.Save.Tip": "Write the result to the file; when no conflicts are left, mark the file resolved", "Dialog.Conflict.SaveFailed": "Could not save: %s", @@ -248,6 +255,8 @@ "Dialog.Conflict.Side.Base": "Base", "Dialog.Conflict.Side.Ours": "Ours", "Dialog.Conflict.Side.Theirs": "Theirs", + "Dialog.Conflict.SyncScroll": "Scroll together", + "Dialog.Conflict.SyncScroll.Tip": "Scroll the sides and the result together, block by block", "Dialog.Conflict.TakeBoth": "Take both", "Dialog.Conflict.TakeBoth.Tip": "Keep both versions: yours first, then theirs", "Dialog.Conflict.TakeOurs": "Take ours", @@ -1007,6 +1016,7 @@ "Menu.Branches.Group.AfterLastSlash": "After the Last Slash", "Menu.Branches.Group.ExceptSingles": "Except Singletons", "Menu.Branches.Group.GroupsFirst": "Groups First", + "Menu.Branches.MainSection": "Main Branches in a Group of Their Own", "Menu.Branches.SelectObsolete": "Select Obsolete Local Branches", "Menu.Branches.Sort": "Sort References", "Menu.Branches.Sort.CommitTime": "By Commit Time", @@ -1319,6 +1329,7 @@ "Pane.Branches.Flow.Releases": "Releases (%d)", "Pane.Branches.Flow.Support": "Support (%d)", "Pane.Branches.Local": "Local", + "Pane.Branches.Main": "Main", "Pane.Branches.Remotes": "Remotes", "Pane.Branches.Stash": "Stash", "Pane.Branches.Submodule.Conflict": "conflict", diff --git a/internal/assets/i18n/ru.json b/internal/assets/i18n/ru.json index 4f33c761..56033977 100644 --- a/internal/assets/i18n/ru.json +++ b/internal/assets/i18n/ru.json @@ -231,6 +231,11 @@ "Dialog.CompareRefs.Sides": "«%s» в сравнении с «%s»", "Dialog.CompareRefs.SidesLabel": "Что с чем сравнить:", "Dialog.CompareRefs.Title": "Сравнение ветвей", + "Dialog.Conflict.AllConflicts": "Все конфликты", + "Dialog.Conflict.AllConflicts.Ours": "Взять нашу в оставшихся конфликтах", + "Dialog.Conflict.AllConflicts.Reset": "Вернуть все конфликты нерешёнными", + "Dialog.Conflict.AllConflicts.Theirs": "Взять их в оставшихся конфликтах", + "Dialog.Conflict.AllConflicts.Tip": "Решить все конфликты файла разом", "Dialog.Conflict.Close": "Закрыть", "Dialog.Conflict.Next.Tip": "Следующий конфликт", "Dialog.Conflict.Note.Base": "файл в последнем общем коммите обеих веток", @@ -238,6 +243,8 @@ "Dialog.Conflict.Note.Theirs": "ветка, которую вы вливаете", "Dialog.Conflict.Position": "Строка %d, столбец %d", "Dialog.Conflict.Prev.Tip": "Предыдущий конфликт", + "Dialog.Conflict.Redo": "Повторить", + "Dialog.Conflict.Redo.Tip": "Вернуть отменённое решение или правку", "Dialog.Conflict.Save": "Сохранить", "Dialog.Conflict.Save.Tip": "Записать итог в файл; если конфликтов не осталось — отметить файл решённым", "Dialog.Conflict.SaveFailed": "Не удалось сохранить: %s", @@ -248,6 +255,8 @@ "Dialog.Conflict.Side.Base": "База", "Dialog.Conflict.Side.Ours": "Наша", "Dialog.Conflict.Side.Theirs": "Их", + "Dialog.Conflict.SyncScroll": "Прокручивать вместе", + "Dialog.Conflict.SyncScroll.Tip": "Прокручивать стороны и итог вместе, по блокам", "Dialog.Conflict.TakeBoth": "Взять обе", "Dialog.Conflict.TakeBoth.Tip": "Оставить оба варианта: сначала ваш, потом их", "Dialog.Conflict.TakeOurs": "Взять нашу", @@ -1007,6 +1016,7 @@ "Menu.Branches.Group.AfterLastSlash": "После последнего слэша", "Menu.Branches.Group.ExceptSingles": "Кроме одиночных", "Menu.Branches.Group.GroupsFirst": "Группы первыми", + "Menu.Branches.MainSection": "Основные ветки отдельной группой", "Menu.Branches.SelectObsolete": "Выбрать устаревшие локальные ветки", "Menu.Branches.Sort": "Сортировать ссылки", "Menu.Branches.Sort.CommitTime": "По времени коммита", @@ -1319,6 +1329,7 @@ "Pane.Branches.Flow.Releases": "Релизы (%d)", "Pane.Branches.Flow.Support": "Поддержка (%d)", "Pane.Branches.Local": "Локальные", + "Pane.Branches.Main": "Основные", "Pane.Branches.Remotes": "Внешние", "Pane.Branches.Stash": "Stash", "Pane.Branches.Submodule.Conflict": "конфликт", diff --git a/internal/assets/icons/tree/branch_main.svg b/internal/assets/icons/tree/branch_main.svg new file mode 100644 index 00000000..e3234593 --- /dev/null +++ b/internal/assets/icons/tree/branch_main.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/internal/assets/ui/dialogs/conflict.xaml b/internal/assets/ui/dialogs/conflict.xaml index 34e74a48..96f29020 100644 --- a/internal/assets/ui/dialogs/conflict.xaml +++ b/internal/assets/ui/dialogs/conflict.xaml @@ -1,7 +1,7 @@ + Width="1232" Height="720"> @@ -13,18 +13,24 @@ - + - + - + + + - + + + + +