Skip to content

Commit

Permalink
updated to use coredom in glide
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoreilly committed Jan 21, 2024
1 parent 24a9820 commit 58f6c80
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 61 deletions.
3 changes: 1 addition & 2 deletions glide/cmd/glide/glide.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ package main
import (
"cogentcore.org/cogent/glide"
"cogentcore.org/core/gi"
"cogentcore.org/core/grr"
)

func main() {
b := gi.NewAppBody("glide").SetTitle("Glide")
pg := glide.NewPage(b, "page")
grr.Log(pg.OpenURL("https://google.com"))
pg.OpenURL("https://google.com")
b.AddAppBar(pg.AppBar)
b.NewWindow().Run().Wait()
}
33 changes: 0 additions & 33 deletions glide/context.go

This file was deleted.

12 changes: 1 addition & 11 deletions glide/gtigen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 17 additions & 15 deletions glide/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ package glide
import (
"net/url"

"cogentcore.org/cogent/glide/gidom"
"cogentcore.org/core/coredom"

Check failure on line 13 in glide/page.go

View workflow job for this annotation

GitHub Actions / build

no required module provides package cogentcore.org/core/coredom; to add it:
"cogentcore.org/core/events"
"cogentcore.org/core/gi"
"cogentcore.org/core/grr"
"cogentcore.org/core/ki"
"cogentcore.org/core/styles"
)
Expand All @@ -23,40 +22,43 @@ type Page struct {
gi.Frame

// The history of URLs that have been visited. The oldest page is first.
History []string
History []string `set:"-"`

// PageURL is the current page URL
PageURL string
// Context is the page's [coredom.Context].
Context *coredom.Context `set:"-"`
}

var _ ki.Ki = (*Page)(nil)

func (pg *Page) OnInit() {
pg.Frame.OnInit()
pg.Context = coredom.NewContext()
pg.Context.OpenURL = pg.OpenURL
pg.Style(func(s *styles.Style) {
s.Direction = styles.Column
})
}

// OpenURL sets the content of the page from the given url.
func (pg *Page) OpenURL(url string) error {
resp, err := gidom.Get(pg.Context(), url)
func (pg *Page) OpenURL(url string) {
resp, err := coredom.Get(pg.Context, url)
if err != nil {
return err
gi.ErrorSnackbar(pg, err, "Error opening page")
return
}
defer resp.Body.Close()
url = resp.Request.URL.String()
pg.PageURL = url
pg.Context.PageURL = url
pg.History = append(pg.History, url)
updt := pg.UpdateStart()
pg.DeleteChildren(true)
err = gidom.ReadHTML(pg.Context(), pg, resp.Body)
err = coredom.ReadHTML(pg.Context, pg, resp.Body)
if err != nil {
return err
gi.ErrorSnackbar(pg, err, "Error opening page")
return
}
pg.Update()
pg.UpdateEndLayout(updt)
return nil
}

// AppBar is the default app bar for a [Page]
Expand All @@ -78,12 +80,12 @@ func (pg *Page) AppBar(tb *gi.Toolbar) {
}
}
ch.OnChange(func(e events.Event) {
u, is := gidom.ParseURL(ch.CurLabel)
u, is := coredom.ParseURL(ch.CurLabel)
if is {
grr.Log(pg.OpenURL(u.String()))
pg.OpenURL(u.String())
} else {
q := url.QueryEscape(ch.CurLabel)
grr.Log(pg.OpenURL("https://google.com/search?q=" + q))
pg.OpenURL("https://google.com/search?q=" + q)
}
e.SetHandled()
})
Expand Down

0 comments on commit 58f6c80

Please sign in to comment.