【问题标题】:Generate "Finder.h" for a SIMBL plugin为 SIMBL 插件生成“Finder.h”
【发布时间】:2012-04-03 10:08:00
【问题描述】:

我正在尝试为 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”。看这个链接 How to Write OS X Finder plugin> 我看到生成 Finder.h 文件是必要的......

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

非常感谢!

【问题讨论】:

    标签: macos finder simbl


    【解决方案1】:

    创建一个“Finder.h”:

    sudo class-dump -H -o /output_directory/Path  /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder
    

    【讨论】:

      【解决方案2】:

      您应该覆盖 TNodeIconAndNameCell 的 drawIconWithFrame: 方法,而不是覆盖 TIconAndTextCell 的 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]);
      

      【讨论】:

        【解决方案3】:

        解决方案不包括 class-dump 生成的所有标头(现在如何生成此标头请查看@jackjr300 答案)。只需要包含使用的头文件并修复编译问题。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-11-05
          • 2011-11-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多