dialogbind 0.9.4.1 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dialogbind.rb +72 -19
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b6ae43bbbb3723872dc171fa5fee54053b579cd4c78a63bc72d1cdf05e9ecae
4
- data.tar.gz: 7c2f954dad2452fe21374eca48e07efd7270e2d88793a74ce7c18629b4bb8556
3
+ metadata.gz: 117589fe831467e5e45659f7338bc5222450aee700e76aeed980682ee6b96695
4
+ data.tar.gz: 450fa5c663f131d086bd526b331d4a108143c3240c2503860b8f3cf472758027
5
5
  SHA512:
6
- metadata.gz: c318c17e91699f02fbf2531d25e8fb8c8d2eada0bcd0f0c9f9882ae0995b3f8f30ee4c55ede97f770659668aa78506a360185779c5f95e989a258d8b12195668
7
- data.tar.gz: 4795b55a9cd36909f618b5454ff686e58114d982fdcbe3746c4f2eb20abcca65e97e4ae789206b834bae24c2b8fbb7e63aebd2c0e7b5501d5cac248b3429558f
6
+ metadata.gz: 23f91664fd2d2742fad0e4b682d6b082d06f3e0bbedbb939c2aa414d60a342f39f9f6d19ff581de3b3468bc778f08c08f3f14032b0552c091dfbdfb4c5bb7d86
7
+ data.tar.gz: 6492ae4777d9d5814860df7dde030f78bf30e24efdc9be6351f380d8e087d202824bad70e910147f537ea05c9e20de56fa43c25b84bdf3e5c47a58ea65cd02cf
data/lib/dialogbind.rb CHANGED
@@ -8,7 +8,7 @@
8
8
  require 'fiddle/import'
9
9
 
10
10
  $dialogbind_macos_script_cmd = ''
11
- $dialogbind_version = '0.9.4.1'
11
+ $dialogbind_version = '0.9.5'
12
12
 
13
13
  # @!visibility private
14
14
  def zenity(arg)
@@ -56,13 +56,13 @@ def kdialog(arg, redirect_output=false)
56
56
  end
57
57
 
58
58
  # @!visibility private
59
- def macdialog(text, buttons=['OK'], type='dialog', error=false, dryrun=false)
59
+ def macdialog(text, buttons=['OK'], type='dialog', error=false, dryrun=false, notificationtitle='')
60
60
  text_fixed = text.gsub("!", "").gsub("'", '').gsub('"', '').gsub('$', '')
61
61
  cmd = "osascript -e 'tell app \"System Events\" to display " + type + ' "' + text_fixed + '"'
62
62
  if type != 'notification' then
63
63
  cmd += ' buttons ' + buttons.to_s.gsub('[', '{').gsub(']', '}')
64
64
  else
65
- cmd += ' with title "' + File.basename($0) + '"'
65
+ cmd += ' with title "' + notificationtitle.gsub("!", "").gsub("'", '').gsub('"', '').gsub('$', '') + '"'
66
66
  end
67
67
  if error then
68
68
  cmd += ' with icon caution'
@@ -107,7 +107,7 @@ end
107
107
  # @!visibility private
108
108
  def macselect(items, text)
109
109
  cmd = 'osascript -e \'tell app "System Events" to choose from list ' + items.to_s.gsub('[', '{').gsub(']', '}').gsub("'", '')
110
- cmd += ' with prompt "' + text + '"\''
110
+ cmd += ' with prompt "' + text.to_s + '"\''
111
111
  cmd_output = `#{cmd}`.gsub("\n", "")
112
112
  if cmd_output == 'false' then
113
113
  return nil
@@ -195,23 +195,30 @@ if $dialogbind_dialog_backend == 'win32' then
195
195
  end
196
196
 
197
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"
198
+ def win32_activexopen(title)
199
+ generated_vbs = 'set ob=CreateObject("Shell.Application")'
200
+ generated_vbs += "\r\nset fldr=ob.BrowseForFolder(0, \"" + title.gsub("\r\n", "\n").gsub("\n", "").gsub('"', "") + '", &H4000, "C:")'
201
+ generated_vbs += "\r\nif not fldr is Nothing then"
202
+ generated_vbs += "\r\nWScript.Echo fldr.Self.Path\r\nend if"
203
+ return win32_generatevbs(generated_vbs)
204
+ end
205
+
206
+ # @!visibility private
207
+ def win32_vbbrowseforfolder(title)
208
+ generated_vbs = 'set ob=CreateObject("Shell.Application")'
209
+ generated_vbs += "\r\nset fldr=ob.BrowseForFolder(0, \"" + title.gsub("\r\n", "\n").gsub("\n", "").gsub('"', "") + '", 0, "C:")'
210
+ generated_vbs += "\r\nif not fldr is Nothing then"
211
+ generated_vbs += "\r\nWScript.Echo fldr.Self.Path\r\nend if"
210
212
  return win32_generatevbs(generated_vbs)
211
213
  end
212
214
  else
213
215
  # @!visibility private
