Filter löschen
Filter löschen

How to know whether contextmenu item was selected by mouse or shortcut?

2 Ansichten (letzte 30 Tage)
I have a uitable that I add/delete rows from using context menu selections. I have the ability to use the mouse and select the contextmenu or just CTRL+ "N" or "Z" to add/delete rows. Is there a way to know whether the callback for that menu selection is triggered by my mouse vs. the shortcut?
The problem I run into with the code below is if a user selects a cell in row 1, but then uses the mouse+contextmenu on a cell in row 2, the table.selection property is not empty so the code below thinks my user selected row 1.
if ~isempty(app.SequenceTable.Selection)
temp = app.SequenceTable.Selection;
row = temp(1);
else
row = event.InteractionInformation.Row;
end
I previously flipped it so my if statement had the condition below, but that caused a similar problem the other way.
isprop(event,'InteractionInformation')
  1 Kommentar
Alex
Alex am 8 Mär. 2024
One potential improvement that may work is looking at the current modifiers for the main figure:
if ~isempty(get(app.Main_UIFigure,'CurrentModifier'))
temp = app.SequenceTable.Selection;
row = temp(1);
else
row = event.InteractionInformation.Row;
end
This works for normal user input, but if someone decides to hold the CTRL button while they right-click and select an item from the context menu, then it will return the row as the currently selected cell rather than the one that was right-clicked on.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Alex
Alex am 8 Mär. 2024
Looked around some more and I think my best proposal for this problem is to use the SelectionType of the app's main figure:
if strcmp(app.Main_UIFigure.SelectionType,'normal')
temp = app.SequenceTable.Selection;
row = temp(1);
else
row = event.InteractionInformation.Row;
end

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by