mirror of
https://github.com/diamondburned/cchat-gtk.git
synced 2025-03-23 10:29:21 +00:00
(maybe) fix attachment dialog
This commit is contained in:
parent
8071885618
commit
744f59cf38
|
@ -1,6 +1,7 @@
|
|||
package gts
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
|
@ -216,8 +217,7 @@ func SpawnUploader(dirpath string, callback func(absolutePaths []string)) {
|
|||
"Upload", "Cancel",
|
||||
)
|
||||
|
||||
App.Throttler.Connect(dialog)
|
||||
BindPreviewer(dialog)
|
||||
// BindPreviewer(dialog)
|
||||
|
||||
if dirpath == "" {
|
||||
p, err := os.Getwd()
|
||||
|
@ -231,7 +231,10 @@ func SpawnUploader(dirpath string, callback func(absolutePaths []string)) {
|
|||
dialog.SetCurrentFolder(dirpath)
|
||||
dialog.SetSelectMultiple(true)
|
||||
|
||||
if res := dialog.Run(); res != int(gtk.RESPONSE_ACCEPT) {
|
||||
res := dialog.Run()
|
||||
dialog.Destroy()
|
||||
|
||||
if res != int(gtk.RESPONSE_ACCEPT) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -244,18 +247,54 @@ func BindPreviewer(fc *gtk.FileChooserNativeDialog) {
|
|||
img, _ := gtk.ImageNew()
|
||||
|
||||
fc.SetPreviewWidget(img)
|
||||
fc.Connect("update-preview",
|
||||
func(fc *gtk.FileChooserNativeDialog) {
|
||||
file := fc.GetPreviewFilename()
|
||||
|
||||
b, err := gdk.PixbufNewFromFileAtScale(file, 256, 256, true)
|
||||
if err != nil {
|
||||
fc.SetPreviewWidgetActive(false)
|
||||
return
|
||||
}
|
||||
|
||||
img.SetFromPixbuf(b)
|
||||
fc.SetPreviewWidgetActive(true)
|
||||
},
|
||||
)
|
||||
fc.Connect("update-preview", func(interface{}) { loadImage(fc, img) })
|
||||
}
|
||||
|
||||
func loadImage(fc *gtk.FileChooserNativeDialog, img *gtk.Image) {
|
||||
file := fc.GetPreviewFilename()
|
||||
|
||||
go func() {
|
||||
var animation *gdk.PixbufAnimation
|
||||
var pixbuf *gdk.Pixbuf
|
||||
|
||||
defer ExecAsync(func() {
|
||||
if fc.GetPreviewFilename() == file {
|
||||
if animation == nil && pixbuf == nil {
|
||||
fc.SetPreviewWidgetActive(false)
|
||||
return
|
||||
}
|
||||
|
||||
if animation != nil {
|
||||
img.SetFromAnimation(animation)
|
||||
} else {
|
||||
img.SetFromPixbuf(pixbuf)
|
||||
}
|
||||
|
||||
fc.SetPreviewWidgetActive(true)
|
||||
}
|
||||
})
|
||||
|
||||
l, err := gdk.PixbufLoaderNew()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if _, err := io.Copy(l, f); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err := l.Close(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if pixbuf == nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
|
|
@ -254,9 +254,6 @@ func (v *View) SetFolded(folded bool) {
|
|||
// Change to a mini breadcrumb if we're collapsed.
|
||||
v.Header.SetMiniBreadcrumb(folded)
|
||||
|
||||
// Show the right back button if we're collapsed.
|
||||
v.Header.SetShowBackButton(folded)
|
||||
|
||||
// Hide the username in the input bar if we're collapsed.
|
||||
v.InputView.Username.SetRevealChild(!folded)
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/diamondburned/cchat-gtk/internal/log"
|
||||
"github.com/diamondburned/cchat-gtk/internal/ui/config/preferences"
|
||||
"github.com/diamondburned/cchat-gtk/internal/ui/messages"
|
||||
"github.com/diamondburned/cchat-gtk/internal/ui/primitives"
|
||||
"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"
|
||||
|
@ -115,6 +116,11 @@ func NewApplication() *App {
|
|||
}
|
||||
})
|
||||
|
||||
// We'd still want to control the visibility of the back button when we
|
||||
// fold, however.
|
||||
primitives.LeafletOnFold(&app.Leaflet,
|
||||
app.MessageView.Header.SetShowBackButton)
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue