1

我正在尝试为 Finder 创建一个 SIMBL 插件,以在某些文件上添加图标覆盖。

我有这个代码:

@implementation NSObject (FAIconOverlay)

- (void)FAIconOverlay_TIconAndTextCell_drawIconWithFrame:(struct CGRect)arg1
{
    [self FAIconOverlay_TIconAndTextCell_drawIconWithFrame:arg1];

    if (![self respondsToSelector:@selector(node)]) {
        return;
    }

    NSLog(@"%@", [[[NSClassFromString(@"FINode") nodeWithFENode:[(TNodeIconAndNameCell *)self node]] fullPath] lastPathComponent]);

    // Draw the icon overlay
}

- (void)FAIconOverlay_TDesktopIcon_drawIconInContext:(struct CGContext *)arg1
{    
    [self FAIconOverlay_TDesktopIcon_drawIconInContext:arg1];
}

@end

我可以绘制图标叠加层,但是,当我尝试获取文件的路径时,我得到“使用未声明的标识符 TNodeIconAndNameCell”。查看此链接<如何编写 OS X Finder 插件> 我发现生成 Finder.h 文件是必需的...

我的问题是:如何生成这个文件?我尝试运行“class-dump -H Finder.app”,但编译错误太多

非常感谢你!

4

3 回答 3

4

创建一个“ Finder.h ”:

sudo class-dump -H -o /output_directory/Path  /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder
于 2012-05-26T02:22:28.457 回答
1

而不是覆盖 TIconAndTextCell 的 drawIconWithFrame: 方法,您应该覆盖 TNodeIconAndNameCell 的 drawIconWithFrame: 方法。

Class finder_class = [objc_getClass("TNodeIconAndNameCell") class];

class_addMethod(finder_class, @selector(FT_drawIconWithFrame:),
                class_getMethodImplementation(self_class, @selector(FT_drawIconWithFrame:)),"v@:{CGRect={CGPoint=dd}{CGSize=dd}}");

old = class_getInstanceMethod(finder_class, @selector(drawIconWithFrame:));
new = class_getInstanceMethod(finder_class, @selector(FT_drawIconWithFrame:));
method_exchangeImplementations(old, new);

然后你可以这样做:

NSLog(@"%@", [[[NSClassFromString(@"FINode") nodeWithFENode:[self node]] fullPath] lastPathComponent]);
于 2012-05-25T23:01:58.980 回答
0

The solution is not include all the headers generated by class-dump (to now how to generate this headers check the @jackjr300 answer). Only is necessary included the used headers and fix the compiling problems.

于 2012-07-05T18:45:08.333 回答