This commit is contained in:
Nuno Cruces 2022-05-19 14:09:21 +01:00
parent fcf0a22b42
commit af8627dee2
6 changed files with 29 additions and 24 deletions

View File

@ -168,7 +168,7 @@ func main() {
case save: case save:
strResult(egestPath(zenity.SelectFileSave(opts...))) strResult(egestPath(zenity.SelectFileSave(opts...)))
case multiple: case multiple:
lstResult(egestPaths(zenity.SelectFileMutiple(opts...))) lstResult(egestPaths(zenity.SelectFileMultiple(opts...)))
} }
case colorSelectionDlg: case colorSelectionDlg:

View File

@ -15,13 +15,18 @@ func SelectFile(options ...Option) (string, error) {
return selectFile(applyOptions(options)) return selectFile(applyOptions(options))
} }
// SelectFileMutiple displays the multiple file selection dialog. // SelectFileMultiple displays the multiple file selection dialog.
// //
// Valid options: Title, Directory, Filename, ShowHidden, FileFilter(s). // Valid options: Title, Directory, Filename, ShowHidden, FileFilter(s).
// //
// May return: ErrCanceled, ErrUnsupported. // May return: ErrCanceled, ErrUnsupported.
func SelectFileMultiple(options ...Option) ([]string, error) {
return selectFileMultiple(applyOptions(options))
}
// Deprecated: use SelectFileMultiple.
func SelectFileMutiple(options ...Option) ([]string, error) { func SelectFileMutiple(options ...Option) ([]string, error) {
return selectFileMutiple(applyOptions(options)) return SelectFileMultiple(options...)
} }
// SelectFileSave displays the save file selection dialog. // SelectFileSave displays the save file selection dialog.

View File

