mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 17:22: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
|
flow(width: 1.0, fill: true) do
|
||||||
@game_path = edit_line "#{@game&.path}", fill: true, height: 1.0
|
@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
|
path = W3DHub.ask_file
|
||||||
@game_path.value = path if !path.empty? && File.exist?(path)
|
@game_path.value = path if !path.empty? && File.exist?(path)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -147,26 +147,16 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.ask_file(title: "Open File", filter: "*game*.exe")
|
def self.ask_file(title: "Open File", filter: "*game*.exe")
|
||||||
if W3DHub.unix?
|
result_ptr = LibUI.open_file(LIBUI_WINDOW)
|
||||||
# search for command
|
result = result_ptr.null? ? "" : result_ptr.to_s.gsub("\\", "/")
|
||||||
cmds = %w{ zenity matedialog qarma kdialog }
|
|
||||||
|
|
||||||
command = cmds.find do |cmd|
|
result
|
||||||
cmd if system("which #{cmd}")
|
end
|
||||||
end
|
|
||||||
|
|
||||||
path = case File.basename(command)
|
def self.ask_folder(title: "Open Folder")
|
||||||
when "zenity", "matedialog", "qarma"
|
result_ptr = LibUI.open_folder(window)
|
||||||
`#{command} --file-selection --title "#{title}" --file-filter "#{filter}"`
|
result = result_ptr.null? ? "" : result_ptr.to_s.gsub("\\", "/")
|
||||||
when "kdialog"
|
|
||||||
`#{command} --title "#{title}" --getopenfilename . "#{filter}"`
|
|
||||||
else
|
|
||||||
raise "No known command found for system file selection dialog!"
|
|
||||||
end
|
|
||||||
|
|
||||||
path.strip
|
result
|
||||||
else
|
|
||||||
raise NotImplementedError
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class W3DHub
|
|||||||
|
|
||||||
flow(width: 1.0, fill: true) do
|
flow(width: 1.0, fill: true) do
|
||||||
@game_path = edit_line "", fill: true, height: 1.0
|
@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
|
path = W3DHub.ask_file
|
||||||
@game_path.value = path if !path.empty? && File.exist?(path)
|
@game_path.value = path if !path.empty? && File.exist?(path)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ require "time"
|
|||||||
require "base64"
|
require "base64"
|
||||||
require "zip"
|
require "zip"
|
||||||
require "excon"
|
require "excon"
|
||||||
require "libui"
|
|
||||||
|
|
||||||
class W3DHub
|
class W3DHub
|
||||||
W3DHUB_DEBUG = ARGV.join.include?("--debug")
|
W3DHUB_DEBUG = ARGV.join.include?("--debug")
|
||||||
@@ -81,6 +80,15 @@ require "i18n"
|
|||||||
require "websocket-client-simple"
|
require "websocket-client-simple"
|
||||||
require "English"
|
require "English"
|
||||||
require "sdl2"
|
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.load_path << Dir["#{W3DHub::GAME_ROOT_PATH}/locales/*.yml"]
|
||||||
I18n.default_locale = :en
|
I18n.default_locale = :en
|
||||||
|
|||||||
Reference in New Issue
Block a user