Mercurial Hosting > editor
comparison src/luan_editor/Window.luan @ 75:7f5b3824f4d4
add Windows
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 18 Jun 2025 18:57:34 -0600 |
parents | e972fb08a574 |
children | 1beb4c57c269 |
comparison
equal
deleted
inserted
replaced
74:c3b0fba5c2bc | 75:7f5b3824f4d4 |
---|---|
10 local String = require "luan:String.luan" | 10 local String = require "luan:String.luan" |
11 local sub_string = String.sub or error() | 11 local sub_string = String.sub or error() |
12 local replace = String.replace or error() | 12 local replace = String.replace or error() |
13 local starts_with = String.starts_with or error() | 13 local starts_with = String.starts_with or error() |
14 local Io = require "luan:Io.luan" | 14 local Io = require "luan:Io.luan" |
15 local Thread = require "luan:Thread.luan" | |
16 local sleep = Thread.sleep or error() | |
17 local thread_safe_function = Thread.thread_safe_function or error() | |
15 local new_file = Io.schemes.file or error() | 18 local new_file = Io.schemes.file or error() |
16 local new_text_area = require("luan:swing/Text_area.luan").new or error() | 19 local new_text_area = require("luan:swing/Text_area.luan").new or error() |
17 local new_frame = require("luan:swing/Frame.luan").new or error() | 20 local new_frame = require("luan:swing/Frame.luan").new or error() |
18 local new_dialog = require("luan:swing/Dialog.luan").new or error() | 21 local new_dialog = require("luan:swing/Dialog.luan").new or error() |
19 local new_panel = require("luan:swing/Component.luan").new_panel or error() | 22 local new_panel = require("luan:swing/Component.luan").new_panel or error() |
30 local File_chooser = require "luan:swing/File_chooser.luan" | 33 local File_chooser = require "luan:swing/File_chooser.luan" |
31 local choose_file = File_chooser.awt_choose_file or error() | 34 local choose_file = File_chooser.awt_choose_file or error() |
32 local Option_pane = require "luan:swing/Option_pane.luan" | 35 local Option_pane = require "luan:swing/Option_pane.luan" |
33 local show_message_dialog = Option_pane.show_message_dialog or error() | 36 local show_message_dialog = Option_pane.show_message_dialog or error() |
34 local Clipboard = require "luan:swing/Clipboard.luan" | 37 local Clipboard = require "luan:swing/Clipboard.luan" |
38 local Swing_runner = require "luan:swing/Swing_runner.luan" | |
39 local swing_run = Swing_runner.run or error() | |
35 local Java = require "classpath:luan_editor/Java.luan" | 40 local Java = require "classpath:luan_editor/Java.luan" |
36 local Logging = require "luan:logging/Logging.luan" | 41 local Logging = require "luan:logging/Logging.luan" |
37 local logger = Logging.logger "editor/Window" | 42 local logger = Logging.logger "editor/Window" |
38 | 43 |
39 | 44 |
48 else | 53 else |
49 return default | 54 return default |
50 end | 55 end |
51 end | 56 end |
52 | 57 |
53 local config_file = Io.uri("file:"..Java.home_dir.."/.luan_editor/config.json") | 58 local config_file = Io.uri("file:"..Java.config_path) |
54 local config = {} | 59 local config = {} |
55 if config_file.exists() then | 60 if config_file.exists() then |
56 try | 61 try |
57 config = json_parse(config_file.read_text()) | 62 config = json_parse(config_file.read_text()) |
58 catch e | 63 catch e |
361 --logger.info("paste_files "..stringify(Clipboard.get_files())) | 366 --logger.info("paste_files "..stringify(Clipboard.get_files())) |
362 local files = Clipboard.get_files() | 367 local files = Clipboard.get_files() |
363 if files == nil then | 368 if files == nil then |
364 return false | 369 return false |
365 end | 370 end |
366 for _, file in ipairs(files) do | 371 local fn = thread_safe_function( new_window ) |
367 new_window(file) | 372 Thread.run( function() |
368 end | 373 for _, file in ipairs(files) do |
374 swing_run( function() | |
375 fn(file) | |
376 end ) | |
377 sleep(100) | |
378 end | |
379 end, true ) | |
369 return true | 380 return true |
370 end | 381 end |
371 local add_menu_bar = require "classpath:luan_editor/menu.luan" | 382 local add_menu_bar = require "classpath:luan_editor/menu.luan" |
372 add_menu_bar(window) | 383 add_menu_bar(window) |
373 frame.pack() | 384 frame.pack() |
380 n_windows = n_windows + 1 | 391 n_windows = n_windows + 1 |
381 return window | 392 return window |
382 end | 393 end |
383 Window.new_window = new_window | 394 Window.new_window = new_window |
384 | 395 |
385 function Window.open_windows(file_paths) | 396 function Window.open_window(file_path) |
386 list_window.to_front() | 397 if file_path == nil then |
387 for _, file_path in ipairs(file_paths) do | |
388 local file = new_file(file_path) | |
389 new_window(file) | |
390 end | |
391 if #file_paths == 0 then | |
392 local window = list_view.selected_value.window | 398 local window = list_view.selected_value.window |
393 window.frame.to_front() | 399 window.frame.to_front() |
394 window.text_area.request_focus_in_window() | 400 window.text_area.request_focus_in_window() |
401 else | |
402 local file = new_file(file_path) | |
403 new_window(file) | |
395 end | 404 end |
396 end | 405 end |
397 | 406 |
398 return Window | 407 return Window |