Questions About Edit Menu Items


I have finally gotten around to upgrading from my very old (2008) version of RB to Xojo (2014–for Macintosh), and now I’m trying to get a handle on some of the things that work a bit differently.

One thing I’ve run into is that I can’t seem to disable EditPaste for particular TextFields. This used to be as simple as saying EditPaste.enabled = false in the EnableMenuItems event handler of the TextField (formerly EditField, actually) in question–but that isn’t working now. Anybody know what the issue is and/or have a workaround?

Relatedly, I see that Xojo now automatically adds “Start Dictation” and “Special Characters” menu items to my Edit Menu. Any way to get it to not do this?

Is Auto-Enable on for the menu item you’re trying to disable? You have to turn it off in the IDE first.

Those are system menu items. They’ll only appear on Mac. Why would you want to get rid of them? They let users with different needs access your software.

Duplicate the MainMenuBar, and in the Edit menu, rename the EditPaste item to myEditPaste.

Then when you want to inhibit paste, simply go

self.MenuBar = MainMenuBar1

To recover the default Paste, simply set the window menubar to MainMenuBar.

Thanks, Michel–that’s definitely an idea. Annoying, though, that it doesn’t let you simply disable the existing menu item!

Tim–yes, I already turned of auto-enable and it didn’t make a difference. And to clarify about the other two items–I don’t want to get rid of them entirely so much as just be able to disable them when I need to (such as in fields where I want to control what kinds of input are allowed).

Would an approach like the one that Michel suggests work for those items as well? That is, change the name of the entire Edit menu in the alternate menu bar when I want to get rid of the automatically added items? I’ll have to give that a try.

Subclass text field
In the subclass implement the enable menu items event and disable edit cut copy paste etc

The auto added items aren’t part of the menu that you can manipulate (the OS adds them automatically) so you can’t manipulate them there

About the only way to disable them would be to rename the entire edit menu - but then no other menu handler will work either when you are using that menu bar so you’ll have crated a lot of extra work for yourself trying to avoid being accessible

Since an item which does not have the regular name will not have a handler, it will appear as disabled. The end result is that you can control each menuitem enabled state that way. Or change the behavior of one by providing a handler.

[quote]Subclass text field
In the subclass implement the enable menu items event and disable edit cut copy paste etc[/quote]

That’s actually what I was doing before I upgraded from RB2008 to Xojo. I realize that in my original post I didn’t make that clear, but when I noted that disabling the item in the TextField’s EnableMenuItems handler wasn’t doing the trick, it was really the handler of my TextField subclass that I was referring to. I don’t know why it doesn’t work anymore, but it doesn’t!

As for the other thing: Changing the name of the entire Edit menu only gets rid of “Start Dictation” and “Special Characters”; it doesn’t impact the rest of the Edit menu items, as long as their names are still “EditPaste,” “EditCopy,” etc. So I wouldn’t actually be losing all that functionality (which is good). HOWEVER, it turns out that it’s the text of the Edit menu (the displayed name) that you have to change in order to suppress the added items–not just its behind-the-scenes “name.” And I don’t want to do that. Besides which, swapping out menubars is really just not that practical a solution for my needs.

What it comes down to is that I need a different way of accomplishing my underlying goal, which is to control the input into certain fields. It actually isn’t hard to do at all via code in my subclass’s TextChange handler; I just didn’t initially want to go that route (for reasons that I won’t get into here). Suffice it to say that it was simpler to just disable paste for this subclass. However, since that doesn’t appear to be possible anymore, I have now modified my TextField subclass accordingly–and as a bonus, the TextChange approach takes care of the problems created by the “Start Dictation” and “Special Characters” items as well as the pasting issue…

Anywya, thanks for the input, everyone.