Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2b4883f

Browse files
committed
Merge branch 'keys' of https://github.com/matthijskooijman/Arduino into matthijskooijman-keys
2 parents fa4876b + 7eea624 commit 2b4883f

File tree

8 files changed

+434
-259
lines changed

8 files changed

+434
-259
lines changed

‎app/src/processing/app/Editor.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.fife.ui.rtextarea.RTextScrollPane;
3939
import processing.app.debug.RunnerException;
4040
import processing.app.forms.PasswordAuthorizationDialog;
41+
import processing.app.helpers.Keys;
4142
import processing.app.helpers.OSUtils;
4243
import processing.app.helpers.PreferencesMapException;
4344
import processing.app.legacy.PApplet;
@@ -312,6 +313,12 @@ public void windowDeactivated(WindowEvent e) {
312313
// to fix ugliness.. normally macosx java 1.3 puts an
313314
// ugly white border around this object, so turn it off.
314315
splitPane.setBorder(null);
316+
// By default, the split pane binds Ctrl-Tab and Ctrl-Shift-Tab for changing
317+
// focus. Since we do not use that, but want to use these shortcuts for
318+
// switching tabs, remove the bindings from the split pane. This allows the
319+
// events to bubble up and be handled by the EditorHeader.
320+
Keys.killBinding(splitPane, Keys.ctrl(KeyEvent.VK_TAB));
321+
Keys.killBinding(splitPane, Keys.ctrlShift(KeyEvent.VK_TAB));
315322

316323
// the default size on windows is too small and kinda ugly
317324
int dividerSize = PreferencesData.getInteger("editor.divider.size");
@@ -1033,7 +1040,6 @@ private SketchTextArea createTextArea() throws IOException {
10331040
textArea.setAntiAliasingEnabled(PreferencesData.getBoolean("editor.antialias"));
10341041
textArea.setTabsEmulated(PreferencesData.getBoolean("editor.tabs.expand"));
10351042
textArea.setTabSize(PreferencesData.getInteger("editor.tabs.size"));
1036-
textArea.setEditorListener(new EditorListener(this));
10371043
textArea.addHyperlinkListener(new HyperlinkListener() {
10381044
@Override
10391045
public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {

‎app/src/processing/app/EditorConsole.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public EditorConsole() {
6363
consoleTextPane.setEditable(false);
6464
DefaultCaret caret = (DefaultCaret) consoleTextPane.getCaret();
6565
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
66+
consoleTextPane.setFocusTraversalKeysEnabled(false);
6667

6768
Color backgroundColour = Theme.getColor("console.color");
6869
consoleTextPane.setBackground(backgroundColour);

‎app/src/processing/app/EditorHeader.java‎

Lines changed: 72 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
*/
2323

2424
package processing.app;
25+
26+
import processing.app.helpers.Keys;
2527
import processing.app.helpers.OSUtils;
28+
import processing.app.helpers.SimpleAction;
2629
import processing.app.tools.MenuScroller;
2730
import static processing.app.I18n.tr;
2831

@@ -72,12 +75,69 @@ public class EditorHeader extends JComponent {
7275

7376
static Image[][] pieces;
7477

75-
//
76-
7778
Image offscreen;
7879
int sizeW, sizeH;
7980
int imageW, imageH;
8081

82+
public class Actions {
83+
public final Action newTab = new SimpleAction(tr("New Tab"),
84+
Keys.ctrlShift(KeyEvent.VK_N),
85+
() -> editor.getSketch().handleNewCode());
86+
87+
public final Action renameTab = new SimpleAction(tr("Rename"),
88+
() -> editor.getSketch().handleRenameCode());
89+
90+
public final Action deleteTab = new SimpleAction(tr("Delete"), () -> {
91+
try {
92+
editor.getSketch().handleDeleteCode();
93+
} catch (IOException e) {
94+
e.printStackTrace();
95+
}
96+
});
97+
98+
public final Action prevTab = new SimpleAction(tr("Previous Tab"),
99+
Keys.ctrlAlt(KeyEvent.VK_LEFT),
100+
() -> editor.sketch.handlePrevCode());
101+
102+
public final Action nextTab = new SimpleAction(tr("Next Tab"),
103+
Keys.ctrlAlt(KeyEvent.VK_RIGHT),
104+
() -> editor.sketch.handleNextCode());
105+
106+
Actions() {
107+
// Explicitly bind keybindings for the actions with accelerators above
108+
// Normally, this happens automatically for any actions bound to menu
109+
// items, but only for menus attached to a window, not for popup menus.
110+
Keys.bind(EditorHeader.this, newTab);
111+
Keys.bind(EditorHeader.this, prevTab);
112+
Keys.bind(EditorHeader.this, nextTab);
113+
114+
// Add alternative keybindings to switch tabs
115+
Keys.bind(EditorHeader.this, prevTab, Keys.ctrlShift(KeyEvent.VK_TAB));
116+
Keys.bind(EditorHeader.this, nextTab, Keys.ctrl(KeyEvent.VK_TAB));
117+
}
118+
}
119+
public Actions actions = new Actions();
120+
121+
/**
122+
* Called whenever we, or any of our ancestors, is added to a container.
123+
*/
124+
public void addNotify() {
125+
super.addNotify();
126+
/*
127+
* Once we get added to a window, remove Ctrl-Tab and Ctrl-Shift-Tab from
128+
* the keys used for focus traversal (so our bindings for these keys will
129+
* work). All components inherit from the window eventually, so this should
130+
* work whenever the focus is inside our window. Some components (notably
131+
* JTextPane / JEditorPane) keep their own focus traversal keys, though, and
132+
* have to be treated individually (either the same as below, or by
133+
* disabling focus traversal entirely).
134+
*/
135+
Window window = SwingUtilities.getWindowAncestor(this);
136+
if (window != null) {
137+
Keys.killFocusTraversalBinding(window, Keys.ctrl(KeyEvent.VK_TAB));
138+
Keys.killFocusTraversalBinding(window, Keys.ctrlShift(KeyEvent.VK_TAB));
139+
}
140+
}
81141

82142
public EditorHeader(Editor eddie) {
83143
this.editor = eddie; // weird name for listener
@@ -236,151 +296,41 @@ public void rebuild() {
236296

237297

238298
public void rebuildMenu() {
239-
//System.out.println("rebuilding");
240299
if (menu != null) {
241300
menu.removeAll();
242301

243302
} else {
244303
menu = new JMenu();
245304
MenuScroller.setScrollerFor(menu);
246305
popup = menu.getPopupMenu();
247-
add(popup);
248306
popup.setLightWeightPopupEnabled(true);
249-
250-
/*
251-
popup.addPopupMenuListener(new PopupMenuListener() {
252-
public void popupMenuCanceled(PopupMenuEvent e) {
253-
// on redraw, the isVisible() will get checked.
254-
// actually, a repaint may be fired anyway, so this
255-
// may be redundant.
256-
repaint();
257-
}
258-
259-
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { }
260-
public void popupMenuWillBecomeVisible(PopupMenuEvent e) { }
261-
});
262-
*/
263307
}
264308
JMenuItem item;
265309

266-
// maybe this shouldn't have a command key anyways..
267-
// since we're not trying to make this a full ide..
268-
//item = Editor.newJMenuItem("New", 'T');
269-
270-
/*
271-
item = Editor.newJMenuItem("Previous", KeyEvent.VK_PAGE_UP);
272-
item.addActionListener(new ActionListener() {
273-
public void actionPerformed(ActionEvent e) {
274-
System.out.println("prev");
275-
}
276-
});
277-
if (editor.sketch != null) {
278-
item.setEnabled(editor.sketch.codeCount > 1);
279-
}
280-
menu.add(item);
281-
282-
item = Editor.newJMenuItem("Next", KeyEvent.VK_PAGE_DOWN);
283-
item.addActionListener(new ActionListener() {
284-
public void actionPerformed(ActionEvent e) {
285-
System.out.println("ext");
286-
}
287-
});
288-
if (editor.sketch != null) {
289-
item.setEnabled(editor.sketch.codeCount > 1);
290-
}
291-
menu.add(item);
292-
293-
menu.addSeparator();
294-
*/
295-
296-
//item = new JMenuItem("New Tab");
297-
item = Editor.newJMenuItemShift(tr("New Tab"), 'N');
298-
item.addActionListener(new ActionListener() {
299-
public void actionPerformed(ActionEvent e) {
300-
editor.getSketch().handleNewCode();
301-
}
302-
});
303-
menu.add(item);
304-
305-
item = new JMenuItem(tr("Rename"));
306-
item.addActionListener(new ActionListener() {
307-
public void actionPerformed(ActionEvent e) {
308-
editor.getSketch().handleRenameCode();
309-
/*
310-
// this is already being called by nameCode(), the second stage of rename
311-
if (editor.sketch.current == editor.sketch.code[0]) {
312-
editor.sketchbook.rebuildMenus();
313-
}
314-
*/
315-
}
316-
});
317-
menu.add(item);
318-
319-
item = new JMenuItem(tr("Delete"));
320-
item.addActionListener(new ActionListener() {
321-
public void actionPerformed(ActionEvent event) {
322-
try {
323-
editor.getSketch().handleDeleteCode();
324-
} catch (IOException e) {
325-
e.printStackTrace();
326-
}
327-
}
328-
});
329-
menu.add(item);
330-
310+
menu.add(new JMenuItem(actions.newTab));
311+
menu.add(new JMenuItem(actions.renameTab));
312+
menu.add(new JMenuItem(actions.deleteTab));
331313
menu.addSeparator();
332-
333-
// KeyEvent.VK_LEFT and VK_RIGHT will make Windows beep
334-
335-
item = new JMenuItem(tr("Previous Tab"));
336-
KeyStroke ctrlAltLeft = KeyStroke
337-
.getKeyStroke(KeyEvent.VK_LEFT, Editor.SHORTCUT_ALT_KEY_MASK);
338-
item.setAccelerator(ctrlAltLeft);
339-
item.addActionListener(new ActionListener() {
340-
@Override
341-
public void actionPerformed(ActionEvent e) {
342-
editor.sketch.handlePrevCode();
343-
}
344-
});
345-
menu.add(item);
346-
347-
item = new JMenuItem(tr("Next Tab"));
348-
KeyStroke ctrlAltRight = KeyStroke
349-
.getKeyStroke(KeyEvent.VK_RIGHT, Editor.SHORTCUT_ALT_KEY_MASK);
350-
item.setAccelerator(ctrlAltRight);
351-
item.addActionListener(new ActionListener() {
352-
@Override
353-
public void actionPerformed(ActionEvent e) {
354-
editor.sketch.handleNextCode();
355-
}
356-
});
357-
menu.add(item);
314+
menu.add(new JMenuItem(actions.prevTab));
315+
menu.add(new JMenuItem(actions.nextTab));
358316

359317
Sketch sketch = editor.getSketch();
360318
if (sketch != null) {
361319
menu.addSeparator();
362-
363-
ActionListener jumpListener = new ActionListener() {
364-
public void actionPerformed(ActionEvent e) {
365-
editor.getSketch().setCurrentCode(e.getActionCommand());
366-
}
367-
};
320+
int i = 0;
368321
for (SketchCode code : sketch.getCodes()) {
322+
final int index = i++;
369323
item = new JMenuItem(code.isExtension(sketch.getDefaultExtension()) ?
370324
code.getPrettyName() : code.getFileName());
371-
item.setActionCommand(code.getFileName());
372-
item.addActionListener(jumpListener);
325+
item.addActionListener((ActionEvent e) -> {
326+
editor.getSketch().setCurrentCode(index);
327+
});
373328
menu.add(item);
374329
}
375330
}
376331
}
377332

378333

379-
public void deselectMenu() {
380-
repaint();
381-
}
382-
383-
384334
public Dimension getPreferredSize() {
385335
return getMinimumSize();
386336
}

‎app/src/processing/app/EditorListener.java‎

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /