Skip to content

Commit

Permalink
Replace channel list TreeView with ListView
Browse files Browse the repository at this point in the history
This migrates gtkcord4's channels list from the deprecated GtkTreeView
API to the newer GtkListView API, which looks far better and is much
less buggy.

Fixes #208.
Fixes #196.
  • Loading branch information
diamondburned committed Dec 27, 2023
1 parent a31ea96 commit 2f8a342
Show file tree
Hide file tree
Showing 20 changed files with 1,241 additions and 1,210 deletions.
36 changes: 36 additions & 0 deletions internal/gtkcord/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package gtkcord

import (
"github.com/diamondburned/arikawa/v3/utils/handler"
"github.com/diamondburned/gotk4/pkg/core/glib"
)

// MainThreadHandler wraps a [handler.Handler] to run all events on the main
// thread.
type MainThreadHandler struct {
h *handler.Handler
}

// NewMainThreadHandler creates a new MainThreadHandler.
func NewMainThreadHandler(h *handler.Handler) *MainThreadHandler {
hh := &MainThreadHandler{h: handler.New()}
h.AddSyncHandler(func(ev any) {
glib.IdleAddPriority(glib.PriorityDefault, func() {
hh.h.Call(ev)
})
})
return hh
}

// AddHandler adds a handler to the handler.Handler.
// The given handler will be called on the main thread.
// The returned function will remove the handler.
func (h *MainThreadHandler) AddHandler(handler any) func() {
return h.h.AddSyncHandler(handler)
}

// AddSyncHandler is the same as [AddHandler].
// It exists for compatibility.
func (h *MainThreadHandler) AddSyncHandler(handler any) func() {
return h.h.AddSyncHandler(handler)
}
12 changes: 7 additions & 5 deletions internal/gtkcord/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const (

// State extends the Discord state controller.
type State struct {
*MainThreadHandler
*ningen.State
}

Expand Down Expand Up @@ -110,9 +111,10 @@ func Wrap(state *state.State) *State {
}

// dumpRawEvents(state)

ningen := ningen.FromState(state)
return &State{
State: ningen.FromState(state),
MainThreadHandler: NewMainThreadHandler(ningen.Handler),
State: ningen,
}
}

Expand Down Expand Up @@ -157,9 +159,9 @@ func InjectState(ctx context.Context, state *State) context.Context {

// WithContext creates a copy of State with a new context.
func (s *State) WithContext(ctx context.Context) *State {
return &State{
State: s.State.WithContext(ctx),
}
s2 := *s
s2.State = s.State.WithContext(ctx)
return &s2
}

// BindHandler is similar to BindWidgetHandler, except the lifetime of the
Expand Down
Binary file modified internal/icons/gtkcord4.gresource
Binary file not shown.
4 changes: 4 additions & 0 deletions internal/icons/gtkcord4.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
<file preprocess="xml-stripblanks" alias="user-invisible-symbolic.svg">scalable/actions/user-invisible-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="user-offline-symbolic.svg">scalable/actions/user-offline-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="user-status-pending-symbolic.svg">scalable/actions/user-status-pending-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="channel-symbolic.svg">scalable/actions/channel-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="channel-voice-symbolic.svg">scalable/actions/channel-voice-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="channel-broadcast-symbolic.svg">scalable/actions/channel-broadcast-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="thread-branch-symbolic.svg">scalable/actions/thread-branch-symbolic.svg</file>
</gresource>
</gresources>
1 change: 0 additions & 1 deletion internal/icons/icons.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ func init() {
if err != nil {
log.Panicln("Failed to create resources: ", err)
}

gio.ResourcesRegister(resources)
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions internal/icons/scalable/actions/channel-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions internal/icons/scalable/actions/channel-voice-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions internal/icons/scalable/actions/thread-branch-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2f8a342

Please sign in to comment.