1 type Editor 2 let reload self (tab_item : TabItem) = 3 let item = self.tab_item_file_items[tab_item] 4 let modified = fs/modified_time item.path 5 let prev_modified = item.modified 6 7 let text_box = self.tab_item_text_boxes[tab_item] 8 if modified > prev_modified || text_box.is_changed then 9 text_box.history.clear 10 let text = fs/read_text item.actual_path 11 load_text text_box text 12 item.modified = modified 13 if text_box.is_changed then 14 text_box.is_changed = false 15 16 let reload_all () = 17 for tab_item in tab_control.tab_items do 18 reload tab_item 19 20 let reload_selected () = 21 if tab_control.selected_tab_item ? Some tab_item then 22 reload tab_item 23 24 let get_next_item (item : FileItem) : FileItem = 25 let parent = item.parent.unwrap 26 let items = parent.items 27 let index = items.index_of item 28 29 when 30 index < items.size - 1 -> items[index + 1] 31 parent.is_root -> item 32 else -> get_next_item parent 33 34 let get_last_item (item : FileItem) : FileItem = 35 if not item.is_directory || not item.is_open || item.items.is_empty 36 then item 37 else get_last_item item.items.last 38 39 type Editor 40 let process_key (key : Key 41 action : KeyAction 42 modifiers : KeyModifiers) = 43 redraw 44 app.display.update_focus 45 if action <> KeyAction/Press then return 46 47 case key of 48 Key/A -> 49 let control = app.display.focus.unwrap 50 if modifiers.contains KeyModifiers/Control then 51 if control is not MultilineTextBox then 52 return 53 54 let tab_item = tab_control.selected_tab_item.unwrap 55 assert tab_item_text_boxes[tab_item] == control 56 let text_box = control as MultilineTextBox 57 let last_pos = text_box.display_text.last_pos 58 if last_pos <> TextPos@zero then 59 text_box.selection = (TextPos.new, last_pos) 60 61 Key/F2 -> 62 case app.display.focus of 63 Some control if control is Tree -> rename 64 else -> () 65 66 Key/F5 | Key/F6 -> 67 if maybe_command.is_none then 68 if changed.is_not_empty then 69 apply 70 71 if content_changed.is_not_empty then 72 save_all 73 74 clear_output 75 output_text_box.update 76 let emit_cpp = key == Key/F5 77 || modifiers.contains KeyModifiers/Control 78 79 let result = compile crate_name emit_cpp 80 if result then 81 state = EditorState/BuildKedr 82 let run = key == Key/F5 83 let command = EditorCommand 84 build_kedr = true 85 =emit_cpp 86 build_cpp = run 87 =run 88 89 maybe_command = command 90 else 91 write_message "cannot connect to compiler" 92 93 Key/L -> 94 if not app.os_window.is_control_pressed then 95 return 96 97 if app.os_window.is_shift_pressed then 98 reload_all 99 else 100 reload_selected 101 102 Key/S -> 103 if not app.os_window.is_control_pressed 104 || app.display.focus.is_none 105 then 106 return 107 108 let control = app.display.focus.unwrap 109 if app.os_window.is_shift_pressed then 110 apply 111 save_all 112 else 113 if control is not MultilineTextBox then 114 return 115 116 let tab_item = tab_control.selected_tab_item.unwrap 117 assert tab_item_text_boxes[tab_item] == control 118 let text_box = control as MultilineTextBox 119 if text_box.is_changed then 120 let file = tab_item_file_items[tab_item] 121 if file.actual_path.is_not_empty then 122 save file text_box 123 text_box.is_changed = false 124 assert not content_changed.contains file 125 126 Key/Left | Key/Right | Key/Up | Key/Down -> 127 if app.display.focus <> Some tree then 128 return 129 130 if modifiers.contains KeyModifiers/Control then 131 case key of 132 Key/Left -> move_horizontal true 133 Key/Right -> move_horizontal false 134 Key/Up -> move_vertical true 135 Key/Down -> move_vertical false 136 else -> fail 137 else 138 case key of 139 Key/Left -> () 140 Key/Right -> () 141 Key/Up -> 142 if tree.selected_item.is_none then 143 return 144 145 let selected_item = tree.selected_item.unwrap as FileItem 146 let parent = selected_item.parent.unwrap 147 let index = parent.items.index_of selected_item 148 let next_selected_item = when 149 index > 0 -> 150 get_last_item parent.items[index - 1] 151 152 not parent.is_root -> parent 153 else -> selected_item 154 155 tree.selected_item = next_selected_item 156 157 Key/Down -> 158 if tree.selected_item.is_none then 159 return 160 161 let selected_item = tree.selected_item.unwrap as FileItem 162 let next_selected_item = 163 if selected_item.is_directory 164 && selected_item.is_open 165 && selected_item.items.is_not_empty 166 then selected_item.items[0] 167 else get_next_item selected_item 168 169 tree.selected_item = next_selected_item 170 171 else -> fail 172 173 Key/Space | Key/Enter -> 174 if app.display.frame_start_focus <> Some tree then 175 return 176 177 if changed.is_not_empty && key == Key/Enter then 178 apply 179 else 180 if tree.selected_item.is_none then 181 return 182 183 let selected_item = tree.selected_item.unwrap as FileItem 184 if selected_item.is_directory then 185 selected_item.is_open = not selected_item.is_open 186 else 187 open selected_item |> ignore 188 189 else -> () 190 191 app.os_window.keys.subscribe { key, action, modifiers -> 192 process_key key action modifiers } |> tokens.add 193