dialogbind 0.9.3 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/dialogbind.rb +263 -110
 - metadata +7 -7
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 15db92bd3bcd2c1f15e7dd00f4f643f0e3cf967e0c4ca6822fd51bba303a9c37
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 0d7f0743dbd44377eed925c1927eb61d85b99ac8d9677341cb407917759cc979
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 3a05bba5157559fe28498d1ea90757f84e21dcf37405331be852d31cb7b9c5f950eaa19ada11ad36a4ad2588af89b1b26e76b6802a13a97b8c8b6069bd0b4ab6
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 501746e21d415a8e7a9b97677e337e13222631bc9792fc0bbf281394cb4127a4f726f6445671b9410511f03606b7986d9fa903b6f469f689bc68bda20efe9c15
         
     | 
    
        data/lib/dialogbind.rb
    CHANGED
    
    | 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #!/usr/bin/env ruby
         
     | 
| 
       2 
2 
     | 
    
         
             
            # DialogBind - a simple library wrapping around message box displaying
         
     | 
| 
       3 
     | 
    
         
            -
            # tools on Linux ( 
     | 
| 
      
 3 
     | 
    
         
            +
            # tools on Linux (zenity and kdialog), macOS and Windows
         
     | 
| 
       4 
4 
     | 
    
         
             
            #
         
     | 
| 
       5 
5 
     | 
    
         
             
            # Copyright (C) Tim K 2018-2019 <timprogrammer@rambler.ru>.
         
     | 
| 
       6 
6 
     | 
    
         
             
            # Licensed under MIT License.
         
     | 
| 
         @@ -8,17 +8,18 @@ 
     | 
|
| 
       8 
8 
     | 
    
         
             
            require 'fiddle/import'
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
            $dialogbind_macos_script_cmd = ''
         
     | 
| 
       11 
     | 
    
         
            -
            $dialogbind_version = '0.9. 
     | 
| 
      
 11 
     | 
    
         
            +
            $dialogbind_version = '0.9.4'
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
            #  
     | 
| 
      
 13 
     | 
    
         
            +
            # @!visibility private
         
     | 
| 
       14 
14 
     | 
    
         
             
            def zenity(arg)
         
     | 
| 
       15 
15 
     | 
    
         
             
            	args_total = ''
         
     | 
| 
       16 
16 
     | 
    
         
             
            	arg.keys.each do |key|
         
     | 
| 
      
 17 
     | 
    
         
            +
            		key_o = key
         
     | 
| 
       17 
18 
     | 
    
         
             
            		if key[-1] == '%' then
         
     | 
| 
       18 
     | 
    
         
            -
            			 
     | 
| 
      
 19 
     | 
    
         
            +
            			key_o = key.gsub('%', '')
         
     | 
| 
       19 
20 
     | 
    
         
             
            		end
         
     | 
| 
       20 
21 
     | 
    
         
             
            		if arg[key] == nil then
         
     | 
| 
       21 
     | 
    
         
            -
            			args_total += '--' +  
     | 
| 
      
 22 
     | 
    
         
            +
            			args_total += '--' + key_o
         
     | 
| 
       22 
23 
     | 
    
         
             
            		elsif arg[key].instance_of? Array then
         
     | 
| 
       23 
24 
     | 
    
         
             
            			arg[key].each do |nested_key|
         
     | 
| 
       24 
25 
     | 
    
         
             
            				if nested_key != nil then
         
     | 
| 
         @@ -26,68 +27,35 @@ def zenity(arg) 
     | 
|
| 
       26 
27 
     | 
    
         
             
            				end
         
     | 
| 
       27 
28 
     | 
    
         
             
            			end
         
     | 
| 
       28 
29 
     | 
    
         
             
            		else
         
     | 
| 
       29 
     | 
    
         
            -
            			args_total += '--' +  
     | 
| 
      
 30 
     | 
    
         
            +
            			args_total += '--' + key_o + "='" + arg[key].to_s.gsub("'", '"') + "'"
         
     | 
| 
       30 
31 
     | 
    
         
             
            		end
         
     | 
| 
       31 
32 
     | 
    
         
             
            		args_total += ' '
         
     | 
| 
       32 
33 
     | 
    
         
             
            	end
         
     | 
| 
       33 
34 
     | 
    
         
             
            	return system('zenity ' + args_total)
         
     | 
| 
       34 
35 
     | 
    
         
             
            end
         
     | 
| 
       35 
36 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
            #  
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
            	 
     | 
| 
       39 
     | 
    
         
            -
            	 
     | 
| 
       40 
     | 
    
         
            -
            		 
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
            		 
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
            		typealias 'UINT', 'unsigned int'
         
     | 
| 
       48 
     | 
    
         
            -
            		typealias 'BOOL', 'int'
         
     | 
| 
       49 
     | 
    
         
            -
            		typealias 'HMODULE', 'void*'
         
     | 
| 
       50 
     | 
    
         
            -
            		typealias 'DWORD', 'unsigned long'
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
            		extern 'int MessageBox(HWND, LPCSTR, LPCSTR, UINT)'
         
     | 
| 
       53 
     | 
    
         
            -
            		extern 'BOOL PlaySound(LPCTSTR, HMODULE, DWORD)'
         
     | 
| 
       54 
     | 
    
         
            -
            	else
         
     | 
| 
       55 
     | 
    
         
            -
            		def MessageBox(arg1, arg2, arg3, arg4)
         
     | 
| 
       56 
     | 
    
         
            -
            			return
         
     | 
| 
       57 
     | 
    
         
            -
            		end
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
            		def PlaySound(arg1, arg2, arg3)
         
     | 
| 
       60 
     | 
    
         
            -
            			return 1
         
     | 
| 
       61 
     | 
    
         
            -
            		end
         
     | 
| 
       62 
     | 
    
         
            -
            	end
         
     | 
| 
       63 
     | 
    
         
            -
            end
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
            # Function used internally in DialogBind to run Win32 MessageBoxA from Ruby code. Please do not use this function directly as its API and behaviour might change in any release.
         
     | 
| 
       66 
     | 
    
         
            -
            def win32_msgbox(text, title='DialogBind', buttons=0)
         
     | 
| 
       67 
     | 
    
         
            -
            	return Win32NativeBindings::MessageBox(nil, text, title, buttons)
         
     | 
| 
       68 
     | 
    
         
            -
            end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
            # Function used internally in DialogBind to run XMessage from Ruby code. Please do not use this function directly as its API and behaviour might change in any release.
         
     | 
| 
       71 
     | 
    
         
            -
            def xmessage(arg, buttons={ 'OK' => 0 }, file=false)
         
     | 
| 
       72 
     | 
    
         
            -
            	build_cmd = 'xmessage -center -buttons "'
         
     | 
| 
       73 
     | 
    
         
            -
            	first = true
         
     | 
| 
       74 
     | 
    
         
            -
            	buttons.keys.each do |button|
         
     | 
