Skip to content

Disable cut and copy if there is not selected text #4790

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 6, 2016
Merged
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
17 changes: 15 additions & 2 deletions app/src/processing/app/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1369,8 +1369,6 @@ private JMenu buildEditMenu() {

menu.addSeparator();

// TODO "cut" and "copy" should really only be enabled
// if some text is currently selected
JMenuItem cutItem = newJMenuItem(tr("Cut"), 'X');
cutItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Expand Down Expand Up @@ -1515,6 +1513,21 @@ public void actionPerformed(ActionEvent e) {
menu.add(useSelectionForFindItem);
}

menu.addMenuListener(new MenuListener() {
@Override
public void menuSelected(MenuEvent e) {
boolean enabled = textarea.getSelectedText() != null;
cutItem.setEnabled(enabled);
copyItem.setEnabled(enabled);
}

@Override
public void menuDeselected(MenuEvent e) {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you Overriding this?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it because MenuListener implements an interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Because I'm instancing an anonymous class from MenuListener, it's mandatory to implement every method. But I choose use only menuSelected for checking if there's selected text.


@Override
public void menuCanceled(MenuEvent e) {}
});

return menu;
}

Expand Down