Cocoa - Adding menu to support versions? (Like in TextEdit)

霸气de小男生 提交于 2019-12-10 12:09:02

问题


In TextEdit, if you click the little dropdown next to the filename you get a menu which shows a couple of entries including Rename, Move to iCloud, Move To, Duplicate, Lock and finally Browse All Versions.

I'm wondering how to support this menu? On my app I have the disclosure indictor, but get no menu which I click it. Do I need to add this menu via code? If so, i'm assuming I need to link it to the window somehow, but I don't see a proper place to do so. Any suggestions on what i'm missing?


回答1:


You get this functionality "for free" when using NSDocument subclasses in document-based applications. As long as you've implemented everything outlined here:

http://developer.apple.com/library/mac/#documentation/DataManagement/Conceptual/DocBasedAppProgrammingGuideForOSX/StandardBehaviors/StandardBehaviors.html

... versioning should "automagically" work as it's directly affected by implementing auto-save.

Things to consider:

  1. What's the minimum OS version you're targeting?
  2. Are you customizing anything to do with the Window's title bar?
  3. Does your NSDocument subclass implement modern (non-deprecated) read/write methods or are you doing something "old or funky"?



回答2:


Figured it out. I was overriding:

- (void)menuNeedsUpdate:(NSMenu *)menu

I didn't need to be overriding this method, so I removed it. As soon as I did that, my menu started working.



来源:https://stackoverflow.com/questions/13821282/cocoa-adding-menu-to-support-versions-like-in-textedit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!