Mercurial Hosting > editor
comparison src/luan_editor/window.luan @ 41:f7e8c1f532c8
start list window
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 17 May 2025 22:20:57 -0600 |
parents | 2a3092ca528e |
children | b76918e3e77c |
comparison
equal
deleted
inserted
replaced
40:38bc1cdf77c8 | 41:f7e8c1f532c8 |
---|---|
8 local replace = String.replace or error() | 8 local replace = String.replace or error() |
9 local starts_with = String.starts_with or error() | 9 local starts_with = String.starts_with or error() |
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_panel = require("luan:swing/Component.luan").new_panel or error() | 14 local new_panel = require("luan:swing/Component.luan").new_panel or error() |
14 local Layout = require "luan:swing/Layout.luan" | 15 local Layout = require "luan:swing/Layout.luan" |
15 local new_mig_layout = Layout.new_mig_layout or error() | 16 local new_mig_layout = Layout.new_mig_layout or error() |
16 local new_scroll_pane = require("luan:swing/Scroll_pane.luan").new or error() | 17 local new_scroll_pane = require("luan:swing/Scroll_pane.luan").new or error() |
17 local new_text_area_line_numbers = require("luan:swing/Text_area_line_numbers.luan").new or error() | 18 local new_text_area_line_numbers = require("luan:swing/Text_area_line_numbers.luan").new or error() |
24 local Swing = require "luan:swing/Swing.luan" | 25 local Swing = require "luan:swing/Swing.luan" |
25 local File_chooser = require "luan:swing/File_chooser.luan" | 26 local File_chooser = require "luan:swing/File_chooser.luan" |
26 local choose_file = File_chooser.awt_choose_file or error() | 27 local choose_file = File_chooser.awt_choose_file or error() |
27 local Option_pane = require "luan:swing/Option_pane.luan" | 28 local Option_pane = require "luan:swing/Option_pane.luan" |
28 local show_message_dialog = Option_pane.show_message_dialog or error() | 29 local show_message_dialog = Option_pane.show_message_dialog or error() |
30 local new_radio_button = require("luan:swing/Radio_button.luan").new or error() | |
31 local new_button_group = require("luan:swing/Button_group.luan").new or error() | |
29 local Logging = require "luan:logging/Logging.luan" | 32 local Logging = require "luan:logging/Logging.luan" |
30 local logger = Logging.logger "editor/window" | 33 local logger = Logging.logger "editor/window" |
31 | 34 |
32 | 35 |
33 local n_windows = 0 | 36 local n_windows = 0 |
55 config.whitespace_visible = bool( config.whitespace_visible, false ) | 58 config.whitespace_visible = bool( config.whitespace_visible, false ) |
56 config.tab_size = config.tab_size or 4 | 59 config.tab_size = config.tab_size or 4 |
57 | 60 |
58 local function save_config() | 61 local function save_config() |
59 config_file.write_text( stringify(config).."\n" ) | 62 config_file.write_text( stringify(config).."\n" ) |
63 end | |
64 | |
65 local list_view = new_panel{ | |
66 --layout = new_mig_layout("insets 0,wrap,fill") | |
67 layout = new_mig_layout("wrap","[grow]") | |
68 } | |
69 local list_scroll_pane = new_scroll_pane{ | |
70 view = list_view | |
71 } | |
72 local list_window = new_dialog{ | |
73 preferred_size = { width=200, height=400 } | |
74 content_pane = list_scroll_pane | |
75 } | |
76 local list_group = new_button_group() | |
77 local function new_list_window_item(text) | |
78 local rb = new_radio_button{ | |
79 constraints = "grow" | |
80 text = text | |
81 horizontal_text_position = "left" | |
82 horizontal_alignment = "right" | |
83 } | |
84 list_view.add(rb) | |
85 list_group.add(rb) | |
86 list_scroll_pane.scroll_to_right() | |
87 list_window.pack() | |
88 return rb | |
60 end | 89 end |
61 | 90 |
62 local function new_window(file,document) | 91 local function new_window(file,document) |
63 local window = {} | 92 local window = {} |
64 if file == nil or not file.exists() then | 93 if file == nil or not file.exists() then |
145 local s = title | 174 local s = title |
146 if not text_area.document.is_unedited() then | 175 if not text_area.document.is_unedited() then |
147 s = s.." *" | 176 s = s.." *" |
148 end | 177 end |
149 frame.title = s | 178 frame.title = s |
179 new_list_window_item(title) | |
150 end | 180 end |
151 set_title() | 181 set_title() |
152 window.set_title = set_title -- dont gc | 182 window.set_title = set_title -- dont gc |
153 text_area.document.add_undo_listener(set_title) | 183 text_area.document.add_undo_listener(set_title) |
154 window.new = new_window | 184 window.new = new_window |
262 end | 292 end |
263 function window.duplicate() | 293 function window.duplicate() |
264 local new = new_window(file,text_area.document) | 294 local new = new_window(file,text_area.document) |
265 new.text_area.set_selection( text_area.get_selection() ) | 295 new.text_area.set_selection( text_area.get_selection() ) |
266 end | 296 end |
297 function window.show_list_window() | |
298 list_window.visible = true | |
299 list_scroll_pane.scroll_to_right() | |
300 end | |
267 add_menu_bar(window) | 301 add_menu_bar(window) |
268 frame.pack() | 302 frame.pack() |
269 if config.location ~= nil then | 303 if config.location ~= nil then |
270 frame.location = config.location | 304 frame.location = config.location |
271 end | 305 end |