You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.0 KiB
Plaintext
78 lines
2.0 KiB
Plaintext
#+build linux
|
|
#+feature dynamic-literals
|
|
package file_dialog
|
|
|
|
import "core:log"
|
|
import "core:strings"
|
|
import os2 "core:os/os2"
|
|
|
|
SAVE_FILE_COMMANDS :: [][]string{
|
|
{"yad", "--file", "--save"}
|
|
}
|
|
|
|
OPEN_SINGLE_FILE_COMMANDS :: [][]string{
|
|
{"yad", "--file"}
|
|
}
|
|
|
|
show_save_file_dialog_linux :: proc(title: string, filters: []File_Filter, default_filename: string = "", default_directory: string = "") -> (result: Result) {
|
|
|
|
result.success = false
|
|
process_desc: os2.Process_Desc
|
|
for command in SAVE_FILE_COMMANDS {
|
|
log.debug("attempting to use", command[0], "to get file path")
|
|
process_desc.command = command
|
|
|
|
state, stdout_bytes, stderr_bytes, err := os2.process_exec(process_desc, context.allocator)
|
|
if err == .Not_Exist {
|
|
log.debug("couldn't find", command[0])
|
|
continue
|
|
} else if err != nil {
|
|
log.error("error whilst getting filename: ", err)
|
|
return
|
|
}
|
|
|
|
stdout := string(stdout_bytes)
|
|
|
|
if len(stdout) == 0 do result.file_path = strings.clone("")
|
|
else if stdout[len(stdout)-1] == '\n' do result.file_path = strings.clone(stdout[:len(stdout)-1])
|
|
else do result.file_path = strings.clone(string(stdout))
|
|
|
|
result.success = true
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
show_open_file_dialog_linux :: proc(
|
|
title: string,
|
|
filters: []File_Filter = {},
|
|
allow_multiple: bool = false
|
|
) -> (result: Result) {
|
|
result.success = false
|
|
process_desc: os2.Process_Desc
|
|
for command in OPEN_SINGLE_FILE_COMMANDS {
|
|
log.debug("attempting to use", command[0], "to get file path")
|
|
process_desc.command = command
|
|
|
|
state, stdout_bytes, stderr_bytes, err := os2.process_exec(process_desc, context.allocator)
|
|
if err == .Not_Exist {
|
|
log.debug("couldn't find", command[0])
|
|
continue
|
|
} else if err != nil {
|
|
log.error("error whilst getting filename: ", err)
|
|
return
|
|
}
|
|
|
|
stdout := string(stdout_bytes)
|
|
|
|
if len(stdout) == 0 do result.file_path = strings.clone("")
|
|
else if stdout[len(stdout)-1] == '\n' do result.file_path = strings.clone(stdout[:len(stdout)-1])
|
|
else do result.file_path = strings.clone(string(stdout))
|
|
|
|
result.success = true
|
|
}
|
|
|
|
return result
|
|
}
|
|
|