214
- def win32_activexopen(filters, title)
216
+ def win32_activexopen(title)
217
+ return ''
218
+ end
219
+
220
+ # @!visibility private
221
+ def win32_vbbrowseforfolder(title)
215
222
  return ''
216
223
  end
217
224
 
@@ -420,7 +427,7 @@ def nativesoundplay(sound_path)
420
427
  if $dialogbind_dialog_backend == 'win32' then
421
428
  win32_activexplay(sound_path)
422
429
  elsif $dialogbind_dialog_backend == 'macos' then
423
- system('afplay "' + unix_cmd_optimized_path + '" > /dev/null 2>&1')
430
+ system('afplay "' + unix_cmd_optimized_path + '" > /dev/null 2>&1 &')
424
431
  else
425
432
  if system('command -v play > /dev/null 2>&1') then
426
433
  system('play "' + unix_cmd_optimized_path + '" > /dev/null 2>&1')
@@ -508,7 +515,7 @@ end
508
515
  # Shows system-native file selection dialog. Currently does not work on Windows.
509
516
  #
510
517
  # @param filter [Array] an array of file patterns. Example: [ '*.rb', 'markdown-doc-toprocess*.md' ]
511
- # @param title [String] an optional parameter specifying the title of the dialog box. Ignored on macOS.
518
+ # @param title [String] an optional parameter specifying the title of the dialog box.
512
519
  # @return [String] either an empty string (if the user cancels the dialog) or the native path to the file.
513
520
  def guifileselect(filter=[], title='DialogBind')
514
521
  if $dialogbind_dialog_backend == 'macos' then
@@ -521,6 +528,8 @@ def guifileselect(filter=[], title='DialogBind')
521
528
  elsif $dialogbind_dialog_backend == 'zenity' then
522
529
  zenity({ 'title' => title, 'file-selection' => nil, '%' => zenityfilter(filter), ' > /tmp/zenity.sock 2>/dev/null' => nil })
523
530
  return File.read('/tmp/zenity.sock').gsub("\n", "")
531
+ elsif $dialogbind_dialog_backend == 'win32' then
532
+ return win32_activexopen(title)
524
533
  else
525
534
  raise 'The selected backend does not support file selection dialog boxes.'
526
535
  return ''
@@ -528,6 +537,29 @@ def guifileselect(filter=[], title='DialogBind')
528
537
  return ''
529
538
  end
530
539
 
540
+ # Shows system-native directory selection dialog.
541
+ #
542
+ # @param title [String] an optional parameter specifying the title of the dialog box.
543
+ # @return [String] either an empty string (if the user cancels the dialog) or the native path to the file.
544
+ def guidirectoryselect(title='DialogBind')
545
+ if $dialogbind_dialog_backend == 'macos' then
546
+ return macopen(title, [], true)
547
+ elsif $dialogbind_dialog_backend == 'kdialog' then
548
+ if kdialog({ 'title' => title, 'getexistingdirectory' => [] }, true) == false then
549
+ return ''
550
+ end
551
+ return File.read('/tmp/kdialog.sock').gsub("\n", "")
552
+ elsif $dialogbind_dialog_backend == 'zenity' then
553
+ zenity({ 'title' => title, 'file-selection' => nil, 'directory' => nil, ' > /tmp/zenity.sock 2>/dev/null' => nil })
554
+ return File.read('/tmp/zenity.sock').gsub("\n", "")
555
+ elsif $dialogbind_dialog_backend == 'win32' then
556
+ return win32_vbbrowseforfolder(title).gsub("\\", '/')
557
+ else
558
+ raise 'The selected backend does not support directory selection dialog boxes.'
559
+ end
560
+ return ''
561
+ end
562
+
531
563
  # Shows an input box with the specified text.
532
564
  #
533
565
  # @param text [String] the text that should be displayed in an input box
@@ -550,3 +582,24 @@ def guigets(text='Type something:', title='DialogBind')
550
582
  end
551
583
  return ''
552
584
  end
585
+
586
+ # Shows a notification in system tray or a message box, depending on operating system notifications support.
587
+ #
588
+ # @param text [String] the text that should be displayed in a notification.
589
+ # @param title [String] an optional parameter specifying the title of the notification.
590
+ # @return [Boolean] true on success, false on fail.
591
+ def guinotify(text, title='DialogBind', sound=DialogBindSystemSounds::Success)
592
+ if $dialogbind_dialog_backend != 'win32' && $dialogbind_dialog_backend != 'kdialog' then
593
+ guisound(sound)
594
+ end
595
+ if $dialogbind_dialog_backend == 'macos' then
596
+ return macdialog(text, [], 'notification', false, false, title)
597
+ elsif $dialogbind_dialog_backend == 'kdialog' then
598
+ return kdialog({ 'title' => title, 'passivepopup' => [ text, 10 ] })
599
+ elsif $dialogbind_dialog_backend == 'zenity' then
600
+ return zenity({ 'title' => title, 'notification' => nil, 'text' => text })
601
+ else
602
+ return guiputs(text, title)
603
+ end
604
+ return false
605
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dialogbind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4.1
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim K