Finder Icon Overlay示例项目代表了一个小而非常基本但实际工作的示例,下面是答案。
https://github.com/lesnie/Finder-Icon-Overlay
我知道这是很老,但有些可能是主题(?)
下面是我这下豹(10.6)完成仍然有兴趣。起初需要Finder的头文件。使用类转储工具来获取它。然后将您的代码编写为SIMBL插件(请参阅文档如何操作),调整一些方法。例如,要在ListView中的图标上绘制图标,必须重写TIconAndTextCell方法的drawIconWithFrame:方法。
下面是方法混写代码:用我的方法方法:
+ (void) Plugin_load
{
Method old, new;
Class self_class = [self class];
Class finder_class = [objc_getClass("TIconAndTextCell") class];
class_addMethod(finder_class, @selector(FT_drawIconWithFrame:),
class_getMethodImplementation(self_class, @selector(FT_drawIconWithFrame:)),"[email protected]:{CGRect={CGPoint=dd}{CGSize=dd}}");
old = class_getInstanceMethod(finder_class, @selector(drawIconWithFrame:));
new = class_getInstanceMethod(finder_class, @selector(FT_drawIconWithFrame:));
method_exchangeImplementations(old, new);
}
我重写 “drawIconWithFrame” “FT_drawIconWithFrame:”。以下是此方法的示例实现。
- (void) FT_drawIconWithFrame:(struct CGRect)arg1
{
[self FT_drawIconWithFrame:arg1];
if ([self respondsToSelector:@selector(node)]) {
if ([[[[NSClassFromString(@"FINode") nodeWithFENode:[(TNodeIconAndNameCell *)self node]] fullPath] lastPathComponent] hasPrefix:@"A"])
[myPrettyIconOverlayImage drawInRect:NSMakeRect(arg1.origin.x, arg1.origin.y, arg1.size.height, arg1.size.height) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
}
}
本质上,它借鉴“myPrettyIconOverlayImage”过与文件名的文件图标的每个以字母“A”开头。这个逻辑取决于你。
注意这条线:[self FT_drawIconWithFrame:arg1];
这是如何调用'超'为了得到正常的图标和名称等我知道,看起来很奇怪,像循环,但实际上它不是。然后换入SIMBL插件,安装SIMBL并...运行。
由于狮子的变化,一些工作必须从头开始(创建新的“Finder.h”文件,其中包含所有需要的声明,找到合适的类别和方法来覆盖),但这种技术仍然有效。
快乐黑客!
自从这篇文章已经有一段时间了,随时可以使用10.6。你有没有达到你想要的?你用Finder插件战术去了吗? – epologee 2011-03-22 11:53:58
有关狮子的任何更新? – Tony 2011-12-26 05:42:44
@LesNie下方链接到他的[Finder Icon Overlay](https://github.com/lesnie/Finder-Icon-Overlay)项目。链接以防其他人难以找到开源OS X Finder插件示例(就像我做的那样)。 – pkamb 2015-01-12 23:35:37