| 
       75 
     | 
    
         
            -
            		if first then
         
     | 
| 
       76 
     | 
    
         
            -
            			first = false
         
     | 
| 
      
 37 
     | 
    
         
            +
            # @!visibility private
         
     | 
| 
      
 38 
     | 
    
         
            +
            def kdialog(arg, redirect_output=false)
         
     | 
| 
      
 39 
     | 
    
         
            +
            	args_total = ''
         
     | 
| 
      
 40 
     | 
    
         
            +
            	arg.keys.each do |key|
         
     | 
| 
      
 41 
     | 
    
         
            +
            		if arg[key].instance_of? Array then
         
     | 
| 
      
 42 
     | 
    
         
            +
            			args_total += '--' + key + ' '
         
     | 
| 
      
 43 
     | 
    
         
            +
            			arg[key].each do |instance_item|
         
     | 
| 
      
 44 
     | 
    
         
            +
            				args_total += "'" + instance_item.to_s.gsub("'", '"') + "' "
         
     | 
| 
      
 45 
     | 
    
         
            +
            			end
         
     | 
| 
      
 46 
     | 
    
         
            +
            		elsif arg[key] != nil then
         
     | 
| 
      
 47 
     | 
    
         
            +
            			args_total += '--' + key + " '" + arg[key].to_s.gsub("'", '"') + "' "
         
     | 
| 
       77 
48 
     | 
    
         
             
            		else
         
     | 
| 
       78 
     | 
    
         
            -
            			 
     | 
| 
      
 49 
     | 
    
         
            +
            			args_total += key
         
     | 
| 
       79 
50 
     | 
    
         
             
            		end
         
     | 
| 
       80 
     | 
    
         
            -
            		build_cmd += button.gsub('"', '') + ':' + buttons[button].to_s
         
     | 
| 
       81 
51 
     | 
    
         
             
            	end
         
     | 
| 
       82 
     | 
    
         
            -
            	 
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
            		build_cmd += '-file '
         
     | 
| 
      
 52 
     | 
    
         
            +
            	if redirect_output then
         
     | 
| 
      
 53 
     | 
    
         
            +
            		args_total += ' > /tmp/kdialog.sock 2>/dev/null'
         
     | 
| 
       85 
54 
     | 
    
         
             
            	end
         
     | 
| 
       86 
     | 
    
         
            -
            	 
     | 
| 
       87 
     | 
    
         
            -
            	return system(build_cmd)
         
     | 
| 
      
 55 
     | 
    
         
            +
            	return system('kdialog ' + args_total)
         
     | 
| 
       88 
56 
     | 
    
         
             
            end
         
     | 
| 
       89 
57 
     | 
    
         | 
| 
       90 
     | 
    
         
            -
            #  
     | 
| 
      
 58 
     | 
    
         
            +
            # @!visibility private
         
     | 
| 
       91 
59 
     | 
    
         
             
            def macdialog(text, buttons=['OK'], type='dialog', error=false, dryrun=false)
         
     | 
| 
       92 
60 
     | 
    
         
             
            	text_fixed = text.gsub("!", "").gsub("'", '').gsub('"', '').gsub('$', '')
         
     | 
| 
       93 
61 
     | 
    
         
             
            	cmd = "osascript -e 'tell app \"System Events\" to display " + type + ' "' + text_fixed + '"'
         
     | 
| 
         @@ -107,13 +75,62 @@ def macdialog(text, buttons=['OK'], type='dialog', error=false, dryrun=false) 
     | 
|
| 
       107 
75 
     | 
    
         
             
            	return false
         
     | 
| 
       108 
76 
     | 
    
         
             
            end
         
     | 
| 
       109 
77 
     | 
    
         | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
      
 78 
     | 
    
         
            +
            # @!visibility private
         
     | 
| 
      
 79 
     | 
    
         
            +
            def macopen(text, ftype=[], folder=false)
         
     | 
| 
      
 80 
     | 
    
         
            +
            	text_fixed = text.gsub("!", "").gsub("'", '').gsub('"', '').gsub('$', '')
         
     | 
| 
      
 81 
     | 
    
         
            +
            	type = 'file'
         
     | 
| 
      
 82 
     | 
    
         
            +
            	if folder then
         
     | 
| 
      
 83 
     | 
    
         
            +
            		type = 'folder'
         
     | 
| 
      
 84 
     | 
    
         
            +
            	end
         
     | 
| 
      
 85 
     | 
    
         
            +
            	cmd = "osascript -e 'tell app \"System Events\" to choose " + type + ' with prompt "' + text_fixed + "\""
         
     | 
| 
      
 86 
     | 
    
         
            +
            	if ftype.length > 0 then
         
     | 
| 
      
 87 
     | 
    
         
            +
            		cmd += ' of type { '
         
     | 
| 
      
 88 
     | 
    
         
            +
            		ftype.each do |extension|
         
     | 
| 
      
 89 
     | 
    
         
            +
            			extension_real = extension.downcase
         
     | 
| 
      
 90 
     | 
    
         
            +
            			if extension_real.include? '.' then
         
     | 
| 
      
 91 
     | 
    
         
            +
            				extension_real = extension_real.split('.')[-1]
         
     | 
| 
      
 92 
     | 
    
         
            +
            			end
         
     | 
| 
      
 93 
     | 
    
         
            +
            			cmd += '"' + extension_real + '", '
         
     | 
| 
      
 94 
     | 
    
         
            +
            		end
         
     | 
| 
      
 95 
     | 
    
         
            +
            		cmd += '"*" }'
         
     | 
| 
      
 96 
     | 
    
         
            +
            	end
         
     | 
| 
      
 97 
     | 
    
         
            +
            	cmd += "'"
         
     | 
| 
      
 98 
     | 
    
         
            +
            	cmd_output = `#{cmd} | cut -d ' ' -f2- | sed 's+:+/+g'`
         
     | 
| 
      
 99 
     | 
    
         
            +
            	cmd_output.gsub!("\n", "")
         
     | 
| 
      
 100 
     | 
    
         
            +
            	cmd_output = '/Volumes/' + cmd_output.clone
         
     | 
| 
      
 101 
     | 
    
         
            +
            	if cmd_output == '/Volumes/' then
         
     | 
| 
      
 102 
     | 
    
         
            +
            		return ''
         
     | 
| 
      
 103 
     | 
    
         
            +
            	end
         
     | 
| 
      
 104 
     | 
    
         
            +
            	return cmd_output
         
     | 
| 
      
 105 
     | 
    
         
            +
            end
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
            # @!visibility private
         
     | 
| 
      
 108 
     | 
    
         
            +
            def macselect(items, text)
         
     | 
| 
      
 109 
     | 
    
         
            +
            	cmd = 'osascript -e \'tell app "System Events" to choose from list ' + items.to_s.gsub('[', '{').gsub(']', '}').gsub("'", '')
         
     | 
