Rename repo.

This commit is contained in:
Nuno Cruces 2019-12-30 01:00:50 +00:00
parent 521d58c99b
commit 6bd07cf824
8 changed files with 28 additions and 29 deletions

View file

@ -1,2 +1 @@
# go-ui
Golang UI utilities
# Zenity for Golang

View file

@ -1,4 +1,4 @@
package dialog
package zenity
type FileFilter struct {
Name string

View file

@ -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",

View file

@ -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)

View file

@ -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)

View file

@ -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.")

View file

@ -1,4 +1,4 @@
package dialog
package zenity
import (
"syscall"

2
go.mod
View file

@ -1,3 +1,3 @@
module github.com/ncruces/go-ui
module github.com/ncruces/zenity
go 1.13