From e7dc9728a1aa4f172433fde663a5d5666f475ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sun, 4 Dec 2022 09:54:28 +0100 Subject: [PATCH] Disable context menus on editation --- .../decompiler/flash/gui/FolderPreviewPanel.java | 5 +++-- .../decompiler/flash/gui/GenericTagTreePanel.java | 3 ++- src/com/jpexs/decompiler/flash/gui/ImagePanel.java | 6 ++++-- src/com/jpexs/decompiler/flash/gui/Main.java | 3 ++- src/com/jpexs/decompiler/flash/gui/MainPanel.java | 6 ++++++ src/com/jpexs/decompiler/flash/gui/PinButton.java | 13 +++++++------ .../jpexs/decompiler/flash/gui/abc/ABCPanel.java | 3 ++- .../flash/gui/tagtree/TagTreeContextMenu.java | 4 +++- 8 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/gui/FolderPreviewPanel.java b/src/com/jpexs/decompiler/flash/gui/FolderPreviewPanel.java index 6b701d565..56ac2c5b0 100644 --- a/src/com/jpexs/decompiler/flash/gui/FolderPreviewPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/FolderPreviewPanel.java @@ -51,6 +51,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.SwingUtilities; import org.pushingpixels.substance.api.ColorSchemeAssociationKind; import org.pushingpixels.substance.api.ComponentState; import org.pushingpixels.substance.api.DecorationAreaType; @@ -123,7 +124,7 @@ public class FolderPreviewPanel extends JPanel { return; } - if (e.getButton() == MouseEvent.BUTTON1 || selectedItems.isEmpty()) { + if (SwingUtilities.isLeftMouseButton(e) || selectedItems.isEmpty()) { if (!e.isControlDown()) { selectedItems.clear(); } @@ -148,7 +149,7 @@ public class FolderPreviewPanel extends JPanel { } } - if (e.getButton() == MouseEvent.BUTTON3) { + if (SwingUtilities.isRightMouseButton(e)) { mainPanel.getContextPopupMenu().update(new ArrayList<>(selectedItems.values())); mainPanel.getContextPopupMenu().show(FolderPreviewPanel.this, e.getX(), e.getY()); } diff --git a/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java b/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java index cceb8f825..36f8c653b 100644 --- a/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/GenericTagTreePanel.java @@ -90,6 +90,7 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JTree; +import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.event.TreeModelListener; import javax.swing.plaf.basic.BasicLabelUI; @@ -456,7 +457,7 @@ public class GenericTagTreePanel extends GenericTagPanel { TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); if (selRow != -1 && selPath != null) { if (e.getClickCount() == 1) { - if (e.getButton() == MouseEvent.BUTTON3) { //right click + if (SwingUtilities.isRightMouseButton(e)) { //right click Object selObject = selPath.getLastPathComponent(); if (selObject instanceof FieldNode) { final FieldNode fnode = (FieldNode) selObject; diff --git a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index 5531095e5..9fa369e45 100644 --- a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -102,7 +102,9 @@ import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.UnsupportedAudioFileException; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.SwingUtilities; import javax.swing.event.MouseInputAdapter; +import jsyntaxpane.util.SwingUtils; import org.pushingpixels.substance.api.ColorSchemeAssociationKind; import org.pushingpixels.substance.api.ComponentState; import org.pushingpixels.substance.api.DecorationAreaType; @@ -549,7 +551,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { MouseInputAdapter mouseInputAdapter = new MouseInputAdapter() { @Override public void mousePressed(MouseEvent e) { - if (e.getButton() == MouseEvent.BUTTON1) { + if (SwingUtilities.isLeftMouseButton(e)) { mouseMoved(e); //to correctly calculate mode, because moseMoved event is not called during dragging setDragStart(e.getPoint()); @@ -564,7 +566,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { @Override public void mouseReleased(MouseEvent e) { - if (e.getButton() == MouseEvent.BUTTON1) { + if (SwingUtilities.isLeftMouseButton(e)) { dragStart = null; if (freeTransformDepth > -1 && mode != Cursor.DEFAULT_CURSOR && registrationPointUpdated != null && transformUpdated != null) { diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index ee03685e8..ab3a8f6f3 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -135,6 +135,7 @@ import java.util.logging.Logger; import java.util.logging.SimpleFormatter; import javax.swing.JFileChooser; import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; import javax.swing.SwingWorker; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; @@ -2673,7 +2674,7 @@ public class Main { */ @Override public void mouseClicked(MouseEvent e) { - if (e.getButton() == MouseEvent.BUTTON1) { + if (SwingUtilities.isLeftMouseButton(e)) { Main.showProxy(); } } diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 904c5a0b4..8974df332 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -452,6 +452,9 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se } private void handleTreeKeyReleased(KeyEvent e) { + if (checkEdited()) { + return; + } AbstractTagTree tree = (AbstractTagTree) e.getSource(); if ((e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_DOWN) @@ -514,6 +517,9 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se } private void handleTreeKeyPressed(KeyEvent e) { + if (checkEdited()) { + return; + } AbstractTagTree tree = (AbstractTagTree) e.getSource(); if ((e.getKeyCode() == 'F') && (e.isControlDown())) { if (tree == tagTree) { diff --git a/src/com/jpexs/decompiler/flash/gui/PinButton.java b/src/com/jpexs/decompiler/flash/gui/PinButton.java index 4e7643288..42b42db66 100644 --- a/src/com/jpexs/decompiler/flash/gui/PinButton.java +++ b/src/com/jpexs/decompiler/flash/gui/PinButton.java @@ -34,6 +34,7 @@ import java.util.List; import javax.swing.BorderFactory; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.SwingUtilities; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.tree.TreePath; @@ -124,10 +125,10 @@ public class PinButton extends JPanel { @Override public void mousePressed(MouseEvent e) { - if (e.getButton() == MouseEvent.BUTTON1) { - //setBorder(loweredBorder); - } - if (e.getButton() == MouseEvent.BUTTON3) { + if (SwingUtilities.isRightMouseButton(e)) { + if (mainPanel.checkEdited()) { + return; + } List itemList = new ArrayList<>(); itemList.add(item); mainPanel.getContextPopupMenu().update(itemList); @@ -137,7 +138,7 @@ public class PinButton extends JPanel { @Override public void mouseReleased(MouseEvent e) { - if (e.getButton() == MouseEvent.BUTTON1) { + if (SwingUtilities.isLeftMouseButton(e)) { /*if (selected) { setBorder(loweredBorder); } else { @@ -223,7 +224,7 @@ public class PinButton extends JPanel { @Override public void mouseReleased(MouseEvent e) { - if (e.getButton() == MouseEvent.BUTTON1) { + if (SwingUtilities.isLeftMouseButton(e)) { PinButton.this.pinned = !PinButton.this.pinned; if (PinButton.this.pinned) { button.setToolTipText(AppStrings.translate("unpin")); diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index 85f150ded..4de783f9e 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -131,6 +131,7 @@ import javax.swing.JTabbedPane; import javax.swing.JTable; import javax.swing.JToggleButton; import javax.swing.SwingConstants; +import javax.swing.SwingUtilities; import javax.swing.SwingWorker; import javax.swing.ToolTipManager; import javax.swing.border.BevelBorder; @@ -1293,7 +1294,7 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener