5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-21 19:39:29 +08:00

Merge remote-tracking branch 'origin/v3-alpha-linux-dialogs' into v3-alpha

This commit is contained in:
Travis McLane 2024-04-08 11:17:56 -05:00
commit 724ca386e7
4 changed files with 34 additions and 15 deletions

View File

@ -272,6 +272,7 @@ func (d *OpenFileDialogStruct) PromptForSingleSelection() (string, error) {
if err == nil { if err == nil {
result = <-selections result = <-selections
} }
close(selections)
return result, err return result, err
} }

View File

@ -10,10 +10,12 @@ func (a *linuxApp) showAboutDialog(title string, message string, icon []byte) {
about.SetTitle(title). about.SetTitle(title).
SetMessage(message). SetMessage(message).
SetIcon(icon) SetIcon(icon)
InvokeAsync(func() {
runQuestionDialog( runQuestionDialog(
pointer(parent), pointer(parent),
about, about,
) )
})
} }
type linuxDialog struct { type linuxDialog struct {
@ -28,6 +30,7 @@ func (m *linuxDialog) show() {
parent, _ = window.(*WebviewWindow).NativeWindowHandle() parent, _ = window.(*WebviewWindow).NativeWindowHandle()
} }
InvokeAsync(func() {
response := runQuestionDialog(pointer(parent), m.dialog) response := runQuestionDialog(pointer(parent), m.dialog)
if response >= 0 && response < len(m.dialog.Buttons) { if response >= 0 && response < len(m.dialog.Buttons) {
button := m.dialog.Buttons[response] button := m.dialog.Buttons[response]
@ -35,6 +38,7 @@ func (m *linuxDialog) show() {
go button.Callback() go button.Callback()
} }
} }
})
} }
func newDialogImpl(d *MessageDialog) *linuxDialog { func newDialogImpl(d *MessageDialog) *linuxDialog {

View File

@ -1556,8 +1556,8 @@ func runChooserDialog(window pointer, allowMultiple, createFolders, showHidden b
selections := make(chan string) selections := make(chan string)
// run this on the gtk thread // run this on the gtk thread
InvokeAsync(func() { InvokeAsync(func() {
go func() {
response := C.gtk_dialog_run((*C.GtkDialog)(fc)) response := C.gtk_dialog_run((*C.GtkDialog)(fc))
go func() {
if response == C.GTK_RESPONSE_ACCEPT { if response == C.GTK_RESPONSE_ACCEPT {
filenames := C.gtk_file_chooser_get_filenames((*C.GtkFileChooser)(fc)) filenames := C.gtk_file_chooser_get_filenames((*C.GtkFileChooser)(fc))
iter := filenames iter := filenames
@ -1570,16 +1570,21 @@ func runChooserDialog(window pointer, allowMultiple, createFolders, showHidden b
} }
count++ count++
} }
close(selections)
C.gtk_widget_destroy((*C.GtkWidget)(unsafe.Pointer(fc)))
} }
}() }()
}) })
C.gtk_widget_destroy((*C.GtkWidget)(unsafe.Pointer(fc)))
return selections, nil return selections, nil
} }
func runOpenFileDialog(dialog *OpenFileDialogStruct) (chan string, error) { func runOpenFileDialog(dialog *OpenFileDialogStruct) (chan string, error) {
const GtkFileChooserActionOpen = C.GTK_FILE_CHOOSER_ACTION_OPEN var action int
if dialog.canChooseDirectories {
action = C.GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER
} else {
action = C.GTK_FILE_CHOOSER_ACTION_OPEN
}
window := nilPointer window := nilPointer
if dialog.window != nil { if dialog.window != nil {
@ -1598,7 +1603,7 @@ func runOpenFileDialog(dialog *OpenFileDialogStruct) (chan string, error) {
dialog.showHiddenFiles, dialog.showHiddenFiles,
dialog.directory, dialog.directory,
dialog.title, dialog.title,
GtkFileChooserActionOpen, action,
buttonText, buttonText,
dialog.filters) dialog.filters)
} }

View File

@ -1084,6 +1084,15 @@ func runChooserDialog(window pointer, allowMultiple, createFolders, showHidden b
// dialog related // dialog related
func runOpenFileDialog(dialog *OpenFileDialogStruct) ([]string, error) { func runOpenFileDialog(dialog *OpenFileDialogStruct) ([]string, error) {
const GtkFileChooserActionOpen = 0 const GtkFileChooserActionOpen = 0
const GtkFileChooserActionSelectFolder = 2
var action int
if dialog.canChooseDirectories {
action = GtkFileChooserActionSelectFolder
} else {
action = GtkFileChooserActionOpen
}
window := pointer(0) window := pointer(0)
if dialog.window != nil { if dialog.window != nil {