NSDocument-based app with programmatically created NSTextView and other objects. App processes Undo and Redo actions accurately for both the text view and the other app objects. The Undo menu item accurately displays the action name for the custom app objects, set via
self.doc.undoManager?.setActionName(NSLocalizedString("widget change", comment: "undo/redo widget change"))
In validateUserInterfaceItem, confirm via log that myTextView.undoManager?.undoActionName is "Typing" after user has typed and "Paste" after the user has pasted. And yet, when the text view is active, the Undo menu item name will either be just "Undo" or continue to be "Undo widget change" or whatever the most recent non-text view action was. That is, any text view action seems to properly change the undoActionName but does not change the Undo menu item's name. Any suggestions for what to look at or try? fwiw, the text view's undo manager is the doc's undo manager.
Thank you!
Related
Need to open an alert to the user when User moves out the dialog(inline popup ) or closes the dialog with out saving in Oracle Apex
Doesn't this do what you need?
open page properties
scroll down to "Navigation"
turn Warn on Unsaved Changes ON
This is what it does:
Warn on Unsaved Changes
Specify if the user is warned when trying to navigate away from the page, where the page contains unsaved changes. Page Items and Buttons also offer more granular control over when this check is performed, and what is included in it. For Buttons, you can specify if clicking the button will perform the check. For Page Items, you can specify if changes to the item are included, or ignored by the check (see the Warn on Unsaved Changes attribute for both).
In decarbonizing I have now come to creating a menubar programmatically using NSMenu.
Carbon seems to be so nice to add standard items to the application menu: Services, Hide app, Hide Others, Show All, Quit app,
and they are even added using the user’s Preferred Language setting in System Preferences’s Language & Region,
so in German Hide Others is added as Andere ausblenden.
I only had to add the About and Preferences items.
However, it seems that in Cocoa I have to add these standard items myself,
but how can I find out what Hide Others is called in the user’s Preferred Language ?
And what is the Cocoa equivalent of CreateStandardWindowMenu ?
If you have Xcode create a new Cocoa application project, it will make a MainMenu.xib that you can examine. It looks like "Hide Others", "Quit" etc. are just menu items with particular actions assigned, but "Services" seems to have some special magic. Even if you don't want to present a whole menu bar from a nib, you could load it from a nib and then pick out certain menu items and move them to another menu, rename them or whatever. Though I'm not sure I understand what you're trying to accomplish. Even if you don't want to localize, you can use a nib.
To address the last part of your revised question, the NSApplication object has a windowsMenu property, i.e., you could create a menu and say [NSApp setWindowsMenu: myMenu]. But I don't know if that adds items like Bring All to Front or if you must create those yourself.
In storyboard, I see key shortcuts in menu items
But when I run app, this shortcuts remove automatically:
I do not understand why!
You have evidently assigned those shortcuts to another menu item, possibly including a pop-menu in the window. If multiple menus have the same shortcuts assigned, it's arbitrary which will actually have it at run time.
Those menus come from default template.
Your app in background calls validateMenuItem: If the menuItem can't perform action (e.g. copy:) the menuItem remains disabled.
object considered for validation is firstResponder (see below picture). If the firstResponder is nil -> menu item will be disabled. Your app in also checks if the object (firstResponder) responds to menu item selectors.
I create a Mac document based project. After I load a file in a window, I want to clear the content by click the "close" menu item, and not close the window. Then I can load other document in the same window.
You are not very specific so it is difficult to give specific advise.
In general if I were doing this I would redirect the 'Close' and 'Open' menu items in the MainMenu.xib file to my own custom IBAction methods. These custom methods would then alter any data and operate on the window and it's views.
What you are trying to do is counter-intuitive for the user who would expect Close to close the window (possibly asking if they want to save the content first).
I think you just need some sort of Clear action (menu item, toolbar button and key binding) which makes the feature far more obvious and will allow your App to conform to Apple's Human Interface Guidelines.
I have a non-document Cocoa application with a menubar icon and status menu. I've added an "Open Recent" menu to the status menu in Interface Builder. Populating the menu works just fine:
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:
[NSURL fileURLWithPath:filename]]
Now I would also like to add a second "Open Recent" menu to a context popup menu. How would I create the menu programmatically so that it gets populated with entries automatically as it does for the version in the status menu?
I tried creating a copy of the one in the status menu, but it does not get populated. I assume that NSDocumentController is not aware of the menu (frankly, I don't know how it knows about the one in the status menu).
For reference, the best documentation on the inner workings of the Open Recent menu that I found is this:
http://lapcatsoftware.com/blog/2007/07/10/working-without-a-nib-part-5-open-recent-menu/
Unfortunately, it doesn’t help much with this, because even if you create the menu like this, it will be ignored by NSDocumentController. The menu must exist in the main menu before applicationDidFinishLaunching: call, otherwise it won’t be picked up — and consequently, duplicate ones are ignored too.
What I ended up doing, and what seems to work so far, is this:
The first idea was to pick the corresponding NSMenu from the main menu and attach it into other menus as well, hoping that reference counting will make this work. No such luck, setSubmenu throws if the submenu is already in another NSMenuItem.
So I “reparent” the submenu instead — when I need to show it in another menu, I remove it from the main menu’s Open Recent item and set it as submenu in the new menu. Later, I move it back. It’s an ugly hack, of course, but it gets the job done.