comparison src/luan_editor/Window.luan @ 84:eb6c42083100 default tip

open multiple files
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 26 Jun 2025 23:14:21 -0600
parents 1beb4c57c269
children
comparison
equal deleted inserted replaced
83:b9be4afaf597 84:eb6c42083100
131 131
132 local black = int_to_color(0x000000) 132 local black = int_to_color(0x000000)
133 local dark_blue = int_to_color(0x0000C0) 133 local dark_blue = int_to_color(0x0000C0)
134 local grey = int_to_color(0x888888) 134 local grey = int_to_color(0x888888)
135 135
136 local function new_window(file,document) 136 local new_window
137
138 local function open_files(files)
139 local fn = thread_safe_function( new_window )
140 Thread.run( function()
141 for _, file in ipairs(files) do
142 swing_run( function()
143 fn(file)
144 end )
145 sleep(100)
146 end
147 end, true )
148 end
149
150 function new_window(file,document)
137 local window = {} 151 local window = {}
138 if file == nil or not file.exists() then 152 if file == nil or not file.exists() then
139 window.has_file = false 153 window.has_file = false
140 elseif file.is_file() then 154 elseif file.is_file() then
141 window.has_file = true 155 window.has_file = true
256 text_area.document.add_undo_listener(undo_listener) 270 text_area.document.add_undo_listener(undo_listener)
257 function window.title() 271 function window.title()
258 return title 272 return title
259 end 273 end
260 function window.open() 274 function window.open()
261 local new_file = choose_file{ 275 local new_files = choose_file{
262 action = "load" 276 action = "load"
263 parent = frame 277 parent = frame
264 directory = file and file.parent() 278 directory = file and file.parent()
279 multiple = true
265 } 280 }
266 if new_file ~= nil then 281 open_files(new_files)
267 new_window(new_file)
268 end
269 end 282 end
270 function window.save() 283 function window.save()
271 if file == nil then 284 if file == nil then
272 file = choose_file{ 285 local files = choose_file{
273 action = "save" 286 action = "save"
274 parent = frame 287 parent = frame
275 } 288 }
276 if file == nil then 289 if #files == 0 then
277 return false 290 return false
278 end 291 end
292 file = files[1]
279 title = file.canonical().to_string() 293 title = file.canonical().to_string()
280 documents[title] = { document = text_area.document, count = 1 } 294 documents[title] = { document = text_area.document, count = 1 }
281 window.is_unedited = nil 295 window.is_unedited = nil
282 undo_listener() 296 undo_listener()
283 end 297 end
374 --logger.info("paste_files "..stringify(Clipboard.get_files())) 388 --logger.info("paste_files "..stringify(Clipboard.get_files()))
375 local files = Clipboard.get_files() 389 local files = Clipboard.get_files()
376 if files == nil then 390 if files == nil then
377 return false 391 return false
378 end 392 end
379 local fn = thread_safe_function( new_window ) 393 open_files(files)
380 Thread.run( function()
381 for _, file in ipairs(files) do
382 swing_run( function()
383 fn(file)
384 end )
385 sleep(100)
386 end
387 end, true )
388 return true 394 return true
389 end 395 end
390 local add_menu_bar = require "classpath:luan_editor/menu.luan" 396 local add_menu_bar = require "classpath:luan_editor/menu.luan"
391 add_menu_bar(window) 397 add_menu_bar(window)
392 frame.pack() 398 frame.pack()