1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-30 19:52:13 +01:00

Merge pull request #7888 from cmaglie/fix-fontsize-keybindings

Fix "Increase Font Size" keybindings
This commit is contained in:
Martino Facchin 2018-08-20 17:31:02 +02:00 committed by GitHub
commit e518050b28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,36 +22,25 @@
package processing.app; package processing.app;
import cc.arduino.packages.BoardPort; import static processing.app.I18n.tr;
import cc.arduino.packages.MonitorFactory; import static processing.app.Theme.scale;
import cc.arduino.packages.Uploader;
import cc.arduino.packages.uploaders.SerialUploader;
import cc.arduino.view.GoToLineNumber;
import cc.arduino.view.StubMenuListener;
import cc.arduino.view.findreplace.FindReplace;
import cc.arduino.CompilerProgressListener;
import com.jcraft.jsch.JSchException;
import jssc.SerialPortException;
import processing.app.debug.RunnerException;
import processing.app.forms.PasswordAuthorizationDialog;
import processing.app.helpers.DocumentTextChangeListener;
import processing.app.helpers.Keys;
import processing.app.helpers.OSUtils;
import processing.app.helpers.PreferencesMapException;
import processing.app.helpers.StringReplacer;
import processing.app.legacy.PApplet;
import processing.app.syntax.PdeKeywords;
import processing.app.syntax.SketchTextArea;
import processing.app.tools.MenuScroller;
import processing.app.tools.Tool;
import javax.swing.*; import java.awt.BorderLayout;
import javax.swing.event.*; import java.awt.Color;
import javax.swing.text.BadLocationException; import java.awt.Component;
import java.awt.*; import java.awt.Container;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
import java.awt.event.*; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.print.PageFormat; import java.awt.print.PageFormat;
import java.awt.print.PrinterException; import java.awt.print.PrinterException;
import java.awt.print.PrinterJob; import java.awt.print.PrinterJob;
@ -62,17 +51,64 @@ import java.io.IOException;
import java.net.ConnectException; import java.net.ConnectException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import java.util.ArrayList;
import static processing.app.I18n.tr; import javax.swing.AbstractAction;
import static processing.app.Theme.scale; import javax.swing.Box;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.TransferHandler;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import javax.swing.text.BadLocationException;
import com.jcraft.jsch.JSchException;
import cc.arduino.CompilerProgressListener;
import cc.arduino.packages.BoardPort;
import cc.arduino.packages.MonitorFactory;
import cc.arduino.packages.Uploader;
import cc.arduino.packages.uploaders.SerialUploader;
import cc.arduino.view.Event;
import cc.arduino.view.GoToLineNumber;
import cc.arduino.view.StubMenuListener;
import cc.arduino.view.findreplace.FindReplace;
import jssc.SerialPortException;
import processing.app.debug.RunnerException;
import processing.app.forms.PasswordAuthorizationDialog;
import processing.app.helpers.DocumentTextChangeListener;
import processing.app.helpers.FileUtils; import processing.app.helpers.FileUtils;
import processing.app.helpers.Keys;
import processing.app.helpers.OSUtils;
import processing.app.helpers.PreferencesMapException;
import processing.app.helpers.StringReplacer;
import processing.app.legacy.PApplet;
import processing.app.syntax.PdeKeywords;
import processing.app.syntax.SketchTextArea;
import processing.app.tools.MenuScroller;
import processing.app.tools.Tool;
/** /**
* Main editor panel for the Processing Development Environment. * Main editor panel for the Processing Development Environment.
@ -534,37 +570,28 @@ public class Editor extends JFrame implements RunnerListener {
fileMenu.setMnemonic(KeyEvent.VK_F); fileMenu.setMnemonic(KeyEvent.VK_F);
item = newJMenuItem(tr("New"), 'N'); item = newJMenuItem(tr("New"), 'N');
item.addActionListener(new ActionListener() { item.addActionListener(event -> {
public void actionPerformed(ActionEvent e) { try {
try { base.handleNew();
base.handleNew(); } catch (Exception e1) {
} catch (Exception e1) { e1.printStackTrace();
e1.printStackTrace(); }
} });
}
});
fileMenu.add(item); fileMenu.add(item);
item = Editor.newJMenuItem(tr("Open..."), 'O'); item = Editor.newJMenuItem(tr("Open..."), 'O');
item.addActionListener(new ActionListener() { item.addActionListener(event -> {
public void actionPerformed(ActionEvent e) { try {
try { base.handleOpenPrompt();
base.handleOpenPrompt(); } catch (Exception e1) {
} catch (Exception e1) { e1.printStackTrace();
e1.printStackTrace(); }
} });
}
});
fileMenu.add(item); fileMenu.add(item);
base.rebuildRecentSketchesMenuItems(); base.rebuildRecentSketchesMenuItems();
recentSketchesMenu = new JMenu(tr("Open Recent")); recentSketchesMenu = new JMenu(tr("Open Recent"));
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(() -> rebuildRecentSketchesMenu());
@Override
public void run() {
rebuildRecentSketchesMenu();
}
});
fileMenu.add(recentSketchesMenu); fileMenu.add(recentSketchesMenu);
if (sketchbookMenu == null) { if (sketchbookMenu == null) {
@ -582,45 +609,25 @@ public class Editor extends JFrame implements RunnerListener {
fileMenu.add(examplesMenu); fileMenu.add(examplesMenu);
item = Editor.newJMenuItem(tr("Close"), 'W'); item = Editor.newJMenuItem(tr("Close"), 'W');
item.addActionListener(new ActionListener() { item.addActionListener(event -> base.handleClose(Editor.this));
public void actionPerformed(ActionEvent e) {
base.handleClose(Editor.this);
}
});
fileMenu.add(item); fileMenu.add(item);
saveMenuItem = newJMenuItem(tr("Save"), 'S'); saveMenuItem = newJMenuItem(tr("Save"), 'S');
saveMenuItem.addActionListener(new ActionListener() { saveMenuItem.addActionListener(event -> handleSave(false));
public void actionPerformed(ActionEvent e) {
handleSave(false);
}
});
fileMenu.add(saveMenuItem); fileMenu.add(saveMenuItem);
saveAsMenuItem = newJMenuItemShift(tr("Save As..."), 'S'); saveAsMenuItem = newJMenuItemShift(tr("Save As..."), 'S');
saveAsMenuItem.addActionListener(new ActionListener() { saveAsMenuItem.addActionListener(event -> handleSaveAs());
public void actionPerformed(ActionEvent e) {
handleSaveAs();
}
});
fileMenu.add(saveAsMenuItem); fileMenu.add(saveAsMenuItem);
fileMenu.addSeparator(); fileMenu.addSeparator();
item = newJMenuItemShift(tr("Page Setup"), 'P'); item = newJMenuItemShift(tr("Page Setup"), 'P');
item.addActionListener(new ActionListener() { item.addActionListener(event -> handlePageSetup());
public void actionPerformed(ActionEvent e) {
handlePageSetup();
}
});
fileMenu.add(item); fileMenu.add(item);
item = newJMenuItem(tr("Print"), 'P'); item = newJMenuItem(tr("Print"), 'P');
item.addActionListener(new ActionListener() { item.addActionListener(event -> handlePrint());
public void actionPerformed(ActionEvent e) {
handlePrint();
}
});
fileMenu.add(item); fileMenu.add(item);
// macosx already has its own preferences and quit menu // macosx already has its own preferences and quit menu
@ -628,21 +635,13 @@ public class Editor extends JFrame implements RunnerListener {
fileMenu.addSeparator(); fileMenu.addSeparator();
item = newJMenuItem(tr("Preferences"), ','); item = newJMenuItem(tr("Preferences"), ',');
item.addActionListener(new ActionListener() { item.addActionListener(event -> base.handlePrefs());
public void actionPerformed(ActionEvent e) {
base.handlePrefs();
}
});
fileMenu.add(item); fileMenu.add(item);
fileMenu.addSeparator(); fileMenu.addSeparator();
item = newJMenuItem(tr("Quit"), 'Q'); item = newJMenuItem(tr("Quit"), 'Q');
item.addActionListener(new ActionListener() { item.addActionListener(event -> base.handleQuit());
public void actionPerformed(ActionEvent e) {
base.handleQuit();
}
});
fileMenu.add(item); fileMenu.add(item);
} }
return fileMenu; return fileMenu;
@ -659,58 +658,35 @@ public class Editor extends JFrame implements RunnerListener {
sketchMenu.removeAll(); sketchMenu.removeAll();
JMenuItem item = newJMenuItem(tr("Verify/Compile"), 'R'); JMenuItem item = newJMenuItem(tr("Verify/Compile"), 'R');
item.addActionListener(new ActionListener() { item.addActionListener(event -> handleRun(false, presentHandler, runHandler));
public void actionPerformed(ActionEvent e) {
handleRun(false, Editor.this.presentHandler, Editor.this.runHandler);
}
});
sketchMenu.add(item); sketchMenu.add(item);
item = newJMenuItem(tr("Upload"), 'U'); item = newJMenuItem(tr("Upload"), 'U');
item.addActionListener(new ActionListener() { item.addActionListener(event -> handleExport(false));
public void actionPerformed(ActionEvent e) {
handleExport(false);
}
});
sketchMenu.add(item); sketchMenu.add(item);
item = newJMenuItemShift(tr("Upload Using Programmer"), 'U'); item = newJMenuItemShift(tr("Upload Using Programmer"), 'U');
item.addActionListener(new ActionListener() { item.addActionListener(event -> handleExport(true));
public void actionPerformed(ActionEvent e) {
handleExport(true);
}
});
sketchMenu.add(item); sketchMenu.add(item);
item = newJMenuItemAlt(tr("Export compiled Binary"), 'S'); item = newJMenuItemAlt(tr("Export compiled Binary"), 'S');
item.addActionListener(new ActionListener() { item.addActionListener(event -> {
public void actionPerformed(ActionEvent e) { if (new ShouldSaveReadOnly().test(sketchController) && !handleSave(true)) {
if (new ShouldSaveReadOnly().test(sketchController) && !handleSave(true)) { System.out.println(tr("Export canceled, changes must first be saved."));
System.out.println(tr("Export canceled, changes must first be saved.")); return;
return; }
} handleRun(false, new ShouldSaveReadOnly(), presentAndSaveHandler, runAndSaveHandler);
handleRun(false, new ShouldSaveReadOnly(), Editor.this.presentAndSaveHandler, Editor.this.runAndSaveHandler); });
}
});
sketchMenu.add(item); sketchMenu.add(item);
// item = new JMenuItem("Stop"); // item = new JMenuItem("Stop");
// item.addActionListener(new ActionListener() { // item.addActionListener(event -> handleStop());
// public void actionPerformed(ActionEvent e) {
// handleStop();
// }
// });
// sketchMenu.add(item); // sketchMenu.add(item);
sketchMenu.addSeparator(); sketchMenu.addSeparator();
item = newJMenuItem(tr("Show Sketch Folder"), 'K'); item = newJMenuItem(tr("Show Sketch Folder"), 'K');
item.addActionListener(new ActionListener() { item.addActionListener(event -> Base.openFolder(sketch.getFolder()));
public void actionPerformed(ActionEvent e) {
Base.openFolder(sketch.getFolder());
}
});
sketchMenu.add(item); sketchMenu.add(item);
item.setEnabled(Base.openFolderAvailable()); item.setEnabled(Base.openFolderAvailable());
@ -722,11 +698,7 @@ public class Editor extends JFrame implements RunnerListener {
sketchMenu.add(importMenu); sketchMenu.add(importMenu);
item = new JMenuItem(tr("Add File...")); item = new JMenuItem(tr("Add File..."));
item.addActionListener(new ActionListener() { item.addActionListener(event -> sketchController.handleAddFile());
public void actionPerformed(ActionEvent e) {
sketchController.handleAddFile();
}
});
sketchMenu.add(item); sketchMenu.add(item);
} }
@ -900,11 +872,9 @@ public class Editor extends JFrame implements RunnerListener {
String title = tool.getMenuTitle(); String title = tool.getMenuTitle();
JMenuItem item = new JMenuItem(title); JMenuItem item = new JMenuItem(title);
item.addActionListener(new ActionListener() { item.addActionListener(event -> {
public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(tool);
SwingUtilities.invokeLater(tool); //new Thread(tool).start();
//new Thread(tool).start();
}
}); });
//menu.add(item); //menu.add(item);
toolItems.put(title, item); toolItems.put(title, item);
@ -975,11 +945,7 @@ public class Editor extends JFrame implements RunnerListener {
tool.init(Editor.this); tool.init(Editor.this);
item.addActionListener(new ActionListener() { item.addActionListener(event -> SwingUtilities.invokeLater(tool));
public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(tool);
}
});
return item; return item;
} catch (Exception e) { } catch (Exception e) {
@ -1132,78 +1098,23 @@ public class Editor extends JFrame implements RunnerListener {
private JMenu buildHelpMenu() { private JMenu buildHelpMenu() {
// To deal with a Mac OS X 10.5 bug, add an extra space after the name
// so that the OS doesn't try to insert its slow help menu.
JMenu menu = new JMenu(tr("Help")); JMenu menu = new JMenu(tr("Help"));
menu.setMnemonic(KeyEvent.VK_H); menu.setMnemonic(KeyEvent.VK_H);
JMenuItem item;
/* JMenuItem item = new JMenuItem(tr("Getting Started"));
// testing internal web server to serve up docs from a zip file item.addActionListener(event -> Base.showArduinoGettingStarted());
item = new JMenuItem("Web Server Test");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//WebServer ws = new WebServer();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
int port = WebServer.launch("/Users/fry/coconut/processing/build/shared/reference.zip");
Base.openURL("http://127.0.0.1:" + port + "/reference/setup_.html");
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
}
});
menu.add(item);
*/
/*
item = new JMenuItem("Browser Test");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//Base.openURL("http://processing.org/learning/gettingstarted/");
//JFrame browserFrame = new JFrame("Browser");
BrowserStartup bs = new BrowserStartup("jar:file:/Users/fry/coconut/processing/build/shared/reference.zip!/reference/setup_.html");
bs.initUI();
bs.launch();
}
});
menu.add(item);
*/
item = new JMenuItem(tr("Getting Started"));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Base.showArduinoGettingStarted();
}
});
menu.add(item); menu.add(item);
item = new JMenuItem(tr("Environment")); item = new JMenuItem(tr("Environment"));
item.addActionListener(new ActionListener() { item.addActionListener(event -> Base.showEnvironment());
public void actionPerformed(ActionEvent e) {
Base.showEnvironment();
}
});
menu.add(item); menu.add(item);
item = new JMenuItem(tr("Troubleshooting")); item = new JMenuItem(tr("Troubleshooting"));
item.addActionListener(new ActionListener() { item.addActionListener(event -> Base.showTroubleshooting());
public void actionPerformed(ActionEvent e) {
Base.showTroubleshooting();
}
});
menu.add(item); menu.add(item);
item = new JMenuItem(tr("Reference")); item = new JMenuItem(tr("Reference"));
item.addActionListener(new ActionListener() { item.addActionListener(event -> Base.showReference());
public void actionPerformed(ActionEvent e) {
Base.showReference();
}
});
menu.add(item); menu.add(item);
menu.addSeparator(); menu.addSeparator();
@ -1213,18 +1124,11 @@ public class Editor extends JFrame implements RunnerListener {
menu.add(item); menu.add(item);
item = new JMenuItem(tr("Getting Started")); item = new JMenuItem(tr("Getting Started"));
item.addActionListener(new ActionListener() { item.addActionListener(event -> Base.showReference("reference/Galileo_help_files", "ArduinoIDE_guide_galileo"));
public void actionPerformed(ActionEvent e) {
Base.showReference("reference/Galileo_help_files", "ArduinoIDE_guide_galileo");
}
});
menu.add(item); menu.add(item);
item = new JMenuItem(tr("Troubleshooting")); item = new JMenuItem(tr("Troubleshooting"));
item.addActionListener(new ActionListener() { item.addActionListener(event -> Base.showReference("reference/Galileo_help_files", "Guide_Troubleshooting_Galileo"));
public void actionPerformed(ActionEvent e) {
Base.showReference("reference/Galileo_help_files", "Guide_Troubleshooting_Galileo");
}
});
menu.add(item); menu.add(item);
menu.addSeparator(); menu.addSeparator();
@ -1234,51 +1138,32 @@ public class Editor extends JFrame implements RunnerListener {
menu.add(item); menu.add(item);
item = new JMenuItem(tr("Getting Started")); item = new JMenuItem(tr("Getting Started"));
item.addActionListener(new ActionListener() { item.addActionListener(event -> Base.showReference("reference/Edison_help_files", "ArduinoIDE_guide_edison"));
public void actionPerformed(ActionEvent e) {
Base.showReference("reference/Edison_help_files", "ArduinoIDE_guide_edison");
}
});
menu.add(item); menu.add(item);
item = new JMenuItem(tr("Troubleshooting")); item = new JMenuItem(tr("Troubleshooting"));
item.addActionListener(new ActionListener() { item.addActionListener(event -> Base.showReference("reference/Edison_help_files", "Guide_Troubleshooting_Edison"));
public void actionPerformed(ActionEvent e) {
Base.showReference("reference/Edison_help_files", "Guide_Troubleshooting_Edison");
}
});
menu.add(item); menu.add(item);
menu.addSeparator(); menu.addSeparator();
item = newJMenuItemShift(tr("Find in Reference"), 'F'); item = newJMenuItemShift(tr("Find in Reference"), 'F');
item.addActionListener(this::handleFindReference); item.addActionListener(event -> handleFindReference(event));
menu.add(item); menu.add(item);
item = new JMenuItem(tr("Frequently Asked Questions")); item = new JMenuItem(tr("Frequently Asked Questions"));
item.addActionListener(new ActionListener() { item.addActionListener(event -> Base.showFAQ());
public void actionPerformed(ActionEvent e) {
Base.showFAQ();
}
});
menu.add(item); menu.add(item);
item = new JMenuItem(tr("Visit Arduino.cc")); item = new JMenuItem(tr("Visit Arduino.cc"));
item.addActionListener(new ActionListener() { item.addActionListener(event -> Base.openURL(tr("http://www.arduino.cc/")));
public void actionPerformed(ActionEvent e) {
Base.openURL(tr("http://www.arduino.cc/"));
}
});
menu.add(item); menu.add(item);
// macosx already has its own about menu // macosx already has its own about menu
if (!OSUtils.hasMacOSStyleMenus()) { if (!OSUtils.hasMacOSStyleMenus()) {
menu.addSeparator(); menu.addSeparator();
item = new JMenuItem(tr("About Arduino")); item = new JMenuItem(tr("About Arduino"));
item.addActionListener(new ActionListener() { item.addActionListener(event -> base.handleAbout());
public void actionPerformed(ActionEvent e) {
base.handleAbout();
}
});
menu.add(item); menu.add(item);
} }
@ -1293,7 +1178,7 @@ public class Editor extends JFrame implements RunnerListener {
undoItem = newJMenuItem(tr("Undo"), 'Z'); undoItem = newJMenuItem(tr("Undo"), 'Z');
undoItem.setName("menuEditUndo"); undoItem.setName("menuEditUndo");
undoItem.addActionListener(e -> getCurrentTab().handleUndo()); undoItem.addActionListener(event -> getCurrentTab().handleUndo());
menu.add(undoItem); menu.add(undoItem);
if (!OSUtils.isMacOS()) { if (!OSUtils.isMacOS()) {
@ -1302,61 +1187,37 @@ public class Editor extends JFrame implements RunnerListener {
redoItem = newJMenuItemShift(tr("Redo"), 'Z'); redoItem = newJMenuItemShift(tr("Redo"), 'Z');
} }
redoItem.setName("menuEditRedo"); redoItem.setName("menuEditRedo");
redoItem.addActionListener(e -> getCurrentTab().handleRedo()); redoItem.addActionListener(event -> getCurrentTab().handleRedo());
menu.add(redoItem); menu.add(redoItem);
menu.addSeparator(); menu.addSeparator();
JMenuItem cutItem = newJMenuItem(tr("Cut"), 'X'); JMenuItem cutItem = newJMenuItem(tr("Cut"), 'X');
cutItem.addActionListener(new ActionListener() { cutItem.addActionListener(event -> getCurrentTab().handleCut());
public void actionPerformed(ActionEvent e) {
getCurrentTab().handleCut();
}
});
menu.add(cutItem); menu.add(cutItem);
JMenuItem copyItem = newJMenuItem(tr("Copy"), 'C'); JMenuItem copyItem = newJMenuItem(tr("Copy"), 'C');
copyItem.addActionListener(new ActionListener() { copyItem.addActionListener(event -> getCurrentTab().getTextArea().copy());
public void actionPerformed(ActionEvent e) {
getCurrentTab().getTextArea().copy();
}
});
menu.add(copyItem); menu.add(copyItem);
JMenuItem copyForumItem = newJMenuItemShift(tr("Copy for Forum"), 'C'); JMenuItem copyForumItem = newJMenuItemShift(tr("Copy for Forum"), 'C');
copyForumItem.addActionListener(new ActionListener() { copyForumItem.addActionListener(event -> getCurrentTab().handleDiscourseCopy());
public void actionPerformed(ActionEvent e) {
getCurrentTab().handleDiscourseCopy();
}
});
menu.add(copyForumItem); menu.add(copyForumItem);
JMenuItem copyHTMLItem = newJMenuItemAlt(tr("Copy as HTML"), 'C'); JMenuItem copyHTMLItem = newJMenuItemAlt(tr("Copy as HTML"), 'C');
copyHTMLItem.addActionListener(new ActionListener() { copyHTMLItem.addActionListener(event -> getCurrentTab().handleHTMLCopy());
public void actionPerformed(ActionEvent e) {
getCurrentTab().handleHTMLCopy();
}
});
menu.add(copyHTMLItem); menu.add(copyHTMLItem);
JMenuItem pasteItem = newJMenuItem(tr("Paste"), 'V'); JMenuItem pasteItem = newJMenuItem(tr("Paste"), 'V');
pasteItem.addActionListener(new ActionListener() { pasteItem.addActionListener(event -> getCurrentTab().handlePaste());
public void actionPerformed(ActionEvent e) {
getCurrentTab().handlePaste();
}
});
menu.add(pasteItem); menu.add(pasteItem);
JMenuItem selectAllItem = newJMenuItem(tr("Select All"), 'A'); JMenuItem selectAllItem = newJMenuItem(tr("Select All"), 'A');
selectAllItem.addActionListener(new ActionListener() { selectAllItem.addActionListener(event -> getCurrentTab().handleSelectAll());
public void actionPerformed(ActionEvent e) {
getCurrentTab().handleSelectAll();
}
});
menu.add(selectAllItem); menu.add(selectAllItem);
JMenuItem gotoLine = newJMenuItem(tr("Go to line..."), 'L'); JMenuItem gotoLine = newJMenuItem(tr("Go to line..."), 'L');
gotoLine.addActionListener(e -> { gotoLine.addActionListener(event -> {
GoToLineNumber goToLineNumber = new GoToLineNumber(Editor.this); GoToLineNumber goToLineNumber = new GoToLineNumber(Editor.this);
goToLineNumber.setLocationRelativeTo(Editor.this); goToLineNumber.setLocationRelativeTo(Editor.this);
goToLineNumber.setVisible(true); goToLineNumber.setVisible(true);
@ -1366,96 +1227,78 @@ public class Editor extends JFrame implements RunnerListener {
menu.addSeparator(); menu.addSeparator();
JMenuItem commentItem = newJMenuItem(tr("Comment/Uncomment"), PreferencesData.get("editor.keys.shortcut_comment", "/").charAt(0)); JMenuItem commentItem = newJMenuItem(tr("Comment/Uncomment"), PreferencesData.get("editor.keys.shortcut_comment", "/").charAt(0));
commentItem.addActionListener(new ActionListener() { commentItem.addActionListener(event -> getCurrentTab().handleCommentUncomment());
public void actionPerformed(ActionEvent e) {
getCurrentTab().handleCommentUncomment();
}
});
menu.add(commentItem); menu.add(commentItem);
JMenuItem increaseIndentItem = new JMenuItem(tr("Increase Indent")); JMenuItem increaseIndentItem = new JMenuItem(tr("Increase Indent"));
increaseIndentItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0)); increaseIndentItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0));
increaseIndentItem.addActionListener(new ActionListener() { increaseIndentItem.addActionListener(event -> getCurrentTab().handleIndentOutdent(true));
public void actionPerformed(ActionEvent e) {
getCurrentTab().handleIndentOutdent(true);
}
});
menu.add(increaseIndentItem); menu.add(increaseIndentItem);
JMenuItem decreseIndentItem = new JMenuItem(tr("Decrease Indent")); JMenuItem decreseIndentItem = new JMenuItem(tr("Decrease Indent"));
decreseIndentItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK)); decreseIndentItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK));
decreseIndentItem.setName("menuDecreaseIndent"); decreseIndentItem.setName("menuDecreaseIndent");
decreseIndentItem.addActionListener(new ActionListener() { decreseIndentItem.addActionListener(event -> getCurrentTab().handleIndentOutdent(false));
public void actionPerformed(ActionEvent e) {
getCurrentTab().handleIndentOutdent(false);
}
});
menu.add(decreseIndentItem); menu.add(decreseIndentItem);
menu.addSeparator(); menu.addSeparator();
JMenuItem increaseFontSizeItem = newJMenuItem(tr("Increase Font Size"), '+'); JMenuItem increaseFontSizeItem = newJMenuItem(tr("Increase Font Size"), KeyEvent.VK_PLUS);
increaseFontSizeItem.addActionListener(new ActionListener() { increaseFontSizeItem.addActionListener(event -> base.handleFontSizeChange(1));
public void actionPerformed(ActionEvent e) {
base.handleFontSizeChange(1);
}
});
menu.add(increaseFontSizeItem); menu.add(increaseFontSizeItem);
// Add alternative shortcut "CTRL SHIFT =" for keyboards that haven't the "+" key
JMenuItem decreaseFontSizeItem = newJMenuItem(tr("Decrease Font Size"), '-'); // in the base layer. This workaround covers all the keyboards that have the "+"
decreaseFontSizeItem.addActionListener(new ActionListener() { // key available as "SHIFT =" that seems to be very common.
public void actionPerformed(ActionEvent e) { KeyStroke ctrlShiftEq = KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, SHORTCUT_KEY_MASK | ActionEvent.SHIFT_MASK);
base.handleFontSizeChange(-1); menu.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(ctrlShiftEq, "IncreaseFontSize");
} menu.getActionMap().put("IncreaseFontSize", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
base.handleFontSizeChange(1);
}
}); });
JMenuItem decreaseFontSizeItem = newJMenuItem(tr("Decrease Font Size"), KeyEvent.VK_MINUS);
decreaseFontSizeItem.addActionListener(event -> base.handleFontSizeChange(-1));
menu.add(decreaseFontSizeItem); menu.add(decreaseFontSizeItem);
menu.addSeparator(); menu.addSeparator();
JMenuItem findItem = newJMenuItem(tr("Find..."), 'F'); JMenuItem findItem = newJMenuItem(tr("Find..."), 'F');
findItem.addActionListener(new ActionListener() { findItem.addActionListener(event -> {
public void actionPerformed(ActionEvent e) { if (find == null) {
if (find == null) { find = new FindReplace(Editor.this, Base.FIND_DIALOG_STATE);
find = new FindReplace(Editor.this, Base.FIND_DIALOG_STATE);
}
if (!OSUtils.isMacOS()) {
find.setFindText(getCurrentTab().getSelectedText());
}
find.setLocationRelativeTo(Editor.this);
find.setVisible(true);
} }
if (!OSUtils.isMacOS()) {
find.setFindText(getCurrentTab().getSelectedText());
}
find.setLocationRelativeTo(Editor.this);
find.setVisible(true);
}); });
menu.add(findItem); menu.add(findItem);
JMenuItem findNextItem = newJMenuItem(tr("Find Next"), 'G'); JMenuItem findNextItem = newJMenuItem(tr("Find Next"), 'G');
findNextItem.addActionListener(new ActionListener() { findNextItem.addActionListener(event -> {
public void actionPerformed(ActionEvent e) { if (find != null) {
if (find != null) { find.findNext();
find.findNext();
}
} }
}); });
menu.add(findNextItem); menu.add(findNextItem);
JMenuItem findPreviousItem = newJMenuItemShift(tr("Find Previous"), 'G'); JMenuItem findPreviousItem = newJMenuItemShift(tr("Find Previous"), 'G');
findPreviousItem.addActionListener(new ActionListener() { findPreviousItem.addActionListener(event -> {
public void actionPerformed(ActionEvent e) { if (find != null) {
if (find != null) { find.findPrevious();
find.findPrevious();
}
} }
}); });
menu.add(findPreviousItem); menu.add(findPreviousItem);
if (OSUtils.isMacOS()) { if (OSUtils.isMacOS()) {
JMenuItem useSelectionForFindItem = newJMenuItem(tr("Use Selection For Find"), 'E'); JMenuItem useSelectionForFindItem = newJMenuItem(tr("Use Selection For Find"), 'E');
useSelectionForFindItem.addActionListener(new ActionListener() { useSelectionForFindItem.addActionListener(event -> {
public void actionPerformed(ActionEvent e) { if (find == null) {
if (find == null) { find = new FindReplace(Editor.this, Base.FIND_DIALOG_STATE);
find = new FindReplace(Editor.this, Base.FIND_DIALOG_STATE);
}
find.setFindText(getCurrentTab().getSelectedText());
} }
find.setFindText(getCurrentTab().getSelectedText());
}); });
menu.add(useSelectionForFindItem); menu.add(useSelectionForFindItem);
} }