2011-12-22 67 views
1

我正在通過mach_inject向Finder上下文菜單中添加項目來編寫一個插件。我已經成功通過掛鉤NSMenu添加它。但是現在我需要獲取右鍵單擊的項目。 有人說我們可以使用下面的代碼,但它只能得到選擇的項目而不是右鍵單擊的項目(它們是不同的!!!!在Finder中,如果選擇一個項目並右鍵單擊另一個項目,則選定的項目將不會改變)。任何人都知道如何在Finder中右鍵單擊項目?謝謝!如何在OSX上的Finder中右鍵單擊文件項目

SBElementArray * selection = [[finder selection] get]; 

NSArray * items = [selection arrayByApplyingSelector:@selector(URL)]; 
for (NSString * item in items) { 
    NSURL * url = [NSURL URLWithString:item]; 
    NSLog(@"selected item url: %@", url); 
} 
+0

+1

struct TFENode { struct OpaqueNodeRef *fNodeRef; }; struct TFENodeVector { struct TFENode *_begin; struct TFENode *_end; struct TFENode *_end_cap; }; - (NSArray *)arrayForNodeVector:(const struct TFENodeVector *)vector { NSInteger capacity = vector->_end - vector->_begin; NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:capacity]; struct TFENode *node; for (node = vector->_begin; node < vector->_end; ++node) { [array addObject: [self pathForNode:node]]; } return array; } 

你可以得到的文件,我也想知道這一點。 – livingtech

回答

2

之前獲得選定的文件,你應該準備一些幫助,這樣的代碼

// Snow Leopard & Lion 
// gNodeHelper is where you put above code 
// override_handleContextMenuCommon: is your override function 

+ (void)override_handleContextMenuCommon:(unsigned int)context 
            nodes:(const struct TFENodeVector *)nodes 
            event:(id)event 
            view:(id)view 
         windowController:(id)windowController 
           addPlugIns:(BOOL)flag 
{ 
    NSArray *paths = [gNodeHelper arrayForNodeVector:nodes]; 

    [self override_handleContextMenuCommon:context 
            nodes:nodes 
            event:event 
            view:view 
         windowController:windowController 
           addPlugIns:flag]; 

} 
相關問題