mirror of
https://github.com/processing/processing4.git
synced 2026-02-14 10:55:38 +01:00
Cut and Copy in the edit menu are active only if some text is selected
This commit is contained in:
@@ -88,10 +88,12 @@ public abstract class Editor extends JFrame implements RunnerListener {
|
||||
private Point sketchWindowLocation;
|
||||
|
||||
// undo fellers
|
||||
private JMenuItem undoItem, redoItem;
|
||||
private JMenuItem undoItem, redoItem, copyItems, cutItems;
|
||||
protected UndoAction undoAction;
|
||||
protected RedoAction redoAction;
|
||||
/** the currently selected tab's undo manager */
|
||||
protected CopyAction copyAction;
|
||||
protected CutAction cutAction;
|
||||
private UndoManager undo;
|
||||
// used internally for every edit. Groups hotkey-event text manipulations and
|
||||
// groups multi-character inputs into a single undos.
|
||||
@@ -734,23 +736,13 @@ public abstract class Editor extends JFrame implements RunnerListener {
|
||||
|
||||
menu.addSeparator();
|
||||
|
||||
// TODO "cut" and "copy" should really only be enabled
|
||||
// if some text is currently selected
|
||||
item = Toolkit.newJMenuItem(Language.text("menu.edit.cut"), 'X');
|
||||
item.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleCut();
|
||||
}
|
||||
});
|
||||
menu.add(item);
|
||||
cutItems = Toolkit.newJMenuItem("Cut", 'X');
|
||||
cutItems.addActionListener(cutAction = new CutAction());
|
||||
menu.add(cutItems);
|
||||
|
||||
item = Toolkit.newJMenuItem(Language.text("menu.edit.copy"), 'C');
|
||||
item.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
textarea.copy();
|
||||
}
|
||||
});
|
||||
menu.add(item);
|
||||
copyItems = Toolkit.newJMenuItem("Copy", 'C');
|
||||
copyItems.addActionListener(copyAction = new CopyAction());
|
||||
menu.add(copyItems);
|
||||
|
||||
item = Toolkit.newJMenuItemShift(Language.text("menu.edit.copy_as_html"), 'C');
|
||||
item.addActionListener(new ActionListener() {
|
||||
@@ -888,7 +880,25 @@ public abstract class Editor extends JFrame implements RunnerListener {
|
||||
}
|
||||
});
|
||||
menu.add(item);
|
||||
|
||||
// Listener to the Edit menu item
|
||||
menu.addMenuListener(new MenuListener() {
|
||||
|
||||
@Override
|
||||
public void menuCanceled(MenuEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void menuDeselected(MenuEvent e) {
|
||||
}
|
||||
/* Updating the copy and cut JMenuItems
|
||||
* as soon as the Edit menu is selected
|
||||
*/
|
||||
@Override
|
||||
public void menuSelected(MenuEvent e) {
|
||||
copyAction.updateCopyState();
|
||||
cutAction.updateCutState();
|
||||
}
|
||||
});
|
||||
return menu;
|
||||
}
|
||||
|
||||
@@ -1275,6 +1285,52 @@ public abstract class Editor extends JFrame implements RunnerListener {
|
||||
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
class CutAction extends AbstractAction {
|
||||
public CutAction() {
|
||||
super("Cut");
|
||||
this.setEnabled(false);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println(e.getActionCommand());
|
||||
handleCut();
|
||||
}
|
||||
|
||||
public void updateCutState() {
|
||||
if (canCut()) {
|
||||
cutItems.setEnabled(true);
|
||||
} else {
|
||||
cutItems.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canCut() {
|
||||
return textarea.isSelectionActive();
|
||||
}
|
||||
}
|
||||
|
||||
class CopyAction extends AbstractAction {
|
||||
public CopyAction() {
|
||||
super("Copy");
|
||||
this.setEnabled(false);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
textarea.copy();
|
||||
}
|
||||
|
||||
public void updateCopyState() {
|
||||
if (canCopy()) {
|
||||
copyItems.setEnabled(true);
|
||||
} else {
|
||||
copyItems.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canCopy() {
|
||||
return textarea.isSelectionActive();
|
||||
}
|
||||
}
|
||||
|
||||
class UndoAction extends AbstractAction {
|
||||
public UndoAction() {
|
||||
|
||||
Reference in New Issue
Block a user