Skip to content

Commit 91cdf53

Browse files
authored
Merge pull request #6551 from facchinm/test_pr6394
Add font size shortcuts (menu, keyboard and mouse)
2 parents 0c4d59d + 388822a commit 91cdf53

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

app/src/processing/app/Base.java

+11
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,17 @@ public void handlePrefs() {
18431843
dialog.setVisible(true);
18441844
}
18451845

1846+
/**
1847+
* Adjust font size
1848+
*/
1849+
public void handleFontSizeChange(int change) {
1850+
String pieces[] = PApplet.split(PreferencesData.get("editor.font"), ',');
1851+
int newSize = Integer.parseInt(pieces[2]) + change;
1852+
pieces[2] = String.valueOf(newSize);
1853+
PreferencesData.set("editor.font", PApplet.join(pieces, ','));
1854+
this.getEditors().forEach(processing.app.Editor::applyPreferences);
1855+
}
1856+
18461857
// XXX: Remove this method and make librariesIndexer non-static
18471858
static public LibraryList getLibraries() {
18481859
return BaseNoGui.librariesIndexer.getInstalledLibraries();

app/src/processing/app/Editor.java

+18
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,24 @@ public void actionPerformed(ActionEvent e) {
13751375

13761376
menu.addSeparator();
13771377

1378+
JMenuItem increaseFontSizeItem = newJMenuItem(tr("Increase Font Size"), '+');
1379+
increaseFontSizeItem.addActionListener(new ActionListener() {
1380+
public void actionPerformed(ActionEvent e) {
1381+
base.handleFontSizeChange(1);
1382+
}
1383+
});
1384+
menu.add(increaseFontSizeItem);
1385+
1386+
JMenuItem decreaseFontSizeItem = newJMenuItem(tr("Decrease Font Size"), '-');
1387+
decreaseFontSizeItem.addActionListener(new ActionListener() {
1388+
public void actionPerformed(ActionEvent e) {
1389+
base.handleFontSizeChange(-1);
1390+
}
1391+
});
1392+
menu.add(decreaseFontSizeItem);
1393+
1394+
menu.addSeparator();
1395+
13781396
JMenuItem findItem = newJMenuItem(tr("Find..."), 'F');
13791397
findItem.addActionListener(new ActionListener() {
13801398
public void actionPerformed(ActionEvent e) {

app/src/processing/app/EditorTab.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
import java.awt.Font;
3131
import java.awt.event.ActionEvent;
3232
import java.awt.event.ActionListener;
33+
import java.awt.event.MouseWheelListener;
34+
import java.awt.event.MouseWheelEvent;
35+
3336
import java.io.IOException;
3437

3538
import javax.swing.Action;
@@ -64,7 +67,7 @@
6467
/**
6568
* Single tab, editing a single file, in the main window.
6669
*/
67-
public class EditorTab extends JPanel implements SketchFile.TextStorage {
70+
public class EditorTab extends JPanel implements SketchFile.TextStorage, MouseWheelListener {
6871
protected Editor editor;
6972
protected SketchTextArea textarea;
7073
protected RTextScrollPane scrollPane;
@@ -106,6 +109,7 @@ public EditorTab(Editor editor, SketchFile file, String contents)
106109
file.setStorage(this);
107110
applyPreferences();
108111
add(scrollPane, BorderLayout.CENTER);
112+
textarea.addMouseWheelListener(this);
109113
}
110114

111115
private RSyntaxDocument createDocument(String contents) {
@@ -178,6 +182,18 @@ private SketchTextArea createTextArea(RSyntaxDocument document)
178182
return textArea;
179183
}
180184

185+
public void mouseWheelMoved(MouseWheelEvent e) {
186+
if (e.isControlDown()) {
187+
if (e.getWheelRotation() < 0) {
188+
editor.base.handleFontSizeChange(1);
189+
} else {
190+
editor.base.handleFontSizeChange(-1);
191+
}
192+
} else {
193+
e.getComponent().getParent().dispatchEvent(e);
194+
}
195+
}
196+
181197
private void configurePopupMenu(final SketchTextArea textarea){
182198

183199
JPopupMenu menu = textarea.getPopupMenu();

0 commit comments

Comments
 (0)