Skip to content

Add contextual menus to input fields #8672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/src/cc/arduino/contributions/ui/FilterJTextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,23 @@ private void updateStyle() {
setFont(getFont().deriveFont(Font.PLAIN));
}
}

@Override
public void paste() {

// Same precondition check as JTextComponent#paste().
if (!isEditable() || !isEnabled()) {
return;
}

// Disable hint to prevent the focus handler from clearing the pasted text.
if (showingHint) {
showingHint = false;
setText("");
updateStyle();
}

// Perform the paste.
super.paste();
}
}
29 changes: 29 additions & 0 deletions app/src/cc/arduino/contributions/ui/InstallerJDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,18 @@
import java.awt.event.WindowEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowAdapter;
import java.util.function.Predicate;

import javax.swing.Action;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
Expand All @@ -64,6 +67,7 @@
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import javax.swing.text.DefaultEditorKit;

import cc.arduino.contributions.ui.listeners.AbstractKeyListener;
import processing.app.Base;
Expand Down Expand Up @@ -130,6 +134,31 @@ protected void onFilter(String[] _filters) {
}
};

// Add cut/copy/paste contextual menu to the search filter input field.
JPopupMenu menu = new JPopupMenu();

Action cut = new DefaultEditorKit.CutAction();
cut.putValue(Action.NAME, tr("Cut"));
menu.add(cut);

Action copy = new DefaultEditorKit.CopyAction();
copy.putValue(Action.NAME, tr("Copy"));
menu.add(copy);

Action paste = new DefaultEditorKit.PasteAction();
paste.putValue(Action.NAME, tr("Paste"));
menu.add(paste);

filterField.setComponentPopupMenu(menu);

// Focus the filter field when the window opens.
addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent e) {
filterField.requestFocus();
}
});

filtersContainer = new JPanel();
filtersContainer.setLayout(new BoxLayout(filtersContainer, BoxLayout.X_AXIS));
filtersContainer.add(Box.createHorizontalStrut(5));
Expand Down
20 changes: 20 additions & 0 deletions app/src/processing/app/AbstractTextMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@
import java.util.Date;
import java.util.StringTokenizer;

import javax.swing.Action;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import javax.swing.text.DefaultCaret;
import javax.swing.text.DefaultEditorKit;

import cc.arduino.packages.BoardPort;

Expand Down Expand Up @@ -82,6 +85,23 @@ public void windowGainedFocus(WindowEvent e) {
}
});

// Add cut/copy/paste contextual menu to the text input field.
JPopupMenu menu = new JPopupMenu();

Action cut = new DefaultEditorKit.CutAction();
cut.putValue(Action.NAME, tr("Cut"));
menu.add(cut);

Action copy = new DefaultEditorKit.CopyAction();
copy.putValue(Action.NAME, tr("Copy"));
menu.add(copy);

Action paste = new DefaultEditorKit.PasteAction();
paste.putValue(Action.NAME, tr("Paste"));
menu.add(paste);

textField.setComponentPopupMenu(menu);

sendButton = new JButton(tr("Send"));
clearButton = new JButton(tr("Clear output"));

Expand Down