Skip to content

Commit

Permalink
Refactor & version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikKalkoken committed Oct 25, 2024
1 parent 4238091 commit 554e6a6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
22 changes: 11 additions & 11 deletions internal/ui/searchbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,7 +48,7 @@ type searchBarFrame struct {

func (u *UI) newSearchBarFrame() *searchBarFrame {
f := &searchBarFrame{
ui: u,
u: u,
searchEntry: widget.NewEntry(),
}
// search frame
Expand All @@ -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(
Expand Down Expand Up @@ -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()
Expand All @@ -146,30 +146,30 @@ 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:
typ = jsondocument.SearchString
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
} else if errors.Is(err, jsondocument.ErrNotFound) {
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)
}()
}
14 changes: 7 additions & 7 deletions internal/ui/selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/ui/statusbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions internal/ui/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,7 +25,7 @@ type valueFrame struct {

func (u *UI) newValueFrame() *valueFrame {
f := &valueFrame{
ui: u,
u: u,
valueDisplay: widget.NewRichText(),
}
// value frame
Expand Down Expand Up @@ -63,18 +63,18 @@ 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:
v = "[...]"
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()
Expand Down

0 comments on commit 554e6a6

Please sign in to comment.