| 
      
 110 
     | 
    
         
            +
            	cmd += ' with prompt "' + text + '"\''
         
     | 
| 
      
 111 
     | 
    
         
            +
            	cmd_output = `#{cmd}`.gsub("\n", "")
         
     | 
| 
      
 112 
     | 
    
         
            +
            	if cmd_output == 'false' then
         
     | 
| 
      
 113 
     | 
    
         
            +
            		return nil
         
     | 
| 
      
 114 
     | 
    
         
            +
            	end
         
     | 
| 
      
 115 
     | 
    
         
            +
            	return cmd_output
         
     | 
| 
      
 116 
     | 
    
         
            +
            end
         
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
            # @!visibility private
         
     | 
| 
      
 119 
     | 
    
         
            +
            def macentry(text)
         
     | 
| 
      
 120 
     | 
    
         
            +
            	cmd = "osascript -e 'display dialog \"" + text.gsub('"', '').gsub("'", '').gsub('!', '') + "\" default answer \"\" with icon note' | cut -d ':' -f3-"
         
     | 
| 
      
 121 
     | 
    
         
            +
            	return `#{cmd}`.gsub("\n", "")
         
     | 
| 
      
 122 
     | 
    
         
            +
            end
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
            $dialogbind_available_backends = [ 'cli', 'zenity', 'kdialog', 'macos', 'win32' ]
         
     | 
| 
      
 125 
     | 
    
         
            +
            $dialogbind_dialog_backend = 'cli'
         
     | 
| 
       112 
126 
     | 
    
         | 
