1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-gtk.git synced 2024-10-01 14:39:29 +00:00
cchat-gtk/internal/ui/ui.go

82 lines
1.9 KiB
Go
Raw Normal View History

2020-05-26 06:51:06 +00:00
package ui
import (
"github.com/diamondburned/cchat"
"github.com/diamondburned/cchat-gtk/internal/gts"
2020-06-04 23:00:41 +00:00
"github.com/diamondburned/cchat-gtk/internal/ui/service"
"github.com/diamondburned/cchat-gtk/internal/ui/service/auth"
"github.com/diamondburned/cchat-gtk/internal/ui/service/session"
2020-05-28 19:26:55 +00:00
"github.com/diamondburned/cchat-gtk/internal/ui/service/session/server"
2020-05-26 06:51:06 +00:00
"github.com/gotk3/gotk3/gtk"
2020-06-06 00:47:28 +00:00
"github.com/markbates/pkger"
2020-05-26 06:51:06 +00:00
)
2020-06-06 00:47:28 +00:00
func init() {
// Load the local CSS.
gts.LoadCSS(pkger.Include("/internal/ui/style.css"))
}
2020-05-26 06:51:06 +00:00
const LeftWidth = 220
2020-06-04 23:00:41 +00:00
type App struct {
2020-05-26 06:51:06 +00:00
window *window
header *header
2020-06-04 23:00:41 +00:00
// used to keep track of what row to highlight and unhighlight
lastRowHighlighter func(bool)
2020-05-26 06:51:06 +00:00
}
var (
2020-06-04 23:00:41 +00:00
_ gts.Windower = (*App)(nil)
_ gts.Headerer = (*App)(nil)
_ service.Controller = (*App)(nil)
2020-05-26 06:51:06 +00:00
)
2020-06-04 23:00:41 +00:00
func NewApplication() *App {
app := &App{
2020-05-26 06:51:06 +00:00
window: newWindow(),
header: newHeader(),
}
return app
}
2020-06-04 23:00:41 +00:00
func (app *App) AddService(svc cchat.Service) {
2020-06-07 07:06:13 +00:00
app.window.Services.AddService(svc, app)
2020-06-07 04:27:28 +00:00
}
2020-06-07 07:06:13 +00:00
func (app *App) RemoveSession(string) {
app.window.MessageView.Reset()
app.header.SetBreadcrumb(nil)
2020-05-28 19:26:55 +00:00
}
2020-06-04 23:00:41 +00:00
func (app *App) MessageRowSelected(ses *session.Row, srv *server.Row, smsg cchat.ServerMessage) {
// Is there an old row that we should unhighlight?
if app.lastRowHighlighter != nil {
app.lastRowHighlighter(false)
}
// Set the new row and highlight it.
app.lastRowHighlighter = srv.Button.SetActive
app.lastRowHighlighter(true)
2020-06-06 00:47:28 +00:00
app.header.SetBreadcrumb(srv.Breadcrumb())
2020-06-04 23:00:41 +00:00
// Show the messages.
app.window.MessageView.JoinServer(ses.Session, smsg)
}
func (app *App) AuthenticateSession(container *service.Container, svc cchat.Service) {
auth.NewDialog(svc.Name(), svc.Authenticate(), func(ses cchat.Session) {
container.AddSession(ses)
})
2020-05-26 06:51:06 +00:00
}
2020-06-04 23:00:41 +00:00
func (app *App) Header() gtk.IWidget {
2020-05-26 06:51:06 +00:00
return app.header
}
2020-06-04 23:00:41 +00:00
func (app *App) Window() gtk.IWidget {
2020-05-26 06:51:06 +00:00
return app.window
}