| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -304,7 +304,7 @@ protected ArrayList<ToolContribution> getCoreTools() { | |||
| 304 | 304 | * solution where the listeners are handled properly. | |
| 305 | 305 | */ | |
| 306 | 306 | protected JEditTextArea createTextArea() { | |
| 307 | - return new JEditTextArea(new PdeTextAreaDefaults(mode)) { | ||
| 307 | + return new JEditTextArea(new PdeTextAreaDefaults(mode), new PdeInputHandler()) { | ||
| 308 | 308 | // this is a kludge that needs to be removed [fry 150120] | |
| 309 | 309 | public void processKeyEvent(KeyEvent evt) { | |
| 310 | 310 | // this had to be added in Processing 007X, because the menu key | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,7 +39,7 @@ public class Settings { | |||
| 39 | 39 | /** | |
| 40 | 40 | * Copy of the defaults in case the user mangles a preference. | |
| 41 | 41 | * It's necessary to keep a copy of the defaults around, because the user may | |
| 42 | - * have mangled a setting on their own. In the past, we used to load the | ||
| 42 | + * have replaced a setting on their own. In the past, we used to load the | ||
| 43 | 43 | * defaults, then replace those with what was in the user's preferences file. | |
| 44 | 44 | * Problem is, if something like a font entry in the user's file no longer | |
| 45 | 45 | * parses properly, we need to be able to get back to a clean version of that | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -86,7 +86,7 @@ public class JEditTextArea extends JComponent | |||
| 86 | 86 | * Creates a new JEditTextArea with the specified settings. | |
| 87 | 87 | * @param defaults The default settings | |
| 88 | 88 | */ | |
| 89 | - public JEditTextArea(TextAreaDefaults defaults) { | ||
| 89 | + public JEditTextArea(TextAreaDefaults defaults, InputHandler inputHandler) { | ||
| 90 | 90 | // Enable the necessary events | |
| 91 | 91 | enableEvents(AWTEvent.KEY_EVENT_MASK); | |
| 92 | 92 | ||
@@ -129,7 +129,7 @@ public void actionPerformed(ActionEvent e) { | |||
| 129 | 129 | setFocusTraversalKeysEnabled(false); | |
| 130 | 130 | ||
| 131 | 131 | // Load the defaults | |
| 132 | - setInputHandler(defaults.inputHandler); | ||
| 132 | + setInputHandler(inputHandler); | ||
| 133 | 133 | setDocument(defaults.document); | |
| 134 | 134 | // editable = defaults.editable; | |
| 135 | 135 | caretVisible = defaults.caretVisible; | |
@@ -1963,6 +1963,27 @@ public void processKeyEvent(KeyEvent evt) { | |||
| 1963 | 1963 | } | |
| 1964 | 1964 | } | |
| 1965 | 1965 | */ | |
| 1966 | + | ||
| 1967 | + | ||
| 1968 | + public void processKeyEvent(KeyEvent event) { | ||
| 1969 | + // this had to be added in Processing 007X, because the menu key | ||
| 1970 | + // events weren't making it up to the frame. | ||
| 1971 | + super.processKeyEvent(event); | ||
| 1972 | + | ||
| 1973 | + if (inputHandler != null) { | ||
| 1974 | + switch (event.getID()) { | ||
| 1975 | + case KeyEvent.KEY_TYPED: | ||
| 1976 | + inputHandler.keyTyped(event); | ||
| 1977 | + break; | ||
| 1978 | + case KeyEvent.KEY_PRESSED: | ||
| 1979 | + inputHandler.keyPressed(event); | ||
| 1980 | + break; | ||
| 1981 | + case KeyEvent.KEY_RELEASED: | ||
| 1982 | + inputHandler.keyReleased(event); | ||
| 1983 | + break; | ||
| 1984 | + } | ||
| 1985 | + } | ||
| 1986 | + } | ||
| 1966 | 1987 | ||
| 1967 | 1988 | ||
| 1968 | 1989 | // protected members | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,184 @@ | |||
| 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 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,8 @@ | |||
| 4 | 4 | PdeTextAreaDefaults - grabs font/color settings for the editor | |
| 5 | 5 | Part of the Processing project - http://processing.org | |
| 6 | 6 | ||
| 7 | - Copyright (c) 2004-06 Ben Fry and Casey Reas | ||
| 7 | + Copyright (c) 2012-14 The Processing Foundation | ||
| 8 | + Copyright (c) 2004-12 Ben Fry and Casey Reas | ||
| 8 | 9 | Copyright (c) 2001-03 Massachusetts Institute of Technology | |
| 9 | 10 | ||
| 10 | 11 | This program is free software; you can redistribute it and/or modify | |
@@ -15,11 +16,11 @@ | |||
| 15 | 16 | This program is distributed in the hope that it will be useful, | |
| 16 | 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 | - GNU General Public License for more details. | ||
| 19 | + GNU General Public License for more details. | ||
| 19 | 20 | ||
| 20 | 21 | You should have received a copy of the GNU General Public License | |
| 21 | - along with this program; if not, write to the Free Software Foundation, | ||
| 22 | - Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 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. | ||
| 23 | 24 | */ | |
| 24 | 25 | ||
| 25 | 26 | package processing.app.syntax; | |
@@ -30,6 +31,7 @@ | |||
| 30 | 31 | public class PdeTextAreaDefaults extends TextAreaDefaults { | |
| 31 | 32 | ||
| 32 | 33 | public PdeTextAreaDefaults(Mode mode) { | |
| 34 | + /* | ||
| 33 | 35 | inputHandler = new DefaultInputHandler(); | |
| 34 | 36 | //inputHandler.addDefaultKeyBindings(); // 0122 | |
| 35 | 37 | ||
@@ -178,6 +180,7 @@ public PdeTextAreaDefaults(Mode mode) { | |||
| 178 | 180 | inputHandler.addKeyBinding("CS+DOWN", InputHandler.SELECT_DOC_END); | |
| 179 | 181 | ||
| 180 | 182 | inputHandler.addKeyBinding(mod + "+ENTER", InputHandler.REPEAT); | |
| 183 | + */ | ||
| 181 | 184 | ||
| 182 | 185 | document = new SyntaxDocument(); | |
| 183 | 186 | // editable = true; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,7 @@ | |||
| 18 | 18 | * creating the text area is that this method is faster. | |
| 19 | 19 | */ | |
| 20 | 20 | public class TextAreaDefaults { | |
| 21 | - public InputHandler inputHandler; | ||
| 21 | + //public InputHandler inputHandler; | ||
| 22 | 22 | public SyntaxDocument document; | |
| 23 | 23 | // public boolean editable; | |
| 24 | 24 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,7 +42,9 @@ protected JavaEditor(Base base, String path, EditorState state, Mode mode) { | |||
| 42 | 42 | ||
| 43 | 43 | ||
| 44 | 44 | protected JEditTextArea createTextArea() { | |
| 45 | - return new JEditTextArea(new PdeTextAreaDefaults(mode)) { | ||
| 45 | + return new JEditTextArea(new PdeTextAreaDefaults(mode), new PdeKeyListener(this)); | ||
| 46 | + /* | ||
| 47 | + return new JEditTextArea(new PdeTextAreaDefaults(mode), new PdeInputHandler()) { | ||
| 46 | 48 | // Forwards key events directly to the input handler. This is slightly | |
| 47 | 49 | // faster than using a KeyListener because some Swing overhead is avoided. | |
| 48 | 50 | PdeKeyListener editorListener = new PdeKeyListener(JavaEditor.this, this); | |
@@ -72,6 +74,7 @@ public void processKeyEvent(KeyEvent evt) { | |||
| 72 | 74 | } | |
| 73 | 75 | } | |
| 74 | 76 | }; | |
| 77 | + */ | ||
| 75 | 78 | } | |
| 76 | 79 | ||
| 77 | 80 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments