Mercurial Hosting > editor
comparison editor.luan @ 0:090f9b3bccf8
start
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Sun, 30 Mar 2025 13:17:48 -0600 |
| parents | |
| children | 9aa38deb5883 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:090f9b3bccf8 |
|---|---|
| 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 | |
| 20 local function make_menu_bar() | |
| 21 local menu_bar = new_menu_bar() | |
| 22 local file_menu = new_menu("File") | |
| 23 local new_file = new_menu_item() | |
| 24 new_file.text = "New File" | |
| 25 new_file.add_action_listener(function() | |
| 26 new_window() | |
| 27 end) | |
| 28 file_menu.add(new_file) | |
| 29 menu_bar.add(file_menu) | |
| 30 return menu_bar | |
| 31 end | |
| 32 | |
| 33 local n_windows = 0 | |
| 34 | |
| 35 function new_window() | |
| 36 local frame = new_frame() | |
| 37 frame.title = "untitled" | |
| 38 frame.add_close_listener(function() | |
| 39 n_windows = n_windows - 1 | |
| 40 if n_windows == 0 then | |
| 41 Luan.exit() | |
| 42 end | |
| 43 end) | |
| 44 local text_area = new_text_area() | |
| 45 text_area.rows = 10 | |
| 46 text_area.columns = 20 | |
| 47 text_area.wrap_style_word = true | |
| 48 text_area.line_wrap = true | |
| 49 text_area.tab_size = 4 | |
| 50 text_area.set_font{ family="Monospaced", size=13 } | |
| 51 --print(text_area.line_count) | |
| 52 local scroll_pane = new_scroll_pane(text_area) | |
| 53 local list = new_list() | |
| 54 list.add_element("1") | |
| 55 list.add_element("2") | |
| 56 list.add_element("3") | |
| 57 --scroll_pane.set_row_header_view(list) | |
| 58 frame.add(scroll_pane) | |
| 59 local menu_bar = make_menu_bar() | |
| 60 frame.set_menu_bar(menu_bar) | |
| 61 frame.pack() | |
| 62 frame.visible = true | |
| 63 text_area.request_focus_in_window() | |
| 64 n_windows = n_windows + 1 | |
| 65 end | |
| 66 | |
| 67 Swing.run(new_window) |
