Rebuild PopUp-menu options when the user clicks to open

4 vues (au cours des 30 derniers jours)
Thomas Watson
Thomas Watson le 10 Août 2018
Commenté : Jan le 14 Août 2018
I've tried searching through most of the popup menu-related questions and didn't find anything similar. Essentially, I'd like to be able to dynamically populate a popup menu every time the user clicks it.
My current approach involves setting the menu's Enable property to ' inactive' so that it appears enabled but still calls my ButtonDownFcn callback. The user clicks the inactive menu, my callback reloads/adds options, and then sets the menu's Enable property to ' on'.
The problem is that the user has to click the menu twice to actually get it to open due to changing it's Enable property.
Is there any way to force the menu to open within my ButtonDownFcn callback so that it behaves normally for the user?
  4 commentaires
Thomas Watson
Thomas Watson le 13 Août 2018
I only know of one standard callback for the popup menu, and that's the 'Callback' property. It only gets called when the user has selected an item in the menu, not before. Please correct me if there are other standard callbacks I am missing.
To reiterate what I'm looking for, I want to be able to reload the popup menu's options when the user clicks on it, just before the menu actually opens. The whole point is so I can dynamically add new options that might have become available since the last time the user opened the menu.
If you need a concrete example, I am essentially creating popup options based on some Matlab files that are present within a directory. It's possible to drop more files in the directory while the program is running, so I have to update the menu options without knowing when an update should actually occur. The most intuitive time to update would be just before the user tries to open the menu, thus the whole ButtonDownFcn callback.
The problem described in my original post is that the user has to click once to run the ButtonDownFcn, which updates the menu, and then again to actually open it. The preferred solution would involve clicking the menu only once.
Jan
Jan le 14 Août 2018
I do not understand, what "when the user clicks on it, just before the menu actually opens" exactly means. But I assume, you find the wanted callback in the Java level: https://undocumentedmatlab.com/blog/uicontrol-callbacks

Connectez-vous pour commenter.

Réponses (1)

Adam Danz
Adam Danz le 13 Août 2018
Modifié(e) : Adam Danz le 13 Août 2018
Here are some ideas for solution
1) Create a small "refresh" button near the menu; the user can click it to refresh the list of files.
2) Create a timer function that continually checks the directory in the background every 'x' seconds and updates the menu whenever there is an update in the directory.
3) Any time the user interacts with the popup menu, it checks for changes in the directory and updates the list (after the user already clicked - which is weird).
If any of those solutions are viable and you need help getting started, I'd be glad to help.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by