如何使用QLPreviewPanel?
如何使用QLPreviewPanel
?我知道它以前不是公共 API,但在 10.6 中已经有了。如何使用它在标准 QuickLook 面板中显示文件预览?
How do I use QLPreviewPanel
? I know it wasn't a public API before, but it is in 10.6. How can I use it to show a preview of a file in a standard QuickLook panel?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看 QuickLookDownloader 代码。它引导您完成将
QLPreviewPanel
合并到代码中所需执行的一些操作。其中包括:QLPreviewItem
协议 - 这告诉 Quick Look 在哪里可以找到您想要预览的文件(并且您正在预览文件 - 您无法传入自定义数据) 。QLPreviewPanel
定义数据源和委托(如果您之前使用过NSTableView
,这应该非常熟悉)。QLPreviewPanelController
协议(您可以在其中分配数据源和委托)配置预览面板。第 1-3 项在示例代码的
MyDocument
类中处理。切换显示主要在 AppDelegate 类中处理。DownloadsTableView
类还支持通过空格键切换QLPreviewPanel
,就像 Finder 一样。Check out the QuickLookDownloader code. It walks you through a couple of things you need to do to incorporate
QLPreviewPanel
into your code. Some of these include:QLPreviewItem
protocol - this tells Quick Look where to find the file you want to preview (and you are previewing files - you can't pass in custom data).QLPreviewPanel
(if you're worked withNSTableView
s before, this should be pretty familiar).QLPreviewPanelController
protocol (where you assign the data source and delegate).Items 1-3 are handled in the
MyDocument
class of the sample code. Toggling the display is mostly handled in theAppDelegate
class. There's also support in theDownloadsTableView
class that toggles theQLPreviewPanel
via the space key, a la the Finder.遗憾的是,Apple QuickLookDownloader 演示使用 Obj-C。我延长了
Josh 的 Demo 具有显示面板功能,以展示它是如何在 Swift 中完成的:
面板和弹出框示例
Sadly Apples QuickLookDownloader Demo uses Obj-C. I extended
Josh's Demo with a show panel functionality to show how it is done in Swift:
Panel and Popover example
我自己也在看这个。并且发现Apple在文档,这里还有一个很好的示例代码和文件 -> animgifqlgen
我正在使用丰富的 HTML 方法,它似乎可以满足我的需要。
这个想法是使用您通常用来解析文件信息的任何代码。并使用 html 进行布局并嵌入解析的信息,然后将 html 显示在 QL 面板中。许多普通的 html 代码的工作原理如下:大小、宽度、长度、bgcolor、src ...
该示例将展示如何编写包括 html 部分的代码。其中使用 NSMutableString 及其appendString 和appendFormat: 来构建 html。
我还没有尝试过其他方法。
为了进行测试,我只是在 plist 中配置了文档内容类型 UTI,并将构建产品(插件)的副本放在我的 /Users/username/Library/QuickLook/ 文件夹中。
您可能必须创建该文件夹。
请注意,当您想通过在文件夹中拖放新副本来替换 QuickLook 文件夹中的插件时,该插件可能正在使用中。
把旧的扔进垃圾桶就行了。我还发现它有助于使用 Activity Monitor 应用程序退出 Quick Look Helper 进程。这样做可以确保我看到的是新版本插件的结果,而不是内存中的旧版本插件的结果。 (我确信有人会告诉我我做得不好;-))
I am just looking at this myself. And have found that Apple provide a good guide with examples in the Docs, Also there is a good example code and files here -> animgifqlgen
I am using the Enriched HTML method, which seems to be working for what I need.
The idea is to Use what ever code you would normally use to parse the info on the file. And use html for the layout and embedding the parsed info,the html is then displayed within the QL Panel. A lot of the normal html code works like size width length,bgcolor,src ...
The example will show how to write the code including the html parts.Which uses a NSMutableString and its appendString and appendFormat: to build the html.
I have not tried the other methods yet.
For testing I just configured the Document Content Type UTIs in the plist and the put a copy of the built product (the plugin) in my /Users/username/Library/QuickLook/ folder.
You may have to create the Folder.
Note that when you want to replace the plugin in the QuickLook folder by drag and dropping a new copy in the folder, it may be in use.
Just put the old one in the trash. I also found it helped quitting the Quick Look Helper process using the Activity Monitor app. Doing so made sure I was seeing the results from the New version plugin rather than the old one still in memory. ( I sure someone will tell me I am doing bad ;-) )