0
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local Io = require "luan:Io.luan"
|
|
4 local print = Io.print or error()
|
|
5 local Swing = require "luan:swing/Swing.luan"
|
|
6 local new_frame = require("luan:swing/Frame.luan").new or error()
|
|
7 local new_label = require("luan:swing/Label.luan").new or error()
|
|
8 local new_text_area = require("luan:swing/Text_area.luan").new or error()
|
|
9 local new_scroll_pane = require("luan:swing/Scroll_pane.luan").new or error()
|
|
10 local new_list = require("luan:swing/List.luan").new or error()
|
|
11 local new_menu_bar = require("luan:swing/Menu_bar.luan").new or error()
|
|
12 local new_menu = require("luan:swing/Menu.luan").new or error()
|
|
13 local new_menu_item = require("luan:swing/Menu_item.luan").new or error()
|
|
14 local Logging = require "luan:logging/Logging.luan"
|
|
15 local logger = Logging.logger "editor"
|
|
16
|
|
17
|
|
18 local new_window
|
|
19
|
1
|
20 local function make_menu_bar(window)
|
0
|
21 local menu_bar = new_menu_bar()
|
1
|
22 local file_menu = new_menu()
|
|
23 file_menu.text = "File"
|
|
24 local new_file = new_menu_item()
|
|
25 new_file.text = "New File"
|
|
26 new_file.accelerator = "meta N"
|
|
27 new_file.add_action_listener(function()
|
|
28 new_window()
|
|
29 end)
|
|
30 file_menu.add(new_file)
|
|
31 local open = new_menu_item()
|
|
32 open.text = "Open..."
|
|
33 open.accelerator = "meta O"
|
|
34 open.add_action_listener(function()
|
|
35 local file_chooser = window.frame.file_chooser_load()
|
|
36 if window.file ~= nil then
|
|
37 file_chooser.directory = window.file.parent()
|
|
38 end
|
|
39 file_chooser.visible = true
|
|
40 local file = file_chooser.file
|
|
41 if file ~= nil then
|
|
42 new_window(file)
|
|
43 end
|
|
44 end)
|
|
45 file_menu.add(open)
|
|
46 menu_bar.add(file_menu)
|
0
|
47 return menu_bar
|
|
48 end
|
|
49
|
|
50 local n_windows = 0
|
|
51
|
1
|
52 function new_window(file)
|
0
|
53 local frame = new_frame()
|
1
|
54 frame.title = file and file.to_string() or "untitled"
|
0
|
55 frame.add_close_listener(function()
|
|
56 n_windows = n_windows - 1
|
|
57 if n_windows == 0 then
|
|
58 Luan.exit()
|
|
59 end
|
|
60 end)
|
|
61 local text_area = new_text_area()
|
1
|
62 if file ~= nil then
|
|
63 text_area.text = file.read_text()
|
|
64 end
|
0
|
65 text_area.rows = 10
|
|
66 text_area.columns = 20
|
|
67 text_area.wrap_style_word = true
|
|
68 text_area.line_wrap = true
|
|
69 text_area.tab_size = 4
|
|
70 text_area.set_font{ family="Monospaced", size=13 }
|
1
|
71 text_area.select(0,0)
|
0
|
72 --print(text_area.line_count)
|
|
73 local scroll_pane = new_scroll_pane(text_area)
|
|
74 local list = new_list()
|
|
75 list.add_element("1")
|
|
76 list.add_element("2")
|
|
77 list.add_element("3")
|
|
78 --scroll_pane.set_row_header_view(list)
|
|
79 frame.add(scroll_pane)
|
1
|
80 local window = {
|
|
81 frame = frame
|
|
82 file = file
|
|
83 }
|
|
84 local menu_bar = make_menu_bar(window)
|
0
|
85 frame.set_menu_bar(menu_bar)
|
|
86 frame.pack()
|
|
87 frame.visible = true
|
|
88 text_area.request_focus_in_window()
|
|
89 n_windows = n_windows + 1
|
|
90 end
|
|
91
|
1
|
92 Swing.run(function()
|
|
93 new_window()
|
|
94 end)
|