mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 09:12:35 +00:00
Ducktape on libui for native file open dialogs
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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}")
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -15,7 +15,6 @@ require "time"
|
||||
require "base64"
|
||||
require "zip"
|
||||
require "excon"
|
||||
require "libui"
|
||||
|
||||
class W3DHub
|
||||
W3DHUB_DEBUG = ARGV.join.include?("--debug")
|
||||
@@ -81,6 +80,15 @@ require "i18n"
|
||||
require "websocket-client-simple"
|
||||
require "English"
|
||||
require "sdl2"
|
||||
require "libui"
|
||||
|
||||
# Using a WHOLE ui library for: native file/folder open dialogs...
|
||||
LibUI.init
|
||||
LIBUI_WINDOW = LibUI.new_window("", 100, 100, 0)
|
||||
at_exit do
|
||||
LibUI.control_destroy(LIBUI_WINDOW)
|
||||
LibUI.uninit
|
||||
end
|
||||
|
||||
I18n.load_path << Dir["#{W3DHub::GAME_ROOT_PATH}/locales/*.yml"]
|
||||
I18n.default_locale = :en
|
||||
|
||||
Reference in New Issue
Block a user