Skip to content

Commit

Permalink
Remove usage of CocoaDialog in favor of tm_dialog. Remove a few unuse…
Browse files Browse the repository at this point in the history
…d library methods.

git-svn-id: http://svn.textmate.org/trunk/Bundles/C++ Qt.tmbundle@9080 dfb7d73b-c2ec-0310-8fea-fb051d288c6d
  • Loading branch information
infininight committed Mar 10, 2008
1 parent 8da3efe commit d792907
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 132 deletions.
7 changes: 6 additions & 1 deletion Support/bin/search.rb
Expand Up @@ -42,7 +42,12 @@ def redirect(url)
rescue
query = nil
end
query = TextMate.input("Input search word", query ? query : "") if do_input
query = TextMate::UI.request_string(
:title => "Documentation Search",
:default => query ? query : "",
:prompt => "Input search word:",
:button1 => 'Search'
) if do_input

if query.nil? or query.length < 1
close_browser
Expand Down
131 changes: 0 additions & 131 deletions Support/lib/rails/text_mate.rb
Expand Up @@ -7,40 +7,6 @@

module TextMate
class <<self
# TextMate shell script exit codes.
# See /Applications/TextMate.app/Contents/SharedSupport/Support/lib/bash_init.sh for a comprehensive list
def exit_discard; exit 200 end
def exit_replace_text; exit 201; end
def exit_replace_document; exit 202 end
def exit_insert_text; exit 203 end
def exit_insert_snippet; exit 204 end
def exit_show_html; exit 205 end
def exit_show_tool_tip; exit 206 end
def exit_create_new_document; exit 207 end

def open_url(url)
`open "#{url}"`
end

def activate
`osascript -e 'tell app "TextMate" to activate' &>/dev/null &`
end

# Open a file in textmate using the txmt:// protocol. Uses 0-based line and column indices.
def open(filename, line_number = nil, column_number = nil)
filename = filename.filepath if filename.is_a? RailsPath
options = []
options << "url=file://#{filename}"
options << "line=#{line_number + 1}" if line_number
options << "column=#{column_number + 1}" if column_number
open_url "txmt://open?" + options.join("&")
end

# Switching away from and then back to TextMate will automatically cause it to refresh the project drawer
def refresh_project_drawer
`osascript -e 'tell application "Dock" to activate'; osascript -e 'tell application "TextMate" to activate'`
end

# Always return something, or nil, for selected_text
def doxygen_style
ds = env(:doxygen_style)
Expand Down Expand Up @@ -83,102 +49,5 @@ def method_missing(method, *args)
super(method, *args)
end
end

# TODO: Move cocoa dialog stuff to its own class or module

def cocoa_dialog_command
"#{support_path}/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog"
end

# See http://cocoadialog.sourceforge.net/documentation.html for documentation
def cocoa_dialog(command, options = {})
options_list = []
options.each_pair do |k, v|
k = k.to_s.gsub('_', '-')
value = v.is_a?(Array) ? %Q{"#{v.join('" "')}"} : "\"#{v}\""
if v
if v.is_a? TrueClass
options_list << "--#{k}"
else
options_list << "--#{k} #{value}"
end
end
end
dialog_command = "\"#{cocoa_dialog_command}\" #{command} #{options_list.join(' ')}"
# $logger.debug "Dialog command: #{dialog_command}"
`#{dialog_command}`.to_a.map { |v| v.strip }
end

# Shows an information bubble with a nice gradient background
#
def message(text, options = {})
options = {:title => "Message", :informative_text => text, :button1 => "Ok"}.update(options)
return cocoa_dialog('msgbox', options)[0] == "1"
end

def textbox(informative_text, text, options = {})
options = {:title => "Message", :informative_text => informative_text, :text => text, :button1 => "Ok"}.update(options)
return cocoa_dialog('textbox', options)[0] == "1"
end

def message_yes_no_cancel(text, options = {})
options = {:title => "Message", :text => text}.update(options)
return cocoa_dialog('yesno-msgbox', options)[0] == "1"
end

def message_ok_cancel(text, informative_text = nil, options = {})
options = {:title => "Message", :text => text, :informative_text => informative_text}.update(options)
return cocoa_dialog('ok-msgbox', options)[0] == "1"
end

def input(text, default_text = "", options = {})
options = {:title => "Input", :informative_text => text, :text => default_text}.update(options)
button, text = cocoa_dialog('standard-inputbox', options)
if button == '1'
return text.strip
else
return nil
end
end

def choose(text, choices = ["none"], options = {})
options = {:title => "Choose", :text => text, :items => choices, :button1 => 'Ok', :button2 => 'Cancel'}.update(options)
button, choice = cocoa_dialog('dropdown', options)
if button == '1'
return choice.strip.to_i
else
return nil
end
end
end
end


module TextMate

def TextMate.call_with_progress( args, &block )
output_filepath = args[:output_filepath] # path to open after execution

title = args[:title] || 'Progress'
message = args[:message] || 'Frobbing the widget...'

cocoa_dialog = "#{ENV['TM_SUPPORT_PATH']}/bin/CocoaDialog.app/Contents/MacOS/CocoaDialog"

tempdir = "/tmp/TextMate_progress_cmd_tmp.#{$PID}"
Dir.mkdir(tempdir)
Dir.chdir(tempdir)
pipe = IO.popen( %Q("#{cocoa_dialog}" progressbar --indeterminate --title "#{title}" --text "#{message}"), "w+")
begin
pipe.puts ""
data = block.call
puts data
ensure
pipe.close
%x{rm -rf "#{tempdir}"}
end

sleep 0.1

end

end
2 changes: 2 additions & 0 deletions Support/lib/rails_bundle_tools.rb
@@ -1,6 +1,8 @@
bundle_lib = ENV['TM_BUNDLE_SUPPORT'] + '/lib'
$LOAD_PATH.unshift(bundle_lib) if ENV['TM_BUNDLE_SUPPORT'] and !$LOAD_PATH.include?(bundle_lib)

require ENV['TM_SUPPORT_PATH'] + '/lib/ui'

require 'rails/text_mate'
require 'rails/unobtrusive_logger'
require 'rails/misc'
Expand Down

0 comments on commit d792907

Please sign in to comment.