Created
March 13, 2012 01:05
-
-
Save k2052/2025863 to your computer and use it in GitHub Desktop.
How to use QuickLook in Macruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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