2020-05-26 06:51:06 +00:00
|
|
|
package ui
|
|
|
|
|
2020-06-06 00:47:28 +00:00
|
|
|
import (
|
|
|
|
"html"
|
|
|
|
"strings"
|
|
|
|
|
2020-07-17 00:21:14 +00:00
|
|
|
"github.com/diamondburned/cchat-gtk/icons"
|
|
|
|
"github.com/diamondburned/cchat-gtk/internal/ui/primitives"
|
2020-07-16 05:41:21 +00:00
|
|
|
"github.com/diamondburned/cchat-gtk/internal/ui/primitives/actions"
|
2020-06-06 00:47:28 +00:00
|
|
|
"github.com/diamondburned/cchat-gtk/internal/ui/service/breadcrumb"
|
2020-07-16 05:41:21 +00:00
|
|
|
"github.com/diamondburned/cchat-gtk/internal/ui/service/session"
|
2020-07-17 00:21:14 +00:00
|
|
|
"github.com/gotk3/gotk3/glib"
|
2020-06-06 00:47:28 +00:00
|
|
|
"github.com/gotk3/gotk3/gtk"
|
|
|
|
)
|
2020-05-26 06:51:06 +00:00
|
|
|
|
|
|
|
type header struct {
|
|
|
|
*gtk.Box
|
2020-07-16 05:41:21 +00:00
|
|
|
left *headerLeft // middle-ish
|
2020-06-06 00:47:28 +00:00
|
|
|
right *headerRight
|
2020-07-17 00:21:14 +00:00
|
|
|
menu *glib.Menu
|
2020-05-26 06:51:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newHeader() *header {
|
2020-06-20 04:40:34 +00:00
|
|
|
left := newHeaderLeft()
|
2020-06-06 00:47:28 +00:00
|
|
|
left.Show()
|
|
|
|
|
|
|
|
right := newHeaderRight()
|
|
|
|
right.Show()
|
|
|
|
|
|
|
|
separator, _ := gtk.SeparatorNew(gtk.ORIENTATION_VERTICAL)
|
|
|
|
separator.Show()
|
|
|
|
|
|
|
|
box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
|
|
|
box.PackStart(left, false, false, 0)
|
|
|
|
box.PackStart(separator, false, false, 0)
|
|
|
|
box.PackStart(right, true, true, 0)
|
2020-05-26 06:51:06 +00:00
|
|
|
box.Show()
|
2020-06-06 00:47:28 +00:00
|
|
|
|
2020-07-17 00:21:14 +00:00
|
|
|
menu := glib.MenuNew()
|
|
|
|
menu.Append("Preferences", "app.preferences")
|
|
|
|
menu.Append("Quit", "app.quit")
|
|
|
|
|
|
|
|
left.appmenu.SetMenuModel(&menu.MenuModel)
|
|
|
|
|
2020-05-26 06:51:06 +00:00
|
|
|
// TODO
|
2020-06-06 00:47:28 +00:00
|
|
|
return &header{
|
|
|
|
box,
|
|
|
|
left,
|
|
|
|
right,
|
2020-07-17 00:21:14 +00:00
|
|
|
menu,
|
2020-06-06 00:47:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-17 00:21:14 +00:00
|
|
|
const BreadcrumbSlash = `<span rise="-1024" size="x-large">/</span>`
|
2020-06-06 00:47:28 +00:00
|
|
|
|
2020-07-16 05:41:21 +00:00
|
|
|
func (h *header) SetBreadcrumber(b breadcrumb.Breadcrumber) {
|
|
|
|
if b == nil {
|
|
|
|
h.right.breadcrumb.SetText("")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var crumb = b.Breadcrumb()
|
|
|
|
for i := range crumb {
|
|
|
|
crumb[i] = html.EscapeString(crumb[i])
|
2020-06-06 00:47:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
h.right.breadcrumb.SetMarkup(
|
2020-07-16 05:41:21 +00:00
|
|
|
BreadcrumbSlash + " " + strings.Join(crumb, " "+BreadcrumbSlash+" "),
|
2020-06-06 00:47:28 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-07-16 05:41:21 +00:00
|
|
|
func (h *header) SetSessionMenu(s *session.Row) {
|
2020-07-17 00:21:14 +00:00
|
|
|
h.left.sesmenu.Bind(s.ActionsMenu)
|
|
|
|
}
|
|
|
|
|
|
|
|
type appMenu struct {
|
|
|
|
*gtk.MenuButton
|
|
|
|
}
|
|
|
|
|
|
|
|
func newAppMenu() *appMenu {
|
|
|
|
img, _ := gtk.ImageNew()
|
|
|
|
img.SetFromPixbuf(icons.Logo256(24))
|
|
|
|
img.Show()
|
|
|
|
|
|
|
|
appmenu, _ := gtk.MenuButtonNew()
|
|
|
|
appmenu.SetImage(img)
|
|
|
|
appmenu.SetUsePopover(true)
|
|
|
|
appmenu.SetHAlign(gtk.ALIGN_CENTER)
|
|
|
|
appmenu.SetMarginStart(8)
|
|
|
|
appmenu.SetMarginEnd(8)
|
|
|
|
|
|
|
|
return &appMenu{appmenu}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *appMenu) SetSizeRequest(w, h int) {
|
|
|
|
// Subtract the margin size.
|
|
|
|
if w -= 8 * 2; w < 0 {
|
|
|
|
w = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
a.MenuButton.SetSizeRequest(w, h)
|
2020-07-16 05:41:21 +00:00
|
|
|
}
|
|
|
|
|
2020-06-20 04:40:34 +00:00
|
|
|
type headerLeft struct {
|
|
|
|
*gtk.Box
|
2020-07-17 00:21:14 +00:00
|
|
|
appmenu *appMenu
|
|
|
|
sesmenu *actions.MenuButton
|
2020-06-20 04:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newHeaderLeft() *headerLeft {
|
2020-07-17 00:21:14 +00:00
|
|
|
appmenu := newAppMenu()
|
|
|
|
appmenu.Show()
|
|
|
|
|
|
|
|
sep, _ := gtk.SeparatorNew(gtk.ORIENTATION_VERTICAL)
|
|
|
|
sep.Show()
|
|
|
|
primitives.AddClass(sep, "titlebutton")
|
|
|
|
|
|
|
|
sesmenu := actions.NewMenuButton()
|
|
|
|
sesmenu.Show()
|
2020-06-20 04:40:34 +00:00
|
|
|
|
|
|
|
box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
2020-07-17 00:21:14 +00:00
|
|
|
box.PackStart(appmenu, false, false, 0)
|
|
|
|
box.PackStart(sep, false, false, 0)
|
|
|
|
box.PackStart(sesmenu, false, false, 5)
|
2020-06-20 04:40:34 +00:00
|
|
|
|
|
|
|
return &headerLeft{
|
2020-07-17 00:21:14 +00:00
|
|
|
Box: box,
|
|
|
|
appmenu: appmenu,
|
|
|
|
sesmenu: sesmenu,
|
2020-06-20 04:40:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-06 00:47:28 +00:00
|
|
|
type headerRight struct {
|
|
|
|
*gtk.Box
|
|
|
|
breadcrumb *gtk.Label
|
|
|
|
}
|
|
|
|
|
|
|
|
func newHeaderRight() *headerRight {
|
|
|
|
bc, _ := gtk.LabelNew(BreadcrumbSlash)
|
|
|
|
bc.SetUseMarkup(true)
|
|
|
|
bc.SetXAlign(0.0)
|
|
|
|
bc.Show()
|
|
|
|
|
|
|
|
box, _ := gtk.BoxNew(gtk.ORIENTATION_HORIZONTAL, 0)
|
|
|
|
box.PackStart(bc, true, true, 14)
|
|
|
|
box.Show()
|
|
|
|
|
|
|
|
return &headerRight{
|
|
|
|
Box: box,
|
|
|
|
breadcrumb: bc,
|
|
|
|
}
|
2020-05-26 06:51:06 +00:00
|
|
|
}
|