Permalink
Browse files

improved docset so we can handle multiple search results. Also improv…

…ed inline documentation
  • Loading branch information...
1 parent 1446cbc commit 19f8a68a50fe1f714f82329c713366997df78835 @mattetti committed May 23, 2009
Showing with 48 additions and 31 deletions.
  1. +1 −1 config/build.yml
  2. +22 −16 lib/application.rb
  3. +25 −14 lib/docset.rb
View
@@ -1,4 +1,4 @@
-name: Cocoadoc
+name: CocoaDoc
load: lib/application.rb
version: "1.0"
icon: resources/HotCocoa.icns
View
@@ -2,8 +2,6 @@
require "#{File.dirname(__FILE__)}/docset.rb"
require "#{File.dirname(__FILE__)}/hotcocoa_doc.rb"
framework 'webkit'
-framework 'QuartzCore'
-framework 'ApplicationServices'
class Application
@@ -15,16 +13,19 @@ def start
application :name => "Cocoa Doc" do |app|
app.delegate = self
@main_window = window :frame => [100, 100, 825, 500], :title => "CocoaDoc" do |win|
- win << label(:text => "Cocoa Documentation", :layout => {:start => false})
+ win << label(:text => "Cocoa & HotCocoa Documentation", :layout => {:start => false})
win << doc_view
win << search_bar
search_box.delegate = app
- set_responders(win)
+ set_responders(win)
win.will_close { exit }
end
end
end
+
+ # layout view including the hotcocoa mappings button
+ # as well as the cocoa search field and button
def search_bar
@search_bar ||= layout_view(:mode => :horizontal, :frame => [0, 0, 0, 40], :layout => {:expand => :width, :bottom_padding => 2}, :margin => 0, :spacing => 0) do |hview|
hview << hotcocoa_button
@@ -33,6 +34,9 @@ def search_bar
end
end
+
+ # a webview displaying the result of the search
+ # the webview sets a delegation to deal with various actions
def doc_view
@web_view ||= web_view( :url => LOCAL_DOC_INDEX,
:layout => {:expand => [:width, :height]} ) do |wv|
@@ -56,15 +60,23 @@ def display_hotcocoa_index(sender)
doc_view.mainFrame.loadHTMLString(HotCocoaDoc.render_index, baseURL:nil)
end
+ # performing a search using the DocSet class
+ # to work properly, the user needs to have the macosx developer tools installed.
def perform_search(sender)
NSLog("searching for #{@search_box.to_s}")
- ref = DocSet.search(@search_box.to_s)
- if ref.respond_to?(:full_path)
- @web_view.url = ref.full_path
- search_box.text = ''
+ begin
+ refs = DocSet.search(@search_box.to_s)
+ rescue DocSetError => error_message
+ alert(:message => "Missing documentation", :info => error_message.to_s)
else
- alert :message => "No documentation found", :info => "Sorry, we couldn't find anything about #{@search_box.to_s}, please use another term and try again."
- search_box.text = ''
+ # TODO fill up the table view with all the results
+ if refs.first.respond_to?(:full_path)
+ @web_view.url = refs.first.full_path
+ search_box.text = ''
+ else
+ alert :message => "No documentation found", :info => "Sorry, we couldn't find anything about #{@search_box.to_s}, please use another term and try again."
+ search_box.text = ''
+ end
end
end
@@ -77,12 +89,6 @@ def win.acceptsFirstResponder; true; end
search_button.nextKeyView = search_box
end
- def control(textView, doCommandBySelector: commandSelector)
- result = false
- NSLog commandSelector.inspect
- true
- end
-
# file/open
def on_open(menu)
end
View
@@ -1,35 +1,46 @@
module DocSet
DOCUTIL_PATH = '/Developer/usr/bin/docsetutil'
- DOCSET_PATH = '/Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset'
-
+ DOCSET_PATH = '/Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset'
Ref = Struct.new(:language, :type, :klass, :thing, :path, :full_path)
+ class DocSetError < StandardError; end
- # Returns the doc reference
+ # Returns an array of doc reference
def self.search(query_string)
+ verify_user_system
query_string = query_string
raw_results = `#{DOCUTIL_PATH} search -skip-text -query #{query_string} #{DOCSET_PATH}`
- NSLog(raw_results)
if raw_results.length > 0
- ref_str, doc_path = raw_results.split("\n")
- convert_references(ref_str)
+ results = raw_results.split("\n")
+ results.map do |ref|
+ convert_references(ref)
+ end.flatten
else
- ''
+ []
end
end
# Split the query result into its component types and document path.
# language is 'Objective-C', 'C', 'C++'
- # type is 'instm' (nstance method), 'clsm' (class method, 'func' , 'econst', 'tag', 'tdef' and so on.
+ # type is 'instm' (instance method), 'clsm' (class method, 'func' , 'econst', 'tag', 'tdef' and so on.
# klass holds the class or '-' if no class is appropriate (for a C function, for example).
# thing is the method, function, constant, etc.
+ #
+ # === Returns
+ # <Array>:: Array of references
def self.convert_references (ref_str)
- return nil unless ref_str
- ref = ref_str.split
- raise "Cannot parse reference: #{query_string}" if ref.length != 2
- language, type, klass, thing = ref[0].split('/')
- Ref.new(language, type, klass, thing, ref[1], "#{DOCSET_PATH}/Contents/Resources/Documents/#{ref[1]}")
- end
+ return nil unless ref_str
+ reference, path = ref_str.split(" ")
+ raise DocSetError, "Cannot parse reference string: #{ref_str}" if reference.nil? || path.nil?
+ language, type, klass, thing = reference.split('/')
+ Ref.new(language, type, klass, thing, path, "#{DOCSET_PATH}/Contents/Resources/Documents/#{path}")
+ end
+
+ protected
+ def self.verify_user_system
+ @@tool_requirements ||= File.exist?(DOCUTIL_PATH) && File.exist?(DOCSET_PATH)
+ raise DocSetError, "The cocoa documentation wasn't found on your machine, make sure to install the MacOSX developer tools that came with your mac" unless @@tool_requirements
+ end
end

0 comments on commit 19f8a68

Please sign in to comment.