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}}; opts.ofType = {{.Filter}};
{{end}} {{end}}
var ret; var res;
try { try {
ret = app[{{.Operation}}](opts); res = app[{{.Operation}}](opts);
} catch (e) { } catch (e) {
if (e.errorNumber !== -128) throw e; if (e.errorNumber !== -128) throw e;
} }
if (Array.isArray(ret)) { if (Array.isArray(res)) {
ret.join('\0'); res.join('\0');
} else if (ret != null) { } else if (res != null) {
ret.toString(); res.toString();
} else { } else {
void 0; void 0;
} }

View file

@ -3,53 +3,53 @@ package dialog
import "testing" import "testing"
func TestOpenFile(t *testing.T) { func TestOpenFile(t *testing.T) {
ret, err := OpenFile("", "", []FileFilter{ res, err := OpenFile("", "", []FileFilter{
{"Go files", []string{".go"}}, {"Go files", []string{".go"}},
{"Web files", []string{".html", ".js", ".css"}}, {"Web files", []string{".html", ".js", ".css"}},
{"Image files", []string{".png", ".ico"}}, {"Image files", []string{".png", ".gif", ".ico", ".jpg", ".webp"}},
}) })
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} else { } else {
t.Logf("%#v", ret) t.Logf("%#v", res)
} }
} }
func TestOpenFiles(t *testing.T) { func TestOpenFiles(t *testing.T) {
ret, err := OpenFiles("", "", []FileFilter{ res, err := OpenFiles("", "", []FileFilter{
{"Go files", []string{".go"}}, {"Go files", []string{".go"}},
{"Web files", []string{".html", ".js", ".css"}}, {"Web files", []string{".html", ".js", ".css"}},
{"Image files", []string{".png", ".ico"}}, {"Image files", []string{".png", ".gif", ".ico", ".jpg", ".webp"}},
}) })
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} else { } else {
t.Logf("%#v", ret) t.Logf("%#v", res)
} }
} }
func TestSaveFile(t *testing.T) { func TestSaveFile(t *testing.T) {
ret, err := SaveFile("", "", true, []FileFilter{ res, err := SaveFile("", "", true, []FileFilter{
{"Go files", []string{".go"}}, {"Go files", []string{".go"}},
{"Web files", []string{".html", ".js", ".css"}}, {"Web files", []string{".html", ".js", ".css"}},
{"Image files", []string{".png", ".ico"}}, {"Image files", []string{".png", ".gif", ".ico", ".jpg", ".webp"}},
}) })
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} else { } else {
t.Logf("%#v", ret) t.Logf("%#v", res)
} }
} }
func TestPickFolder(t *testing.T) { func TestPickFolder(t *testing.T) {
ret, err := PickFolder("", "") res, err := PickFolder("", "")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} else { } 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) { func OpenFile(title, defaultPath string, filters []FileFilter) (string, error) {
var args _OPENFILENAME var args _OPENFILENAME
args.StructSize = uint32(unsafe.Sizeof(args)) args.StructSize = uint32(unsafe.Sizeof(args))
args.Flags = 0x00080000 // OFN_EXPLORER args.Flags = 0x00080008 // OFN_NOCHANGEDIR|OFN_EXPLORER
if title != "" { if title != "" {
args.Title = syscall.StringToUTF16Ptr(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) { func OpenFiles(title, defaultPath string, filters []FileFilter) ([]string, error) {
var args _OPENFILENAME var args _OPENFILENAME
args.StructSize = uint32(unsafe.Sizeof(args)) args.StructSize = uint32(unsafe.Sizeof(args))
args.Flags = 0x00080200 // OFN_EXPLORER|OFN_ALLOWMULTISELECT args.Flags = 0x00080208 // OFN_NOCHANGEDIR|OFN_ALLOWMULTISELECT|OFN_EXPLORER
if title != "" { if title != "" {
args.Title = syscall.StringToUTF16Ptr(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) { func SaveFile(title, defaultPath string, confirmOverwrite bool, filters []FileFilter) (string, error) {
var args _OPENFILENAME var args _OPENFILENAME
args.StructSize = uint32(unsafe.Sizeof(args)) args.StructSize = uint32(unsafe.Sizeof(args))
args.Flags = 0x00080000 // OFN_EXPLORER args.Flags = 0x00080008 // OFN_NOCHANGEDIR|OFN_EXPLORER
if title != "" { if title != "" {
args.Title = syscall.StringToUTF16Ptr(title) args.Title = syscall.StringToUTF16Ptr(title)