Rename repo.
This commit is contained in:
parent
521d58c99b
commit
6bd07cf824
8 changed files with 28 additions and 29 deletions
|
@ -1,2 +1 @@
|
||||||
# go-ui
|
# Zenity for Golang
|
||||||
Golang UI utilities
|
|
|
@ -1,4 +1,4 @@
|
||||||
package dialog
|
package zenity
|
||||||
|
|
||||||
type FileFilter struct {
|
type FileFilter struct {
|
||||||
Name string
|
Name string
|
|
@ -1,4 +1,4 @@
|
||||||
package dialog
|
package zenity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -8,7 +8,7 @@ import (
|
||||||
"strings"
|
"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 := exec.Command("osascript", "-l", "JavaScript")
|
||||||
cmd.Stdin = scriptExpand(scriptData{
|
cmd.Stdin = scriptExpand(scriptData{
|
||||||
Operation: "chooseFile",
|
Operation: "chooseFile",
|
||||||
|
@ -26,7 +26,7 @@ func OpenFile(title, defaultPath string, filters []FileFilter) (string, error) {
|
||||||
return string(out), nil
|
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 := exec.Command("osascript", "-l", "JavaScript")
|
||||||
cmd.Stdin = scriptExpand(scriptData{
|
cmd.Stdin = scriptExpand(scriptData{
|
||||||
Operation: "chooseFile",
|
Operation: "chooseFile",
|
||||||
|
@ -48,7 +48,7 @@ func OpenFiles(title, defaultPath string, filters []FileFilter) ([]string, error
|
||||||
return strings.Split(string(out), "\x00"), nil
|
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 := exec.Command("osascript", "-l", "JavaScript")
|
||||||
cmd.Stdin = scriptExpand(scriptData{
|
cmd.Stdin = scriptExpand(scriptData{
|
||||||
Operation: "chooseFileName",
|
Operation: "chooseFileName",
|
||||||
|
@ -65,7 +65,7 @@ func SaveFile(title, defaultPath string, confirmOverwrite bool, filters []FileFi
|
||||||
return string(out), nil
|
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 := exec.Command("osascript", "-l", "JavaScript")
|
||||||
cmd.Stdin = scriptExpand(scriptData{
|
cmd.Stdin = scriptExpand(scriptData{
|
||||||
Operation: "chooseFolder",
|
Operation: "chooseFolder",
|
|
@ -1,11 +1,11 @@
|
||||||
package dialog
|
package zenity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func OpenFile(title, defaultPath string, filters []FileFilter) (string, error) {
|
func SelectFile(title, defaultPath string, filters []FileFilter) (string, error) {
|
||||||
args := []string{"--file-selection"}
|
args := []string{"--file-selection"}
|
||||||
if title != "" {
|
if title != "" {
|
||||||
args = append(args, "--title="+title)
|
args = append(args, "--title="+title)
|
||||||
|
@ -28,7 +28,7 @@ func OpenFile(title, defaultPath string, filters []FileFilter) (string, error) {
|
||||||
return string(out), nil
|
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"}
|
args := []string{"--file-selection", "--multiple", "--separator=\x1e"}
|
||||||
if title != "" {
|
if title != "" {
|
||||||
args = append(args, "--title="+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
|
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"}
|
args := []string{"--file-selection", "--save"}
|
||||||
if title != "" {
|
if title != "" {
|
||||||
args = append(args, "--title="+title)
|
args = append(args, "--title="+title)
|
||||||
|
@ -77,7 +77,7 @@ func SaveFile(title, defaultPath string, confirmOverwrite bool, filters []FileFi
|
||||||
return string(out), nil
|
return string(out), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func PickFolder(title, defaultPath string) (string, error) {
|
func SelectDirectory(title, defaultPath string) (string, error) {
|
||||||
args := []string{"--file-selection", "--directory"}
|
args := []string{"--file-selection", "--directory"}
|
||||||
if title != "" {
|
if title != "" {
|
||||||
args = append(args, "--title="+title)
|
args = append(args, "--title="+title)
|
|
@ -1,11 +1,11 @@
|
||||||
package dialog
|
package zenity
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
const defaultPath = ""
|
const defaultPath = ""
|
||||||
|
|
||||||
func TestOpenFile(t *testing.T) {
|
func TestSelectFile(t *testing.T) {
|
||||||
res, err := OpenFile("", defaultPath, []FileFilter{
|
res, err := SelectFile("", defaultPath, []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", ".gif", ".ico", ".jpg", ".webp"}},
|
{"Image files", []string{".png", ".gif", ".ico", ".jpg", ".webp"}},
|
||||||
|
@ -18,8 +18,8 @@ func TestOpenFile(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOpenFiles(t *testing.T) {
|
func TestSelectFileMutiple(t *testing.T) {
|
||||||
res, err := OpenFiles("", defaultPath, []FileFilter{
|
res, err := SelectFileMutiple("", defaultPath, []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", ".gif", ".ico", ".jpg", ".webp"}},
|
{"Image files", []string{".png", ".gif", ".ico", ".jpg", ".webp"}},
|
||||||
|
@ -32,8 +32,8 @@ func TestOpenFiles(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSaveFile(t *testing.T) {
|
func TestSelectFileSave(t *testing.T) {
|
||||||
res, err := SaveFile("", defaultPath, true, []FileFilter{
|
res, err := SelectFileSave("", defaultPath, 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", ".gif", ".ico", ".jpg", ".webp"}},
|
{"Image files", []string{".png", ".gif", ".ico", ".jpg", ".webp"}},
|
||||||
|
@ -46,8 +46,8 @@ func TestSaveFile(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPickFolder(t *testing.T) {
|
func TestSelectDirectory(t *testing.T) {
|
||||||
res, err := PickFolder("", defaultPath)
|
res, err := SelectDirectory("", defaultPath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
|
@ -1,4 +1,4 @@
|
||||||
package dialog
|
package zenity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
@ -27,7 +27,7 @@ var (
|
||||||
shCreateItemFromParsingName = shell32.NewProc("SHCreateItemFromParsingName")
|
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
|
var args _OPENFILENAME
|
||||||
args.StructSize = uint32(unsafe.Sizeof(args))
|
args.StructSize = uint32(unsafe.Sizeof(args))
|
||||||
args.Flags = 0x80008 // OFN_NOCHANGEDIR|OFN_EXPLORER
|
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
|
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
|
var args _OPENFILENAME
|
||||||
args.StructSize = uint32(unsafe.Sizeof(args))
|
args.StructSize = uint32(unsafe.Sizeof(args))
|
||||||
args.Flags = 0x80208 // OFN_NOCHANGEDIR|OFN_ALLOWMULTISELECT|OFN_EXPLORER
|
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
|
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
|
var args _OPENFILENAME
|
||||||
args.StructSize = uint32(unsafe.Sizeof(args))
|
args.StructSize = uint32(unsafe.Sizeof(args))
|
||||||
args.Flags = 0x80008 // OFN_NOCHANGEDIR|OFN_EXPLORER
|
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
|
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
|
hr, _, _ := coInitializeEx.Call(0, 0x6) // COINIT_APARTMENTTHREADED|COINIT_DISABLE_OLE1DDE
|
||||||
if hr < 0 {
|
if hr < 0 {
|
||||||
return "", errors.New("COM initialization failed.")
|
return "", errors.New("COM initialization failed.")
|
|
@ -1,4 +1,4 @@
|
||||||
package dialog
|
package zenity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"syscall"
|
"syscall"
|
2
go.mod
2
go.mod
|
@ -1,3 +1,3 @@
|
||||||
module github.com/ncruces/go-ui
|
module github.com/ncruces/zenity
|
||||||
|
|
||||||
go 1.13
|
go 1.13
|
||||||
|
|
Loading…
Reference in a new issue