Introduce a new layout system for managing main window content and tabs. Integrate file selection and drag-and-drop functionality for adding files to the conversion list, with automatic tab switching to "Added Files". Refactor existing components to support these features.
140 lines
3.1 KiB
Go
140 lines
3.1 KiB
Go
package convertor
|
|
|
|
import (
|
|
"fyne.io/fyne/v2"
|
|
"fyne.io/fyne/v2/canvas"
|
|
"fyne.io/fyne/v2/container"
|
|
"fyne.io/fyne/v2/theme"
|
|
"fyne.io/fyne/v2/widget"
|
|
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/ffmpeg"
|
|
)
|
|
|
|
type ItemsToConvertContract interface {
|
|
Add(file *ffmpeg.File)
|
|
Clear()
|
|
GetItems() map[int]ItemToConvertContract
|
|
GetItemsContainer() *fyne.Container
|
|
AfterAddingQueue()
|
|
GetIsAutoRemove() bool
|
|
SetIsAutoRemove(isAutoRemove bool)
|
|
}
|
|
|
|
type itemsToConvert struct {
|
|
ffmpeg ffmpeg.UtilitiesContract
|
|
nextId int
|
|
items map[int]ItemToConvertContract
|
|
itemsContainer *fyne.Container
|
|
isAutoRemove bool
|
|
}
|
|
|
|
func NewItemsToConvert(ffmpeg ffmpeg.UtilitiesContract) ItemsToConvertContract {
|
|
return &itemsToConvert{
|
|
ffmpeg: ffmpeg,
|
|
nextId: 0,
|
|
items: map[int]ItemToConvertContract{},
|
|
itemsContainer: container.NewVBox(),
|
|
isAutoRemove: true,
|
|
}
|
|
}
|
|
|
|
func (items *itemsToConvert) GetItemsContainer() *fyne.Container {
|
|
return items.itemsContainer
|
|
}
|
|
|
|
func (items *itemsToConvert) Add(file *ffmpeg.File) {
|
|
nextId := items.nextId
|
|
var content *fyne.Container
|
|
var buttonPlay *widget.Button
|
|
|
|
buttonPlay = widget.NewButtonWithIcon("", theme.Icon(theme.IconNameMediaPlay), func() {
|
|
buttonPlay.Disable()
|
|
go func() {
|
|
ffplay, err := items.ffmpeg.GetFFplay()
|
|
if err != nil {
|
|
fyne.Do(func() {
|
|
buttonPlay.Enable()
|
|
})
|
|
return
|
|
}
|
|
|
|
_ = ffplay.Play(file)
|
|
fyne.Do(func() {
|
|
buttonPlay.Enable()
|
|
})
|
|
}()
|
|
})
|
|
|
|
buttonRemove := widget.NewButtonWithIcon("", theme.Icon(theme.IconNameDelete), func() {
|
|
items.itemsContainer.Remove(content)
|
|
items.itemsContainer.Refresh()
|
|
delete(items.items, nextId)
|
|
})
|
|
buttonRemove.Importance = widget.DangerImportance
|
|
|
|
content = container.NewVBox(
|
|
container.NewBorder(
|
|
nil,
|
|
nil,
|
|
buttonPlay,
|
|
buttonRemove,
|
|
container.NewHScroll(widget.NewLabel(file.Name)),
|
|
),
|
|
container.NewHScroll(widget.NewLabel(file.Path)),
|
|
container.NewPadded(),
|
|
canvas.NewLine(theme.Color(theme.ColorNameFocus)),
|
|
container.NewPadded(),
|
|
)
|
|
|
|
items.itemsContainer.Add(content)
|
|
items.items[nextId] = newItemToConvert(file, content)
|
|
items.nextId++
|
|
}
|
|
|
|
func (items *itemsToConvert) GetIsAutoRemove() bool {
|
|
return items.isAutoRemove
|
|
}
|
|
|
|
func (items *itemsToConvert) SetIsAutoRemove(isAutoRemove bool) {
|
|
items.isAutoRemove = isAutoRemove
|
|
}
|
|
|
|
func (items *itemsToConvert) GetItems() map[int]ItemToConvertContract {
|
|
return items.items
|
|
}
|
|
|
|
func (items *itemsToConvert) AfterAddingQueue() {
|
|
if items.isAutoRemove {
|
|
items.Clear()
|
|
}
|
|
}
|
|
|
|
func (items *itemsToConvert) Clear() {
|
|
items.itemsContainer.RemoveAll()
|
|
items.items = map[int]ItemToConvertContract{}
|
|
}
|
|
|
|
type ItemToConvertContract interface {
|
|
GetFile() *ffmpeg.File
|
|
GetContent() *fyne.Container
|
|
}
|
|
|
|
type itemToConvert struct {
|
|
file *ffmpeg.File
|
|
content *fyne.Container
|
|
}
|
|
|
|
func newItemToConvert(file *ffmpeg.File, content *fyne.Container) ItemToConvertContract {
|
|
return &itemToConvert{
|
|
file: file,
|
|
content: content,
|
|
}
|
|
}
|
|
|
|
func (item *itemToConvert) GetFile() *ffmpeg.File {
|
|
return item.file
|
|
}
|
|
|
|
func (item *itemToConvert) GetContent() *fyne.Container {
|
|
return item.content
|
|
}
|