Open Recent menu - how to populate it?
Hi, All, I'm writing a simple (in GUI) application, where NSDocument is not used. I use NSOpenPanel to get a file name, then process file and close it. There is no UI, related to file, where NSDocument could help significantly. At least I believe so. My problem is that Recent menu is empty, because in Cocoa (AFAIK) it is maintained automatically by NSDocumentController, which is absent in my app. So, my question is - how to create and update the Open Recent menu manually? Where to store its items? How to populate this submenu when my app is loaded? Or should I use NSDocumentController anyway? Thanks. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Open Recent menu - how to populate it?
On 21/07/2009, at 1:36 AM, Alexander Bokovikov wrote: Hi, All, I'm writing a simple (in GUI) application, where NSDocument is not used. I use NSOpenPanel to get a file name, then process file and close it. There is no UI, related to file, where NSDocument could help significantly. At least I believe so. My problem is that Recent menu is empty, because in Cocoa (AFAIK) it is maintained automatically by NSDocumentController, which is absent in my app. So, my question is - how to create and update the Open Recent menu manually? Where to store its items? How to populate this submenu when my app is loaded? Or should I use NSDocumentController anyway? If your app isn't document based, it might complicate things too much to have an NSDocumentController there (which is a global/singleton). Handling a recent items menu is pretty straightforward though - just keep a list of the n most recent file paths you opened in an array and use a menu delegate to update the menu from this. For extra credit, check the validity/existence of the file when updating the menu and remove bad ones and disambiguate duplicates. Someone might have written a class to do this already. The relevant functionality could go in the app's delegate or a separate controller object with an outlet from the app's delegate. --Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Open Recent menu - how to populate it?
On 20.07.2009, at 21:47, Graham Cox wrote: ... and use a menu delegate to update the menu from this. This is just what is unclear for me, as I'm still learning Cocoa :) Do you have in mind that I must: 1 - create an outlet, pointing to Open Recent menu item 2 - create an outlet, pointing to the Main Menu itself (or is there any ready-to-use one?) 3 - set my AppController, as a Main Menu delegate (e.g. in awaikFromNib, using outlet, created in #2) 4 - add some delegate message to my AppController class (what message should I intercept?) 5 - write some code like populating submenu of the menu item referenced by outlet, created in #1 If the sequence above is correct, then, OK, I'll try to do it, though I have one unclear point - will newly created menu items respond to onClick: action automatically, or should I assign onClick: action for each dynamically created item? If I should, then how to do it? For extra credit, check the validity/existence of the file when updating the menu and remove bad ones and disambiguate duplicates. Someone might have written a class to do this already. This is obvious, but my problem is in the menu dynamic creation. On 20.07.2009, at 21:55, Tony S. Wu wrote: i'd store the plist file in Library/Application support folder, and just process the file upon startup. Am I correct in my understanding, that my application can create a subdirectory within /Library/Application Support/ directory? Or should it be done through an installer, where Administrator's password is asked? Thanks. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Open Recent menu - how to populate it?
You can just go ahead and invoke -noteNewRecentDocumentURL: on [NSDocumentController sharedDocumentController]. You don't have to worry about explicitly creating or managing an NSDocumentController, or do anything else that requires NSDocument. TextEdit in Tiger did this (before it was converted to NSDocument). Ali On Jul 20, 2009, at 8:47 , Graham Cox wrote: On 21/07/2009, at 1:36 AM, Alexander Bokovikov wrote: Hi, All, I'm writing a simple (in GUI) application, where NSDocument is not used. I use NSOpenPanel to get a file name, then process file and close it. There is no UI, related to file, where NSDocument could help significantly. At least I believe so. My problem is that Recent menu is empty, because in Cocoa (AFAIK) it is maintained automatically by NSDocumentController, which is absent in my app. So, my question is - how to create and update the Open Recent menu manually? Where to store its items? How to populate this submenu when my app is loaded? Or should I use NSDocumentController anyway? If your app isn't document based, it might complicate things too much to have an NSDocumentController there (which is a global/ singleton). Handling a recent items menu is pretty straightforward though - just keep a list of the n most recent file paths you opened in an array and use a menu delegate to update the menu from this. For extra credit, check the validity/existence of the file when updating the menu and remove bad ones and disambiguate duplicates. Someone might have written a class to do this already. The relevant functionality could go in the app's delegate or a separate controller object with an outlet from the app's delegate. --Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Open Recent menu - how to populate it?
On 20.07.2009, at 23:13, Ali Ozer wrote: You probably want to call this when you open a doc, or revert, or do save as... (if you have any of these commands in your app, of course). Das ist fantastisch... 8-( ) [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL URLWithString:filename]]; Just one line of code Thank you very much! ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com