comparison src/luan_editor/window.luan @ 38:8c90e0077cfe

add duplicate window
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 15 May 2025 11:03:48 -0600
parents b7ff52d45b9a
children 2a3092ca528e
comparison
equal deleted inserted replaced
37:b7ff52d45b9a 38:8c90e0077cfe
55 55
56 local function save_config() 56 local function save_config()
57 config_file.write_text( stringify(config).."\n" ) 57 config_file.write_text( stringify(config).."\n" )
58 end 58 end
59 59
60 local function new_window(file) 60 local function new_window(file,document)
61 local window = {} 61 local window = {}
62 window.has_file = file~=nil and file.is_file() 62 window.has_file = file~=nil and file.is_file()
63 local text_area = new_text_area{ 63 local text_area = new_text_area{
64 wrap_style_word = true 64 wrap_style_word = true
65 line_wrap = config.line_wrap 65 line_wrap = config.line_wrap
67 tab_size = config.tab_size 67 tab_size = config.tab_size
68 font = { family="Monospaced", size=13 } 68 font = { family="Monospaced", size=13 }
69 } 69 }
70 window.text_area = text_area 70 window.text_area = text_area
71 local title = file and file.canonical().to_string() or "new" 71 local title = file and file.canonical().to_string() or "new"
72 if file ~= nil then 72 if document ~= nil then
73 text_area.document = document
74 elseif file ~= nil then
73 local document = documents[title] 75 local document = documents[title]
74 if document == nil then 76 if document == nil then
75 documents[title] = text_area.document 77 documents[title] = text_area.document
76 else 78 else
77 text_area.document = document 79 text_area.document = document
237 function window.set_tab_size(tab_size) 239 function window.set_tab_size(tab_size)
238 text_area.tab_size = tab_size 240 text_area.tab_size = tab_size
239 config.tab_size = tab_size 241 config.tab_size = tab_size
240 save_config() 242 save_config()
241 end 243 end
244 function window.duplicate()
245 local new = new_window(file,text_area.document)
246 new.text_area.set_selection( text_area.get_selection() )
247 end
242 add_menu_bar(window) 248 add_menu_bar(window)
243 frame.pack() 249 frame.pack()
244 if config.location ~= nil then 250 if config.location ~= nil then
245 frame.location = config.location 251 frame.location = config.location
246 end 252 end
247 frame.visible = true 253 frame.visible = true
248 text_area.request_focus_in_window() 254 text_area.request_focus_in_window()
249 n_windows = n_windows + 1 255 n_windows = n_windows + 1
256 return window
250 end 257 end
251 258
252 return new_window 259 return new_window