Hi,

I tried today the methods of NSDocumentController used to manage recent open 
documents, and discovered that you just have to call noteNewRecentDocumentURL, 
clearRecentDocuments and recentDocumentURLs methods through JNI to manage an 
"Open recent" menu in a sandboxed Java application, without any need of a dummy 
nib file or Xcode:

* [[NSDocumentController sharedDocumentController] 
noteNewRecentDocumentURL:documentURL];
adds documentURL to the list of recently opened files or moves it to the top of 
the list. documentURL should be a document that was actually opened with AWT 
FileDialog. If you have the string path of the document and not its URL, you 
can get its URL with fileURLWithPath method in NSURL class.

* [[NSDocumentController sharedDocumentController] clearRecentDocuments:nil]; 
clears the list of recently opened files.

* NSArray* recentDocumentURLs = [[NSDocumentController 
sharedDocumentController] recentDocumentURLs];
returns the list of recently opened files stored by Mac OS X for your 
application. To convert the returned array of URLs to an array of string paths, 
have a look to the implementation of nativeRunFileDialog native method in 
CFileDialog class at 
https://github.com/openjdk-mirror/jdk7u-jdk/blob/master/src/macosx/native/sun/awt/CFileDialog.m#L211

I programmed the calls to these methods on my side and could test them 
successfully in a sandboxed version of my program.
But could it be possible in a future release to add the matching native methods 
in com.apple.eawt.Application to avoid Java programmers to provide their own 
JNI implementation? 

Have a nice weekend,
--
Emmanuel PUYBARET
Sweet Home 3D developer
Email  : puyba...@eteks.com
Web    : http://www.eteks.com
         http://www.sweethome3d.com

> Le 9 mars 2015 à 19:29, Emmanuel Puybaret <puyba...@eteks.com> a écrit :
> 
> Hi,
> 
> As you probably know, an Apple sandboxed application can read only files that 
> the user selected with a standard file dialog box or from an Open Recent 
> menu. In a sandboxed Swing application, this obliges to use FileDialog AWT 
> class to select files but this is not a big issue since JFileChooser class is 
> so poor. Managing an Open Recent menu from a such an application is much more 
> tricky because Apple lets you read only the recent files managed by a menu 
> created with a nib file, and menus in a Swing application are not created 
> that way.
> As all programers who use a non standard framework for their application have 
> the same issue, a simple search 
> https://www.google.com/search?q=%22open+recent%22+sandbox
> might give some tips like the following one
> http://www.juce.com/comment/287990#comment-287990
> which proposes to create a dummy nib file containing only "File > Open 
> recent" menu, retrieve recent files returned by recentDocumentURLs in 
> NSDocumentController class, and then uses these recent files to populate your 
> own menu.
> Would it be possible to use this tip to create a new method in 
> com.apple.eawt.Application that would return the recent files?
> 
> Thanks for your suggestions,
> --
> Emmanuel PUYBARET
> Sweet Home 3D developer
> Email  : puyba...@eteks.com
> Web    : http://www.eteks.com
>         http://www.sweethome3d.com
> 

Reply via email to