1+ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2+
3+ /*
4+ PdeInputHandler - PDE-specific handling of keys
5+ Part of the Processing project - http://processing.org
6+
7+ Copyright (c) 2012-14 The Processing Foundation
8+ Copyright (c) 2004-12 Ben Fry and Casey Reas
9+ Copyright (c) 2001-03 Massachusetts Institute of Technology
10+
11+ This program is free software; you can redistribute it and/or modify
12+ it under the terms of the GNU General Public License as published by
13+ the Free Software Foundation; either version 2 of the License, or
14+ (at your option) any later version.
15+
16+ This program is distributed in the hope that it will be useful,
17+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+ GNU General Public License for more details.
20+
21+ You should have received a copy of the GNU General Public License
22+ along with this program; if not, write to the Free Software Foundation, Inc.
23+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24+ */
25+
26+ package processing .app .syntax ;
27+
28+ import processing .app .Base ;
29+ import processing .app .Preferences ;
30+
31+
32+ /**
33+ * Sets key bindings used by the PDE, except for those that are Mode-specific.
34+ */
35+ public class PdeInputHandler extends DefaultInputHandler {
36+
37+ public PdeInputHandler () {
38+ // Use option on mac for text edit controls that are ctrl on Windows/Linux.
39+ // (i.e. ctrl-left/right is option-left/right on OS X)
40+ String mod = Base .isMacOS () ? "A" : "C" ;
41+
42+ // right now, ctrl-up/down is select up/down, but mod should be
43+ // used instead, because the mac expects it to be option(alt)
44+
45+ addKeyBinding ("BACK_SPACE" , InputHandler .BACKSPACE );
46+ // for 0122, shift-backspace is delete, for 0176, it's now a preference,
47+ // to prevent holy warriors from attacking me for it.
48+ if (Preferences .getBoolean ("editor.keys.shift_backspace_is_delete" )) {
49+ addKeyBinding ("S+BACK_SPACE" , InputHandler .DELETE );
50+ } else {
51+ // Made the default for 0215, deemed better for our audience.
52+ addKeyBinding ("S+BACK_SPACE" , InputHandler .BACKSPACE );
53+ }
54+
55+ addKeyBinding ("DELETE" , InputHandler .DELETE );
56+ addKeyBinding ("S+DELETE" , InputHandler .DELETE );
57+
58+ // the following two were changed for 0122 for better mac/pc compatability
59+ addKeyBinding (mod + "+BACK_SPACE" , InputHandler .BACKSPACE_WORD ); // 0122
60+ addKeyBinding (mod + "S+BACK_SPACE" , InputHandler .BACKSPACE_WORD ); // 0215
61+ addKeyBinding (mod + "+DELETE" , InputHandler .DELETE_WORD ); // 0122
62+ addKeyBinding (mod + "S+DELETE" , InputHandler .DELETE_WORD ); // 0215
63+
64+ // handled by listener, don't bother here
65+ //addKeyBinding("ENTER", InputHandler.INSERT_BREAK);
66+ //addKeyBinding("TAB", InputHandler.INSERT_TAB);
67+
68+ addKeyBinding ("INSERT" , InputHandler .OVERWRITE );
69+
70+ // http://dev.processing.org/bugs/show_bug.cgi?id=162
71+ // added for 0176, though the bindings do not appear relevant for osx
72+ if (Preferences .getBoolean ("editor.keys.alternative_cut_copy_paste" )) {
73+ addKeyBinding ("C+INSERT" , InputHandler .CLIPBOARD_COPY );
74+ addKeyBinding ("S+INSERT" , InputHandler .CLIPBOARD_PASTE );
75+ addKeyBinding ("S+DELETE" , InputHandler .CLIPBOARD_CUT );
76+ }
77+
78+ // disabling for 0122, not sure what this does
79+ //addKeyBinding("C+\\", InputHandler.TOGGLE_RECT);
80+
81+ // for 0122, these have been changed for better compatibility
82+ // HOME and END now mean the beginning/end of the document
83+ // for 0176 changed this to a preference so that the Mac OS X people
84+ // can get the "normal" behavior as well if they prefer.
85+ if (Preferences .getBoolean ("editor.keys.home_and_end_travel_far" )) {
86+ addKeyBinding ("HOME" , InputHandler .DOCUMENT_HOME );
87+ addKeyBinding ("END" , InputHandler .DOCUMENT_END );
88+ addKeyBinding ("S+HOME" , InputHandler .SELECT_DOC_HOME );
89+ addKeyBinding ("S+END" , InputHandler .SELECT_DOC_END );
90+ } else {
91+ // for 0123 added the proper windows defaults
92+ addKeyBinding ("HOME" , InputHandler .HOME );
93+ addKeyBinding ("END" , InputHandler .END );
94+ addKeyBinding ("S+HOME" , InputHandler .SELECT_HOME );
95+ addKeyBinding ("S+END" , InputHandler .SELECT_END );
96+ addKeyBinding ("C+HOME" , InputHandler .DOCUMENT_HOME );
97+ addKeyBinding ("C+END" , InputHandler .DOCUMENT_END );
98+ addKeyBinding ("CS+HOME" , InputHandler .SELECT_DOC_HOME );
99+ addKeyBinding ("CS+END" , InputHandler .SELECT_DOC_END );
100+ }
101+
102+ if (Base .isMacOS ()) {
103+ // Additional OS X key bindings added for 0215.
104+ // Also note that two more are added above and marked 0215.
105+ // http://code.google.com/p/processing/issues/detail?id=1354
106+ // Could not find a proper Apple guide, but a partial reference is here:
107+ // http://guides.macrumors.com/Keyboard_shortcuts§ion=10#Text_Shortcuts
108+
109+ // control-A move to start of current paragraph
110+ addKeyBinding ("C+A" , InputHandler .HOME );
111+ addKeyBinding ("CS+A" , InputHandler .SELECT_HOME );
112+ // control-E move to end of current paragraph
113+ addKeyBinding ("C+E" , InputHandler .END );
114+ addKeyBinding ("CS+E" , InputHandler .SELECT_END );
115+
116+ // control-D forward delete
117+ addKeyBinding ("C+D" , InputHandler .DELETE );
118+
119+ // control-B move left one character
120+ addKeyBinding ("C+B" , InputHandler .PREV_CHAR );
121+ addKeyBinding ("CS+B" , InputHandler .SELECT_PREV_CHAR );
122+ // control-F move right one character
123+ addKeyBinding ("C+F" , InputHandler .NEXT_CHAR );
124+ addKeyBinding ("CS+F" , InputHandler .SELECT_NEXT_CHAR );
125+
126+ // control-H delete (just ASCII for backspace)
127+ addKeyBinding ("C+H" , InputHandler .BACKSPACE );
128+
129+ // control-N move down one line
130+ addKeyBinding ("C+N" , InputHandler .NEXT_LINE );
131+ addKeyBinding ("CS+N" , InputHandler .SELECT_NEXT_LINE );
132+ // control-P move up one line
133+ addKeyBinding ("C+P" , InputHandler .PREV_LINE );
134+ addKeyBinding ("CS+P" , InputHandler .SELECT_PREV_LINE );
135+
136+ // might be nice, but no handlers currently available
137+ // control-O insert new line after cursor
138+ // control-T transpose (swap) two surrounding character
139+ // control-V move to end, then left one character
140+ // control-K delete remainder of current paragraph
141+ // control-Y paste text previously deleted with control-K
142+ }
143+
144+ if (Base .isMacOS ()) {
145+ addKeyBinding ("M+LEFT" , InputHandler .HOME );
146+ addKeyBinding ("M+RIGHT" , InputHandler .END );
147+ addKeyBinding ("MS+LEFT" , InputHandler .SELECT_HOME ); // 0122
148+ addKeyBinding ("MS+RIGHT" , InputHandler .SELECT_END ); // 0122
149+ } else {
150+ addKeyBinding ("C+LEFT" , InputHandler .HOME ); // 0122
151+ addKeyBinding ("C+RIGHT" , InputHandler .END ); // 0122
152+ addKeyBinding ("CS+HOME" , InputHandler .SELECT_HOME ); // 0122
153+ addKeyBinding ("CS+END" , InputHandler .SELECT_END ); // 0122
154+ }
155+
156+ addKeyBinding ("PAGE_UP" , InputHandler .PREV_PAGE );
157+ addKeyBinding ("PAGE_DOWN" , InputHandler .NEXT_PAGE );
158+ addKeyBinding ("S+PAGE_UP" , InputHandler .SELECT_PREV_PAGE );
159+ addKeyBinding ("S+PAGE_DOWN" , InputHandler .SELECT_NEXT_PAGE );
160+
161+ addKeyBinding ("LEFT" , InputHandler .PREV_CHAR );
162+ addKeyBinding ("S+LEFT" , InputHandler .SELECT_PREV_CHAR );
163+ addKeyBinding (mod + "+LEFT" , InputHandler .PREV_WORD );
164+ addKeyBinding (mod + "S+LEFT" , InputHandler .SELECT_PREV_WORD );
165+ addKeyBinding ("RIGHT" , InputHandler .NEXT_CHAR );
166+ addKeyBinding ("S+RIGHT" , InputHandler .SELECT_NEXT_CHAR );
167+ addKeyBinding (mod + "+RIGHT" , InputHandler .NEXT_WORD );
168+ addKeyBinding (mod + "S+RIGHT" , InputHandler .SELECT_NEXT_WORD );
169+
170+ addKeyBinding ("UP" , InputHandler .PREV_LINE );
171+ addKeyBinding (mod + "+UP" , InputHandler .PREV_LINE ); // p5
172+ addKeyBinding ("S+UP" , InputHandler .SELECT_PREV_LINE );
173+ addKeyBinding ("DOWN" , InputHandler .NEXT_LINE );
174+ addKeyBinding (mod + "+DOWN" , InputHandler .NEXT_LINE ); // p5
175+ addKeyBinding ("S+DOWN" , InputHandler .SELECT_NEXT_LINE );
176+
177+ addKeyBinding ("MS+UP" , InputHandler .SELECT_DOC_HOME );
178+ addKeyBinding ("CS+UP" , InputHandler .SELECT_DOC_HOME );
179+ addKeyBinding ("MS+DOWN" , InputHandler .SELECT_DOC_END );
180+ addKeyBinding ("CS+DOWN" , InputHandler .SELECT_DOC_END );
181+
182+ addKeyBinding (mod + "+ENTER" , InputHandler .REPEAT );
183+ }
184+ }
0 commit comments