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 text_box = control as MultilineTextBox 55 let last_pos = text_box.display_text.last_pos 56 if last_pos <> TextPos@zero then 57 text_box.selection = (TextPos.new, last_pos) 58 59 Key/F2 -> 60 case app.display.focus of 61 Some control if control is Tree -> rename 62 else -> () 63 64 Key/F5 | Key/F6 -> 65 if maybe_command.is_none then 66 if changed.is_not_empty then 67 apply 68 69 if content_changed.is_not_empty then 70 save_all 71 72 clear_output 73 output_text_box.update 74 let emit_cpp = key == Key/F5 75 || modifiers.contains KeyModifiers/Control 76 77 let result = compile crate_name emit_cpp 78 if result then 79 state = EditorState/BuildKedr 80 let run = key == Key/F5 81 let command = EditorCommand 82 build_kedr = true 83 =emit_cpp 84 build_cpp = run 85 =run 86 87 maybe_command = command 88 else 89 write_message "cannot connect to compiler" 90 91 Key/L -> 92 if not app.os_window.is_control_pressed then 93 return 94 95 if app.os_window.is_shift_pressed then 96 reload_all 97 else 98 reload_selected 99 100 Key/S -> 101 if not app.os_window.is_control_pressed 102 || app.display.focus.is_none 103 then 104 return 105 106 let control = app.display.focus.unwrap 107 if app.os_window.is_shift_pressed then 108 apply 109 save_all 110 else 111 if control is not MultilineTextBox then 112 return 113 114 let tab_item = tab_control.selected_tab_item.unwrap 115 assert tab_item_text_boxes[tab_item] == control 116 let text_box = control as MultilineTextBox 117 if text_box.is_changed then 118 let file = tab_item_file_items[tab_item] 119 if file.actual_path.is_not_empty then 120 save file text_box 121 text_box.is_changed = false 122 assert not content_changed.contains file 123 124 Key/Left | Key/Right | Key/Up | Key/Down -> 125 if app.display.focus <> Some tree then 126 return 127 128 if modifiers.contains KeyModifiers/Control then 129 case key of 130 Key/Left -> move_horizontal true 131 Key/Right -> move_horizontal false 132 Key/Up -> move_vertical true 133 Key/Down -> move_vertical false 134 else -> fail 135 else 136 case key of 137 Key/Left -> () 138 Key/Right -> () 139 Key/Up -> 140 if tree.selected_item.is_none then 141 return 142 143 let selected_item = tree.selected_item.unwrap as FileItem 144 let parent = selected_item.parent.unwrap 145 let index = parent.items.index_of selected_item 146 let next_selected_item = when 147 index > 0 -> 148 get_last_item parent.items[index - 1] 149 150 not parent.is_root -> parent 151 else -> selected_item 152 153 tree.selected_item = next_selected_item 154 155 Key/Down -> 156 if tree.selected_item.is_none then 157 return 158 159 let selected_item = tree.selected_item.unwrap as FileItem 160 let next_selected_item = 161 if selected_item.is_directory 162 && selected_item.is_open 163 && selected_item.items.is_not_empty 164 then selected_item.items[0] 165 else get_next_item selected_item 166 167 tree.selected_item = next_selected_item 168 169 else -> fail 170 171 Key/Space | Key/Enter -> 172 if app.display.frame_start_focus <> Some tree then 173 return 174 175 if changed.is_not_empty && key == Key/Enter then 176 apply 177 else 178 if tree.selected_item.is_none then 179 return 180 181 let selected_item = tree.selected_item.unwrap as FileItem 182 if selected_item.is_directory then 183 selected_item.is_open = not selected_item.is_open 184 else 185 open selected_item |> ignore 186 187 else -> () 188 189 app.os_window.keys.subscribe { key, action, modifiers -> 190 process_key key action modifiers } |> tokens.add 191