Guest User

Untitled

a guest
Feb 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. module CocaDialog
  2. require "escape.rb"
  3. module_function
  4.  
  5. def request_string(hash = Hash.new,&block)
  6. options = Hash.new
  7. options["type"] = "inputbox"
  8. options["title"] = hash[:title] || "Enter String"
  9. options["informative-text"] = hash[:prompt] || ""
  10. options["text"] = hash[:default] || ""
  11. options["button1"] = "Ok"
  12. options["button2"] = "Cancel"
  13. return self.dialog(options,&block)
  14. end
  15. def request_secure_string(hash = Hash.new,&block)
  16. options = Hash.new
  17. options["type"] = "secure-inputbox"
  18. options["title"] = hash[:title] || "Enter Password"
  19. options["informative-text"] = hash[:prompt] || ""
  20. options["text"] = hash[:default] || ""
  21. options["string-output"] = ""
  22. options["button1"] = "Ok"
  23. options["button2"] = "Cancel"
  24. return self.dialog(options,&block)
  25. end
  26. def drop_down(hash = Hash.new,&block)
  27. items = hash[:items] || []
  28. if items.empty? then
  29. block_given? raise SystemExit : return nil
  30. elsif items.length == 1 then
  31. block_given? yield items[0] : return items[0]
  32. else
  33. options = Hash.new
  34. options["type"] = "dropdown"
  35. options["title"] = hash[:title] || "Select Item"
  36. options["text"] = hash[:prompt] || ""
  37. options["string-output"] = ""
  38. options["button1"] = "Ok"
  39. options["button2"] = "Cancel"
  40. return self.dialog(options,&block)
  41. end
  42. end
  43.  
  44. private
  45.  
  46. def dialog(options)
  47. type = options.delete("type")
  48. str = ""
  49. options.each_pair do |key, value|
  50. str << " --#{e_sh key} "
  51. str << Array(value).map { |s| e_sh s }.join(" ")
  52. end
  53. cd = ENV['TM_SUPPORT_PATH'] + '/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog'
  54. result = %x{#{e_sh cd} 2>/dev/console #{e_sh type} #{str} --float}
  55. return_value, result = result.to_a.map{|line| line.chomp}
  56. if return_value == "Cancel" then
  57. if block_given? then
  58. raise SystemExit
  59. else
  60. return nil
  61. end
  62. else
  63. block_given? ? yield result : result
  64. end
  65. end
  66. end
Add Comment
Please, Sign In to add comment