From 48f1f16066770732a2ac1eaa90e36778a07baad3 Mon Sep 17 00:00:00 2001 From: ErikKalkoken Date: Sat, 2 Nov 2024 22:09:45 +0100 Subject: [PATCH 1/2] Replace toggle widget with switch and add key handler for all dialogs --- go.mod | 4 ++-- go.sum | 4 ++++ internal/ui/about.go | 3 +++ internal/ui/menu.go | 4 ++++ internal/ui/searchbar.go | 3 +++ internal/ui/settings.go | 6 ++++-- internal/ui/ui.go | 4 ++++ 7 files changed, 24 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 972fe3c..cdb9cfb 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.23 require ( fyne.io/fyne/v2 v2.5.2 - github.com/ErikKalkoken/fyne-kx v0.0.0-20241025174815-e140dbe057e4 + github.com/ErikKalkoken/fyne-kx v0.1.0 github.com/dweymouth/fyne-tooltip v0.2.1 github.com/hashicorp/go-version v1.7.0 github.com/jarcoal/httpmock v1.3.1 @@ -18,7 +18,7 @@ require ( github.com/BurntSushi/toml v1.4.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fredbi/uri v1.1.0 // indirect - github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/fsnotify/fsnotify v1.8.0 // indirect github.com/fyne-io/gl-js v0.0.0-20230506162202-1fdaa286a934 // indirect github.com/fyne-io/glfw-js v0.0.0-20240101223322-6e1efdc71b7a // indirect github.com/fyne-io/image v0.0.0-20240417123036-dc0ee9e7c964 // indirect diff --git a/go.sum b/go.sum index 69ebca9..613f329 100644 --- a/go.sum +++ b/go.sum @@ -47,6 +47,8 @@ github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/ErikKalkoken/fyne-kx v0.0.0-20241025174815-e140dbe057e4 h1:7JZ55BPANlRZtMeHevNiFRtLhGYrTenLyoNpQJisGaQ= github.com/ErikKalkoken/fyne-kx v0.0.0-20241025174815-e140dbe057e4/go.mod h1:N/YVe+viCUiSOr2TziRV7s9iEOlIfS/n/s5r5LiPcXg= +github.com/ErikKalkoken/fyne-kx v0.1.0 h1:vJ7ja3DnIAR/wDSatFcJbqcMqlv8F4Zz8O87mw8uTjU= +github.com/ErikKalkoken/fyne-kx v0.1.0/go.mod h1:N/YVe+viCUiSOr2TziRV7s9iEOlIfS/n/s5r5LiPcXg= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= @@ -84,6 +86,8 @@ github.com/fredbi/uri v1.1.0/go.mod h1:aYTUoAXBOq7BLfVJ8GnKmfcuURosB1xyHDIfWeC/i github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M= +github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= github.com/fyne-io/gl-js v0.0.0-20230506162202-1fdaa286a934 h1:dZC5aKobSN07hf71oMivxUmAofFja5GrfPK2rBlttX4= github.com/fyne-io/gl-js v0.0.0-20230506162202-1fdaa286a934/go.mod h1:d4clgH0/GrRwWjRzJJQXxT/h1TyuNSfF/X64zb/3Ggg= github.com/fyne-io/glfw-js v0.0.0-20240101223322-6e1efdc71b7a h1:ybgRdYvAHTn93HW79bLiBiJwVL4jVeyGQRZMgImoeWs= diff --git a/internal/ui/about.go b/internal/ui/about.go index 8e16067..602823f 100644 --- a/internal/ui/about.go +++ b/internal/ui/about.go @@ -7,6 +7,8 @@ import ( "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/dialog" "fyne.io/fyne/v2/widget" + + kxdialog "github.com/ErikKalkoken/fyne-kx/dialog" ) func (u *UI) showAboutDialog() { @@ -26,5 +28,6 @@ func (u *UI) showAboutDialog() { widget.NewHyperlink("Website", x), ) d := dialog.NewCustom("About", "OK", c, u.window) + kxdialog.AddDialogKeyHandler(d, u.window) d.Show() } diff --git a/internal/ui/menu.go b/internal/ui/menu.go index 41aeaa5..9e564ac 100644 --- a/internal/ui/menu.go +++ b/internal/ui/menu.go @@ -10,6 +10,8 @@ import ( "fyne.io/fyne/v2/dialog" "fyne.io/fyne/v2/driver/desktop" "fyne.io/fyne/v2/storage" + kxdialog "github.com/ErikKalkoken/fyne-kx/dialog" + "github.com/ErikKalkoken/janice/internal/jsondocument" ) @@ -71,6 +73,7 @@ func (u *UI) makeMenu() *fyne.MainMenu { return } }, u.window) + kxdialog.AddDialogKeyHandler(d, u.window) d.Show() }), fyne.NewMenuItem("Export Selection To Clipboard", func() { @@ -149,6 +152,7 @@ func (u *UI) fileOpen() { } u.loadDocument(reader) }, u.window) + kxdialog.AddDialogKeyHandler(d, u.window) d.Show() filterEnabled := u.app.Preferences().BoolWithFallback(settingExtensionFilter, settingExtensionDefault) if filterEnabled { diff --git a/internal/ui/searchbar.go b/internal/ui/searchbar.go index a340202..661c6f0 100644 --- a/internal/ui/searchbar.go +++ b/internal/ui/searchbar.go @@ -12,6 +12,7 @@ import ( "fyne.io/fyne/v2/layout" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" + kxdialog "github.com/ErikKalkoken/fyne-kx/dialog" ttwidget "github.com/dweymouth/fyne-tooltip/widget" "github.com/ErikKalkoken/janice/internal/jsondocument" @@ -132,6 +133,7 @@ func (f *searchBarFrame) doSearch() { cancel() }) d := dialog.NewCustomWithoutButtons("Search", container.NewVBox(c, b), f.u.window) + kxdialog.AddDialogKeyHandler(d, f.u.window) d.Show() d.SetOnClosed(func() { cancel() @@ -164,6 +166,7 @@ func (f *searchBarFrame) doSearch() { fmt.Sprintf("No %s found matching %s", searchType, search), f.u.window, ) + kxdialog.AddDialogKeyHandler(d, f.u.window) d2.Show() return } else if err != nil { diff --git a/internal/ui/settings.go b/internal/ui/settings.go index ea3fb02..322a490 100644 --- a/internal/ui/settings.go +++ b/internal/ui/settings.go @@ -3,6 +3,7 @@ package ui import ( "fyne.io/fyne/v2/dialog" "fyne.io/fyne/v2/widget" + kxdialog "github.com/ErikKalkoken/fyne-kx/dialog" kxwidget "github.com/ErikKalkoken/fyne-kx/widget" ) @@ -26,13 +27,13 @@ func (u *UI) showSettingsDialog() { } // apply file filter - extFilter := kxwidget.NewToggle(func(v bool) { + extFilter := kxwidget.NewSwitch(func(v bool) { u.app.Preferences().SetBool(settingExtensionFilter, v) }) y := u.app.Preferences().BoolWithFallback(settingExtensionFilter, settingExtensionDefault) extFilter.SetState(y) - notifyUpdates := kxwidget.NewToggle(func(v bool) { + notifyUpdates := kxwidget.NewSwitch(func(v bool) { u.app.Preferences().SetBool(settingNotifyUpdates, v) }) z := u.app.Preferences().BoolWithFallback(settingNotifyUpdates, settingNotifyUpdatesDefault) @@ -44,5 +45,6 @@ func (u *UI) showSettingsDialog() { {Text: "Notify about updates", Widget: notifyUpdates, HintText: "Wether to notify when an update is available (requires restart)"}, } d := dialog.NewCustom("Settings", "Close", widget.NewForm(items...), u.window) + kxdialog.AddDialogKeyHandler(d, u.window) d.Show() } diff --git a/internal/ui/ui.go b/internal/ui/ui.go index 68e15d5..b18693a 100644 --- a/internal/ui/ui.go +++ b/internal/ui/ui.go @@ -20,6 +20,8 @@ import ( "golang.org/x/text/language" "golang.org/x/text/message" + kxdialog "github.com/ErikKalkoken/fyne-kx/dialog" + "github.com/ErikKalkoken/janice/internal/jsondocument" ) @@ -207,6 +209,7 @@ func (u *UI) showErrorDialog(message string, err error) { slog.Error(message, "err", err) } d := dialog.NewInformation("Error", message, u.window) + kxdialog.AddDialogKeyHandler(d, u.window) d.Show() } @@ -286,6 +289,7 @@ func (u *UI) loadDocument(reader fyne.URIReadCloser) { d2.SetOnClosed(func() { cancel() }) + kxdialog.AddDialogKeyHandler(d2, u.window) d2.Show() go func() { doc := jsondocument.New() From efbe35ae8f1e80e084d618941f4b2a043d4e4682 Mon Sep 17 00:00:00 2001 From: ErikKalkoken Date: Sat, 2 Nov 2024 22:12:44 +0100 Subject: [PATCH 2/2] Fix: Canceling load early returns error --- FyneApp.toml | 2 +- internal/jsondocument/jsondocument.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/FyneApp.toml b/FyneApp.toml index abd308a..1c64fc4 100644 --- a/FyneApp.toml +++ b/FyneApp.toml @@ -4,7 +4,7 @@ Website = "https://github.com/ErikKalkoken/janice" Icon = "icon.png" Name = "Janice" ID = "io.github.erikkalkoken.janice" - Version = "0.6.0" + Version = "0.6.1" Build = 1 [Release] diff --git a/internal/jsondocument/jsondocument.go b/internal/jsondocument/jsondocument.go index 8fd4102..7361d6f 100644 --- a/internal/jsondocument/jsondocument.go +++ b/internal/jsondocument/jsondocument.go @@ -148,6 +148,9 @@ func (j *JSONDocument) Value(uid widget.TreeNodeID) Node { func (j *JSONDocument) Load(ctx context.Context, reader fyne.URIReadCloser, progressInfo binding.Untyped) error { j.progressInfo = progressInfo data, err := j.load(ctx, reader) + if errors.Is(err, context.Canceled) { + err = ErrCallerCanceled + } if err != nil { return err }