Tony CHEMIT pushed to branch develop-7.x at ultreiaio / ird-observe Commits: a14ba256 by Tony CHEMIT at 2018-06-17T11:42:59Z Des racourcis clavier interfèrent avec l'autocomplétion des listes déroulantes - Closes #953 - - - - - 2 changed files: - client/src/main/java/fr/ird/observe/client/ui/actions/UIActionSupport.java - client/src/main/java/fr/ird/observe/client/ui/actions/main/menu/MenuActionSupport.java Changes: ===================================== client/src/main/java/fr/ird/observe/client/ui/actions/UIActionSupport.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/actions/UIActionSupport.java +++ b/client/src/main/java/fr/ird/observe/client/ui/actions/UIActionSupport.java @@ -6,15 +6,15 @@ * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the + * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public + * + * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% @@ -125,7 +125,9 @@ public abstract class UIActionSupport extends AbstractAction { //FIXME Attention on introduit un état dans l'action et si l'action est utilisée plusieurs fois dans un même écran //FIXME cela va introduire des effets de bord putValue(EDITOR, editor); - register(inputMap, actionMap); + if (inputMap != null && actionMap != null) { + register(inputMap, actionMap); + } } private void register(InputMap inputMap, ActionMap actionMap) { ===================================== client/src/main/java/fr/ird/observe/client/ui/actions/main/menu/MenuActionSupport.java ===================================== --- a/client/src/main/java/fr/ird/observe/client/ui/actions/main/menu/MenuActionSupport.java +++ b/client/src/main/java/fr/ird/observe/client/ui/actions/main/menu/MenuActionSupport.java @@ -10,12 +10,12 @@ package fr.ird.observe.client.ui.actions.main.menu; * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-3.0.html>. @@ -30,7 +30,11 @@ import javax.swing.AbstractButton; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; +import javax.swing.event.PopupMenuEvent; +import javax.swing.event.PopupMenuListener; import java.awt.event.ActionEvent; import java.util.Objects; @@ -41,6 +45,8 @@ import java.util.Objects; */ public abstract class MenuActionSupport extends UIActionSupport { + private boolean menuSelected; + protected MenuActionSupport(ObserveMainUI mainUI, String actionCommandKey, String label, String shortDescription, String actionIcon, KeyStroke acceleratorKey) { super(mainUI, actionCommandKey, label, shortDescription, actionIcon, acceleratorKey, false); } @@ -52,7 +58,6 @@ public abstract class MenuActionSupport extends UIActionSupport { @Override public void actionPerformed(ActionEvent e) { - if (canExecuteAction(e)) { doActionPerformed(e); } @@ -67,20 +72,36 @@ public abstract class MenuActionSupport extends UIActionSupport { return false; } if (editor instanceof JMenuItem) { - return ((JMenuItem) editor).isArmed(); + return menuSelected && ((JMenuItem) editor).isArmed(); } return editor.isShowing(); } @Override public void initForMainUi(AbstractButton editor) { - super.initForMainUi(editor); - if (editor instanceof JButton) { + JComponent parent = (JComponent) editor.getParent(); + if (parent instanceof JPopupMenu) { + ((JPopupMenu) parent).addPopupMenuListener(new PopupMenuListener() { + @Override + public void popupMenuWillBecomeVisible(PopupMenuEvent e) { + menuSelected = true; + } - // this is a normal button using a menu action, let's add to text accelerator + @Override + public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { + SwingUtilities.invokeLater(() -> menuSelected = false); + } + @Override + public void popupMenuCanceled(PopupMenuEvent e) { + menuSelected = false; + } + }); + } + initForMainUi(editor, null, null); + if (editor instanceof JButton) { + // this is a normal button using a menu action, let's add to text accelerator ObserveKeyStrokes.addKeyStoreToText(editor, this); } - } } View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/a14ba256b742a730e3892160fa18... -- View it on GitLab: https://gitlab.com/ultreiaio/ird-observe/commit/a14ba256b742a730e3892160fa18... You're receiving this email because of your account on gitlab.com.
participants (1)
-
Tony CHEMIT