2012-03-18 48 views
1

我正在嘗試爲Finder創建一個SIMBL插件,以便在某些文件上添加圖標疊加層。爲SIMBL插件生成「Finder.h」

我有這樣的代碼:

@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」,但是編譯錯誤太多

非常感謝!

回答

0

的溶液並不包括由類產生的所有頭轉儲(到現在如何生成這個標題檢查@ jackjr300答案)。只需要包含已使用的標題並修復編譯問題。

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:)),"[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); 

然後你可以這樣做:

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

要創建一個 「Finder.h」:

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