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 lang = when 16 name.ends_with ".kd" -> Lang/Kedr 17 name.ends_with ".jl" -> Lang/Julia 18 else -> fail 19 20 let file_text = if item.actual_path.is_empty 21 then "" 22 else fs/read_text item.actual_path 23 24 let text_box = MultilineTextBox 25 min_width = 400 26 text = file_text 27 show_line_numbers = true 28 update_colors = { update_colors _ _ _ lang } 29 30 load_text text_box file_text 31 32 let border = Border 33 up = 1 34 color = Colors.tab_item_content_border 35 text_box 36 37 control/arrange_unmeasured border 38 tab_control.presenter.width 39 tab_control.presenter.height 40 41 let tab_item = TabItem 42 header = name 43 can_close = true 44 border 45 46 let clear_highlight () = 47 if text_box.highlighted_line ? Some line then 48 line.clear_highlight 49 text_box.highlighted_line = None 50 51 text_box.is_changed@atom.subscribe 52 { _ x -> let color = if x 53 then Colors.tab_text_changed 54 else tab_control.foreground 55 item.foreground = color 56 if x then content_changed.add item 57 else content_changed.remove item 58 59 clear_highlight } 60 |> tab_item.push_token 61 62 text_box.cursor_pos@atom.subscribe { clear_highlight } 63 |> text_box.push_token 64 65 item.foreground@atom.bind { tab_item.foreground = _ } 66 |> tab_item.push_token 67 68 tab_item_text_boxes.add tab_item text_box 69 file_item_tab_items.add item tab_item 70 tab_item_file_items.add tab_item item 71 tab_control.tab_items.add tab_item 72 select tab_item 73 true 74 75 tree.on_open.add { item -> 76 let file = item as FileItem 77 if file.is_directory then 78 file.is_open = not file.is_open 79 else 80 open file |> ignore } 81