diff options
| author | 2020-06-08 21:36:16 +0200 | |
|---|---|---|
| committer | 2020-06-08 21:36:16 +0200 | |
| commit | f6e5a31c82a3b65df913915abddd1760f4d21b32 (patch) | |
| tree | 4c67cc18ed0cfbeeec36462c913ec49926e48f72 /enigma-swing/src | |
| parent | Merge pull request #257 from 2xsaiko/classnames (diff) | |
| download | enigma-f6e5a31c82a3b65df913915abddd1760f4d21b32.tar.gz enigma-f6e5a31c82a3b65df913915abddd1760f4d21b32.tar.xz enigma-f6e5a31c82a3b65df913915abddd1760f4d21b32.zip | |
Fix editor contents being changeable through certain key combinations (#258)
* Fix editor contents being changeable through certain key combinations
* Clarify comment
* Clarify comment even more
* Please stop trying to insert tabs in a spaces formatted file, IDEA.
Diffstat (limited to 'enigma-swing/src')
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/EnigmaSyntaxKit.java | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/EnigmaSyntaxKit.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/EnigmaSyntaxKit.java index d4a71f59..4f1b6e6e 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/EnigmaSyntaxKit.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/EnigmaSyntaxKit.java | |||
| @@ -1,11 +1,12 @@ | |||
| 1 | package cuchaz.enigma.gui; | 1 | package cuchaz.enigma.gui; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.gui.config.Config; | ||
| 4 | import de.sciss.syntaxpane.DefaultSyntaxKit; | 3 | import de.sciss.syntaxpane.DefaultSyntaxKit; |
| 5 | import de.sciss.syntaxpane.components.LineNumbersRuler; | 4 | import de.sciss.syntaxpane.components.LineNumbersRuler; |
| 6 | import de.sciss.syntaxpane.syntaxkits.JavaSyntaxKit; | 5 | import de.sciss.syntaxpane.syntaxkits.JavaSyntaxKit; |
| 7 | import de.sciss.syntaxpane.util.Configuration; | 6 | import de.sciss.syntaxpane.util.Configuration; |
| 8 | 7 | ||
| 8 | import cuchaz.enigma.gui.config.Config; | ||
| 9 | |||
| 9 | public class EnigmaSyntaxKit extends JavaSyntaxKit { | 10 | public class EnigmaSyntaxKit extends JavaSyntaxKit { |
| 10 | 11 | ||
| 11 | private static Configuration configuration = null; | 12 | private static Configuration configuration = null; |
| @@ -19,8 +20,21 @@ public class EnigmaSyntaxKit extends JavaSyntaxKit { | |||
| 19 | } | 20 | } |
| 20 | 21 | ||
| 21 | public void initConfig(Configuration baseConfig) { | 22 | public void initConfig(Configuration baseConfig) { |
| 22 | configuration = baseConfig; | 23 | configuration = flattenConfiguration(baseConfig, EnigmaSyntaxKit.class); |
| 23 | //See de.sciss.syntaxpane.TokenType | 24 | |
| 25 | // Remove all actions except a select few because they disregard the | ||
| 26 | // editable state of the editor, or at least are useless anyway because | ||
| 27 | // they would try editing the file. | ||
| 28 | // Also includes the Action.insert-date action which is written in | ||
| 29 | // Javascript and causes the editor to freeze on first load for a short | ||
| 30 | // time. | ||
| 31 | configuration.keySet().removeIf(s -> s.startsWith("Action.") && | ||
| 32 | !(s.startsWith("Action.find") || | ||
| 33 | s.startsWith("Action.goto-line") || | ||
| 34 | s.startsWith("Action.jump-to-pair") || | ||
| 35 | s.startsWith("Action.quick-find"))); | ||
| 36 | |||
| 37 | // See de.sciss.syntaxpane.TokenType | ||
| 24 | configuration.put("Style.KEYWORD", Config.getInstance().highlightColor + ", 0"); | 38 | configuration.put("Style.KEYWORD", Config.getInstance().highlightColor + ", 0"); |
| 25 | configuration.put("Style.KEYWORD2", Config.getInstance().highlightColor + ", 3"); | 39 | configuration.put("Style.KEYWORD2", Config.getInstance().highlightColor + ", 3"); |
| 26 | configuration.put("Style.STRING", Config.getInstance().stringColor + ", 0"); | 40 | configuration.put("Style.STRING", Config.getInstance().stringColor + ", 0"); |
| @@ -38,11 +52,23 @@ public class EnigmaSyntaxKit extends JavaSyntaxKit { | |||
| 38 | configuration.put("RightMarginColumn", "999"); //No need to have a right margin, if someone wants it add a config | 52 | configuration.put("RightMarginColumn", "999"); //No need to have a right margin, if someone wants it add a config |
| 39 | 53 | ||
| 40 | configuration.put("Action.quick-find", "cuchaz.enigma.gui.QuickFindAction, menu F"); | 54 | configuration.put("Action.quick-find", "cuchaz.enigma.gui.QuickFindAction, menu F"); |
| 55 | } | ||
| 41 | 56 | ||
| 42 | // This is an action written in javascript that is useless for enigma's | 57 | /** |
| 43 | // use case, and removing it causes the editor to load way faster the | 58 | * Creates a new configuration from the passed configuration so that it has |
| 44 | // first time | 59 | * no parents and all its values are on the same level. This is needed since |
| 45 | configuration.remove("Action.insert-date"); | 60 | * there is no way to remove map entries from parent configurations. |
| 61 | * | ||
| 62 | * @param source the configuration to flatten | ||
| 63 | * @param configClass the class for the new configuration | ||
| 64 | * @return a new configuration | ||
| 65 | */ | ||
| 66 | private static Configuration flattenConfiguration(Configuration source, Class<?> configClass) { | ||
| 67 | Configuration config = new Configuration(configClass, null); | ||
| 68 | for (String p : source.stringPropertyNames()) { | ||
| 69 | config.put(p, source.getString(p)); | ||
| 70 | } | ||
| 71 | return config; | ||
| 46 | } | 72 | } |
| 47 | 73 | ||
| 48 | public static void invalidate() { | 74 | public static void invalidate() { |