From 554e6a6d5e93cc1dc36011d901b1e883d1a2d71e Mon Sep 17 00:00:00 2001 From: ErikKalkoken Date: Fri, 25 Oct 2024 21:46:38 +0200 Subject: [PATCH] Refactor & version bump --- FyneApp.toml | 2 +- internal/ui/searchbar.go | 22 +++++++++++----------- internal/ui/selection.go | 14 +++++++------- internal/ui/statusbar.go | 4 ++-- internal/ui/value.go | 10 +++++----- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/FyneApp.toml b/FyneApp.toml index 5239862..abd308a 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.5.0" + Version = "0.6.0" Build = 1 [Release] diff --git a/internal/ui/searchbar.go b/internal/ui/searchbar.go index 868e763..a340202 100644 --- a/internal/ui/searchbar.go +++ b/internal/ui/searchbar.go @@ -36,7 +36,7 @@ var type2importance = map[jsondocument.JSONType]widget.Importance{ // searchBarFrame represents the search bar frame in the UI. type searchBarFrame struct { content *fyne.Container - ui *UI + u *UI searchEntry *widget.Entry searchButton *ttwidget.Button @@ -48,7 +48,7 @@ type searchBarFrame struct { func (u *UI) newSearchBarFrame() *searchBarFrame { f := &searchBarFrame{ - ui: u, + u: u, searchEntry: widget.NewEntry(), } // search frame @@ -71,15 +71,15 @@ func (u *UI) newSearchBarFrame() *searchBarFrame { }) f.searchButton.SetToolTip("Search") f.scrollBottom = ttwidget.NewButtonWithIcon("", theme.NewThemedResource(resourceVerticalalignbottomSvg), func() { - f.ui.treeWidget.ScrollToBottom() + f.u.treeWidget.ScrollToBottom() }) f.scrollBottom.SetToolTip("Scroll to bottom") f.scrollTop = ttwidget.NewButtonWithIcon("", theme.NewThemedResource(resourceVerticalaligntopSvg), func() { - f.ui.treeWidget.ScrollToTop() + f.u.treeWidget.ScrollToTop() }) f.scrollTop.SetToolTip("Scroll to top") f.collapseAll = ttwidget.NewButtonWithIcon("", theme.NewThemedResource(resourceUnfoldlessSvg), func() { - f.ui.treeWidget.CloseAllBranches() + f.u.treeWidget.CloseAllBranches() }) f.collapseAll.SetToolTip("Collapse all") c := container.NewBorder( @@ -131,7 +131,7 @@ func (f *searchBarFrame) doSearch() { b := widget.NewButton("Cancel", func() { cancel() }) - d := dialog.NewCustomWithoutButtons("Search", container.NewVBox(c, b), f.ui.window) + d := dialog.NewCustomWithoutButtons("Search", container.NewVBox(c, b), f.u.window) d.Show() d.SetOnClosed(func() { cancel() @@ -146,7 +146,7 @@ func (f *searchBarFrame) doSearch() { search = strings.ToLower(search) if search != "true" && search != "false" && search != "null" { d.Hide() - f.ui.showErrorDialog("Allowed keywords are: true, false, null", nil) + f.u.showErrorDialog("Allowed keywords are: true, false, null", nil) return } case searchTypeString: @@ -154,7 +154,7 @@ func (f *searchBarFrame) doSearch() { case searchTypeNumber: typ = jsondocument.SearchNumber } - uid, err := f.ui.document.Search(ctx, f.ui.selection.selectedUID, search, typ) + uid, err := f.u.document.Search(ctx, f.u.selection.selectedUID, search, typ) d.Hide() if errors.Is(err, jsondocument.ErrCallerCanceled) { return @@ -162,14 +162,14 @@ func (f *searchBarFrame) doSearch() { d2 := dialog.NewInformation( "No match", fmt.Sprintf("No %s found matching %s", searchType, search), - f.ui.window, + f.u.window, ) d2.Show() return } else if err != nil { - f.ui.showErrorDialog("Search failed", err) + f.u.showErrorDialog("Search failed", err) return } - f.ui.scrollTo(uid) + f.u.scrollTo(uid) }() } diff --git a/internal/ui/selection.go b/internal/ui/selection.go index b26d4c3..d36fae9 100644 --- a/internal/ui/selection.go +++ b/internal/ui/selection.go @@ -15,7 +15,7 @@ import ( // selection represents the selection frame in the UI. type selectionFrame struct { content *fyne.Container - ui *UI + u *UI selectedUID widget.TreeNodeID selectedPath *fyne.Container @@ -27,7 +27,7 @@ func (u *UI) newSelectionFrame() *selectionFrame { myHBox := layout.NewCustomPaddedHBoxLayout(-5) f := &selectionFrame{ - ui: u, + u: u, selectedPath: container.New(myHBox), } f.jumpToSelection = ttwidget.NewButtonWithIcon("", theme.NewThemedResource(resourceReadmoreSvg), func() { @@ -88,19 +88,19 @@ type NodePlus struct { func (f *selectionFrame) set(uid string) { f.selectedUID = uid - p := f.ui.document.Path(uid) + p := f.u.document.Path(uid) var path []NodePlus for _, uid2 := range p { - path = append(path, NodePlus{Node: f.ui.document.Value(uid2), UID: uid2}) + path = append(path, NodePlus{Node: f.u.document.Value(uid2), UID: uid2}) } - path = append(path, NodePlus{Node: f.ui.document.Value(uid), UID: uid}) + path = append(path, NodePlus{Node: f.u.document.Value(uid), UID: uid}) f.selectedPath.RemoveAll() for i, n := range path { isLast := i == len(path)-1 if !isLast { l := kxwidget.NewTappableLabel(n.Key, func() { - f.ui.scrollTo(n.UID) - f.ui.selectElement(n.UID) + f.u.scrollTo(n.UID) + f.u.selectElement(n.UID) }) f.selectedPath.Add(l) } else { diff --git a/internal/ui/statusbar.go b/internal/ui/statusbar.go index 20678c1..42baf9d 100644 --- a/internal/ui/statusbar.go +++ b/internal/ui/statusbar.go @@ -23,14 +23,14 @@ const ( // statusBarFrame represents the status bar frame in the UI. type statusBarFrame struct { content *fyne.Container - ui *UI + u *UI elementsCount *ttwidget.Label } func (u *UI) newStatusBarFrame() *statusBarFrame { f := &statusBarFrame{ - ui: u, + u: u, elementsCount: ttwidget.NewLabel(""), } f.elementsCount.SetToolTip("Total count of elements in the JSON document") diff --git a/internal/ui/value.go b/internal/ui/value.go index f6d8d59..99251c3 100644 --- a/internal/ui/value.go +++ b/internal/ui/value.go @@ -16,7 +16,7 @@ import ( // valueFrame represents the value frame in the UI. type valueFrame struct { content *fyne.Container - ui *UI + u *UI copyValueClipboard *ttwidget.Button valueDisplay *widget.RichText @@ -25,7 +25,7 @@ type valueFrame struct { func (u *UI) newValueFrame() *valueFrame { f := &valueFrame{ - ui: u, + u: u, valueDisplay: widget.NewRichText(), } // value frame @@ -63,10 +63,10 @@ func (f *valueFrame) reset() { } func (f *valueFrame) set(uid widget.TreeNodeID) { - node := f.ui.document.Value(uid) + node := f.u.document.Value(uid) typeText := fmt.Sprint(node.Type) var v string - if f.ui.document.IsBranch(uid) { + if f.u.document.IsBranch(uid) { f.copyValueClipboard.Disable() switch node.Type { case jsondocument.Array: @@ -74,7 +74,7 @@ func (f *valueFrame) set(uid widget.TreeNodeID) { case jsondocument.Object: v = "{...}" } - ids := f.ui.document.ChildUIDs(uid) + ids := f.u.document.ChildUIDs(uid) typeText += fmt.Sprintf(", %d elements", len(ids)) } else { f.copyValueClipboard.Enable()