Skip to content

Commit

Permalink
Add tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikKalkoken committed Aug 3, 2024
1 parent 1ab3fd5 commit 707d6ee
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 40 deletions.
5 changes: 2 additions & 3 deletions FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ Website = "https://github.com/ErikKalkoken/janice"
Icon = "icon.png"
Name = "Janice"
ID = "io.github.erikkalkoken.janice"
Version = "0.2.3"
Version = "0.3.0"
Build = 1

[Release]
BuildName = "janice"
Summary = "A desktop app for viewing large JSON files"
Description = "<p>A desktop app for viewing large JSON files. Please see website for details.</p>"
License = "MIT"
Screenshots = "https://cdn.imgpile.com/f/0IrYBjJ_xl.png"
Expand All @@ -18,5 +17,5 @@ Website = "https://github.com/ErikKalkoken/janice"
[LinuxAndBSD]
GenericName = "JSON viewer"
Categories = ["Utility"]
Comment = "View large JSON files"
Comment = "A desktop app for viewing large JSON files"
Keywords = ["json", "viewer"]
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.22.4

require (
fyne.io/fyne/v2 v2.5.0
github.com/dweymouth/fyne-tooltip v0.1.0
github.com/hashicorp/go-version v1.7.0
github.com/jarcoal/httpmock v1.3.1
github.com/json-iterator/go v1.1.12
Expand All @@ -28,7 +29,7 @@ require (
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/jeandeaual/go-locale v0.0.0-20240223122105-ce5225dcaa49 // indirect
github.com/jsummers/gobmp v0.0.0-20230614200233-a9de23ed2e25 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nicksnyder/go-i18n/v2 v2.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand All @@ -37,7 +38,7 @@ require (
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
github.com/yuin/goldmark v1.7.4 // indirect
golang.org/x/image v0.18.0 // indirect
golang.org/x/mobile v0.0.0-20240707233753-b765e5d5218f // indirect
golang.org/x/mobile v0.0.0-20240716161057-1ad2df20a8b6 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
9 changes: 6 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dweymouth/fyne-tooltip v0.1.0 h1:Qd1KU1TXop/M67pozmxEA2PMy/Jokcn7OgTcdrj4hUs=
github.com/dweymouth/fyne-tooltip v0.1.0/go.mod h1:zEgy7p9tSVIuy2GufFbOCoK3Q04zhyDPOotlU4G3Ma4=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down Expand Up @@ -233,8 +235,9 @@ github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0Qu
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
Expand Down Expand Up @@ -347,8 +350,8 @@ golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPI
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mobile v0.0.0-20211207041440-4e6c2922fdee/go.mod h1:pe2sM7Uk+2Su1y7u/6Z8KJ24D7lepUjFZbhFOrmDfuQ=
golang.org/x/mobile v0.0.0-20240707233753-b765e5d5218f h1:2Syp6WwwHOaGteLQmOlHCCXA8EyxXppdeDEyNtod9Os=
golang.org/x/mobile v0.0.0-20240707233753-b765e5d5218f/go.mod h1:TCsc78+c4cqb8IKEosz2LwJ6YRNkIjMuAYeHYjchGDE=
golang.org/x/mobile v0.0.0-20240716161057-1ad2df20a8b6 h1:/VlmIrkuLf2wzPjkZ8imSpckHoW7Y71h66dxbLHSpi8=
golang.org/x/mobile v0.0.0-20240716161057-1ad2df20a8b6/go.mod h1:TCsc78+c4cqb8IKEosz2LwJ6YRNkIjMuAYeHYjchGDE=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
Expand Down
2 changes: 1 addition & 1 deletion internal/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type githubRelease struct {
TagName string `json:"tag_name"`
}

// AvailableUpdate return the version of the latest release and reports wether the update is newer.
// AvailableUpdate returns the version of the latest release and reports wether the update is newer.
func AvailableUpdate(owner, repo, current string) (string, bool, error) {
v1, err := version.NewVersion(current)
if err != nil {
Expand Down
11 changes: 7 additions & 4 deletions internal/ui/about.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ import (
)

func (u *UI) showAboutDialog() {
info := u.app.Metadata()
current := info.Version
x, _ := url.Parse(websiteURL)
data := u.app.Metadata()
current := data.Version
x, err := url.Parse(data.Custom["Website"])
if err != nil || x.Path == "" {
x, _ = url.Parse(websiteURL)
}
c := container.NewVBox(
widget.NewRichTextFromMarkdown(
fmt.Sprintf("## %s\n\n"+
"**Version:** %s\n\n"+
"(c) 2024 Erik Kalkoken", info.Name, current),
"(c) 2024 Erik Kalkoken", data.Name, current),
),
widget.NewLabel("A desktop app for viewing large JSON files."),
widget.NewHyperlink("Website", x),
Expand Down
27 changes: 17 additions & 10 deletions internal/ui/searchbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
ttwidget "github.com/dweymouth/fyne-tooltip/widget"

"github.com/ErikKalkoken/janice/internal/jsondocument"
)

Expand All @@ -37,11 +39,11 @@ type searchBarFrame struct {
ui *UI

searchEntry *widget.Entry
searchButton *widget.Button
searchType *widget.Select
scrollBottom *widget.Button
scrollTop *widget.Button
collapseAll *widget.Button
searchButton *ttwidget.Button
searchType *ttwidget.Select
scrollBottom *ttwidget.Button
scrollTop *ttwidget.Button
collapseAll *ttwidget.Button
}

func (u *UI) newSearchBarFrame() *searchBarFrame {
Expand All @@ -50,31 +52,36 @@ func (u *UI) newSearchBarFrame() *searchBarFrame {
searchEntry: widget.NewEntry(),
}
// search frame
f.searchType = widget.NewSelect([]string{
f.searchType = ttwidget.NewSelect([]string{
searchTypeKey,
searchTypeKeyword,
searchTypeNumber,
searchTypeString,
}, nil)
f.searchType.SetSelected(searchTypeKey)
f.searchType.SetToolTip("Select what to search")
f.searchType.Disable()
f.searchEntry.SetPlaceHolder(
"Enter pattern to search for...")
f.searchEntry.OnSubmitted = func(s string) {
f.doSearch()
}
f.searchButton = widget.NewButtonWithIcon("", theme.SearchIcon(), func() {
f.searchButton = ttwidget.NewButtonWithIcon("", theme.SearchIcon(), func() {
f.doSearch()
})
f.scrollBottom = widget.NewButtonWithIcon("", theme.NewThemedResource(resourceVerticalalignbottomSvg), func() {
f.searchButton.SetToolTip("Search")
f.scrollBottom = ttwidget.NewButtonWithIcon("", theme.NewThemedResource(resourceVerticalalignbottomSvg), func() {
f.ui.treeWidget.ScrollToBottom()
})
f.scrollTop = widget.NewButtonWithIcon("", theme.NewThemedResource(resourceVerticalaligntopSvg), func() {
f.scrollBottom.SetToolTip("Scroll to bottom")
f.scrollTop = ttwidget.NewButtonWithIcon("", theme.NewThemedResource(resourceVerticalaligntopSvg), func() {
f.ui.treeWidget.ScrollToTop()
})
f.collapseAll = widget.NewButtonWithIcon("", theme.NewThemedResource(resourceUnfoldlessSvg), func() {
f.scrollTop.SetToolTip("Scroll to top")
f.collapseAll = ttwidget.NewButtonWithIcon("", theme.NewThemedResource(resourceUnfoldlessSvg), func() {
f.ui.treeWidget.CloseAllBranches()
})
f.collapseAll.SetToolTip("Collapse all")
c := container.NewBorder(
nil,
nil,
Expand Down
12 changes: 8 additions & 4 deletions internal/ui/selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
ttwidget "github.com/dweymouth/fyne-tooltip/widget"

"github.com/ErikKalkoken/janice/internal/jsondocument"
"github.com/ErikKalkoken/janice/internal/widgets"
)
Expand All @@ -17,8 +19,8 @@ type selectionFrame struct {

selectedUID widget.TreeNodeID
selectedPath *fyne.Container
jumpToSelection *widget.Button
copyKeyClipboard *widget.Button
jumpToSelection *ttwidget.Button
copyKeyClipboard *ttwidget.Button
}

func (u *UI) newSelectionFrame() *selectionFrame {
Expand All @@ -28,14 +30,16 @@ func (u *UI) newSelectionFrame() *selectionFrame {
ui: u,
selectedPath: container.New(myHBox),
}
f.jumpToSelection = widget.NewButtonWithIcon("", theme.NewThemedResource(resourceReadmoreSvg), func() {
f.jumpToSelection = ttwidget.NewButtonWithIcon("", theme.NewThemedResource(resourceReadmoreSvg), func() {
u.scrollTo(f.selectedUID)
})
f.jumpToSelection.SetToolTip("Jump to selection")
f.jumpToSelection.Disable()
f.copyKeyClipboard = widget.NewButtonWithIcon("", theme.ContentCopyIcon(), func() {
f.copyKeyClipboard = ttwidget.NewButtonWithIcon("", theme.ContentCopyIcon(), func() {
n := u.document.Value(f.selectedUID)
u.window.Clipboard().SetContent(n.Key)
})
f.copyKeyClipboard.SetToolTip("Copy key to clipboard")
f.copyKeyClipboard.Disable()
c := container.NewBorder(
nil,
Expand Down
24 changes: 14 additions & 10 deletions internal/ui/statusbar.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package ui

import (
"fmt"
"log/slog"
"net/url"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
"github.com/ErikKalkoken/janice/internal/github"
ttwidget "github.com/dweymouth/fyne-tooltip/widget"
"golang.org/x/text/language"
"golang.org/x/text/message"

"github.com/ErikKalkoken/janice/internal/github"
)

const (
Expand All @@ -23,21 +25,22 @@ type statusBarFrame struct {
content *fyne.Container
ui *UI

statusTreeSize *widget.Label
elementsCount *ttwidget.Label
}

func (u *UI) newStatusBarFrame() *statusBarFrame {
f := &statusBarFrame{
ui: u,
statusTreeSize: widget.NewLabel(""),
ui: u,
elementsCount: ttwidget.NewLabel(""),
}
f.elementsCount.SetToolTip("Total count of elements in the JSON document")
// status bar frame
c := container.NewHBox(f.statusTreeSize)
c := container.NewHBox(f.elementsCount)
notifyUpdates := u.app.Preferences().BoolWithFallback(settingNotifyUpdates, settingNotifyUpdatesDefault)
if notifyUpdates {
go func() {
current := u.app.Metadata().Version
_, isNewer, err := github.AvailableUpdate(githubOwner, githubRepo, current)
latest, isNewer, err := github.AvailableUpdate(githubOwner, githubRepo, current)
if err != nil {
slog.Error("Failed to fetch latest version from github", "err", err)
return
Expand All @@ -47,7 +50,8 @@ func (u *UI) newStatusBarFrame() *statusBarFrame {
}
c.Add(layout.NewSpacer())
x, _ := url.Parse(websiteURL + "/releases")
l := widget.NewHyperlink("Update available", x)
l := ttwidget.NewHyperlink("Update available", x)
l.SetToolTip(fmt.Sprintf("Newer version %s available for download", latest))
c.Add(l)
}()
}
Expand All @@ -56,9 +60,9 @@ func (u *UI) newStatusBarFrame() *statusBarFrame {
}

func (f *statusBarFrame) reset() {
f.statusTreeSize.SetText("")
f.elementsCount.SetText("")
}
func (f *statusBarFrame) set(size int) {
p := message.NewPrinter(language.English)
f.statusTreeSize.SetText(p.Sprintf("%d elements", size))
f.elementsCount.SetText(p.Sprintf("%d elements", size))
}
3 changes: 2 additions & 1 deletion internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
fynetooltip "github.com/dweymouth/fyne-tooltip"
"golang.org/x/text/language"
"golang.org/x/text/message"

Expand Down Expand Up @@ -82,7 +83,7 @@ func NewUI(app fyne.App) (*UI, error) {
nil,
container.NewStack(u.welcomeMessage, u.treeWidget))

u.window.SetContent(c)
u.window.SetContent(fynetooltip.AddWindowToolTipLayer(c, u.window.Canvas()))
u.window.SetMainMenu(u.makeMenu())
u.toogleHasDocument(false)
u.updateRecentFilesMenu()
Expand Down
7 changes: 5 additions & 2 deletions internal/ui/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
ttwidget "github.com/dweymouth/fyne-tooltip/widget"

"github.com/ErikKalkoken/janice/internal/jsondocument"
)

Expand All @@ -16,7 +18,7 @@ type valueFrame struct {
content *fyne.Container
ui *UI

copyValueClipboard *widget.Button
copyValueClipboard *ttwidget.Button
valueDisplay *widget.RichText
valueRaw string
}
Expand All @@ -27,9 +29,10 @@ func (u *UI) newValueFrame() *valueFrame {
valueDisplay: widget.NewRichText(),
}
// value frame
f.copyValueClipboard = widget.NewButtonWithIcon("", theme.ContentCopyIcon(), func() {
f.copyValueClipboard = ttwidget.NewButtonWithIcon("", theme.ContentCopyIcon(), func() {
u.window.Clipboard().SetContent(f.valueRaw)
})
f.copyValueClipboard.SetToolTip("Copy value to clipboard")
f.copyValueClipboard.Disable()
c := container.NewBorder(
nil,
Expand Down

0 comments on commit 707d6ee

Please sign in to comment.