Add drag-and-drop support for single file selection

Implemented functionality to handle single file drag-and-drop in the UI, including error handling for multiple files and directories. Updated localization files to support new messages related to drag-and-drop usage and errors.
This commit is contained in:
Leonid Nikitin 2025-05-11 15:07:37 +05:00
parent 6be10dbd75
commit bf3340e526
Signed by: kor-elf
GPG Key ID: DAB5355A11C22541
5 changed files with 91 additions and 1 deletions

View File

@ -14,6 +14,7 @@ import (
"git.kor-elf.net/kor-elf/gui-for-ffmpeg/setting" "git.kor-elf.net/kor-elf/gui-for-ffmpeg/setting"
"github.com/nicksnyder/go-i18n/v2/i18n" "github.com/nicksnyder/go-i18n/v2/i18n"
"image/color" "image/color"
"os"
"path/filepath" "path/filepath"
) )
@ -195,6 +196,10 @@ func newFileForConversion(app kernel.AppContract) *fileForConversion {
buttonTitle := app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{ buttonTitle := app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
MessageID: "choose", MessageID: "choose",
}) + "\n\r\n\r" + app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
MessageID: "or",
}) + "\n\r\n\r" + app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
MessageID: "dragAndDrop1File",
}) })
fileForConversion.message = canvas.NewText("", color.RGBA{R: 255, G: 0, B: 0, A: 255}) fileForConversion.message = canvas.NewText("", color.RGBA{R: 255, G: 0, B: 0, A: 255})
@ -225,10 +230,54 @@ func newFileForConversion(app kernel.AppContract) *fileForConversion {
fileForConversion.eventSelectFile(nil) fileForConversion.eventSelectFile(nil)
listableURI := storage.NewFileURI(filepath.Dir(r.URI().Path())) listableURI := storage.NewFileURI(filepath.Dir(r.URI().Path()))
locationURI, err = storage.ListerForURI(listableURI) locationURI, _ = storage.ListerForURI(listableURI)
}, locationURI) }, locationURI)
}) })
app.GetWindow().SetOnDropped(func(position fyne.Position, uris []fyne.URI) {
if len(uris) == 0 {
return
}
if len(uris) > 1 {
fileForConversion.message.Text = app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
MessageID: "errorDragAndDrop1File",
})
setStringErrorStyle(fileForConversion.message)
fileForConversion.eventSelectFile(errors.New(fileForConversion.message.Text))
return
}
uri := uris[0]
info, err := os.Stat(uri.Path())
if err != nil {
fileForConversion.message.Text = err.Error()
setStringErrorStyle(fileForConversion.message)
fileForConversion.eventSelectFile(err)
return
}
if info.IsDir() {
fileForConversion.message.Text = app.GetLocalizerService().GetMessage(&i18n.LocalizeConfig{
MessageID: "errorIsFolder",
})
setStringErrorStyle(fileForConversion.message)
fileForConversion.eventSelectFile(errors.New(fileForConversion.message.Text))
return
}
fileForConversion.file.Path = uri.Path()
fileForConversion.file.Name = uri.Name()
fileForConversion.file.Ext = uri.Extension()
fileForConversion.message.Text = uri.Path()
setStringSuccessStyle(fileForConversion.message)
fileForConversion.eventSelectFile(nil)
listableURI := storage.NewFileURI(filepath.Dir(uri.Path()))
locationURI, _ = storage.ListerForURI(listableURI)
})
return fileForConversion return fileForConversion
} }

View File

