5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-21 11:29: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 {
result = <-selections
}
close(selections)
return result, err
}

View File

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

View File

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

View File

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