mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-07-20 06:28:04 +00:00
Moved UI methods to their own struct
This commit is contained in:
30
internal/ui/dialogs.go
Normal file
30
internal/ui/dialogs.go
Normal file
@ -0,0 +1,30 @@
|
||||
package ui
|
||||
|
||||
import "github.com/ncruces/zenity"
|
||||
|
||||
func (u *UI) OpenDirectory(id, title string) string {
|
||||
if title == "" {
|
||||
title = "Choose a directory"
|
||||
}
|
||||
|
||||
dir, err := zenity.SelectFile(zenity.Title(title), zenity.Directory())
|
||||
|
||||
if err != nil && err != zenity.ErrCanceled {
|
||||
zenity.Error("Error while opening directory", zenity.ErrorIcon)
|
||||
}
|
||||
|
||||
return dir
|
||||
}
|
||||
|
||||
func (u *UI) EnterText(title, info, defaultEntry string) string {
|
||||
input, err := zenity.Entry(info, zenity.Title(title), zenity.EntryText(defaultEntry))
|
||||
|
||||
if err == zenity.ErrCanceled {
|
||||
return ""
|
||||
} else if err != nil {
|
||||
zenity.Error(err.Error(), zenity.Title("Encountered an error!"), zenity.ErrorIcon)
|
||||
return ""
|
||||
} else {
|
||||
return input
|
||||
}
|
||||
}
|
6
internal/ui/open.go
Normal file
6
internal/ui/open.go
Normal file
@ -0,0 +1,6 @@
|
||||
package ui
|
||||
|
||||
// Reveal reveals the specified file in the Finder.
|
||||
func (u *UI) Reveal(fname string) {
|
||||
reveal(fname)
|
||||
}
|
9
internal/ui/open_darwin.go
Normal file
9
internal/ui/open_darwin.go
Normal file
@ -0,0 +1,9 @@
|
||||
//go:build darwin
|
||||
|
||||
package ui
|
||||
|
||||
import "os/exec"
|
||||
|
||||
func reveal(fname string) {
|
||||
exec.Command("open", "--reveal", fname).Run()
|
||||
}
|
9
internal/ui/open_windows.go
Normal file
9
internal/ui/open_windows.go
Normal file
@ -0,0 +1,9 @@
|
||||
//go:build windows
|
||||
|
||||
package ui
|
||||
|
||||
import "os/exec"
|
||||
|
||||
func reveal(fname string) {
|
||||
exec.Command("explorer", fname).Run()
|
||||
}
|
27
internal/ui/ui.go
Normal file
27
internal/ui/ui.go
Normal file
@ -0,0 +1,27 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"runtime"
|
||||
|
||||
"github.com/gen2brain/beeep"
|
||||
)
|
||||
|
||||
type UI struct {
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func New() *UI {
|
||||
return &UI{}
|
||||
}
|
||||
|
||||
func (u *UI) Startup(ctx context.Context) {
|
||||
u.ctx = ctx
|
||||
}
|
||||
|
||||
func (u *UI) Beep() {
|
||||
if runtime.GOOS == "windows" {
|
||||
return
|
||||
}
|
||||
beeep.Beep(beeep.DefaultFreq, beeep.DefaultDuration)
|
||||
}
|
Reference in New Issue
Block a user