Mercurial Hosting > editor
comparison editor.luan @ 24:da93a58e24aa
work
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 09 Apr 2025 11:43:31 -0600 |
parents | e4af9e024d63 |
children | ce3d1dc406a8 |
comparison
equal
deleted
inserted
replaced
23:e4af9e024d63 | 24:da93a58e24aa |
---|---|
226 local documents = {} | 226 local documents = {} |
227 | 227 |
228 function new_window(file) | 228 function new_window(file) |
229 local window = {} | 229 local window = {} |
230 window.has_file = file~=nil and file.is_file() | 230 window.has_file = file~=nil and file.is_file() |
231 local frame = new_frame() | 231 local text_area = new_text_area{ |
232 window.frame = frame | 232 rows = 10 |
233 columns = 20 | |
234 wrap_style_word = true | |
235 line_wrap = true | |
236 tab_size = 4 | |
237 font = { family="Monospaced", size=13 } | |
238 border = create_empty_border(0,4,0,4) | |
239 } | |
240 window.text_area = text_area | |
233 local title = file and file.canonical().to_string() or "new" | 241 local title = file and file.canonical().to_string() or "new" |
234 frame.add_close_listener(function() | |
235 n_windows = n_windows - 1 | |
236 if n_windows == 0 then | |
237 Luan.exit() | |
238 end | |
239 end) | |
240 local text_area = new_text_area{} | |
241 window.text_area = text_area | |
242 if file ~= nil then | 242 if file ~= nil then |
243 local document = documents[title] | 243 local document = documents[title] |
244 if document == nil then | 244 if document == nil then |
245 documents[title] = text_area.document | 245 documents[title] = text_area.document |
246 else | 246 else |
249 if file.is_file() then | 249 if file.is_file() then |
250 text_area.text = file.read_text() | 250 text_area.text = file.read_text() |
251 text_area.document.clear_unedited() | 251 text_area.document.clear_unedited() |
252 end | 252 end |
253 end | 253 end |
254 text_area.set_selection(0) | |
255 local frame = new_frame{ | |
256 content_pane = new_scroll_pane{ | |
257 view = text_area | |
258 row_header_view = new_text_area_line_numbers{ | |
259 text_area = text_area | |
260 foreground_color = int_to_color(0x888888) | |
261 border = create_empty_border(0,8,0,8) | |
262 } | |
263 } | |
264 } | |
265 window.frame = frame | |
266 frame.add_close_listener(function() | |
267 n_windows = n_windows - 1 | |
268 if n_windows == 0 then | |
269 Luan.exit() | |
270 end | |
271 end) | |
254 local function set_title() | 272 local function set_title() |
255 local s = title | 273 local s = title |
256 if not text_area.document.is_unedited() then | 274 if not text_area.document.is_unedited() then |
257 s = s.." *" | 275 s = s.." *" |
258 end | 276 end |
259 frame.title = s | 277 frame.title = s |
260 end | 278 end |
261 set_title() | 279 set_title() |
262 text_area.dont_gc(set_title) | 280 window.set_title = set_title -- dont gc |
263 text_area.document.add_undo_listener(set_title) | 281 text_area.document.add_undo_listener(set_title) |
264 text_area.rows = 10 | |
265 text_area.columns = 20 | |
266 text_area.wrap_style_word = true | |
267 text_area.line_wrap = true | |
268 text_area.tab_size = 4 | |
269 text_area.set_font{ family="Monospaced", size=13 } | |
270 text_area.set_selection(0) | |
271 --print(text_area.line_count) | |
272 local scroll_pane = new_scroll_pane{ | |
273 view = text_area | |
274 } | |
275 local line_numbers = new_text_area_line_numbers{ | |
276 text_area = text_area | |
277 } | |
278 line_numbers.foreground_color = int_to_color(0x888888) | |
279 line_numbers.border = create_empty_border(0,8,0,8) | |
280 scroll_pane.set_row_header_view(line_numbers) | |
281 frame.add(scroll_pane) | |
282 function window.open() | 282 function window.open() |
283 local file_chooser = frame.file_chooser_load() | 283 local file_chooser = frame.file_chooser_load() |
284 if file ~= nil then | 284 if file ~= nil then |
285 file_chooser.directory = file.parent() | 285 file_chooser.directory = file.parent() |
286 end | 286 end |