Permalink
Browse files

conflicts

  • Loading branch information...
2 parents 283749d + 37abe92 commit 6ca2c199c4251eeea1a60fc33780dc085bb4ec2b @rdp committed Nov 23, 2011
Showing with 173 additions and 14 deletions.
  1. +4 −0 spec/common.rb
  2. +20 −8 spec/swing_helpers.spec.rb
  3. +15 −6 swing_helpers.rb
  4. +134 −0 vendor/reveal
View
@@ -0,0 +1,4 @@
+require 'rubygems'
+require 'rspec/autorun'
+require 'sane'
+$: << '..'
View
@@ -16,10 +16,10 @@
along with Sensible Cinema. If not, see <http://www.gnu.org/licenses/>.
=end
require File.expand_path(File.dirname(__FILE__) + '/common')
-require 'os'
-require_relative '../lib/swing_helpers'
-module SensibleSwing
-describe SensibleSwing do
+require_relative '../swing_helpers'
+
+module SwingHelpers
+describe 'functionality' do
it "should close its modeless dialog" do
@@ -33,12 +33,24 @@ module SensibleSwing
it "should be able to convert filenames well" do
if OS.windows?
- "a/b/c".to_filename.should == "a\\b\\c"
+ "a/b/c".to_filename.should == File.expand_path("a\\b\\c")
else
- "a/b/c".to_filename.should == "a/b/c"
+ "a/b/c".to_filename.should == File.expand_path("a/b/c")
end
end
+ it "should reveal a file" do
+ FileUtils.touch "a b"
+ SwingHelpers.show_in_explorer "a b"
+ Dir.mkdir "a dir"
+ SwingHelpers.show_in_explorer "a dir"
+ end
+
+ it "should reveal a url" do
+ SwingHelper.show_url_in_browser "www.google.com"
+ end
+
+ end
+
end
-end
-puts 'close the windows...'
+puts 'close the windows...'
View
@@ -16,7 +16,7 @@
along with Sensible Cinema. If not, see <http://www.gnu.org/licenses/>.
=end
require 'java'
-
+require 'sane' # gem
module SwingHelpers
include_package 'javax.swing'
@@ -60,7 +60,7 @@ def self.show_select_buttons_prompt message, names_hash = {}
old.each{|name, old_setting| UIManager.put(name, old_setting)}
out = JOptionReturnValuesTranslator[returned]
if !out || !names_hash.key?(out)
- raise 'canceled or exited:' + out
+ raise 'canceled or exited:' + out.to_s
end
out
end
@@ -125,7 +125,8 @@ def self.open_url_to_view_it_non_blocking url
if OS.windows?
system("start #{url.gsub('&', '^&')}") # LODO would launchy help/work here with the full url?
else
- system_non_blocking "#{OS.open_file_command} \"#{url}\"" # LODO test!
+ system "#{OS.open_file_command} \"#{url}\""
+ sleep 2 # disallow exiting immediately after...LODO
end
end
@@ -229,13 +230,21 @@ def self.get_user_input(message, default = '', cancel_ok = false)
end
received
end
-
+
def self.show_in_explorer filename_or_path
raise 'nonexist cannot reveal in explorer?' + filename_or_path unless File.exist?(filename_or_path)
- begin
+ if OS.doze?
+ begin
c = "explorer /e,/select,\"#{filename_or_path.to_filename}\""
system c # command returns immediately...so system is ok
- rescue => why_does_this_happen_ignore_this_exception_it_probably_actually_succeeded
+ rescue => why_does_this_happen_ignore_this_exception_it_probably_actually_succeeded
+ end
+ elsif OS.mac?
+ c = File.expand_path(__DIR__ + "/vendor/reveal") + " \"" + File.expand_path(filename_or_path) + "\""
+ puts c
+ system c
+ else
+ raise 'os unsupported?'
end
end
View
@@ -0,0 +1,134 @@
+#!/bin/zsh
+
+commandName=${0##*/}
+
+usage() {
+ if [[ $1 != '' ]] ; then echo 1>&2 "\n$1" ; fi
+ echo 1>&2 "
+Usage: $commandName
+ $commandName [ -l ] [ -v ] item ...
+
+Tells the Finder to reveal the current directory or a list of the given items.
+The -l argument tells the Finder to set the last window it opens to list view.
+The -v argument causes the AppleScript to be echoed to stderr.
+
+In the multiple-arguments case, the Finder will open one window that cantains
+all of the items and select them all. Maybe someday it will do that even if
+the items are not all in the same folder (using list view and expanded subfolders).
+
+Author: Dave@Yost.com 2002-12-09, 2004-06-05, 2006-07-07
+Version 1.2
+"
+ exit 2
+}
+
+zparseopts -D -K - -help=argHelp l=argList v=argVerbose
+
+if [[ $#argHelp != 0 ]] ; then
+ usage
+fi
+
+case $1 in
+-*) usage "Unknown option: $1"
+ ;;
+esac
+
+#-----------------------------------------
+
+# unix path -> old-style Mac path for AppleScript
+colonize() {
+ sed 's,.*,"&",
+ s,/,\&,g
+ s,:,/,g
+ s,^"&Volumes&,",
+ s,^"&.*,& of startup disk,' \
+ | sed 's,&,:,g' \
+ | tr -d '\012'
+}
+
+# Reveal unix paths in the Finder
+reveal() {
+ if [ $# = 0 ] ; then
+ args=( . )
+ else
+ args=( $* )
+ fi
+
+ itemList=
+ for x in $args
+ do
+ case "$x" in
+ /*) item="$x" ;;
+ .) item="`/bin/pwd`" ;;
+ *) item="`/bin/pwd`/$x" ;;
+ esac
+
+ # All /x/../ -> /
+ previtem=
+ while [ "$previtem" != "$item" ]
+ do
+ previtem="$item"
+ item=`echo "$item" | sed 's,[^/]*/\.\./,,'`
+ done
+
+ if [ $item = / ] ; then
+ itemColonized="startup disk"
+ else
+ itemColonized="item $(echo -n $item | colonize)"
+ fi
+
+ # Add it to the list
+ if [ "$itemList" = "" ] ; then
+ itemList="Â
+ $itemColonized"
+ else
+ itemList="$itemList, Â
+ $itemColonized"
+ fi
+ done
+
+ script='
+ tell application "Finder"
+ reveal { '$itemList' Â
+ }'
+ if [ "$#argList" != 0 ] ; then
+ script="$script
+ get every Finder window whose index is 1
+ set the current view of item 1 of the result to list view"
+ fi
+ script="$script"'
+ activate
+ end tell'
+ if [[ $#argVerbose != 0 ]] ; then
+ echo 1>&2 "[osascript -e '$script
+']"
+ fi
+ osascript -e "$script"
+}
+
+test() {
+ # If there are any mounted volumes, try the first one.
+ mountedVolume=`mount | grep Volumes | sed -n '1s,^[^ ]* on \(.*\) (*[^(]*,\1,p'`
+ if [ "$mountedVolume" != "" ] ; then
+ $commandName "$mountedVolume"
+ fi
+ cd /Library
+ $commandName
+ $commandName "/"
+ $commandName Preferences
+ $commandName "/Applications/QuickTime Player.app" \
+ "/Applications/Utilities/Java/../../System Preferences.app"
+}
+
+case $# in
+0) reveal "`/bin/pwd`"
+ ;;
+*) case "$1" in
+ --test)
+ test
+ ;;
+ *) $commandName $*
+ ;;
+ esac
+ ;;
+esac

0 comments on commit 6ca2c19

Please sign in to comment.