Skip to content

Commit

Permalink
Allow hiding value frame
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikKalkoken committed Jul 18, 2024
1 parent 056f55c commit 6908814
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
18 changes: 18 additions & 0 deletions internal/ui/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
settingRecentFileCountDefault = 5
settingLastWindowHeight = "last-window-height"
settingLastWindowWidth = "last-window-width"
settingLastValueFrameHidden = "last-show-value-detail"
)

func (u *UI) makeMenu() *fyne.MainMenu {
Expand Down Expand Up @@ -105,6 +106,10 @@ func (u *UI) makeMenu() *fyne.MainMenu {
u.showSettingsDialog()
}),
)
toogleValueDetail := fyne.NewMenuItem("Show value detail", func() {
u.toogleViewDetail()
})
toogleValueDetail.Checked = !u.detail.Hidden
u.viewMenu = fyne.NewMenu("View",
fyne.NewMenuItem("Scroll to top", func() {
u.treeWidget.ScrollToTop()
Expand All @@ -122,6 +127,8 @@ func (u *UI) makeMenu() *fyne.MainMenu {
fyne.NewMenuItem("Collapse All", func() {
u.treeWidget.CloseAllBranches()
}),
fyne.NewMenuItemSeparator(),
toogleValueDetail,
)
helpMenu := fyne.NewMenu("Help",
fyne.NewMenuItem("Report a bug", func() {
Expand Down Expand Up @@ -199,3 +206,14 @@ func (u *UI) updateRecentFilesMenu() {
u.fileMenu.Items[3].ChildMenu.Items = items
u.fileMenu.Refresh()
}

func (u *UI) toogleViewDetail() {
if u.detail.Hidden {
u.detail.Show()
} else {
u.detail.Hide()
}
toogleValueDetail := u.viewMenu.Items[7]
toogleValueDetail.Checked = !u.detail.Hidden
u.viewMenu.Refresh()
}
7 changes: 5 additions & 2 deletions internal/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type UI struct {
jumpToSelection *widget.Button
copyKeyClipboard *widget.Button

detail *fyne.Container
copyValueClipboard *widget.Button
valueDisplay *widget.RichText
valueRaw string
Expand Down Expand Up @@ -167,13 +168,14 @@ func NewUI(app fyne.App) (*UI, error) {
u.window.Clipboard().SetContent(u.valueRaw)
})
u.copyValueClipboard.Disable()
detail := container.NewBorder(
u.detail = container.NewBorder(
nil,
nil,
nil,
u.copyValueClipboard,
container.NewScroll(u.valueDisplay),
)
u.detail.Hidden = app.Preferences().BoolWithFallback(settingLastValueFrameHidden, false)

// status bar frame
statusBar := container.NewHBox(u.statusTreeSize)
Expand All @@ -196,7 +198,7 @@ func NewUI(app fyne.App) (*UI, error) {
}

c := container.NewBorder(
container.NewVBox(searchBar, selection, detail, widget.NewSeparator()),
container.NewVBox(searchBar, selection, u.detail, widget.NewSeparator()),
container.NewVBox(widget.NewSeparator(), statusBar),
nil,
nil,
Expand Down Expand Up @@ -228,6 +230,7 @@ func NewUI(app fyne.App) (*UI, error) {
u.window.SetOnClosed(func() {
app.Preferences().SetFloat(settingLastWindowWidth, float64(u.window.Canvas().Size().Width))
app.Preferences().SetFloat(settingLastWindowHeight, float64(u.window.Canvas().Size().Height))
app.Preferences().SetBool(settingLastValueFrameHidden, u.detail.Hidden)
})
return u, nil
}
Expand Down

0 comments on commit 6908814

Please sign in to comment.