Xojo - Copy (and … ?) MenuHandlers in a ListBox

Someone in this forum, sometimes ago, (thank you) told me to create a sub-class of a ListBox to set my own Copy MenuItem Handler when I discovers that a Copy MenuItem set in a WIndow for a standard ListBox is useless / never fired.

I seem to recall that Paste (I think) was also in the same boat, and maybe Cut ? and… ?

So, I started a quest and do not found an entry anywhere about that in the documentation.

Even Auto Complete does not know about ListBox’s Copy (Me.C + \Tab does not complete norr show a COpu entry !).

Do you know where this is documented ?
[I checked in all Release Notes I found in my Release Notes folder (since FYI to REAL SOftware, then Xojo) and found nothing.]

No one knows.

I didn’t started a conversation about SQLIte “If Table Exists“ that does not appears (too) in Xojo documentation (I searched and do not found). I have to go back (in time) in a project I used it (after a question in the old Forum, I think.

The answer is in the sqlite.com web server. Its Xojo syntax have to be defined.

The copy/paste menuhandlers are submenus of Edit, so they will be named EditCopy, EditPaste, EditCut, etc. Even so, they shouldn’t appear in autocomplete, since you can’t call them directly. But they should show up in the Name field when you add a MenuHandler.

Not sure what you mean about “If Table Exists”. You would check the presence or absence of a table via TableSchema. Or do you have something specific in mind?

Apologies for reviving an old thread, but I seem to be hitting the same problem. I’ve got a ListBox and I can use EditCut and EditPaste menu options just fine and trigger those via the Menu Handler to run my own functions, but I can’t seem to get EditCopy to work. My EditCopy menu handler will fire if I have no listbox items selected / highlighted, but as soon as I have a row selected, the menu handler stops firing and some ListBox internal copy shortcut seems to be happening instead.

When I have a listbox row selected, EditCopy seems to be copying the line as tab-delimited text to the Windows clipboard, but that isn’t what I want to happen in this case. I want to make my own menu handler fire, so that I can make a copy into my own internal app clipboard.

Is there any way around this, or do I have to subclass the ListBox? I don’t understand why EditCut and EditPaste work fine without subclassing, but not EditCopy… unless there’s something peculiar about my own code.

Quick test shows EditCopy works with Xojo 2016v3 on OS X 10.11.

Hmm, I’ve got Xojo 2016v3 and OS X 10.11, and it isn’t working for me. Try this example:

  • Create a new project and add a ListBox control
  • Add some InitialValue to the ListBox (I added 3 lines of random text)
  • Add a Menu Handler for EditCopy, and make that MenuHandler display a MsgBox.

Now run the app - if you press Command-C with nothing selected in the ListBox, you’ll get a MsgBox displayed. But if you now select one of your ListBox items, then press Command-C with the item selected/highlighted, your MsgBox doesn’t fire. Instead, it seems to just copy the text of that ListBox item to the Windows clipboard & your Menu Handler is never triggered.

(For the moment, I’m working around it by renaming EditCopy to EditCopySpecial, and using “If MainWindow.Focus = MainWindow.Listbox” / “If MainWindow.Focus = MainWindow.Notes” to determine which control has the focus. But by doing that, I lose the built-in EditCopy support while editing text items in the Listbox.)

EditCopy is handled by the system as default. Change its name if you want to handle it yourself. What you did is just fine.

What you can do is change the menuItem when you want the default EditCopy. From what you describe, it should be relatively easy to switch based on the Listbox selected status.

Start a new desktop project
Drag a listbox from the Library all the way to the left (into the navigator)
This creates a subclass of Listbox
This step is important

You can, in this subclass, implement whatever special handling you want for edit cut copy paste etc by adding the menu handlers to it OR you could raise an event and have any instance handle it in a custom fashion

Now why cant you do it right on an instance ON the layout ?
Listbox already has several of these implemented on the framework class so the only way you get to override a menu handler is to create a subclass

Aha, that makes sense! I’m guessing that the default ListBox doesn’t have special handling for cut & paste, and that’s why I hadn’t encountered the problem with those two. Guess I can’t avoid subclassing this ListBox after all :slight_smile: [Though the menu renaming & control focus testing seems an okay temporary workaround for some of my use cases.]

Thanks for your help, everyone!

If you would like to see some production code of these techniques in action: https://github.com/thommcgrath/Beacon/blob/master/Project/Custom%20Controls/BeaconListbox.xojo_code

Kohan,

Imagine you want to copy (or cut) the header lines with the selected rows: use Norman advice and implement there your EditCopy / EditCut, etc. (you can add the Heading strings with Rows in a custom EditPaste).

In fact, often, I cannot do something simply because I do not even think this can be done with Xojo. Most of the time there is a way (to be discovered) to do what you want.

Tim: sorry for never answering your question (I do not saw it then).

In SQLite, If Table Exists avoid to try to create a Table when it already exists.

Think (for example) you drop the tables from a file on purpose (not an error) and re-use the same db file, you may want to use this to avoid error.
OK: here’s a real project line use:

db.SQLExecute("DROP TABLE IF EXISTS List_Service")

In this case, I am sure to drop the table ONLY if it exists.

I hope this is clear (I am not sure)

Emile - since you would be writing SQL for SQLite the right place to look for that is in SQLite’s documentation not Xojo’s
And if you were working with mysql you’d look in their documentation
For postgres’ you’d look in theirs
and so on

[quote=294250:@Kohan Ikin]Hmm, I’ve got Xojo 2016v3 and OS X 10.11, and it isn’t working for me. Try this example:

  • Create a new project and add a ListBox control
  • Add some InitialValue to the ListBox (I added 3 lines of random text)
  • Add a Menu Handler for EditCopy, and make that MenuHandler display a MsgBox.

Now run the app - if you press Command-C with nothing selected in the ListBox, you’ll get a MsgBox displayed. But if you now select one of your ListBox items, then press Command-C with the item selected/highlighted, your MsgBox doesn’t fire.[/quote]
That’s because you added a menu handler to the window, not to the listbox (which you need to do in a subclass).

[quote=246895:@Emile Schwarz]No one knows.

I didn’t started a conversation about SQLIte “If Table Exists“ that does not appears (too) in Xojo documentation (I searched and do not found). I have to go back (in time) in a project I used it (after a question in the old Forum, I think.

The answer is in the sqlite.com web server. Its Xojo syntax have to be defined.[/quote]
As Norman pointed out, this isn’t a Xojo question. It’s an SQL question. You won’t find it in the Xojo documentation, because it doesn’t belong there.