1     def load_text (text_box : MultilineTextBox) (s : String) =
2         let text = text_box.display_text
3         if text.is_not_empty then
4             text.clear
5     
6         text.insert TextPos.new s
7         text_box.update_colors 0 text.lines.size
8                  update_mesh
9     
10    type Editor
11        val tree = Tree
12            =data
13            min_width = 320
14    
15        val output_text_box = MultilineTextBox
16            min_width = 320
17            is_readonly = true
18    
19        local output = output_text_box.display_text
20    
21        val tab_control = TabControl
22            set_foreground = false
23            on_closing = { args ->
24                let text_box = tab_item_text_boxes[args.tab_item]
25                if text_box.is_changed && not app.os_window.is_control_pressed then
26                    args.is_cancelled = true }
27    
28            on_closed = { tab_item ->
29                let file_item = tab_item_file_items[tab_item]
30                tab_item_text_boxes.remove tab_item
31                tab_item_file_items.remove tab_item
32                file_item_tab_items.remove file_item }
33    
34        val apply_button = Button.new
35        let menu = Menu
36            apply_button
37                text = "apply"
38                command = Command/Apply
39            Button
40                text = "revert"
41                command = Command/Revert
42            Button
43                text = "save"
44                command = Command/SaveAll
45            Button
46                text = "remove"
47                command = Command/Remove
48            Button
49                text = "rename"
50                command = Command/Rename
51            Button
52                text = "file"
53                command = Command/File
54            Button
55                text = "directory"
56                command = Command/Directory
57    
58        let left_rectangle = Rectangle
59            color = Colors.tree_background
60            Scroller
61                color = Colors.tree_scroller
62                tree
63    
64        let border = Border
65            left = 2
66            right = 1
67            is_visible = false
68            color = Colors.tab_control_border
69            tab_control
70    
71        tab_control.tab_items
72        |> Obs.subscribe { border.is_visible = tab_control.tab_items.is_not_empty }
73        |> tokens.add
74    
75        let rectangle = Rectangle
76            color = Colors.background
77            Margin
78                up = 5
79                Resizer
80                    separator_offset = -1
81                    Resizer
82                        is_first_primary = false
83                        separator_offset = 1
84                        left_rectangle
85                        border
86    
87                    output_text_box
88    
89        let splitter = Splitter
90            ratio = 0
91            is_vertical = true
92            menu
93            rectangle
94    
95        app.set_content splitter
96    
97        tab_control.selected_tab_item@atom.subscribe
98            { maybe_prev_tab_item maybe_tab_item ->
99                  if maybe_prev_tab_item.is_some && maybe_tab_item.is_some then
100                     let prev_tab_item = maybe_prev_tab_item.unwrap
101                     let tab_item = maybe_tab_item.unwrap
102                     let prev_text_box = tab_item_text_boxes[prev_tab_item]
103                     if app.display.focus == Some prev_text_box then
104                         let text_box = tab_item_text_boxes[tab_item]
105                         app.display.focus = text_box }
106       |> tokens.add
107   
108       let default_foreground = apply_button.foreground
109       changed.bind
110           { index _ -> if index == 0 && changed.size == 1 then
111                            apply_button.foreground = Colors.apply_active }
112   
113           { index _ -> if index == 0 && changed.is_empty then
114                            apply_button.foreground = default_foreground }
115       |> tokens.add
116