Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix gcs issue #681 / zenity save dialog not opening on linux #31

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const (
ModalResponseDiscard = iota - 1
ModalResponseOK
ModalResponseCancel
ModalResponseError
ModalResponseUserBase = 100
)

Expand Down
30 changes: 26 additions & 4 deletions save_dialog_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,32 @@ func (d *linuxSaveDialog) runKDialog(kdialog string) bool {
list := strings.Join(allowed, " ")
cmd.Args = append(cmd.Args, fmt.Sprintf("%[1]s (%[1]s)", list))
}
return d.runModal(cmd, "\n")
return d.runModal(cmd, "\n") == ModalResponseOK
}

func (d *linuxSaveDialog) runZenity(zenity string) bool {
ext, allowed := d.prepExt()

cmd := exec.Command(zenity, "--file-selection", "--save", "--confirm-overwrite",
"--filename="+d.InitialDirectory()+"/untitled"+ext)
if len(allowed) != 0 {
cmd.Args = append(cmd.Args, "--file-filter="+strings.Join(allowed, " "))
}
return d.runModal(cmd, "|")

ret := d.runModal(cmd, "|")

if ret == ModalResponseError {
// retry without "--confirm-overwrite"
cmd = exec.Command(zenity, "--file-selection", "--save",
"--filename="+d.InitialDirectory()+"/untitled"+ext)
if len(allowed) != 0 {
cmd.Args = append(cmd.Args, "--file-filter="+strings.Join(allowed, " "))
}

return d.runModal(cmd, "|") == ModalResponseOK
} else {
return ret == ModalResponseOK
}
}

func (d *linuxSaveDialog) prepExt() (string, []string) {
Expand All @@ -105,14 +120,14 @@ func (d *linuxSaveDialog) prepExt() (string, []string) {
return ext, allowed
}

func (d *linuxSaveDialog) runModal(cmd *exec.Cmd, splitOn string) bool {
func (d *linuxSaveDialog) runModal(cmd *exec.Cmd, splitOn string) int {
wnd, err := NewWindow("", FloatingWindowOption(), UndecoratedWindowOption(), NotResizableWindowOption())
if err != nil {
jot.Error(err)
}
wnd.SetFrameRect(NewRect(-10000, -10000, 1, 1))
InvokeTaskAfter(func() { go d.runCmd(wnd, cmd, splitOn) }, time.Millisecond)
return wnd.RunModal() == ModalResponseOK
return wnd.RunModal()
}

func (d *linuxSaveDialog) runCmd(wnd *Window, cmd *exec.Cmd, splitOn string) {
Expand All @@ -124,12 +139,19 @@ func (d *linuxSaveDialog) runCmd(wnd *Window, cmd *exec.Cmd, splitOn string) {
if errors.As(err, &exitErr) && exitErr.ExitCode() == 1 {
return
}
if exitErr.ExitCode() == 255 {
code = ModalResponseError
}
jot.Error(errs.Wrap(err))
return
}
if cmd.ProcessState.ExitCode() != 0 {
if cmd.ProcessState.ExitCode() == 255 {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to be redundant

code = ModalResponseError
}
return
}
d.fallback.(*fileDialog).paths = strings.Split(strings.TrimSuffix(string(out), "\n"), splitOn)
code = ModalResponseOK
return
}