Mercurial Hosting > editor
comparison src/luan_editor/window.luan @ 47:f66f704118e3
list window uses JList
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 20 May 2025 19:07:30 -0600 |
parents | 1eef35fa48f3 |
children | ca5ae0a36db7 |
comparison
equal
deleted
inserted
replaced
46:1eef35fa48f3 | 47:f66f704118e3 |
---|---|
10 local Io = require "luan:Io.luan" | 10 local Io = require "luan:Io.luan" |
11 local new_text_area = require("luan:swing/Text_area.luan").new or error() | 11 local new_text_area = require("luan:swing/Text_area.luan").new or error() |
12 local new_frame = require("luan:swing/Frame.luan").new or error() | 12 local new_frame = require("luan:swing/Frame.luan").new or error() |
13 local new_dialog = require("luan:swing/Dialog.luan").new or error() | 13 local new_dialog = require("luan:swing/Dialog.luan").new or error() |
14 local new_panel = require("luan:swing/Component.luan").new_panel or error() | 14 local new_panel = require("luan:swing/Component.luan").new_panel or error() |
15 local new_list = require("luan:swing/List.luan").new or error() | |
15 local Layout = require "luan:swing/Layout.luan" | 16 local Layout = require "luan:swing/Layout.luan" |
16 local new_mig_layout = Layout.new_mig_layout or error() | 17 local new_mig_layout = Layout.new_mig_layout or error() |
17 local new_scroll_pane = require("luan:swing/Scroll_pane.luan").new or error() | 18 local new_scroll_pane = require("luan:swing/Scroll_pane.luan").new or error() |
18 local new_text_area_line_numbers = require("luan:swing/Text_area_line_numbers.luan").new or error() | 19 local new_text_area_line_numbers = require("luan:swing/Text_area_line_numbers.luan").new or error() |
19 local int_to_color = require("luan:swing/Color.luan").int_to_color or error() | 20 local int_to_color = require("luan:swing/Color.luan").int_to_color or error() |
26 local run_later = Swing.run_later or error() | 27 local run_later = Swing.run_later or error() |
27 local File_chooser = require "luan:swing/File_chooser.luan" | 28 local File_chooser = require "luan:swing/File_chooser.luan" |
28 local choose_file = File_chooser.awt_choose_file or error() | 29 local choose_file = File_chooser.awt_choose_file or error() |
29 local Option_pane = require "luan:swing/Option_pane.luan" | 30 local Option_pane = require "luan:swing/Option_pane.luan" |
30 local show_message_dialog = Option_pane.show_message_dialog or error() | 31 local show_message_dialog = Option_pane.show_message_dialog or error() |
31 local new_radio_button = require("luan:swing/Radio_button.luan").new or error() | |
32 local new_button_group = require("luan:swing/Button_group.luan").new or error() | |
33 local Logging = require "luan:logging/Logging.luan" | 32 local Logging = require "luan:logging/Logging.luan" |
34 local logger = Logging.logger "editor/window" | 33 local logger = Logging.logger "editor/window" |
35 | 34 |
36 | 35 |
37 local n_windows = 0 | 36 local n_windows = 0 |
63 | 62 |
64 local function save_config() | 63 local function save_config() |
65 config_file.write_text( stringify(config).."\n" ) | 64 config_file.write_text( stringify(config).."\n" ) |
66 end | 65 end |
67 | 66 |
68 local list_view = new_panel{ | 67 local list_view = new_list{ |
69 --layout = new_mig_layout("insets 0,wrap,fill") | 68 --layout = new_mig_layout("insets 0,wrap,fill") |
70 layout = new_mig_layout("wrap","[grow]") | 69 --layout = new_mig_layout("wrap","[grow]") |
70 horizontal_alignment = "right" | |
71 hover_background = int_to_color(0xEEEEEE) | |
71 } | 72 } |
72 local list_scroll_pane = new_scroll_pane{ | 73 local list_scroll_pane = new_scroll_pane{ |
73 view = list_view | 74 view = list_view |
74 } | 75 } |
75 local list_window = new_dialog{ | 76 local list_window = new_dialog{ |
94 end | 95 end |
95 list_window.visible = true | 96 list_window.visible = true |
96 list_scroll_pane.scroll_to_right() | 97 list_scroll_pane.scroll_to_right() |
97 end | 98 end |
98 | 99 |
99 local list_group = new_button_group() | 100 local function add_list_window_item(item) |
100 | 101 list_view.add_element(item) |
101 local function new_list_window_item(text) | |
102 local rb = new_radio_button{ | |
103 constraints = "grow" | |
104 text = text | |
105 horizontal_text_position = "left" | |
106 horizontal_alignment = "right" | |
107 } | |
108 list_view.add(rb) | |
109 list_group.add(rb) | |
110 list_scroll_pane.scroll_to_right() | 102 list_scroll_pane.scroll_to_right() |
111 return rb | 103 end |
112 end | 104 local function remove_list_window_item(item) |
113 local function remove_list_window_item(list_window_item) | 105 list_view.remove_element(item) --or error() |
114 list_view.remove(list_window_item) | 106 end |
115 list_group.remove(list_window_item) | 107 list_view.add_list_selection_listener( function(item) |
116 end | 108 item.window.text_area.request_focus() |
109 end ) | |
117 | 110 |
118 local black = int_to_color(0x000000) | 111 local black = int_to_color(0x000000) |
119 local blue = int_to_color(0x0000FF) | 112 local dark_blue = int_to_color(0x0000C0) |
120 local grey = int_to_color(0x888888) | 113 local grey = int_to_color(0x888888) |
121 | 114 |
122 local function new_window(file,document) | 115 local function new_window(file,document) |
123 local window = {} | 116 local window = {} |
124 if file == nil or not file.exists() then | 117 if file == nil or not file.exists() then |
156 text_area.document.clear_unedited() | 149 text_area.document.clear_unedited() |
157 end | 150 end |
158 end | 151 end |
159 end | 152 end |
160 text_area.set_selection(0) | 153 text_area.set_selection(0) |
161 local list_window_item = new_list_window_item(title) | 154 local list_window_item = { |
162 list_window_item.add_action_listener(function(_) | 155 text = title |
163 text_area.request_focus() | 156 window = window |
164 end) | 157 } |
165 --window.list_window_item = list_window_item | 158 add_list_window_item(list_window_item) |
166 local status_bar = new_label{ | 159 local status_bar = new_label{ |
167 constraints = "span,growx" | 160 constraints = "span,growx" |
168 text = " " | 161 text = " " |
169 border = create_empty_border(2,16,4,16) | 162 border = create_empty_border(2,16,4,16) |
170 } | 163 } |
196 Luan.exit() | 189 Luan.exit() |
197 end | 190 end |
198 remove_list_window_item(list_window_item) | 191 remove_list_window_item(list_window_item) |
199 end) | 192 end) |
200 frame.add_window_focus_listener(function() | 193 frame.add_window_focus_listener(function() |
201 list_window_item.is_selected = true | 194 list_view.set_selected_value(list_window_item) |
202 list_window_item.scroll_into_view_vertically() | |
203 end) | 195 end) |
204 frame.add_resize_stopped_listener( 200, function() | 196 frame.add_resize_stopped_listener( 200, function() |
205 --logger.info(stringify(frame.size)) | 197 --logger.info(stringify(frame.size)) |
206 config.size = frame.size | 198 config.size = frame.size |
207 save_config() | 199 save_config() |
220 local s = title | 212 local s = title |
221 if not is_unedited then | 213 if not is_unedited then |
222 s = s.." *" | 214 s = s.." *" |
223 end | 215 end |
224 frame.title = s | 216 frame.title = s |
225 list_window_item.foreground_color = is_unedited and black or blue | 217 list_window_item.foreground_color = is_unedited and black or dark_blue |
218 list_view.repaint(list_window_item) | |
226 end | 219 end |
227 undo_listener() | 220 undo_listener() |
228 --window.undo_listener = undo_listener -- dont gc | 221 --window.undo_listener = undo_listener -- dont gc |
229 text_area.document.add_undo_listener(undo_listener) | 222 text_area.document.add_undo_listener(undo_listener) |
230 window.new = new_window | 223 window.new = new_window |