preventing duplicates in umenu

jamesson's icon

I have a umenu that is populated by javascript. However, sometimes the output of the javascript is already in the umenu. In this case I need to prevent the duplicate from being added. How may I do this?

Thanks much in advance

Joe

dhjdhjdhj's icon

I usually just send a 'clear' message to the umenu first

jamesson's icon

I mean, for append messages. I don't rebuild the menu, I just add stuff to it.

dhjdhjdhj's icon

You didn't mention a coll!

I don't know offhand whether the umenu has an attribute to prevent duplicates but in general it's not a good idea to use a view as the model as well.

Keep your collection of data stored somewhere else (in a model) and handle (prevent) duplicates there.

Then whenever there's a change, your model will update umenu. The easy way to do that if you don't want your model to keep track of what it has previously sent, is to clear the umenu and resend everything.

woodslanding's icon

there is a patch that does this in the st.ools collection called St.oleMenu

But I would second the advice about keeping the list elsewhere--esp as you can't get umenu to dump its contents afaik. I'm pretty sure St.oleMenu does this itself.

Luke Hall's icon

If you're doing this in javascript you should be able to check the [umenu] objects "items" attribute and use an if statement to make sure that the string you want to add isn't already present.

Let me know if you'd like an example patch for this.

11OLSEN's icon
Max Patch
Copy patch and select New From Clipboard in Max.

here's a way to not append if it's already in there, but i used objects, not js, so i don't know if this can help you.
O.