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

View File

@ -15,6 +15,8 @@ import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import javax.swing.MenuSelectionManager;
import javax.swing.MenuElement;
import java.awt.Graphics;
import java.awt.Font;
import java.awt.FontMetrics;
@ -488,7 +490,6 @@ implements ActionListener {
public void
resetFocus()
{
//bodyScrollPane.getVerticalScrollBar().setValue(0);
media.requestFocusInWindow();
}
@ -521,9 +522,18 @@ implements ActionListener {
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();
if (command.startsWith("misc"))
}
else if (command.startsWith("misc"))
{
int rx = replyMisc.getWidth() / 2;
int ry = replyMisc.getHeight() - miscMenu.getHeight();
@ -531,6 +541,7 @@ implements ActionListener {
}
return;
}
else miscMenu.setVisible(false);
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.addMouseMotionListener(this);
this.addKeyListener(this);
setFocusable(true);
}
}

View File

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