From 6bd07cf8240170b2e9370726af5eadfc1dbe34a7 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Mon, 30 Dec 2019 01:00:50 +0000 Subject: [PATCH] Rename repo. --- README.md | 3 +-- dialog/dialog.go => file.go | 2 +- dialog/dialog_darwin.go => file_darwin.go | 10 +++++----- dialog/dialog_linux.go => file_linux.go | 10 +++++----- dialog/dialog_test.go => file_test.go | 18 +++++++++--------- dialog/dialog_windows.go => file_windows.go | 10 +++++----- ...log_windows_test.go => file_windows_test.go | 2 +- go.mod | 2 +- 8 files changed, 28 insertions(+), 29 deletions(-) rename dialog/dialog.go => file.go (78%) rename dialog/dialog_darwin.go => file_darwin.go (87%) rename dialog/dialog_linux.go => file_linux.go (87%) rename dialog/dialog_test.go => file_test.go (66%) rename dialog/dialog_windows.go => file_windows.go (96%) rename dialog/dialog_windows_test.go => file_windows_test.go (89%) diff --git a/README.md b/README.md index 96d4710..d1da7b6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1 @@ -# go-ui -Golang UI utilities +# Zenity for Golang \ No newline at end of file diff --git a/dialog/dialog.go b/file.go similarity index 78% rename from dialog/dialog.go rename to file.go index c3ee92c..e6227e1 100644 --- a/dialog/dialog.go +++ b/file.go @@ -1,4 +1,4 @@ -package dialog +package zenity type FileFilter struct { Name string diff --git a/dialog/dialog_darwin.go b/file_darwin.go similarity index 87% rename from dialog/dialog_darwin.go rename to file_darwin.go index a6a0355..84b1113 100644 --- a/dialog/dialog_darwin.go +++ b/file_darwin.go @@ -1,4 +1,4 @@ -package dialog +package zenity import ( "bytes" @@ -8,7 +8,7 @@ import ( "strings" ) -func OpenFile(title, defaultPath string, filters []FileFilter) (string, error) { +func SelectFile(title, defaultPath string, filters []FileFilter) (string, error) { cmd := exec.Command("osascript", "-l", "JavaScript") cmd.Stdin = scriptExpand(scriptData{ Operation: "chooseFile", @@ -26,7 +26,7 @@ func OpenFile(title, defaultPath string, filters []FileFilter) (string, error) { return string(out), nil } -func OpenFiles(title, defaultPath string, filters []FileFilter) ([]string, error) { +func SelectFileMutiple(title, defaultPath string, filters []FileFilter) ([]string, error) { cmd := exec.Command("osascript", "-l", "JavaScript") cmd.Stdin = scriptExpand(scriptData{ Operation: "chooseFile", @@ -48,7 +48,7 @@ func OpenFiles(title, defaultPath string, filters []FileFilter) ([]string, error return strings.Split(string(out), "\x00"), nil } -func SaveFile(title, defaultPath string, confirmOverwrite bool, filters []FileFilter) (string, error) { +func SelectFileSave(title, defaultPath string, confirmOverwrite bool, filters []FileFilter) (string, error) { cmd := exec.Command("osascript", "-l", "JavaScript") cmd.Stdin = scriptExpand(scriptData{ Operation: "chooseFileName", @@ -65,7 +65,7 @@ func SaveFile(title, defaultPath string, confirmOverwrite bool, filters []FileFi return string(out), nil } -func PickFolder(title, defaultPath string) (string, error) { +func SelectDirectory(title, defaultPath string) (string, error) { cmd := exec.Command("osascript", "-l", "JavaScript") cmd.Stdin = scriptExpand(scriptData{ Operation: "chooseFolder", diff --git a/dialog/dialog_linux.go b/file_linux.go similarity index 87% rename from dialog/dialog_linux.go rename to file_linux.go index e8cbcf3..123f7a2 100644 --- a/dialog/dialog_linux.go +++ b/file_linux.go @@ -1,11 +1,11 @@ -package dialog +package zenity import ( "os/exec" "strings" ) -func OpenFile(title, defaultPath string, filters []FileFilter) (string, error) { +func SelectFile(title, defaultPath string, filters []FileFilter) (string, error) { args := []string{"--file-selection"} if title != "" { args = append(args, "--title="+title) @@ -28,7 +28,7 @@ func OpenFile(title, defaultPath string, filters []FileFilter) (string, error) { return string(out), nil } -func OpenFiles(title, defaultPath string, filters []FileFilter) ([]string, error) { +func SelectFileMutiple(title, defaultPath string, filters []FileFilter) ([]string, error) { args := []string{"--file-selection", "--multiple", "--separator=\x1e"} if title != "" { args = append(args, "--title="+title) @@ -51,7 +51,7 @@ func OpenFiles(title, defaultPath string, filters []FileFilter) ([]string, error return strings.Split(string(out), "\x1e"), nil } -func SaveFile(title, defaultPath string, confirmOverwrite bool, filters []FileFilter) (string, error) { +func SelectFileSave(title, defaultPath string, confirmOverwrite bool, filters []FileFilter) (string, error) { args := []string{"--file-selection", "--save"} if title != "" { args = append(args, "--title="+title) @@ -77,7 +77,7 @@ func SaveFile(title, defaultPath string, confirmOverwrite bool, filters []FileFi return string(out), nil } -func PickFolder(title, defaultPath string) (string, error) { +func SelectDirectory(title, defaultPath string) (string, error) { args := []string{"--file-selection", "--directory"} if title != "" { args = append(args, "--title="+title) diff --git a/dialog/dialog_test.go b/file_test.go similarity index 66% rename from dialog/dialog_test.go rename to file_test.go index 89df211..42f2ae9 100644 --- a/dialog/dialog_test.go +++ b/file_test.go @@ -1,11 +1,11 @@ -package dialog +package zenity import "testing" const defaultPath = "" -func TestOpenFile(t *testing.T) { - res, err := OpenFile("", defaultPath, []FileFilter{ +func TestSelectFile(t *testing.T) { + res, err := SelectFile("", defaultPath, []FileFilter{ {"Go files", []string{".go"}}, {"Web files", []string{".html", ".js", ".css"}}, {"Image files", []string{".png", ".gif", ".ico", ".jpg", ".webp"}}, @@ -18,8 +18,8 @@ func TestOpenFile(t *testing.T) { } } -func TestOpenFiles(t *testing.T) { - res, err := OpenFiles("", defaultPath, []FileFilter{ +func TestSelectFileMutiple(t *testing.T) { + res, err := SelectFileMutiple("", defaultPath, []FileFilter{ {"Go files", []string{".go"}}, {"Web files", []string{".html", ".js", ".css"}}, {"Image files", []string{".png", ".gif", ".ico", ".jpg", ".webp"}}, @@ -32,8 +32,8 @@ func TestOpenFiles(t *testing.T) { } } -func TestSaveFile(t *testing.T) { - res, err := SaveFile("", defaultPath, true, []FileFilter{ +func TestSelectFileSave(t *testing.T) { + res, err := SelectFileSave("", defaultPath, true, []FileFilter{ {"Go files", []string{".go"}}, {"Web files", []string{".html", ".js", ".css"}}, {"Image files", []string{".png", ".gif", ".ico", ".jpg", ".webp"}}, @@ -46,8 +46,8 @@ func TestSaveFile(t *testing.T) { } } -func TestPickFolder(t *testing.T) { - res, err := PickFolder("", defaultPath) +func TestSelectDirectory(t *testing.T) { + res, err := SelectDirectory("", defaultPath) if err != nil { t.Error(err) diff --git a/dialog/dialog_windows.go b/file_windows.go similarity index 96% rename from dialog/dialog_windows.go rename to file_windows.go index 9f30426..ed5b99a 100644 --- a/dialog/dialog_windows.go +++ b/file_windows.go @@ -1,4 +1,4 @@ -package dialog +package zenity import ( "errors" @@ -27,7 +27,7 @@ var ( shCreateItemFromParsingName = shell32.NewProc("SHCreateItemFromParsingName") ) -func OpenFile(title, defaultPath string, filters []FileFilter) (string, error) { +func SelectFile(title, defaultPath string, filters []FileFilter) (string, error) { var args _OPENFILENAME args.StructSize = uint32(unsafe.Sizeof(args)) args.Flags = 0x80008 // OFN_NOCHANGEDIR|OFN_EXPLORER @@ -56,7 +56,7 @@ func OpenFile(title, defaultPath string, filters []FileFilter) (string, error) { return syscall.UTF16ToString(res[:]), nil } -func OpenFiles(title, defaultPath string, filters []FileFilter) ([]string, error) { +func SelectFileMutiple(title, defaultPath string, filters []FileFilter) ([]string, error) { var args _OPENFILENAME args.StructSize = uint32(unsafe.Sizeof(args)) args.Flags = 0x80208 // OFN_NOCHANGEDIR|OFN_ALLOWMULTISELECT|OFN_EXPLORER @@ -110,7 +110,7 @@ func OpenFiles(title, defaultPath string, filters []FileFilter) ([]string, error return split, nil } -func SaveFile(title, defaultPath string, confirmOverwrite bool, filters []FileFilter) (string, error) { +func SelectFileSave(title, defaultPath string, confirmOverwrite bool, filters []FileFilter) (string, error) { var args _OPENFILENAME args.StructSize = uint32(unsafe.Sizeof(args)) args.Flags = 0x80008 // OFN_NOCHANGEDIR|OFN_EXPLORER @@ -142,7 +142,7 @@ func SaveFile(title, defaultPath string, confirmOverwrite bool, filters []FileFi return syscall.UTF16ToString(res[:]), nil } -func PickFolder(title, defaultPath string) (string, error) { +func SelectDirectory(title, defaultPath string) (string, error) { hr, _, _ := coInitializeEx.Call(0, 0x6) // COINIT_APARTMENTTHREADED|COINIT_DISABLE_OLE1DDE if hr < 0 { return "", errors.New("COM initialization failed.") diff --git a/dialog/dialog_windows_test.go b/file_windows_test.go similarity index 89% rename from dialog/dialog_windows_test.go rename to file_windows_test.go index 61f8de8..cc2f736 100644 --- a/dialog/dialog_windows_test.go +++ b/file_windows_test.go @@ -1,4 +1,4 @@ -package dialog +package zenity import ( "syscall" diff --git a/go.mod b/go.mod index ed74fb0..b62b7b6 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/ncruces/go-ui +module github.com/ncruces/zenity go 1.13