Skip to content

Commit

Permalink
Windows traling \r\n fixed, guiselect implemented for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
tenfensw committed Jul 23, 2019
1 parent 4c63f62 commit b182ec7
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/dialogbind.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
require 'fiddle/import'

$dialogbind_macos_script_cmd = ''
$dialogbind_version = '0.9.4'
$dialogbind_version = '0.9.4.1'

# @!visibility private
def zenity(arg)
Expand Down Expand Up @@ -182,14 +182,14 @@ def win32_generatevbs(write_out)
end
File.write(tmpfile_loc, write_out)
tmpfile_loc_w = tmpfile_loc.gsub('/', "\\")
cmd_out = `cscript //Nologo "#{tmpfile_loc_w}"`.gsub("\r\n", "")
cmd_out = `cscript //Nologo "#{tmpfile_loc_w}"`.gsub("\r\n", "\n").gsub("\n", "")
File.delete(tmpfile_loc)
return cmd_out
end

# @!visibility private
def win32_vbinputbox(text)
write_out = 'a = inputbox("' + text.gsub('"', '') + '")'
write_out = 'a = inputbox("' + text.gsub('"', '').gsub("\r\n", "\n").gsub("\n", "\" + chr(13) + _ \n \"") + '")'
write_out += "\r\nWScript.Echo a"
return win32_generatevbs(write_out)
end
Expand Down Expand Up @@ -346,7 +346,7 @@ def entry2buttonshash(entries)

# Shows either a message box with buttons matching the items specified in the array ``entries`` or a list message box.
#
# @param entries [Array] an array of strings that should be displayed as list in a message box. More than two items are currently not supported.
# @param entries [Array] an array of strings that should be displayed as list in a message box.
# @param text [String] the text that should be displayed in a message box
# @param title [String] an optional parameter specifying the title of the message box. Ignored on macOS.
# @return [String] the selected string or nil on cancel
Expand Down Expand Up @@ -377,12 +377,28 @@ def guiselect(entries, text='Choose one of the items below:', title='DialogBind'
return nil
end
item_index = File.read('/tmp/kdialog.sock').gsub("\n", "").to_i
if item_index > entries.length then
return ''
end
return entries[item_index].clone
elsif $dialogbind_dialog_backend == 'macos' then
if entries.include? 'false' then
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.'
end
return macselect(entries, text)
elsif $dialogbind_dialog_backend == 'win32' then
combined_msg = text.clone
count = 0
entries.each do |entry_item|
combined_msg += "\r\n" + count.to_s + '. ' + entry_item.to_s
count += 1
end
combined_msg += "\r\n" + " (To select one of the items above, enter the matching number before the dot)"
entered_id = win32_vbinputbox(combined_msg).to_i
if entered_id > entries.length then
return ''
end
return entries[entered_id].clone
else
raise 'The selected backend does not support license message boxes.'
return false
Expand Down

0 comments on commit b182ec7

Please sign in to comment.