Skip to content

Instantly share code, notes, and snippets.

@k2052
Created March 13, 2012 01:05
Show Gist options
  • Save k2052/2025863 to your computer and use it in GitHub Desktop.
Save k2052/2025863 to your computer and use it in GitHub Desktop.
How to use QuickLook in Macruby
require 'rubygems' # disable this for a deployed application
require 'hotcocoa'
framework 'Quartz'
# This Needs to conformal to QLPreviewItem
class Item
attr_accessor :previewItemURL
end
module QLookBehaviors
attr_accessor :item
def acceptsPreviewPanelControl(panel)
return true
end
def beginPreviewPanelControl(panel)
panel.delegate = self
panel.dataSource = self
end
def endPreviewPanelControl(panel)
@previewPanel = nil
end
def numberOfPreviewItemsInPreviewPanel(panel)
return 1
end
def previewPanel(panel, previewItemAtIndex:index)
return @item
end
def togglePreviewPanel()
if QLPreviewPanel.sharedPreviewPanelExists && QLPreviewPanel.sharedPreviewPanel.isVisible
QLPreviewPanel.sharedPreviewPanel.orderOut(nil)
else
QLPreviewPanel.sharedPreviewPanel.makeKeyAndOrderFront(self)
end
end
end
class RQuicklook
include HotCocoa
def start
application name: 'RQuicklook' do |app|
app.delegate = self
@main_window = window(:frame => [100, 100, 600, 500], :title => "HotCocoa Demo Application") do |win|
win.will_close { exit }
win.extend(QLookBehaviors)
win.item = Item.new
win.item.previewItemURL = NSURL.alloc.initFileURLWithPath('filepath')
win.togglePreviewPanel()
end
end
end
end
RQuicklook.new.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment