Add layout system and file selection logic
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.
This commit is contained in:
@@ -2,12 +2,7 @@ package window
|
||||
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/dialog"
|
||||
"fyne.io/fyne/v2/lang"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/application/convertor"
|
||||
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/internal/utils"
|
||||
@@ -18,17 +13,25 @@ type WindowContract interface {
|
||||
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 *fyne.Container
|
||||
layout LayoutContract
|
||||
itemsToConvert convertor.ItemsToConvertContract
|
||||
progressBarService application.ProgressBarContract
|
||||
queueLayout QueueLayoutContract
|
||||
}
|
||||
|
||||
func NewMainWindow(fyneWindow fyne.Window, progressBarService application.ProgressBarContract, itemsToConvert convertor.ItemsToConvertContract, queueLayout QueueLayoutContract) WindowContract {
|
||||
func NewMainWindow(
|
||||
fyneWindow fyne.Window,
|
||||
progressBarService application.ProgressBarContract,
|
||||
itemsToConvert convertor.ItemsToConvertContract,
|
||||
queueLayout QueueLayoutContract,
|
||||
) WindowContract {
|
||||
fyneWindow.Resize(fyne.Size{Width: 1039, Height: 599})
|
||||
fyneWindow.CenterOnScreen()
|
||||
|
||||
@@ -42,14 +45,14 @@ func NewMainWindow(fyneWindow fyne.Window, progressBarService application.Progre
|
||||
|
||||
func (w *mainWindow) InitLayout() {
|
||||
fyne.Do(func() {
|
||||
rContainer := newRightContainer(w.progressBarService.GetContainer(), w.itemsToConvert, w.queueLayout)
|
||||
layout := container.NewAdaptiveGrid(2, widget.NewLabel(""), rContainer.GetCanvasObject())
|
||||
w.fyneWindow.SetContent(layout)
|
||||
|
||||
w.layout = layout
|
||||
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)
|
||||
@@ -60,6 +63,16 @@ func (w *mainWindow) NewFileOpen(callback func(fyne.URIReadCloser, error), locat
|
||||
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 {
|
||||
@@ -67,8 +80,7 @@ func (w *mainWindow) SetContent(content fyne.CanvasObject) {
|
||||
return
|
||||
}
|
||||
|
||||
w.layout.Objects[0] = content
|
||||
w.fyneWindow.SetContent(w.layout)
|
||||
w.fyneWindow.SetContent(w.layout.SetContent(content))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -76,116 +88,8 @@ func (w *mainWindow) Show() {
|
||||
w.fyneWindow.Show()
|
||||
}
|
||||
|
||||
type RightMainContainerContract interface {
|
||||
GetCanvasObject() fyne.CanvasObject
|
||||
GetTabs() *container.AppTabs
|
||||
SelectFileQueueTab()
|
||||
SelectAddedFilesTab()
|
||||
}
|
||||
|
||||
type rightMainContainer struct {
|
||||
container fyne.CanvasObject
|
||||
tabs *container.AppTabs
|
||||
addedFilesTab *container.TabItem
|
||||
fileQueueTab *container.TabItem
|
||||
}
|
||||
|
||||
func newRightContainer(blockProgressbar *fyne.Container, itemsToConvert convertor.ItemsToConvertContract, queueLayout QueueLayoutContract) RightMainContainerContract {
|
||||
addedFilesTab := container.NewTabItem(lang.L("addedFilesTitle"), addedFilesContainer(itemsToConvert))
|
||||
fileQueueTab := container.NewTabItem(lang.L("fileQueueTitle"), fileQueueContainer(queueLayout))
|
||||
|
||||
tabs := container.NewAppTabs(
|
||||
addedFilesTab,
|
||||
fileQueueTab,
|
||||
)
|
||||
|
||||
rightContainer := container.NewBorder(
|
||||
container.NewVBox(
|
||||
blockProgressbar,
|
||||
widget.NewSeparator(),
|
||||
),
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
tabs,
|
||||
)
|
||||
|
||||
return &rightMainContainer{
|
||||
container: rightContainer,
|
||||
tabs: tabs,
|
||||
addedFilesTab: addedFilesTab,
|
||||
fileQueueTab: fileQueueTab,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *rightMainContainer) GetCanvasObject() fyne.CanvasObject {
|
||||
return r.container
|
||||
}
|
||||
|
||||
func (r *rightMainContainer) GetTabs() *container.AppTabs {
|
||||
return r.tabs
|
||||
}
|
||||
|
||||
func (r *rightMainContainer) SelectFileQueueTab() {
|
||||
func (w *mainWindow) SetOnDropped(callback func(position fyne.Position, uris []fyne.URI)) {
|
||||
fyne.Do(func() {
|
||||
r.tabs.Select(r.fileQueueTab)
|
||||
w.fyneWindow.SetOnDropped(callback)
|
||||
})
|
||||
}
|
||||
|
||||
func (r *rightMainContainer) SelectAddedFilesTab() {
|
||||
fyne.Do(func() {
|
||||
r.tabs.Select(r.addedFilesTab)
|
||||
})
|
||||
}
|
||||
|
||||
func addedFilesContainer(itemsToConvert convertor.ItemsToConvertContract) *fyne.Container {
|
||||
line := canvas.NewLine(theme.Color(theme.ColorNameFocus))
|
||||
line.StrokeWidth = 5
|
||||
checkboxAutoRemove := widget.NewCheck(
|
||||
lang.L("autoClearAfterAddingToQueue"),
|
||||
func(checked bool) {
|
||||
itemsToConvert.SetIsAutoRemove(checked)
|
||||
},
|
||||
)
|
||||
checkboxAutoRemove.SetChecked(itemsToConvert.GetIsAutoRemove())
|
||||
|
||||
buttonClear := widget.NewButton(
|
||||
lang.L("clearAll"),
|
||||
func() {
|
||||
itemsToConvert.Clear()
|
||||
},
|
||||
)
|
||||
buttonClear.Importance = widget.DangerImportance
|
||||
return container.NewVBox(
|
||||
container.NewPadded(),
|
||||
container.NewBorder(nil, nil, nil, buttonClear, container.NewHScroll(checkboxAutoRemove)),
|
||||
container.NewPadded(),
|
||||
line,
|
||||
container.NewPadded(),
|
||||
itemsToConvert.GetItemsContainer(),
|
||||
)
|
||||
}
|
||||
|
||||
func fileQueueContainer(queueLayout QueueLayoutContract) *fyne.Container {
|
||||
title := widget.NewLabel(lang.L("queue"))
|
||||
title.TextStyle.Bold = true
|
||||
|
||||
line := canvas.NewLine(theme.Color(theme.ColorNameFocus))
|
||||
line.StrokeWidth = 5
|
||||
|
||||
queueLayout.GetQueueStatistics().GetWaiting().SetTitle(lang.L("waitingQueue"))
|
||||
queueLayout.GetQueueStatistics().GetInProgress().SetTitle(lang.L("inProgressQueue"))
|
||||
queueLayout.GetQueueStatistics().GetCompleted().SetTitle(lang.L("completedQueue"))
|
||||
queueLayout.GetQueueStatistics().GetError().SetTitle(lang.L("errorQueue"))
|
||||
queueLayout.GetQueueStatistics().GetTotal().SetTitle(lang.L("total"))
|
||||
|
||||
return container.NewVBox(
|
||||
container.NewPadded(),
|
||||
container.NewHBox(title, queueLayout.GetQueueStatistics().GetCompleted().GetCheckbox(), queueLayout.GetQueueStatistics().GetError().GetCheckbox()),
|
||||
container.NewHBox(queueLayout.GetQueueStatistics().GetInProgress().GetCheckbox(), queueLayout.GetQueueStatistics().GetWaiting().GetCheckbox(), queueLayout.GetQueueStatistics().GetTotal().GetCheckbox()),
|
||||
container.NewPadded(),
|
||||
line,
|
||||
container.NewPadded(),
|
||||
queueLayout.GetItemsContainer(),
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user