Ducktape on libui for native file open dialogs

This commit is contained in:
2024-03-11 13:45:10 -05:00
parent c1ca3ec80e
commit 02307f1789
4 changed files with 19 additions and 21 deletions

View File

@@ -31,7 +31,7 @@ class W3DHub
flow(width: 1.0, fill: true) do
@game_path = edit_line "#{@game&.path}", fill: true, height: 1.0
button "Browse...", width: 128, height: 1.0, enabled: W3DHub.unix?, tip: W3DHub.unix? ? "Browse for game executable" : "Not available on Windows" do
button "Browse...", width: 128, height: 1.0, tip: "Browse for game executable" do
path = W3DHub.ask_file
@game_path.value = path if !path.empty? && File.exist?(path)
end

View File

@@ -147,26 +147,16 @@ class W3DHub
end
def self.ask_file(title: "Open File", filter: "*game*.exe")
if W3DHub.unix?
# search for command
cmds = %w{ zenity matedialog qarma kdialog }
result_ptr = LibUI.open_file(LIBUI_WINDOW)
result = result_ptr.null? ? "" : result_ptr.to_s.gsub("\\", "/")
command = cmds.find do |cmd|
cmd if system("which #{cmd}")
end
result
end
path = case File.basename(command)
when "zenity", "matedialog", "qarma"
`#{command} --file-selection --title "#{title}" --file-filter "#{filter}"`
when "kdialog"
`#{command} --title "#{title}" --getopenfilename . "#{filter}"`
else
raise "No known command found for system file selection dialog!"
end
def self.ask_folder(title: "Open Folder")
result_ptr = LibUI.open_folder(window)
result = result_ptr.null? ? "" : result_ptr.to_s.gsub("\\", "/")
path.strip
else
raise NotImplementedError
end
result
end
end

View File

@@ -26,7 +26,7 @@ class W3DHub
flow(width: 1.0, fill: true) do
@game_path = edit_line "", fill: true, height: 1.0
button "Browse...", width: 128, height: 1.0, enabled: W3DHub.unix?, tip: W3DHub.unix? ? "Browse for game executable" : "Not available on Windows" do
button "Browse...", width: 128, height: 1.0, tip: "Browse for game executable" do
path = W3DHub.ask_file
@game_path.value = path if !path.empty? && File.exist?(path)
end