@ -12,6 +12,7 @@ type WindowContract interface {
SetMainMenu(menu *fyne.MainMenu) SetMainMenu(menu *fyne.MainMenu)
NewFileOpen(callback func(fyne.URIReadCloser, error), location fyne.ListableURI) *dialog.FileDialog NewFileOpen(callback func(fyne.URIReadCloser, error), location fyne.ListableURI) *dialog.FileDialog
NewFolderOpen(callback func(fyne.ListableURI, 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))
ShowAndRun() ShowAndRun()
GetLayout() LayoutContract GetLayout() LayoutContract
} }
@ -80,3 +81,7 @@ func (w Window) ShowAndRun() {
func (w Window) GetLayout() LayoutContract { func (w Window) GetLayout() LayoutContract {
return w.layout return w.layout
} }
func (w Window) SetOnDropped(callback func(position fyne.Position, uris []fyne.URI)) {
w.windowFyne.SetOnDropped(callback)
}

View File

@ -62,6 +62,10 @@ other = "Will be downloaded from the site:"
hash = "sha1-55f87f114628fa2d5d8e67d1e1cda22c0e4f9271" hash = "sha1-55f87f114628fa2d5d8e67d1e1cda22c0e4f9271"
other = "Downloading..." other = "Downloading..."
[dragAndDrop1File]
hash = "sha1-7259670822df1cc92ef5f06ed3c0e9407746975a"
other = "drag and drop 1 file"
[encoderGroupAudio] [encoderGroupAudio]
hash = "sha1-24321cb5400df96be8f3e2131918bebdb3a01bba" hash = "sha1-24321cb5400df96be8f3e2131918bebdb3a01bba"
other = "Audio" other = "Audio"
@ -218,6 +222,10 @@ other = "Couldn't convert video"
hash = "sha1-531abc3f0d12727e542df6e5a22de91098380fc1" hash = "sha1-531abc3f0d12727e542df6e5a22de91098380fc1"
other = "could not create file 'database' in folder 'data'" other = "could not create file 'database' in folder 'data'"
[errorDragAndDrop1File]
hash = "sha1-a8edb5cbd622f3ce4ec07a2377e22ec5fad4491b"
other = "You can only drag and drop 1 file."
[errorFFmpeg] [errorFFmpeg]
hash = "sha1-ccf0b95c0d1b392dc215258d917eb4e5d0b88ed0" hash = "sha1-ccf0b95c0d1b392dc215258d917eb4e5d0b88ed0"
other = "this is not FFmpeg" other = "this is not FFmpeg"
@ -234,6 +242,10 @@ other = "this is not FFprobe"
hash = "sha1-da7b37d7df3fafbd153665b13888413d52b24c17" hash = "sha1-da7b37d7df3fafbd153665b13888413d52b24c17"
other = "Failed to determine FFprobe version" other = "Failed to determine FFprobe version"
[errorIsFolder]
hash = "sha1-f937d090b6e320957514d850657cdf2f911dc6aa"
other = "You can only drag and drop a file"
[errorQueue] [errorQueue]
hash = "sha1-72aecd9ad85642d84d62dbbf3cf70953c5f696c7" hash = "sha1-72aecd9ad85642d84d62dbbf3cf70953c5f696c7"
other = "Error" other = "Error"
@ -294,6 +306,10 @@ other = "License information"
hash = "sha1-359fff328717c05104e51a2d29f05bf1875d26b7" hash = "sha1-359fff328717c05104e51a2d29f05bf1875d26b7"
other = "Licenses from other products used in the program" other = "Licenses from other products used in the program"
[or]
hash = "sha1-30bb0333ca1583110e4ced513b5d2455b86f529b"
other = "or"
[parameterCheckbox] [parameterCheckbox]
hash = "sha1-9e35221d454870996fd51d576249cf47d1784a3c" hash = "sha1-9e35221d454870996fd51d576249cf47d1784a3c"
other = "Enable option" other = "Enable option"

View File

@ -62,6 +62,10 @@ other = "Сайттан жүктеледі:"
hash = "sha1-55f87f114628fa2d5d8e67d1e1cda22c0e4f9271" hash = "sha1-55f87f114628fa2d5d8e67d1e1cda22c0e4f9271"
other = "Жүктеп алынуда..." other = "Жүктеп алынуда..."
[dragAndDrop1File]
hash = "sha1-7259670822df1cc92ef5f06ed3c0e9407746975a"
other = "1 файлды сүйреңіз"
[encoderGroupAudio] [encoderGroupAudio]
hash = "sha1-24321cb5400df96be8f3e2131918bebdb3a01bba" hash = "sha1-24321cb5400df96be8f3e2131918bebdb3a01bba"
other = "Аудио" other = "Аудио"
@ -218,6 +222,10 @@ other = "Бейнені түрлендіру мүмкін болмады"
hash = "sha1-531abc3f0d12727e542df6e5a22de91098380fc1" hash = "sha1-531abc3f0d12727e542df6e5a22de91098380fc1"
other = "'data' қалтасында 'database' файлын жасау мүмкін болмады" other = "'data' қалтасында 'database' файлын жасау мүмкін болмады"
[errorDragAndDrop1File]
hash = "sha1-a8edb5cbd622f3ce4ec07a2377e22ec5fad4491b"
other = "Тек 1 файлды сүйреп апаруға болады"
[errorFFmpeg] [errorFFmpeg]
hash = "sha1-ccf0b95c0d1b392dc215258d917eb4e5d0b88ed0" hash = "sha1-ccf0b95c0d1b392dc215258d917eb4e5d0b88ed0"
other = "бұл FFmpeg емес" other = "бұл FFmpeg емес"
@ -234,6 +242,10 @@ other = "бұл FFprobe емес"
hash = "sha1-da7b37d7df3fafbd153665b13888413d52b24c17" hash = "sha1-da7b37d7df3fafbd153665b13888413d52b24c17"
other = "FFprobe нұсқасын анықтау мүмкін болмады" other = "FFprobe нұсқасын анықтау мүмкін болмады"
[errorIsFolder]
hash = "sha1-f937d090b6e320957514d850657cdf2f911dc6aa"
other = "Тек файлды сүйреп апаруға болады"
[errorQueue] [errorQueue]
hash = "sha1-72aecd9ad85642d84d62dbbf3cf70953c5f696c7" hash = "sha1-72aecd9ad85642d84d62dbbf3cf70953c5f696c7"
other = "Қате" other = "Қате"
@ -294,6 +306,10 @@ other = "Лицензия туралы ақпарат"
hash = "sha1-359fff328717c05104e51a2d29f05bf1875d26b7" hash = "sha1-359fff328717c05104e51a2d29f05bf1875d26b7"
other = "Бағдарламада пайдаланылатын басқа өнімдердің лицензиялары" other = "Бағдарламада пайдаланылатын басқа өнімдердің лицензиялары"
[or]
hash = "sha1-30bb0333ca1583110e4ced513b5d2455b86f529b"
other = "немесе"
[parameterCheckbox] [parameterCheckbox]
hash = "sha1-9e35221d454870996fd51d576249cf47d1784a3c" hash = "sha1-9e35221d454870996fd51d576249cf47d1784a3c"
other = "Опцияны қосу" other = "Опцияны қосу"

View File

@ -14,6 +14,7 @@ converterVideoFilesTitle = "Конвертер видео, аудио и кар
download = "Скачать" download = "Скачать"
downloadFFmpegFromSite = "Будет скачано с сайта:" downloadFFmpegFromSite = "Будет скачано с сайта:"
downloadRun = "Скачивается..." downloadRun = "Скачивается..."
dragAndDrop1File = "перетащить 1 файл"
encoderGroupAudio = "Аудио" encoderGroupAudio = "Аудио"
encoderGroupImage = "Картинки" encoderGroupImage = "Картинки"
encoderGroupVideo = "Видео" encoderGroupVideo = "Видео"
@ -53,10 +54,12 @@ encoder_xbm = "XBM (X BitMap) image"
error = "Произошла ошибка!" error = "Произошла ошибка!"
errorConverter = "не смогли отконвертировать видео" errorConverter = "не смогли отконвертировать видео"
errorDatabase = "не смогли создать файл 'database' в папке 'data'" errorDatabase = "не смогли создать файл 'database' в папке 'data'"
errorDragAndDrop1File = "Можно перетащить только 1 файл"
errorFFmpeg = "это не FFmpeg" errorFFmpeg = "это не FFmpeg"
errorFFmpegVersion = "Не смогли определить версию FFmpeg" errorFFmpegVersion = "Не смогли определить версию FFmpeg"
errorFFprobe = "это не FFprobe" errorFFprobe = "это не FFprobe"
errorFFprobeVersion = "Не смогли определить версию FFprobe" errorFFprobeVersion = "Не смогли определить версию FFprobe"
errorIsFolder = "Можно перетаскивать только файл"
errorQueue = "Ошибка" errorQueue = "Ошибка"
errorSelectedEncoder = "Конвертер не выбран" errorSelectedEncoder = "Конвертер не выбран"
errorSelectedFolderSave = "Папка для сохранения не выбрана!" errorSelectedFolderSave = "Папка для сохранения не выбрана!"
@ -72,6 +75,7 @@ languageSelectionFormHead = "Переключить язык"
languageSelectionHead = "Выберите язык" languageSelectionHead = "Выберите язык"
licenseLink = "Сведения о лицензии" licenseLink = "Сведения о лицензии"
licenseLinkOther = "Лицензии от других продуктов, которые используются в программе" licenseLinkOther = "Лицензии от других продуктов, которые используются в программе"
or = "или"
parameterCheckbox = "Включить параметр" parameterCheckbox = "Включить параметр"
pathToFfmpeg = "Путь к FFmpeg:" pathToFfmpeg = "Путь к FFmpeg:"
pathToFfprobe = "Путь к FFprobe:" pathToFfprobe = "Путь к FFprobe:"