This commit is contained in:
Nuno Cruces 2019-12-14 02:16:06 +00:00
parent 76b9e744aa
commit 48a6137218
3 changed files with 20 additions and 20 deletions

View file

@ -128,16 +128,16 @@ opts.multipleSelectionsAllowed = {{.Multiple}};
opts.ofType = {{.Filter}};
{{end}}
var ret;
var res;
try {
ret = app[{{.Operation}}](opts);
res = app[{{.Operation}}](opts);
} catch (e) {
if (e.errorNumber !== -128) throw e;
}
if (Array.isArray(ret)) {
ret.join('\0');
} else if (ret != null) {
ret.toString();
if (Array.isArray(res)) {
res.join('\0');
} else if (res != null) {
res.toString();
} else {
void 0;
}

View file

@ -3,53 +3,53 @@ package dialog
import "testing"
func TestOpenFile(t *testing.T) {
ret, err := OpenFile("", "", []FileFilter{
res, err := OpenFile("", "", []FileFilter{
{"Go files", []string{".go"}},
{"Web files", []string{".html", ".js", ".css"}},
{"Image files", []string{".png", ".ico"}},
{"Image files", []string{".png", ".gif", ".ico", ".jpg", ".webp"}},
})
if err != nil {
t.Error(err)
} else {
t.Logf("%#v", ret)
t.Logf("%#v", res)
}
}
func TestOpenFiles(t *testing.T) {
ret, err := OpenFiles("", "", []FileFilter{
res, err := OpenFiles("", "", []FileFilter{
{"Go files", []string{".go"}},
{"Web files", []string{".html", ".js", ".css"}},
{"Image files", []string{".png", ".ico"}},
{"Image files", []string{".png", ".gif", ".ico", ".jpg", ".webp"}},
})
if err != nil {
t.Error(err)
} else {
t.Logf("%#v", ret)
t.Logf("%#v", res)
}
}
func TestSaveFile(t *testing.T) {
ret, err := SaveFile("", "", true, []FileFilter{
res, err := SaveFile("", "", true, []FileFilter{
{"Go files", []string{".go"}},
{"Web files", []string{".html", ".js", ".css"}},
{"Image files", []string{".png", ".ico"}},
{"Image files", []string{".png", ".gif", ".ico", ".jpg", ".webp"}},
})
if err != nil {
t.Error(err)
} else {
t.Logf("%#v", ret)
t.Logf("%#v", res)
}
}
func TestPickFolder(t *testing.T) {
ret, err := PickFolder("", "")
res, err := PickFolder("", "")
if err != nil {
t.Error(err)
} else {
t.Logf("%#v", ret)
t.Logf("%#v", res)
}
}

View file

@ -22,7 +22,7 @@ var (
func OpenFile(title, defaultPath string, filters []FileFilter) (string, error) {
var args _OPENFILENAME
args.StructSize = uint32(unsafe.Sizeof(args))
args.Flags = 0x00080000 // OFN_EXPLORER
args.Flags = 0x00080008 // OFN_NOCHANGEDIR|OFN_EXPLORER
if title != "" {
args.Title = syscall.StringToUTF16Ptr(title)
@ -43,7 +43,7 @@ func OpenFile(title, defaultPath string, filters []FileFilter) (string, error) {
func OpenFiles(title, defaultPath string, filters []FileFilter) ([]string, error) {
var args _OPENFILENAME
args.StructSize = uint32(unsafe.Sizeof(args))
args.Flags = 0x00080200 // OFN_EXPLORER|OFN_ALLOWMULTISELECT
args.Flags = 0x00080208 // OFN_NOCHANGEDIR|OFN_ALLOWMULTISELECT|OFN_EXPLORER
if title != "" {
args.Title = syscall.StringToUTF16Ptr(title)
@ -89,7 +89,7 @@ func OpenFiles(title, defaultPath string, filters []FileFilter) ([]string, error
func SaveFile(title, defaultPath string, confirmOverwrite bool, filters []FileFilter) (string, error) {
var args _OPENFILENAME
args.StructSize = uint32(unsafe.Sizeof(args))
args.Flags = 0x00080000 // OFN_EXPLORER
args.Flags = 0x00080008 // OFN_NOCHANGEDIR|OFN_EXPLORER
if title != "" {
args.Title = syscall.StringToUTF16Ptr(title)