Skip to content

Commit

Permalink
feat: port View Source dialog to adw.Dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
tfuxu authored and diamondburned committed Aug 27, 2024
1 parent c6234cc commit 3904703
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions internal/messages/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,20 @@ func (m *message) ShowEmojiChooser() {
e.Popup()
}

// ShowSource opens a JSON showing the message JSON.
// ShowSource opens a dialog showing a JSON representation of the message.
func (m *message) ShowSource() {
d := adw.NewWindow()
d := adw.NewDialog()
d.SetTitle(locale.Get("View Source"))
d.SetTransientFor(app.GTKWindowFromContext(m.ctx()))
d.SetModal(true)
d.SetDefaultSize(500, 300)
d.SetContentWidth(500)
d.SetContentHeight(300)

h := adw.NewHeaderBar()
h.SetCenteringPolicy(adw.CenteringPolicyStrict)

toolbarView := adw.NewToolbarView()
toolbarView.SetTopBarStyle(adw.ToolbarFlat)
toolbarView.AddTopBar(h)

buf := gtk.NewTextBuffer(nil)

if raw, err := json.MarshalIndent(m.message, "", "\t"); err != nil {
Expand Down Expand Up @@ -292,8 +295,10 @@ func (m *message) ShowSource() {
box.Append(h)
box.Append(s)

d.SetContent(box)
d.Present()
toolbarView.SetContent(box)

d.SetChild(toolbarView)
d.Present(app.GTKWindowFromContext(m.ctx()))
}

// cozyMessage is a large cozy message with an avatar.
Expand Down

0 comments on commit 3904703

Please sign in to comment.