如何编写 OS X Finder 插件 [英] How to Write OS X Finder plugin

查看:34
本文介绍了如何编写 OS X Finder 插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找编写 Mac OS X Finder 插件的指南或示例代码?它想知道如何做一些简单的动作:

I'm looking for a guide or sample code for writing Mac OS X Finder plugins? It would like to know how to do some simple actions:

  1. 为图标添加图像叠加层
  2. 添加上下文菜单项
  3. 监听文件更改

我找到了以下两个资源:

I found the following two resources:

  • Writing Contextual Menu Plugins for OS X: An outdated document from 2002 that uses the COM API targeting Mac OS X 8/9.
  • SCPlugin: Open-source SVN Mac application that includes a Finder plug-in.

我很想查看 SCPlugin 代码,但希望找到一个更容易理解的示例.

I am tempted to review the SCPlugin code, but was hoping to find an easier sample to digest.

推荐答案

遗憾的是,编写 Finder 插件实际上确实仍然需要您亲自接触 COM.如果您查看 SCPlugin 项目的 SCFinderPlugin 子项目,您会发现它遵循与您在第一个链接中概述的完全相同的技术,包括为 COM 设置 vtable、编写 AddRef/ReleaseRef 函数等.编写一个插件,同时管理老式的 Carbon 内存管理、COM 风格的内存管理和 Cocoa/新型的 Carbon 内存管理,这可能是一种令人难以置信的痛苦—这完全忽略了这样一个事实:你将在三个或更多完全不同的 API 中交互,具有不同的命名约定和调用语义.将情况称为歇斯底里地糟糕将是一种轻描淡写的说法.

Sadly, programming a Finder plugin actually does still require getting your hands dirty with COM. If you look at the SCFinderPlugin subproject of the SCPlugin project, you will find that it follows exactly the same techniques outlined in your first link, including setting up a vtable for COM, writing AddRef/ReleaseRef functions, and so on. Writing a plugin, where you're simultaneously managing old-school Carbon memory management, COM-style memory management, and Cocoa/new-style Carbon memory management, can be an incredible pain—and that totally ignores the fact that you'll be interacting in three or more radically different APIs, with different naming conventions and calling semantics. Calling the situation hysterically poor would be a vast understatement.

从好的方面来说,Mac OS X 10.6 Snow Leopard 中的 Finder 已经完全用 Cocoa 重写了——随之而来的是非常出色的插件界面.如果您有幸遇到实际上只能针对 Snow Leopard 的情况,您可能应该获得 ADC Premier 或更高级别的会员资格,下载预发布版本,并针对该情况编写代码.此外,如果没有 Cocoa 重写,您的插件无论如何可能无法在 10.6 上运行,因此无论如何,在 Snow Leopard 发布之前查看它可能是有意义的.

On the bright side, the Finder in Mac OS X 10.6 Snow Leopard has been fully rewritten in Cocoa--and with that come vastly superior plugin interfaces. If you are lucky enough to be in a situation where you can actually only target Snow Leopard, you probably should grab an ADC Premier or higher membership, download the prerelease builds, and code against that. Besides, your plugin may not work on 10.6 anyway without a Cocoa rewrite, so it might make good sense to take a look at Snow Leopard before it gets released, regardless.

这篇关于如何编写 OS X Finder 插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