Fixed keyboard controls for misc menu in post window

This commit is contained in:
Snowyfox 2022-05-21 23:14:21 -04:00
parent 174df078a5
commit 150773de8b
4 changed files with 77 additions and 24 deletions

View File

@ -6,6 +6,7 @@ import javax.swing.JTextField;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JComboBox; import javax.swing.JComboBox;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JSeparator;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
@ -121,6 +122,7 @@ ComposeWindow extends JFrame {
{ {
setContentPane(contentsDisplay); setContentPane(contentsDisplay);
revalidate(); revalidate();
contentsDisplay.requestFocusInWindow();
} }
public void public void
@ -128,6 +130,7 @@ ComposeWindow extends JFrame {
{ {
setContentPane(attachmentsDisplay); setContentPane(attachmentsDisplay);
revalidate(); revalidate();
attachmentsDisplay.requestFocusInWindow();
} }
// - -%- - // - -%- -
@ -338,7 +341,12 @@ implements ActionListener, CaretListener, KeyListener {
caretUpdate(CaretEvent eCa) { updateTextLength(); } caretUpdate(CaretEvent eCa) { updateTextLength(); }
public void public void
keyPressed(KeyEvent eK) { updateTextLength(); } keyPressed(KeyEvent eK)
{
boolean esc = eK.getKeyCode() == KeyEvent.VK_ESCAPE;
if (esc) showAttachmentsPage.requestFocusInWindow();
else updateTextLength();
}
public void public void
keyReleased(KeyEvent eK) { } keyReleased(KeyEvent eK) { }
@ -521,9 +529,9 @@ implements ActionListener {
attachment3.addActionListener(this); attachment3.addActionListener(this);
attachment4.addActionListener(this); attachment4.addActionListener(this);
JPanel left = new JPanel(); JPanel leftleft = new JPanel();
left.setOpaque(false); leftleft.setOpaque(false);
left.setLayout(null); leftleft.setLayout(null);
// BoxLayout wasn't listening to my // BoxLayout wasn't listening to my
// preferred nor minimum sizes. // preferred nor minimum sizes.
attachment1.setSize(40, 40); attachment1.setSize(40, 40);
@ -534,25 +542,30 @@ implements ActionListener {
attachment2.setLocation(0, 44); attachment2.setLocation(0, 44);
attachment3.setLocation(0, 88); attachment3.setLocation(0, 88);
attachment4.setLocation(0, 132); attachment4.setLocation(0, 132);
left.add(attachment1); leftleft.add(attachment1);
left.add(attachment2); leftleft.add(attachment2);
left.add(attachment3); leftleft.add(attachment3);
left.add(attachment4); leftleft.add(attachment4);
left.setPreferredSize(new Dimension(40, 172)); leftleft.setPreferredSize(new Dimension(40, 172));
JSeparator line = new JSeparator(JSeparator.VERTICAL);
JPanel left = new JPanel();
left.setLayout(new BorderLayout(8, 0));
left.add(leftleft, BorderLayout.CENTER);
left.add(line, BorderLayout.EAST);
delete = new JButton("Delete"); delete = new JButton("Delete");
revert = new JButton("Revert"); revert = new JButton("Revert");
close = new JButton("Save & close"); close = new JButton("Save all & close");
delete.addActionListener(this); delete.addActionListener(this);
revert.addActionListener(this); revert.addActionListener(this);
close.addActionListener(this); close.addActionListener(this);
Box bottom = Box.createHorizontalBox(); Box bottom = Box.createHorizontalBox();
bottom.add(close);
bottom.add(Box.createGlue());
bottom.add(delete); bottom.add(delete);
bottom.add(Box.createHorizontalStrut(16)); bottom.add(Box.createHorizontalStrut(16));
bottom.add(revert); bottom.add(revert);
bottom.add(Box.createGlue());
bottom.add(close);
description = new JTextArea(); description = new JTextArea();
description.setLineWrap(true); description.setLineWrap(true);
@ -571,7 +584,7 @@ implements ActionListener {
Box right = Box.createVerticalBox(); Box right = Box.createVerticalBox();
right.add(row1); right.add(row1);
setLayout(new BorderLayout(12, 10)); setLayout(new BorderLayout(8, 8));
add(right, BorderLayout.CENTER); add(right, BorderLayout.CENTER);
add(left, BorderLayout.WEST); add(left, BorderLayout.WEST);
add(bottom, BorderLayout.SOUTH); add(bottom, BorderLayout.SOUTH);

View File

@ -15,6 +15,8 @@ import javax.swing.BorderFactory;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.MenuSelectionManager;
import javax.swing.MenuElement;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Font; import java.awt.Font;
import java.awt.FontMetrics; import java.awt.FontMetrics;
@ -488,7 +490,6 @@ implements ActionListener {
public void public void
resetFocus() resetFocus()
{ {
//bodyScrollPane.getVerticalScrollBar().setValue(0);
media.requestFocusInWindow(); media.requestFocusInWindow();
} }
@ -521,9 +522,18 @@ implements ActionListener {
if (src == replyMisc) if (src == replyMisc)
{ {
if (command.startsWith("reply")) if (miscMenu.isVisible())
{
Component sel = getSelected(miscMenu);
if (sel == null) return;
assert sel instanceof JMenuItem;
((JMenuItem)sel).doClick();
}
else if (command.startsWith("reply"))
{
primaire.reply(); primaire.reply();
if (command.startsWith("misc")) }
else if (command.startsWith("misc"))
{ {
int rx = replyMisc.getWidth() / 2; int rx = replyMisc.getWidth() / 2;
int ry = replyMisc.getHeight() - miscMenu.getHeight(); int ry = replyMisc.getHeight() - miscMenu.getHeight();
@ -531,6 +541,7 @@ implements ActionListener {
} }
return; return;
} }
else miscMenu.setVisible(false);
if (src == nextPrev) if (src == nextPrev)
{ {
@ -590,6 +601,26 @@ implements ActionListener {
); );
} }
// - -%- -
private static Component
getSelected(JPopupMenu menu)
{
MenuElement[] sel =
MenuSelectionManager.defaultManager()
.getSelectedPath();
/*
* () For some reason, the selection model of the
* JPopupMenu doesn't do anything. So we have to
* consult this apparently global menu manager.
*/
for (int o = 0; o < sel.length - 1; ++o)
{
if (sel[o] == menu)
return sel[o + 1].getComponent();
}
return null;
}
// ---%-@-%--- // ---%-@-%---

View File

@ -654,6 +654,7 @@ implements
this.addMouseListener(this); this.addMouseListener(this);
this.addMouseMotionListener(this); this.addMouseMotionListener(this);
this.addKeyListener(this); this.addKeyListener(this);
setFocusable(true);
} }
} }

View File

@ -129,20 +129,28 @@ implements KeyListener, MouseListener, FocusListener {
public void public void
mousePressed(MouseEvent eM) mousePressed(MouseEvent eM)
{ {
switch (eM.getButton()) { boolean shift = eM.isShiftDown();
case MouseEvent.BUTTON1: togglePrimary(); break; boolean prim = eM.getButton() == MouseEvent.BUTTON1;
case MouseEvent.BUTTON3: toggleSecondary(); break; boolean secon = eM.getButton() == MouseEvent.BUTTON3;
} secon |= shift && prim;
if (secon) toggleSecondary();
else if (prim) togglePrimary();
requestFocusInWindow(); requestFocusInWindow();
} }
public void public void
keyPressed(KeyEvent eK) keyPressed(KeyEvent eK)
{ {
switch (eK.getKeyCode()) { boolean shift = eK.isShiftDown();
case KeyEvent.VK_SPACE: togglePrimary(); break; boolean prim = eK.getKeyCode() == KeyEvent.VK_SPACE;
case KeyEvent.VK_ENTER: toggleSecondary(); break; boolean secon = eK.getKeyCode() == KeyEvent.VK_ENTER;
} secon |= shift && prim;
if (secon) toggleSecondary();
else if (prim) togglePrimary();
requestFocusInWindow(); requestFocusInWindow();
} }