Dynamic context menus?

7 ビュー (過去 30 日間)
Dr. Seis
Dr. Seis 2011 年 10 月 25 日
Is it possible to create a dynamic context menu in a Matlab GUI? For example, I would like to create a context menu with the same look and feel as the one available at the main command line (for example - if you were to type "quad" and then hit tab you would get a list of functions that begin with "quad" like "quad2d" , "quadgk" , ... ). I would like to be able to type something inside of an edit box, hit tab, get the list (in one case their might be 3 matches, but in another there might be 15 matches), arrow up/down to the right one, and select it.
Any hints/clues would be most helpful.

回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 10 月 26 日
Thank goodness I had Lazarus Forms Recovery installed, as I had typed a complete answer only to lose it when the system was taken down for maintenance!
Here goes:
If you use a figure key press function callback then you can detect the tab being pressed. You could then create a popup list or listbox and shift the focus to it. Both popup and listbox allow up/down arrow to move the selection, and allow return to select. You would determine the selected variation, set() the edit box string to that.
Warning: there are known difficulties in using key press callbacks within an edit box. The edit box String property automatic update behavior is weird enough when you have a key press callback that the only practical way to proceed is to remember every keypress yourself under the assumption that the String property will be wrong.
Because of this edit box key behavior, most people who want to change the edit box behavior do so at the JAVA level; for information on that, see http://undocumentedmatlab.com
  2 件のコメント
Dr. Seis
Dr. Seis 2011 年 10 月 26 日
Thanks, Walter. I am trying to avoid adding a listbox or popup to my layout... or creating a new GUI to handle this functionality. It is also an issue I am trying to resolve for one of my "normal" menu bar items. Right now I have something in one of my menu bar items that is similar to something in Microsoft Office products that displays "recently opened" items. I have 5 dummy slots, but these were manually added/created. What I was hoping, is that there was a way of somehow dynamically creating these slots so that if there were 3 recently opened files, or 15 or whatever, then it would only display those. Right now, if there were three files, my menu bar window (I don't know the correct term for this) would look like:
File >
Recently Opened >
file01.xml
file02.xml
file03.xml
No file to display
No file to display
So... I impose a limit of 5 most recent files to look at, but if there are fewer then I have "No file to display" as a place holder (which I would rather not do).
This is the sort of thing I was wondering if was possible to overcome.
Dr. Seis
Dr. Seis 2011 年 10 月 26 日
The section "uicontextmenu" looks sort of promising. But I am not sure how I could apply this sort of on-the-fly-context-menu-creator to a current menu item. I will have to experiment a little.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by