2011-06-10 28 views
3

我發現一堆人問這個(刪除或禁用最近的項目子菜單),沒有答案。刪除可可應用程序中的「打開最近」菜單項

經過一番調查...問題是,蘋果已經暗中硬編碼該特定的菜單總是出現 - 即使你刪除它,NSWindowController會默默地重新創建它。

回答

6

編輯:有些白癡覺得像改寫我的答案。別。否則我會刪除它。根據最初拒絕編輯的評論者:「此編輯太小;建議的編輯應該是針對帖子中多個問題的實質性改進。」所以:不要。


蘋果有一個官方的解決方法(在那裏他們勉強接受自己的錯誤,在硬編碼菜單):

http://developer.apple.com/library/mac/#qa/qa2001/qa1289.html

似乎工作確定,一旦你設置一個IBOutlet:

@property(nonatomic, retain) IBOutlet NSMenu* fileMenu; 

...並確保你有你的AppDelegate類在MainWindow.xib中表示(例如,使用藍色立方體對象,並將該類設置爲任何類你的AppDelegate是)...所以你可以將NIB中的文件菜單本身直接連接到你的應用代理。

編輯:實際上,修改 - Apple的源代碼與Xcode4編譯不正確,生成編譯器警告。你需要這個:

NSInteger openDocumentMenuItemIndex = [self.fileMenu indexOfItemWithTarget:nil andAction:@selector(openDocument:)]; 

if (openDocumentMenuItemIndex>=0 && 
    [[self.fileMenu itemAtIndex:openDocumentMenuItemIndex+1] hasSubmenu]) 
{ 
    // APPLE'S COMMENT: We'll presume it's the Open Recent menu item, because this is 
    // APPLE'S COMMENT: the heuristic that NSDocumentController uses to add it to the 
    // APPLE'S COMMENT: File menu 
    [self.fileMenu removeItemAtIndex:openDocumentMenuItemIndex+1]; 
} 
相關問題