Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add to the "Open Recent" menu an item that doesn't point to a file

Is there a way to add an item that doesn't point to a file that exists on the file system to the "Open Recent" menu?

In an application not based on NSDocument, I can add an item to the "Open Recent" submenu with the following code:

[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL URLWithString:stringToFilePath]];

It works as documented, as long as the URL points to a file that exists on the file system.

If the url doesn't point to a file on the system, such as a web url, or a custom url scheme, nothing happens.

For example, this code has no effect, and produce no log during execution, even if my app handles the scheme used in the URL:

[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL URLWithString:@"http://www.stackoverflow.com"]];

Update: someone found (a long time ago) a way to tweak this menu to have it show files whether they exist or not: http://lists.apple.com/archives/cocoa-dev/2007/Apr/msg00651.html

I successfully managed to subclass NSDocumentController, but my override of the method - (NSArray *)recentDocumentURLs is never called.

It's not very surprising, as the doc says:

This method is not a good one to override since the internals of NSDocumentController do not generally use it.

But the doc doesn't say what to use instead and the poster didn't give more detail. Any idea?


If there is no solution, on workaround would be to rewrite the entire menu from scratch. If possible, I would prefer to avoid that, for all the stuff I get for free (like when you have two items with the same name, it displays the parent directory as well to help differentiate them).

like image 512
Guillaume Avatar asked Jul 13 '10 11:07

Guillaume


1 Answers

It looks like you'll probably have to create your own menu and maintain your own separate list. This menu automatically excludes files that don't exist.

I believe this is also true of files on removable media that is absent (ie, if the media comes back, the I believe the file is once again available in the list if it hasn't been pushed off by more recent items).

like image 121
Joshua Nozzi Avatar answered Nov 09 '22 14:11

Joshua Nozzi