Cocoa - Adding menu to support versions? (Like in

2019-06-10 02:20发布

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.

TextEdit

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?

SQL

2条回答
We Are One
2楼-- · 2019-06-10 03:04

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"?
查看更多
不美不萌又怎样
3楼-- · 2019-06-10 03:05

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.

查看更多
登录 后发表回答