@ -19,7 +19,7 @@ func selectFile(opts options) (string, error) {
return strResult(opts, out, err) return strResult(opts, out, err)
} }
func selectFileMutiple(opts options) ([]string, error) { func selectFileMultiple(opts options) ([]string, error) {
var data zenutil.File var data zenutil.File
data.Options.Prompt = opts.title data.Options.Prompt = opts.title
data.Options.Invisibles = opts.showHidden data.Options.Invisibles = opts.showHidden

View File

@ -26,8 +26,8 @@ func ExampleSelectFile() {
}) })
} }
func ExampleSelectFileMutiple() { func ExampleSelectFileMultiple() {
zenity.SelectFileMutiple( zenity.SelectFileMultiple(
zenity.Filename(defaultPath), zenity.Filename(defaultPath),
zenity.FileFilters{ zenity.FileFilters{
{"Go files", []string{"*.go"}}, {"Go files", []string{"*.go"}},
@ -53,8 +53,8 @@ func ExampleSelectFile_directory() {
zenity.Directory()) zenity.Directory())
} }
func ExampleSelectFileMutiple_directory() { func ExampleSelectFileMultiple_directory() {
zenity.SelectFileMutiple( zenity.SelectFileMultiple(
zenity.Filename(defaultPath), zenity.Filename(defaultPath),
zenity.Directory()) zenity.Directory())
} }
@ -68,12 +68,12 @@ var fileFuncs = []struct {
{"Directory", func(o ...zenity.Option) (string, error) { {"Directory", func(o ...zenity.Option) (string, error) {
return zenity.SelectFile(append(o, zenity.Directory())...) return zenity.SelectFile(append(o, zenity.Directory())...)
}}, }},
{"Mutiple", func(o ...zenity.Option) (string, error) { {"Multiple", func(o ...zenity.Option) (string, error) {
_, err := zenity.SelectFileMutiple(append(o, zenity.Directory())...) _, err := zenity.SelectFileMultiple(append(o, zenity.Directory())...)
return "", err return "", err
}}, }},
{"MutipleDirectory", func(o ...zenity.Option) (string, error) { {"MultipleDirectory", func(o ...zenity.Option) (string, error) {
_, err := zenity.SelectFileMutiple(o...) _, err := zenity.SelectFileMultiple(o...)
return "", err return "", err
}}, }},
} }
@ -162,38 +162,38 @@ func TestSelectFile_script(t *testing.T) {
}) })
} }
func TestSelectFileMutiple_script(t *testing.T) { func TestSelectFileMultiple_script(t *testing.T) {
if testing.Short() { if testing.Short() {
t.Skip("skipping test in short mode.") t.Skip("skipping test in short mode.")
} }
t.Run("Cancel", func(t *testing.T) { t.Run("Cancel", func(t *testing.T) {
zenity.Info(fmt.Sprintf("In the file selection dialog, cancel.")) zenity.Info(fmt.Sprintf("In the file selection dialog, cancel."))
lst, err := zenity.SelectFileMutiple() lst, err := zenity.SelectFileMultiple()
if skip, err := skip(err); skip { if skip, err := skip(err); skip {
t.Skip("skipping:", err) t.Skip("skipping:", err)
} }
if lst != nil || err != zenity.ErrCanceled { if lst != nil || err != zenity.ErrCanceled {
t.Errorf("SelectFileMutiple() = %v, %v; want nil, %v", lst, err, zenity.ErrCanceled) t.Errorf("SelectFileMultiple() = %v, %v; want nil, %v", lst, err, zenity.ErrCanceled)
} }
}) })
t.Run("Files", func(t *testing.T) { t.Run("Files", func(t *testing.T) {
zenity.Info(fmt.Sprintf("In the file selection dialog, pick two files.")) zenity.Info(fmt.Sprintf("In the file selection dialog, pick two files."))
lst, err := zenity.SelectFileMutiple() lst, err := zenity.SelectFileMultiple()
if skip, err := skip(err); skip { if skip, err := skip(err); skip {
t.Skip("skipping:", err) t.Skip("skipping:", err)
} }
if lst == nil || err != nil { if lst == nil || err != nil {
t.Errorf("SelectFileMutiple() = %v, %v; want [path, path], nil", lst, err) t.Errorf("SelectFileMultiple() = %v, %v; want [path, path], nil", lst, err)
} }
for _, str := range lst { for _, str := range lst {
if _, serr := os.Stat(str); serr != nil { if _, serr := os.Stat(str); serr != nil {
t.Errorf("SelectFileMutiple() = %q, %v; %v", lst, err, serr) t.Errorf("SelectFileMultiple() = %q, %v; %v", lst, err, serr)
} }
} }
}) })
t.Run("Directories", func(t *testing.T) { t.Run("Directories", func(t *testing.T) {
zenity.Info(fmt.Sprintf("In the file selection dialog, pick two directories.")) zenity.Info(fmt.Sprintf("In the file selection dialog, pick two directories."))
lst, err := zenity.SelectFileMutiple(zenity.Directory()) lst, err := zenity.SelectFileMultiple(zenity.Directory())
if skip, err := skip(err); skip { if skip, err := skip(err); skip {
t.Skip("skipping:", err) t.Skip("skipping:", err)
} }
@ -201,13 +201,13 @@ func TestSelectFileMutiple_script(t *testing.T) {
t.Skip("was not unsupported:", err) t.Skip("was not unsupported:", err)
} }
if lst == nil || err != nil { if lst == nil || err != nil {
t.Errorf("SelectFileMutiple() = %v, %v; want [path, path], nil", lst, err) t.Errorf("SelectFileMultiple() = %v, %v; want [path, path], nil", lst, err)
} }
for _, str := range lst { for _, str := range lst {
if s, serr := os.Stat(str); serr != nil { if s, serr := os.Stat(str); serr != nil {
t.Errorf("SelectFileMutiple() = %q, %v; %v", str, err, serr) t.Errorf("SelectFileMultiple() = %q, %v; %v", str, err, serr)
} else if !s.IsDir() { } else if !s.IsDir() {
t.Errorf("SelectFileMutiple() = %q, %v; not a directory", str, err) t.Errorf("SelectFileMultiple() = %q, %v; not a directory", str, err)
} }
} }
}) })

View File

@ -17,7 +17,7 @@ func selectFile(opts options) (string, error) {
return strResult(opts, out, err) return strResult(opts, out, err)
} }
func selectFileMutiple(opts options) ([]string, error) { func selectFileMultiple(opts options) ([]string, error) {
args := []string{"--file-selection", "--multiple", "--separator", zenutil.Separator} args := []string{"--file-selection", "--multiple", "--separator", zenutil.Separator}
args = appendTitle(args, opts) args = appendTitle(args, opts)
args = appendFileArgs(args, opts) args = appendFileArgs(args, opts)

View File

@ -62,7 +62,7 @@ func selectFile(opts options) (string, error) {
return syscall.UTF16ToString(res[:]), nil return syscall.UTF16ToString(res[:]), nil
} }
func selectFileMutiple(opts options) ([]string, error) { func selectFileMultiple(opts options) ([]string, error) {
if opts.directory { if opts.directory {
_, res, err := pickFolders(opts, true) _, res, err := pickFolders(opts, true)
return res, err return res, err