5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-09 03:40:44 +08:00

[v3 windows] Dialogs to use invokeSync

This commit is contained in:
Lea Anthony 2023-05-08 20:11:51 +10:00
parent c8dae94b5b
commit a829b38a34
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
2 changed files with 59 additions and 61 deletions

View File

@ -100,7 +100,7 @@ func (d *MessageDialog) Show() {
if d.impl == nil {
d.impl = newDialogImpl(d)
}
d.impl.show()
invokeSync(d.impl.show)
}
func (d *MessageDialog) SetIcon(icon []byte) *MessageDialog {
@ -248,7 +248,7 @@ func (d *OpenFileDialog) PromptForSingleSelection() (string, error) {
if d.impl == nil {
d.impl = newOpenFileDialogImpl(d)
}
selection, err := d.impl.show()
selection, err := invokeSyncWithResultAndError(d.impl.show)
var result string
if len(selection) > 0 {
result = selection[0]
@ -272,7 +272,7 @@ func (d *OpenFileDialog) PromptForMultipleSelection() ([]string, error) {
if d.impl == nil {
d.impl = newOpenFileDialogImpl(d)
}
return d.impl.show()
return invokeSyncWithResultAndError(d.impl.show)
}
func (d *OpenFileDialog) SetMessage(message string) *OpenFileDialog {
@ -412,7 +412,7 @@ func (d *SaveFileDialog) PromptForSingleSelection() (string, error) {
if d.impl == nil {
d.impl = newSaveFileDialogImpl(d)
}
return d.impl.show()
return invokeSyncWithResultAndError(d.impl.show)
}
func (d *SaveFileDialog) SetButtonText(text string) *SaveFileDialog {

View File

@ -13,63 +13,61 @@ type windowsDialog struct {
}
func (m *windowsDialog) show() {
globalApplication.dispatchOnMainThread(func() {
//
//// Mac can only have 4 Buttons on a dialog
//if len(m.dialog.Buttons) > 4 {
// m.dialog.Buttons = m.dialog.Buttons[:4]
//}
//
//if m.nsDialog != nil {
// C.releaseDialog(m.nsDialog)
//}
//var title *C.char
//if m.dialog.Title != "" {
// title = C.CString(m.dialog.Title)
//}
//var message *C.char
//if m.dialog.Message != "" {
// message = C.CString(m.dialog.Message)
//}
//var iconData unsafe.Pointer
//var iconLength C.int
//if m.dialog.Icon != nil {
// iconData = unsafe.Pointer(&m.dialog.Icon[0])
// iconLength = C.int(len(m.dialog.Icon))
//} else {
// // if it's an error, use the application Icon
// if m.dialog.DialogType == ErrorDialog {
// iconData = unsafe.Pointer(&globalApplication.options.Icon[0])
// iconLength = C.int(len(globalApplication.options.Icon))
// }
//}
//
//alertType, ok := alertTypeMap[m.dialog.DialogType]
//if !ok {
// alertType = C.NSAlertStyleInformational
//}
//
//m.nsDialog = C.createAlert(alertType, title, message, iconData, iconLength)
//
//// Reverse the Buttons so that the default is on the right
//reversedButtons := make([]*Button, len(m.dialog.Buttons))
//var count = 0
//for i := len(m.dialog.Buttons) - 1; i >= 0; i-- {
// button := m.dialog.Buttons[i]
// C.alertAddButton(m.nsDialog, C.CString(button.Label), C.bool(button.IsDefault), C.bool(button.IsCancel))
// reversedButtons[count] = m.dialog.Buttons[i]
// count++
//}
//
//buttonPressed := int(C.dialogRunModal(m.nsDialog))
//if len(m.dialog.Buttons) > buttonPressed {
// button := reversedButtons[buttonPressed]
// if button.callback != nil {
// button.callback()
// }
//}
panic("implement me")
})
//
//// Mac can only have 4 Buttons on a dialog
//if len(m.dialog.Buttons) > 4 {
// m.dialog.Buttons = m.dialog.Buttons[:4]
//}
//
//if m.nsDialog != nil {
// C.releaseDialog(m.nsDialog)
//}
//var title *C.char
//if m.dialog.Title != "" {
// title = C.CString(m.dialog.Title)
//}
//var message *C.char
//if m.dialog.Message != "" {
// message = C.CString(m.dialog.Message)
//}
//var iconData unsafe.Pointer
//var iconLength C.int
//if m.dialog.Icon != nil {
// iconData = unsafe.Pointer(&m.dialog.Icon[0])
// iconLength = C.int(len(m.dialog.Icon))
//} else {
// // if it's an error, use the application Icon
// if m.dialog.DialogType == ErrorDialog {
// iconData = unsafe.Pointer(&globalApplication.options.Icon[0])
// iconLength = C.int(len(globalApplication.options.Icon))
// }
//}
//
//alertType, ok := alertTypeMap[m.dialog.DialogType]
//if !ok {
// alertType = C.NSAlertStyleInformational
//}
//
//m.nsDialog = C.createAlert(alertType, title, message, iconData, iconLength)
//
//// Reverse the Buttons so that the default is on the right
//reversedButtons := make([]*Button, len(m.dialog.Buttons))
//var count = 0
//for i := len(m.dialog.Buttons) - 1; i >= 0; i-- {
// button := m.dialog.Buttons[i]
// C.alertAddButton(m.nsDialog, C.CString(button.Label), C.bool(button.IsDefault), C.bool(button.IsCancel))
// reversedButtons[count] = m.dialog.Buttons[i]
// count++
//}
//
//buttonPressed := int(C.dialogRunModal(m.nsDialog))
//if len(m.dialog.Buttons) > buttonPressed {
// button := reversedButtons[buttonPressed]
// if button.callback != nil {
// button.callback()
// }
//}
panic("implement me")
}