| 994 | this.p = prompt; |
| 995 | } |
| 996 | |
| 997 | @Override |
| 998 | public void run() { |
| 999 | |
| 1000 | Map<Pair<String, String>, Runnable> m = new LinkedHashMap<>(); |
| 1001 | |
| 1002 | //Prompt for a new hotkey |
| 1003 | p.prompt("set hotkey to...", m, new ExtendedCommand() { |
| 1004 | String altWas = null; |
| 1005 | |
| 1006 | @Override |
| 1007 | public void begin(SupportsPrompt prompt, String alternativeChosen) { |
| 1008 | altWas = ""; |
| 1009 | String[] indivKeys = alternativeChosen.trim() |
| 1010 | .toLowerCase() |
| 1011 | .split("-"); |
| 1012 | for (String key : indivKeys) { |
| 1013 | altWas += key.substring(0, 1) |
| 1014 | .toUpperCase() + key.substring(1) + "-"; |
| 1015 | } |
| 1016 | altWas = altWas.substring(0, altWas.length() - 1); |
| 1017 | } |
| 1018 | |
| 1019 | @Override |
| 1020 | public void run() { |
| 1021 | if (altWas == null) return; |
| 1022 | |
| 1023 | //Set up file reading |
| 1024 | File file = new File(System.getProperty("user.home") + "/.field/hotkeys.txt"); |
| 1025 | String contents = ""; |
| 1026 | |
| 1027 | //Read properties text file into a string (contents) |
| 1028 | try (BufferedReader in = new BufferedReader(new FileReader(file))) { |
| 1029 | while (in.ready()) contents += in.readLine() + "\n"; |
| 1030 | } catch (IOException x) { |
| 1031 | Log.log("hotkeys.error", () -> "Error: Cannot open properties text file in read, file is " + file); |
| 1032 | Log.log("hotkeys.error", () -> x); |
| 1033 | } |
| 1034 | |
| 1035 | String[] lines = contents.split("\n"); |
| 1036 | String next = ""; |
| 1037 | int n = 1; |
| 1038 | for (String line : lines) { |
| 1039 | String[] parts = line.split(":"); |
| 1040 | if (parts.length != 2) { |
| 1041 | final int finalN = n; |
| 1042 | Log.log("hotkeys.error", () -> "couldn't parse <" + line + "> in file, on line " + finalN); |
| 1043 | } else { |
| 1044 | if (parts[0].trim() |
| 1045 | .equals(altWas)) { |
| 1046 | // filter it out |
| 1047 | } else { |
| 1048 | next += line + "\n"; |
| 1049 | } |
| 1050 | } |
| 1051 | n++; |
| 1052 | } |
| 1053 | |