1# 2# AppController.rb 3# Spotlight 4# 5# Created by Norberto Ortigoza on 9/11/05. 6# Copyright (c) 2005 CrossHorizons. All rights reserved. 7# 8require 'osx/cocoa' 9include OSX 10 11class AppController < NSObject 12 13 attr :spotlight 14 ib_outlets :fileView, :mdItemController, :metaDataView 15 16 def init 17 @spotlight = Spotlight.alloc.init 18 @spotlight.predicate = "kMDItemContentType == 'public.ruby-script'" 19 return self 20 end 21 22 def awakeFromNib 23 @metaDataView.setBackgroundColor(NSColor.lightGrayColor) 24 @spotlight.register_for_notification(self, "updateSearching:") 25 NSNotificationCenter.defaultCenter.objc_send :addObserver, self, 26 :selector, "updateSearching:", 27 :name, :NSTableViewSelectionDidChangeNotification, 28 :object, @fileView 29 end 30 31 def refresh_metaDataView 32 info = NSMutableString.stringWithCapacity(150); 33 @mdItemController.selectedObjects.to_a.each do |item| 34 item.attributes.to_a.each do |attr_name| 35 info.appendString(attr_name) 36 info.appendString(" = ") 37 info.appendString(item.valueForAttribute(attr_name).description) 38 info.appendString("\n") 39 end 40 end 41 @metaDataView.textStorage.mutableString.setString(info) 42 end 43 44 def dealloc 45 @spotlight.removeDelegate(self) 46 NSNotificationCenter.defaultCenter.removeObserver(aDelegate, 47 :name, :NSTableViewSelectionDidChangeNotification, 48 :object, nil); 49 50 end 51 52 #Notification and Event Handlers 53 def updateSearching (sender) 54 refresh_metaDataView 55 end 56 ib_action :updateSearching 57 58 def search (sender) 59 @spotlight.search() 60 end 61 ib_action :search 62 63end 64