| 
       113 
     | 
    
         
            -
            if system('command -v  
     | 
| 
      
 127 
     | 
    
         
            +
            if system('command -v kdialog > /dev/null 2>&1') && ENV.keys.include?('KDE_SESSION_VERSION') then
         
     | 
| 
      
 128 
     | 
    
         
            +
            	$dialogbind_dialog_backend = 'kdialog'
         
     | 
| 
      
 129 
     | 
    
         
            +
            elsif system('command -v zenity > /dev/null 2>&1') then
         
     | 
| 
       114 
130 
     | 
    
         
             
            	$dialogbind_dialog_backend = 'zenity'
         
     | 
| 
       115 
131 
     | 
    
         
             
            elsif ENV.keys.include?('OS') && ENV['OS'] == 'Windows_NT' then
         
     | 
| 
       116 
132 
     | 
    
         
             
            	$dialogbind_dialog_backend = 'win32'
         
     | 
| 
      
 133 
     | 
    
         
            +
            	require 'win32ole'
         
     | 
| 
       117 
134 
     | 
    
         
             
            elsif `uname`.gsub("\n", "") == 'Darwin' then
         
     | 
| 
       118 
135 
     | 
    
         
             
            	$dialogbind_dialog_backend = 'macos'
         
     | 
| 
       119 
136 
     | 
    
         
             
            end
         
     | 
| 
         @@ -125,18 +142,107 @@ if $dialogbind_available_backends.include?($dialogbind_dialog_backend) == false 
     | 
|
| 
       125 
142 
     | 
    
         
             
            	raise 'Dialog backend "' + $dialogbind_dialog_backend + '" is not available. Available frontends: ' + $dialogbind_available_backends.join(', ')
         
     | 
| 
       126 
143 
     | 
    
         
             
            end
         
     | 
| 
       127 
144 
     | 
    
         | 
| 
      
 145 
     | 
    
         
            +
            # @!visibility private
         
     | 
| 
      
 146 
     | 
    
         
            +
            module Win32NativeBindings
         
     | 
| 
      
 147 
     | 
    
         
            +
            	# based on https://gist.github.com/Youka/3ebbdfd03454afa7d0c4
         
     | 
| 
      
 148 
     | 
    
         
            +
            	if $dialogbind_dialog_backend == 'win32' then
         
     | 
| 
      
 149 
     | 
    
         
            +
            		extend Fiddle::Importer
         
     | 
| 
      
 150 
     | 
    
         
            +
             
     | 
| 
      
 151 
     | 
    
         
            +
            		dlload 'user32'
         
     | 
| 
      
 152 
     | 
    
         
            +
            		typealias 'HANDLE', 'void*'
         
     | 
| 
      
 153 
     | 
    
         
            +
            		typealias 'HWND', 'HANDLE'
         
     | 
| 
      
 154 
     | 
    
         
            +
            		typealias 'LPCSTR', 'const char*'
         
     | 
| 
      
 155 
     | 
    
         
            +
            		typealias 'UINT', 'unsigned int'
         
     | 
| 
      
 156 
     | 
    
         
            +
             
     | 
| 
      
 157 
     | 
    
         
            +
            		extern 'int MessageBox(HWND, LPCSTR, LPCSTR, UINT)'
         
     | 
| 
      
 158 
     | 
    
         
            +
            	else
         
     | 
| 
      
 159 
     | 
    
         
            +
            		def MessageBox(arg1, arg2, arg3, arg4)
         
     | 
| 
      
 160 
     | 
    
         
            +
            			return
         
     | 
| 
      
 161 
     | 
    
         
            +
            		end
         
     | 
| 
      
 162 
     | 
    
         
            +
            	end
         
     | 
| 
      
 163 
     | 
    
         
            +
            end
         
     | 
| 
      
 164 
     | 
    
         
            +
             
     | 
| 
      
 165 
     | 
    
         
            +
            if $dialogbind_dialog_backend == 'win32' then
         
     | 
| 
      
 166 
     | 
    
         
            +
            	# @!visibility private
         
     | 
| 
      
 167 
     | 
    
         
            +
            	def win32_msgbox(text, title='DialogBind', buttons=0)
         
     | 
| 
      
 168 
     | 
    
         
            +
            		return Win32NativeBindings.MessageBox(nil, text, title, buttons)
         
     | 
| 
      
 169 
     | 
    
         
            +
            	end
         
     | 
| 
      
 170 
     | 
    
         
            +
             
     | 
| 
      
 171 
     | 
    
         
            +
            	# @!visibility private
         
     | 
| 
      
 172 
     | 
    
         
            +
            	def win32_activexplay(path)
         
     | 
| 
      
 173 
     | 
    
         
            +
            		player = WIN32OLE.new('WMPlayer.OCX')
         
     | 
| 
      
 174 
     | 
    
         
            +
            		player.OpenPlayer(sound_path)
         
     | 
| 
      
 175 
     | 
    
         
            +
            	end
         
     | 
| 
      
 176 
     | 
    
         
            +
             
     | 
| 
      
 177 
     | 
    
         
            +
            	# @!visibility private
         
     | 
| 
      
 178 
     | 
    
         
            +
            	def win32_generatevbs(write_out)
         
     | 
| 
      
 179 
     | 
    
         
            +
            		tmpfile_loc = ENV['TEMP'].gsub("\\", "/") + '/dialogbind_vbs_ibox' + rand(9999).to_s + '.vbs'
         
     | 
| 
      
 180 
     | 
    
         
            +
            		if File.exists? tmpfile_loc then
         
     | 
| 
      
 181 
     | 
    
         
            +
            			File.delete(tmpfile_loc)
         
     | 
| 
      
 182 
     | 
    
         
            +
            		end
         
     | 
| 
      
 183 
     | 
    
         
            +
            		File.write(tmpfile_loc, write_out)
         
     | 
| 
      
 184 
     | 
    
         
            +
            		tmpfile_loc_w = tmpfile_loc.gsub('/', "\\")
         
     | 
| 
      
 185 
     | 
    
         
            +
            		cmd_out = `cscript //Nologo "#{tmpfile_loc_w}"`.gsub("\r\n", "")
         
     | 
| 
      
 186 
     | 
    
         
            +
            		File.delete(tmpfile_loc)
         
     | 
| 
      
 187 
     | 
    
         
            +
            		return cmd_out
         
     | 
| 
      
 188 
     | 
    
         
            +
            	end
         
     | 
| 
      
 189 
     | 
    
         
            +
             
     | 
| 
      
 190 
     | 
    
         
            +
            	# @!visibility private
         
     | 
| 
      
 191 
     | 
    
         
            +
            	def win32_vbinputbox(text)
         
     | 
| 
      
 192 
     | 
    
         
            +
            		write_out = 'a = inputbox("' + text.gsub('"', '') + '")'
         
     | 
| 
      
 193 
     | 
    
         
            +
            		write_out += "\r\nWScript.Echo a"
         
     | 
| 
      
 194 
     | 
    
         
            +
            		return win32_generatevbs(write_out)
         
     | 
| 
      
 195 
     | 
    
         
            +
            	end
         
     | 
| 
      
 196 
     | 
    
         
            +
             
     | 
| 
      
 197 
     | 
    
         
            +
            	# @!visibility private
         
     | 
| 
      
 198 
     | 
    
         
            +
            	def win32_activexopen(filters, title)
         
     | 
| 
      
 199 
     | 
    
         
            +
            		filters_str = ''
         
     | 
| 
      
 200 
     | 
    
         
            +
            		filters.each do |filter_pattern|
         
     | 
| 
      
 201 
     | 
    
         
            +
            			to_append = 'Files matching pattern ' + filter_pattern + '|' + filter_pattern
         
     | 
| 
      
 202 
     | 
    
         
            +
            			if filters_str == '' then
         
     | 
| 
      
 203 
     | 
    
         
            +
            				filters_str = to_append
         
     | 
| 
      
 204 
     | 
    
         
            +
            			else
         
     | 
| 
      
 205 
     | 
    
         
            +
            				filters_str += '|' + to_append
         
     | 
| 
      
 206 
     | 
    
         
            +
            			end
         
     | 
| 
      
 207 
     | 
    
         
            +
            		end
         
     | 
| 
      
 208 
     | 
    
         
            +
            		generated_vbs = "fso=CreateObject(\"UserAccounts.CommonDialog\")\r\nfso.Filter=\"" + filters_str + "\"\r\n"
         
     | 
| 
      
 209 
     | 
    
         
            +
            		generated_vbs += "fso.FilterIndex=" + filters.length.to_s + "\r\nif fso.showOpen then\r\nWScript.Echo fso.fileName\r\nend if"
         
     | 
| 
      
 210 
     | 
    
         
            +
            		return win32_generatevbs(generated_vbs)
         
     | 
| 
      
 211 
     | 
    
         
            +
            	end
         
     | 
| 
      
 212 
     | 
    
         
            +
            else
         
     | 
| 
      
 213 
     | 
    
         
            +
            	# @!visibility private
         
     | 
| 
      
 214 
     | 
    
         
            +
            	def win32_activexopen(filters, title)
         
     | 
| 
      
 215 
     | 
    
         
            +
            		return ''
         
     | 
| 
      
 216 
     | 
    
         
            +
            	end
         
     | 
| 
      
 217 
     | 
    
         
            +
             
     | 
| 
      
 218 
     | 
    
         
            +
            	# @!visibility private
         
     | 
| 
      
 219 
     | 
    
         
            +
            	def win32_msgbox(text, title='DialogBind', buttons=0)
         
     | 
| 
      
 220 
     | 
    
         
            +
            		return -1
         
     | 
| 
      
 221 
     | 
    
         
            +
            	end
         
     | 
| 
      
 222 
     | 
    
         
            +
             
     | 
| 
      
 223 
     | 
    
         
            +
            	# @!visibility private
         
     | 
| 
      
 224 
     | 
    
         
            +
            	def win32_activexplay(path)
         
     | 
| 
      
 225 
     | 
    
         
            +
            		return
         
     | 
| 
      
 226 
     | 
    
         
            +
            	end
         
     | 
| 
      
 227 
     | 
    
         
            +
             
     | 
| 
      
 228 
     | 
    
         
            +
            	# @!visibility private
         
     | 
| 
      
 229 
     | 
    
         
            +
            	def win32_vbinputbox(text)
         
     | 
| 
      
 230 
     | 
    
         
            +
            		return ''
         
     | 
| 
      
 231 
     | 
    
         
            +
            	end
         
     | 
| 
      
 232 
     | 
    
         
            +
            end
         
     | 
| 
      
 233 
     | 
    
         
            +
             
     | 
| 
       128 
234 
     | 
    
         
             
            # Shows a simple message box (or information message box when using Zenity backend).
         
     | 
| 
       129 
235 
     | 
    
         
             
            #
         
     | 
| 
       130 
236 
     | 
    
         
             
            # @param text [String] the text that should be displayed in a message box
         
     | 
| 
       131 
237 
     | 
    
         
             
            # @param title [String] an optional parameter specifying the title of the message box. Ignored on macOS.
         
     | 
| 
       132 
238 
     | 
    
         
             
            # @return [Boolean] true on success, false if something went wrong
         
     | 
| 
       133 
239 
     | 
    
         
             
            def guiputs(text, title='DialogBind')
         
     | 
| 
       134 
     | 
    
         
            -
            	if $dialogbind_dialog_backend == ' 
     | 
| 
       135 
     | 
    
         
            -
            		return xmessage(text, { 'OK' => 0 })
         
     | 
| 
       136 
     | 
    
         
            -
            	elsif $dialogbind_dialog_backend == 'zenity' then
         
     | 
| 
      
 240 
     | 
    
         
            +
            	if $dialogbind_dialog_backend == 'zenity' then
         
     | 
| 
       137 
241 
     | 
    
         
             
            		return zenity({ 'info' => nil, 'title' => title, 'text' => text })
         
     | 
| 
       138 
242 
     | 
    
         
             
            	elsif $dialogbind_dialog_backend == 'macos' then
         
     | 
| 
       139 
243 
     | 
    
         
             
            		return macdialog(text)
         
     | 
| 
      
 244 
     | 
    
         
            +
            	elsif $dialogbind_dialog_backend == 'kdialog' then
         
     | 
| 
      
 245 
     | 
    
         
            +
            		return kdialog({ 'title' => title, 'msgbox' => text })
         
     | 
| 
       140 
246 
     | 
    
         
             
            	elsif $dialogbind_dialog_backend == 'win32' then
         
     | 
| 
       141 
247 
     | 
    
         
             
            		win32_msgbox(text, title, 0)
         
     | 
| 
       142 
248 
     | 
    
         
             
            		return true
         
     | 
| 
         @@ -153,9 +259,7 @@ end 
     | 
|
| 
       153 
259 
     | 
    
         
             
            # @param title [String] an optional parameter specifying the title of the message box. Ignored on macOS.
         
     | 
| 
       154 
260 
     | 
    
         
             
            # @return [Boolean] true if the user presses yes, false if the user pressed no
         
     | 
| 
       155 
261 
     | 
    
         
             
            def guiyesno(text, title='DialogBind')
         
     | 
| 
       156 
     | 
    
         
            -
            	if $dialogbind_dialog_backend == ' 
     | 
| 
       157 
     | 
    
         
            -
            		return xmessage(text, { 'Yes' => 0, 'No' => 1})
         
     | 
| 
       158 
     | 
    
         
            -
            	elsif $dialogbind_dialog_backend == 'zenity' then
         
     | 
| 
      
 262 
     | 
    
         
            +
            	if $dialogbind_dialog_backend == 'zenity' then
         
     | 
| 
       159 
263 
     | 
    
         
             
            		return zenity('question' => nil, 'title' => title, 'text' => text)
         
     | 
| 
       160 
264 
     | 
    
         
             
            	elsif $dialogbind_dialog_backend == 'macos' then
         
     | 
| 
       161 
265 
     | 
    
         
             
            		macdialog(text, [ 'Yes', 'No' ], 'dialog', false, true)
         
     | 
| 
         @@ -166,6 +270,8 @@ def guiyesno(text, title='DialogBind') 
     | 
|
| 
       166 
270 
     | 
    
         
             
            		if output.split(':')[1].downcase == 'yes' then
         
     | 
| 
       167 
271 
     | 
    
         
             
            			return true
         
     | 
| 
       168 
272 
     | 
    
         
             
            		end
         
     | 
| 
      
 273 
     | 
    
         
            +
            	elsif $dialogbind_dialog_backend == 'kdialog' then
         
     | 
| 
      
 274 
     | 
    
         
            +
            		return kdialog({ 'title' => title, 'yesno' => text })
         
     | 
| 
       169 
275 
     | 
    
         
             
            	elsif $dialogbind_dialog_backend == 'win32' then
         
     | 
| 
       170 
276 
     | 
    
         
             
            		retv_msgbox = win32_msgbox(text, title, 36)
         
     | 
| 
       171 
277 
     | 
    
         
             
            		return (retv_msgbox == 6)
         
     | 
| 
         @@ -181,12 +287,12 @@ end 
     | 
|
| 
       181 
287 
     | 
    
         
             
            # @param title [String] an optional parameter specifying the title of the message box. Ignored on macOS.
         
     | 
| 
       182 
288 
     | 
    
         
             
            # @return [Boolean] true on success, false if something went wrong
         
     | 
| 
       183 
289 
     | 
    
         
             
            def guierror(text, title='DialogBind')
         
     | 
| 
       184 
     | 
    
         
            -
            	if $dialogbind_dialog_backend == ' 
     | 
| 
       185 
     | 
    
         
            -
            		return xmessage('ERROR. ' + text, { 'OK' => 0 })
         
     | 
| 
       186 
     | 
    
         
            -
            	elsif $dialogbind_dialog_backend == 'zenity' then
         
     | 
| 
      
 290 
     | 
    
         
            +
            	if $dialogbind_dialog_backend == 'zenity' then
         
     | 
| 
       187 
291 
     | 
    
         
             
            		return zenity('error' => nil, 'title' => title, 'text' => text)
         
     | 
| 
       188 
292 
     | 
    
         
             
            	elsif $dialogbind_dialog_backend == 'macos' then
         
     | 
| 
       189 
293 
     | 
    
         
             
            		return macdialog(text, [ 'OK' ], 'dialog', true)
         
     | 
| 
      
 294 
     | 
    
         
            +
            	elsif $dialogbind_dialog_backend == 'kdialog' then
         
     | 
| 
      
 295 
     | 
    
         
            +
            		return kdialog({ 'title' => title, 'error' => text })
         
     | 
| 
       190 
296 
     | 
    
         
             
            	elsif $dialogbind_dialog_backend == 'win32' then
         
     | 
| 
       191 
297 
     | 
    
         
             
            		return win32_msgbox(text, title, 16)
         
     | 
| 
       192 
298 
     | 
    
         
             
            	else
         
     | 
| 
         @@ -195,26 +301,6 @@ def guierror(text, title='DialogBind') 
     | 
|
| 
       195 
301 
     | 
    
         
             
            	return false
         
     | 
| 
       196 
302 
     | 
    
         
             
            end
         
     | 
| 
       197 
303 
     | 
    
         | 
| 
       198 
     | 
    
         
            -
            # Shows either a buttonless message box with the specified text or a progress message box with the specified text. Does not work on Windows.
         
     | 
| 
       199 
     | 
    
         
            -
            # This function is not async, just like all other functions, so you should actually start it in a seperate thread.
         
     | 
| 
       200 
     | 
    
         
            -
            #
         
     | 
| 
       201 
     | 
    
         
            -
            # @param text [String] the text that should be displayed in a message box
         
     | 
| 
       202 
     | 
    
         
            -
            # @param title [String] an optional parameter specifying the title of the message box. Ignored on macOS.
         
     | 
| 
       203 
     | 
    
         
            -
            # @return [Boolean] true on success, false if something went wrong
         
     | 
| 
       204 
     | 
    
         
            -
            def guiprogress(text='Please wait...', title='DialogBind')
         
     | 
| 
       205 
     | 
    
         
            -
            	if $dialogbind_dialog_backend == 'xmessage' then
         
     | 
| 
       206 
     | 
    
         
            -
            		return xmessage(text, { })
         
     | 
| 
       207 
     | 
    
         
            -
            	elsif $dialogbind_dialog_backend == 'zenity' then
         
     | 
| 
       208 
     | 
    
         
            -
            		return zenity({ 'progress' => nil, 'title' => title, 'text' => text, 'no-cancel' => nil, 'percentage' => 2, 'pulsate' => nil })
         
     | 
| 
       209 
     | 
    
         
            -
            	elsif $dialogbind_dialog_backend == 'macos' then
         
     | 
| 
       210 
     | 
    
         
            -
            		return macdialog(text, [], 'notification', false)
         
     | 
| 
       211 
     | 
    
         
            -
            	else
         
     | 
| 
       212 
     | 
    
         
            -
            		raise 'The selected backend does not support progress message boxes.'
         
     | 
| 
       213 
     | 
    
         
            -
            		return false
         
     | 
| 
       214 
     | 
    
         
            -
            	end
         
     | 
| 
       215 
     | 
    
         
            -
            	return false
         
     | 
| 
       216 
     | 
    
         
            -
            end
         
     | 
| 
       217 
     | 
    
         
            -
             
     | 
| 
       218 
304 
     | 
    
         
             
            # Shows a message box containing the license agreement that is stored in the specified file.
         
     | 
| 
       219 
305 
     | 
    
         
             
            #
         
     | 
| 
       220 
306 
     | 
    
         
             
            # @param file [String] the file that contains the licensing terms
         
     | 
| 
         @@ -225,9 +311,7 @@ def guilicense(file, title='DialogBind') 
     | 
|
| 
       225 
311 
     | 
    
         
             
            		guierror('File "' + file + '" does not exist.', title)
         
     | 
| 
       226 
312 
     | 
    
         
             
            		return false
         
     | 
| 
       227 
313 
     | 
    
         
             
            	end
         
     | 
| 
       228 
     | 
    
         
            -
            	if $dialogbind_dialog_backend == ' 
     | 
| 
       229 
     | 
    
         
            -
            		return xmessage(file, { 'Accept' => 0, 'Decline' => 1 }, true)
         
     | 
| 
       230 
     | 
    
         
            -
            	elsif $dialogbind_dialog_backend == 'zenity' then
         
     | 
| 
      
 314 
     | 
    
         
            +
            	if $dialogbind_dialog_backend == 'zenity' then
         
     | 
| 
       231 
315 
     | 
    
         
             
            		return zenity({ 'text-info' => nil, 'title' => title, 'filename' => file, 'checkbox' => 'I have read and accepted the terms of the license agreement.' })
         
     | 
| 
       232 
316 
     | 
    
         
             
            	elsif $dialogbind_dialog_backend == 'macos' then
         
     | 
| 
       233 
317 
     | 
    
         
             
            		macdialog('Right now, the license agreement will be shown in TextEdit. Close TextEdit using Command-Q to continue,', ['OK'])
         
     | 
| 
         @@ -236,6 +320,12 @@ def guilicense(file, title='DialogBind') 
     | 
|
| 
       236 
320 
     | 
    
         
             
            	elsif $dialogbind_dialog_backend == 'win32' then
         
     | 
| 
       237 
321 
     | 
    
         
             
            		retv_msgbox = win32_msgbox("Do you accept the terms of the license agreement below?\n\n" + File.read(file), title, 36)
         
     | 
| 
       238 
322 
     | 
    
         
             
            		return (retv_msgbox == 6)
         
     | 
| 
      
 323 
     | 
    
         
            +
            	elsif $dialogbind_dialog_backend == 'kdialog' then
         
     | 
| 
      
 324 
     | 
    
         
            +
            		kdialog({ 'textbox' => file, 'title' => title })
         
     | 
| 
      
 325 
     | 
    
         
            +
            		if kdialog({ 'yesno' => 'Do you accept the terms of the license agreement?', 'title' => title }) then
         
     | 
| 
      
 326 
     | 
    
         
            +
            			return true
         
     | 
| 
      
 327 
     | 
    
         
            +
            		end
         
     | 
| 
      
 328 
     | 
    
         
            +
            		return false
         
     | 
| 
       239 
329 
     | 
    
         
             
            	else
         
     | 
| 
       240 
330 
     | 
    
         
             
            		raise 'The selected backend does not support license message boxes.'
         
     | 
| 
       241 
331 
     | 
    
         
             
            		return false
         
     | 
| 
         @@ -243,6 +333,7 @@ def guilicense(file, title='DialogBind') 
     | 
|
| 
       243 
333 
     | 
    
         
             
            	return false
         
     | 
| 
       244 
334 
     | 
    
         
             
            end
         
     | 
| 
       245 
335 
     | 
    
         | 
| 
      
 336 
     | 
    
         
            +
            # @!visibility private
         
     | 
| 
       246 
337 
     | 
    
         
             
            def entry2buttonshash(entries)
         
     | 
| 
       247 
338 
     | 
    
         
             
            	hash = {}
         
     | 
| 
       248 
339 
     | 
    
         
             
            	count = 0
         
     | 
| 
         @@ -260,33 +351,38 @@ end 
     | 
|
| 
       260 
351 
     | 
    
         
             
            # @param title [String] an optional parameter specifying the title of the message box. Ignored on macOS.
         
     | 
| 
       261 
352 
     | 
    
         
             
            # @return [String] the selected string or nil on cancel
         
     | 
| 
       262 
353 
     | 
    
         
             
            def guiselect(entries, text='Choose one of the items below:', title='DialogBind')
         
     | 
| 
       263 
     | 
    
         
            -
            	if  
     | 
| 
       264 
     | 
    
         
            -
            		 
     | 
| 
       265 
     | 
    
         
            -
             
     | 
| 
       266 
     | 
    
         
            -
             
     | 
| 
       267 
     | 
    
         
            -
             
     | 
| 
       268 
     | 
    
         
            -
            			 
     | 
| 
       269 
     | 
    
         
            -
             
     | 
| 
       270 
     | 
    
         
            -
            			return entries[1]
         
     | 
| 
       271 
     | 
    
         
            -
            		end
         
     | 
| 
       272 
     | 
    
         
            -
            	elsif $dialogbind_dialog_backend == 'zenity' then
         
     | 
| 
       273 
     | 
    
         
            -
            		array_of_items = [0, entries[0], nil, nil]
         
     | 
| 
       274 
     | 
    
         
            -
            		if entries.length > 1 then
         
     | 
| 
       275 
     | 
    
         
            -
            			array_of_items[2] = 1
         
     | 
| 
       276 
     | 
    
         
            -
            			array_of_items[3] = entries[1]
         
     | 
| 
      
 354 
     | 
    
         
            +
            	if $dialogbind_dialog_backend == 'zenity' then
         
     | 
| 
      
 355 
     | 
    
         
            +
            		array_of_items = []
         
     | 
| 
      
 356 
     | 
    
         
            +
            		item_count_zenity = 0
         
     | 
| 
      
 357 
     | 
    
         
            +
            		entries.each do |item|
         
     | 
| 
      
 358 
     | 
    
         
            +
            			array_of_items.push(item_count_zenity)
         
     | 
| 
      
 359 
     | 
    
         
            +
            			array_of_items.push(item)
         
     | 
| 
      
 360 
     | 
    
         
            +
            			item_count_zenity += 1
         
     | 
| 
       277 
361 
     | 
    
         
             
            		end
         
     | 
| 
       278 
362 
     | 
    
         
             
            		if zenity({'list' => nil, 'radiolist' => nil, 'text' => text, 'print-column' => 'ALL', 'column' => '#', 'column%' => 'Items', '' => array_of_items, ' > /tmp/zenity.sock 2>/dev/null' => nil }) then
         
     | 
| 
       279 
363 
     | 
    
         
             
            			return File.read('/tmp/zenity.sock').gsub("\n", "")
         
     | 
| 
       280 
364 
     | 
    
         
             
            		else
         
     | 
| 
       281 
365 
     | 
    
         
             
            			return nil
         
     | 
| 
       282 
366 
     | 
    
         
             
            		end
         
     | 
| 
       283 
     | 
    
         
            -
            	elsif $dialogbind_dialog_backend == ' 
     | 
| 
       284 
     | 
    
         
            -
            		 
     | 
| 
       285 
     | 
    
         
            -
            		 
     | 
| 
       286 
     | 
    
         
            -
            		 
     | 
| 
      
 367 
     | 
    
         
            +
            	elsif $dialogbind_dialog_backend == 'kdialog' then
         
     | 
| 
      
 368 
     | 
    
         
            +
            		list_args = [ text ]
         
     | 
| 
      
 369 
     | 
    
         
            +
            		item_count = 0
         
     | 
| 
      
 370 
     | 
    
         
            +
            		entries.each do |list_item|
         
     | 
| 
      
 371 
     | 
    
         
            +
            			list_args.push(item_count)
         
     | 
| 
      
 372 
     | 
    
         
            +
            			list_args.push(list_item)
         
     | 
| 
      
 373 
     | 
    
         
            +
            			list_args.push('-')
         
     | 
| 
      
 374 
     | 
    
         
            +
            			item_count += 1
         
     | 
| 
      
 375 
     | 
    
         
            +
            		end
         
     | 
| 
      
 376 
     | 
    
         
            +
            		if kdialog({ 'title' => title, 'radiolist' => list_args,}, true) == false then
         
     | 
| 
       287 
377 
     | 
    
         
             
            			return nil
         
     | 
| 
       288 
378 
     | 
    
         
             
            		end
         
     | 
| 
       289 
     | 
    
         
            -
            		 
     | 
| 
      
 379 
     | 
    
         
            +
            		item_index = File.read('/tmp/kdialog.sock').gsub("\n", "").to_i
         
     | 
| 
      
 380 
     | 
    
         
            +
            		return entries[item_index].clone
         
     | 
| 
      
 381 
     | 
    
         
            +
            	elsif $dialogbind_dialog_backend == 'macos' then
         
     | 
| 
      
 382 
     | 
    
         
            +
            		if entries.include? 'false' then
         
     | 
| 
      
 383 
     | 
    
         
            +
            			raise 'The list of items to present to the user cannot contain the words "true" or "false" without additional punctuation due to limitations of AppleScript that is called from Ruby on macOS to display dialogs.'
         
     | 
| 
      
 384 
     | 
    
         
            +
            		end
         
     | 
| 
      
 385 
     | 
    
         
            +
            		return macselect(entries, text)
         
     | 
| 
       290 
386 
     | 
    
         
             
            	else
         
     | 
| 
       291 
387 
     | 
    
         
             
            		raise 'The selected backend does not support license message boxes.'
         
     | 
| 
       292 
388 
     | 
    
         
             
            		return false
         
     | 
| 
         @@ -302,10 +398,11 @@ module DialogBindSystemSounds 
     | 
|
| 
       302 
398 
     | 
    
         
             
            	Attention = 3
         
     | 
| 
       303 
399 
     | 
    
         
             
            end
         
     | 
| 
       304 
400 
     | 
    
         | 
| 
      
 401 
     | 
    
         
            +
            # @!visibility private
         
     | 
| 
       305 
402 
     | 
    
         
             
            def nativesoundplay(sound_path)
         
     | 
| 
       306 
403 
     | 
    
         
             
            	unix_cmd_optimized_path = sound_path.gsub('"', "\\\"")
         
     | 
| 
       307 
404 
     | 
    
         
             
            	if $dialogbind_dialog_backend == 'win32' then
         
     | 
| 
       308 
     | 
    
         
            -
            		 
     | 
| 
      
 405 
     | 
    
         
            +
            		win32_activexplay(sound_path)
         
     | 
| 
       309 
406 
     | 
    
         
             
            	elsif $dialogbind_dialog_backend == 'macos' then
         
     | 
| 
       310 
407 
     | 
    
         
             
            		system('afplay "' + unix_cmd_optimized_path + '" > /dev/null 2>&1')
         
     | 
| 
       311 
408 
     | 
    
         
             
            	else
         
     | 
| 
         @@ -325,6 +422,7 @@ def nativesoundplay(sound_path) 
     | 
|
| 
       325 
422 
     | 
    
         
             
            	end
         
     | 
| 
       326 
423 
     | 
    
         
             
            end
         
     | 
| 
       327 
424 
     | 
    
         | 
| 
      
 425 
     | 
    
         
            +
            # @!visibility private
         
     | 
| 
       328 
426 
     | 
    
         
             
            def linuxsound(sound_v)
         
     | 
| 
       329 
427 
     | 
    
         
             
            	sound_theme = '/usr/share/sounds/freedesktop/stereo'
         
     | 
| 
       330 
428 
     | 
    
         
             
            	sound_theme_success = sound_theme + '/complete.oga'
         
     | 
| 
         @@ -381,3 +479,58 @@ def guisound(sound_v) 
     | 
|
| 
       381 
479 
     | 
    
         
             
            		nativesoundplay(constant_sound_attention)
         
     | 
| 
       382 
480 
     | 
    
         
             
            	end
         
     | 
| 
       383 
481 
     | 
    
         
             
            end
         
     | 
| 
      
 482 
     | 
    
         
            +
             
     | 
| 
      
 483 
     | 
    
         
            +
            # @!visibility private
         
     | 
| 
      
 484 
     | 
    
         
            +
            def zenityfilter(filter)
         
     | 
| 
      
 485 
     | 
    
         
            +
            	filter_out = []
         
     | 
| 
      
 486 
     | 
    
         
            +
            	filter.each do |filter_item|
         
     | 
| 
      
 487 
     | 
    
         
            +
            		filter_out.append('--file-filter=' + filter_item)
         
     | 
| 
      
 488 
     | 
    
         
            +
            	end
         
     | 
| 
      
 489 
     | 
    
         
            +
            	return filter_out
         
     | 
| 
      
 490 
     | 
    
         
            +
            end
         
     | 
| 
      
 491 
     | 
    
         
            +
             
     | 
| 
      
 492 
     | 
    
         
            +
            # Shows system-native file selection dialog. Currently does not work on Windows.
         
     | 
| 
      
 493 
     | 
    
         
            +
            #
         
     | 
| 
      
 494 
     | 
    
         
            +
            # @param filter [Array] an array of file patterns. Example: [ '*.rb', 'markdown-doc-toprocess*.md' ]
         
     | 
| 
      
 495 
     | 
    
         
            +
            # @param title [String] an optional parameter specifying the title of the dialog box. Ignored on macOS.
         
     | 
| 
      
 496 
     | 
    
         
            +
            # @return [String] either an empty string (if the user cancels the dialog) or the native path to the file.
         
     | 
| 
      
 497 
     | 
    
         
            +
            def guifileselect(filter=[], title='DialogBind')
         
     | 
| 
      
 498 
     | 
    
         
            +
            	if $dialogbind_dialog_backend == 'macos' then
         
     | 
| 
      
 499 
     | 
    
         
            +
            		return macopen(title, filter, false)
         
     | 
| 
      
 500 
     | 
    
         
            +
            	elsif $dialogbind_dialog_backend == 'kdialog' then
         
     | 
| 
      
 501 
     | 
    
         
            +
            		if kdialog({ 'title' => title, 'getopenfilename' => [] }, true) == false then
         
     | 
| 
      
 502 
     | 
    
         
            +
            			return ''
         
     | 
| 
      
 503 
     | 
    
         
            +
            		end
         
     | 
| 
      
 504 
     | 
    
         
            +
            		return File.read('/tmp/kdialog.sock').gsub("\n", "")
         
     | 
| 
      
 505 
     | 
    
         
            +
            	elsif $dialogbind_dialog_backend == 'zenity' then
         
     | 
| 
      
 506 
     | 
    
         
            +
            		zenity({ 'title' => title, 'file-selection' => nil, '%' => zenityfilter(filter), ' > /tmp/zenity.sock 2>/dev/null' => nil })
         
     | 
| 
      
 507 
     | 
    
         
            +
            		return File.read('/tmp/zenity.sock').gsub("\n", "")
         
     | 
| 
      
 508 
     | 
    
         
            +
            	else
         
     | 
| 
      
 509 
     | 
    
         
            +
            		raise 'The selected backend does not support file selection dialog boxes.'
         
     | 
| 
      
 510 
     | 
    
         
            +
            		return ''
         
     | 
| 
      
 511 
     | 
    
         
            +
            	end
         
     | 
| 
      
 512 
     | 
    
         
            +
            	return ''
         
     | 
| 
      
 513 
     | 
    
         
            +
            end
         
     | 
| 
      
 514 
     | 
    
         
            +
             
     | 
| 
      
 515 
     | 
    
         
            +
            # Shows an input box with the specified text.
         
     | 
| 
      
 516 
     | 
    
         
            +
            #
         
     | 
| 
      
 517 
     | 
    
         
            +
            # @param text [String] the text that should be displayed in an input box
         
     | 
| 
      
 518 
     | 
    
         
            +
            # @param title [String] an optional parameter specifying the title of the input box. Ignored on macOS and Windows.
         
     | 
| 
      
 519 
     | 
    
         
            +
            # @return [String] the string that the user has typed in
         
     | 
| 
      
 520 
     | 
    
         
            +
            def guigets(text='Type something:', title='DialogBind')
         
     | 
| 
      
 521 
     | 
    
         
            +
            	if $dialogbind_dialog_backend == 'macos' then
         
     | 
| 
      
 522 
     | 
    
         
            +
            		return macentry(text)
         
     | 
| 
      
 523 
     | 
    
         
            +
            	elsif $dialogbind_dialog_backend == 'kdialog' then
         
     | 
| 
      
 524 
     | 
    
         
            +
            		kdialog({ 'title' => title, 'inputbox' => [ text, '' ] }, true)
         
     | 
| 
      
 525 
     | 
    
         
            +
            		return File.read('/tmp/kdialog.sock').gsub("\n", "")
         
     | 
| 
      
 526 
     | 
    
         
            +
            	elsif $dialogbind_dialog_backend == 'zenity' then
         
     | 
| 
      
 527 
     | 
    
         
            +
            		zenity({ 'title' => title, 'entry' => nil, 'text' => text, ' > /tmp/zenity.sock 2>/dev/null' => nil })
         
     | 
| 
      
 528 
     | 
    
         
            +
            		return File.read('/tmp/zenity.sock').gsub("\n", "")
         
     | 
| 
      
 529 
     | 
    
         
            +
            	elsif $dialogbind_dialog_backend == 'win32' then
         
     | 
| 
      
 530 
     | 
    
         
            +
            		return win32_vbinputbox(text)
         
     | 
| 
      
 531 
     | 
    
         
            +
            	else
         
     | 
| 
      
 532 
     | 
    
         
            +
            		raise 'The selected backend does not support input boxes.'
         
     | 
| 
      
 533 
     | 
    
         
            +
            		return ''
         
     | 
| 
      
 534 
     | 
    
         
            +
            	end
         
     | 
| 
      
 535 
     | 
    
         
            +
            	return ''
         
     | 
| 
      
 536 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,16 +1,17 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: dialogbind
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.9. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.9.4
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Tim K
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2019-07- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2019-07-23 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       13 
     | 
    
         
            -
            description: 
         
     | 
| 
      
 13 
     | 
    
         
            +
            description: 'DialogBind is a library providing a cross-platform API for creating
         
     | 
| 
      
 14 
     | 
    
         
            +
              dialog and message boxes from Ruby code. Docs are available here: https://www.rubydoc.info/gems/dialogbind/'
         
     | 
| 
       14 
15 
     | 
    
         
             
            email:
         
     | 
| 
       15 
16 
     | 
    
         
             
            - timprogrammer@rambler.ru
         
     | 
| 
       16 
17 
     | 
    
         
             
            executables: []
         
     | 
| 
         @@ -30,7 +31,7 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       30 
31 
     | 
    
         
             
              requirements:
         
     | 
| 
       31 
32 
     | 
    
         
             
              - - ">="
         
     | 
| 
       32 
33 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       33 
     | 
    
         
            -
                  version: 2. 
     | 
| 
      
 34 
     | 
    
         
            +
                  version: 2.2.0
         
     | 
| 
       34 
35 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       35 
36 
     | 
    
         
             
              requirements:
         
     | 
| 
       36 
37 
     | 
    
         
             
              - - ">="
         
     | 
| 
         @@ -40,7 +41,6 @@ requirements: [] 
     | 
|
| 
       40 
41 
     | 
    
         
             
            rubygems_version: 3.0.4
         
     | 
| 
       41 
42 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       42 
43 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       43 
     | 
    
         
            -
            summary: DialogBind provides a Ruby API  
     | 
| 
       44 
     | 
    
         
            -
               
     | 
| 
       45 
     | 
    
         
            -
              for documentation. Updates for this library are released frequently.
         
     | 
| 
      
 44 
     | 
    
         
            +
            summary: DialogBind provides a portable Ruby API for creating simple message box-based
         
     | 
| 
      
 45 
     | 
    
         
            +
              interfaces that work on Linux, macOS and Windows.
         
     | 
| 
       46 
46 
     | 
    
         
             
            test_files: []
         
     |