95 lines
2.5 KiB
Go
95 lines
2.5 KiB
Go
package window
|
|
|
|
import (
|
|
"fyne.io/fyne/v2"
|
|
"fyne.io/fyne/v2/dialog"
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application/convertor"
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/utils"
|
|
)
|
|
|
|
type WindowContract interface {
|
|
SetContent(content fyne.CanvasObject)
|
|
Show()
|
|
InitLayout()
|
|
NewFileOpen(callback func(fyne.URIReadCloser, error), location fyne.ListableURI) *dialog.FileDialog
|
|
NewFolderOpen(callback func(fyne.ListableURI, error), location fyne.ListableURI) *dialog.FileDialog
|
|
SetOnDropped(callback func(position fyne.Position, uris []fyne.URI))
|
|
GetLayout() LayoutContract
|
|
}
|
|
|
|
type mainWindow struct {
|
|
fyneWindow fyne.Window
|
|
layout LayoutContract
|
|
itemsToConvert convertor.ItemsToConvertContract
|
|
progressBarService convertor.ProgressBarContract
|
|
queueLayout QueueLayoutContract
|
|
}
|
|
|
|
func NewMainWindow(
|
|
fyneWindow fyne.Window,
|
|
progressBarService convertor.ProgressBarContract,
|
|
itemsToConvert convertor.ItemsToConvertContract,
|
|
queueLayout QueueLayoutContract,
|
|
) WindowContract {
|
|
fyneWindow.Resize(fyne.Size{Width: 1039, Height: 599})
|
|
fyneWindow.CenterOnScreen()
|
|
|
|
return &mainWindow{
|
|
fyneWindow: fyneWindow,
|
|
progressBarService: progressBarService,
|
|
itemsToConvert: itemsToConvert,
|
|
queueLayout: queueLayout,
|
|
}
|
|
}
|
|
|
|
func (w *mainWindow) InitLayout() {
|
|
fyne.Do(func() {
|
|
w.layout = NewLayout(w.progressBarService, w.itemsToConvert, w.queueLayout)
|
|
})
|
|
}
|
|
|
|
func (w *mainWindow) GetLayout() LayoutContract {
|
|
return w.layout
|
|
}
|
|
|
|
func (w *mainWindow) NewFileOpen(callback func(fyne.URIReadCloser, error), location fyne.ListableURI) *dialog.FileDialog {
|
|
fileDialog := dialog.NewFileOpen(callback, w.fyneWindow)
|
|
utils.FileDialogResize(fileDialog, w.fyneWindow)
|
|
fileDialog.Show()
|
|
if location != nil {
|
|
fileDialog.SetLocation(location)
|
|
}
|
|
return fileDialog
|
|
}
|
|
|
|
func (w *mainWindow) NewFolderOpen(callback func(fyne.ListableURI, error), location fyne.ListableURI) *dialog.FileDialog {
|
|
fileDialog := dialog.NewFolderOpen(callback, w.fyneWindow)
|
|
utils.FileDialogResize(fileDialog, w.fyneWindow)
|
|
fileDialog.Show()
|
|
if location != nil {
|
|
fileDialog.SetLocation(location)
|
|
}
|
|
return fileDialog
|
|
}
|
|
|
|
func (w *mainWindow) SetContent(content fyne.CanvasObject) {
|
|
fyne.Do(func() {
|
|
if w.layout == nil {
|
|
w.fyneWindow.SetContent(content)
|
|
return
|
|
}
|
|
|
|
w.fyneWindow.SetContent(w.layout.SetContent(content))
|
|
})
|
|
}
|
|
|
|
func (w *mainWindow) Show() {
|
|
w.fyneWindow.Show()
|
|
}
|
|
|
|
func (w *mainWindow) SetOnDropped(callback func(position fyne.Position, uris []fyne.URI)) {
|
|
fyne.Do(func() {
|
|
w.fyneWindow.SetOnDropped(callback)
|
|
})
|
|
}
|