1 type MultilineTextBox 2 var highlighted_line : Option<TextLine> = None 3 4 type Editor 5 def open (item : FileItem) : bool = 6 if item.is_directory then 7 return false 8 9 if file_item_tab_items.contains item then 10 let tab_item = file_item_tab_items[item] 11 tab_control.select tab_item 12 false 13 else 14 let name = item.name 15 let file_text = if item.actual_path.is_empty 16 then "" 17 else fs/read_text item.actual_path 18 19 let text_box = MultilineTextBox 20 min_width = 400 21 text = file_text 22 show_line_numbers = true 23 update_colors = { update_colors _ _ _ } 24 25 load_text text_box file_text 26 27 let border = Border 28 up = 1 29 color = Colors.tab_item_content_border 30 text_box 31 32 control/arrange_unmeasured border 33 tab_control.presenter.width 34 tab_control.presenter.height 35 36 let tab_item = TabItem 37 header = name 38 can_close = true 39 border 40 41 let clear_highlight () = 42 if text_box.highlighted_line ? Some line then 43 line.clear_background 44 text_box.highlighted_line = None 45 46 text_box.is_changed@atom.subscribe 47 { _ x -> let color = if x 48 then Colors.tab_text_changed 49 else tab_control.foreground 50 item.foreground = color 51 if x then content_changed.add item 52 else content_changed.remove item 53 54 clear_highlight } 55 |> tab_item.push_token 56 57 text_box.cursor_pos@atom.subscribe { clear_highlight } 58 |> text_box.push_token 59 60 item.foreground@atom.bind { tab_item.foreground = _ } 61 |> tab_item.push_token 62 63 tab_item_text_boxes.add tab_item text_box 64 file_item_tab_items.add item tab_item 65 tab_item_file_items.add tab_item item 66 tab_control.tab_items.add tab_item 67 select tab_item 68 true 69 70 tree.on_open.add { item -> 71 let file = item as FileItem 72 if file.is_directory then 73 file.is_open = not file.is_open 74 else 75 open file |> ignore } 76