Mercurial Hosting > editor
changeset 47:f66f704118e3
list window uses JList
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 20 May 2025 19:07:30 -0600 |
parents | 1eef35fa48f3 |
children | ca5ae0a36db7 |
files | src/luan_editor/window.luan |
diffstat | 1 files changed, 22 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/src/luan_editor/window.luan Mon May 19 20:14:26 2025 -0600 +++ b/src/luan_editor/window.luan Tue May 20 19:07:30 2025 -0600 @@ -12,6 +12,7 @@ local new_frame = require("luan:swing/Frame.luan").new or error() local new_dialog = require("luan:swing/Dialog.luan").new or error() local new_panel = require("luan:swing/Component.luan").new_panel or error() +local new_list = require("luan:swing/List.luan").new or error() local Layout = require "luan:swing/Layout.luan" local new_mig_layout = Layout.new_mig_layout or error() local new_scroll_pane = require("luan:swing/Scroll_pane.luan").new or error() @@ -28,8 +29,6 @@ local choose_file = File_chooser.awt_choose_file or error() local Option_pane = require "luan:swing/Option_pane.luan" local show_message_dialog = Option_pane.show_message_dialog or error() -local new_radio_button = require("luan:swing/Radio_button.luan").new or error() -local new_button_group = require("luan:swing/Button_group.luan").new or error() local Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "editor/window" @@ -65,9 +64,11 @@ config_file.write_text( stringify(config).."\n" ) end -local list_view = new_panel{ +local list_view = new_list{ --layout = new_mig_layout("insets 0,wrap,fill") - layout = new_mig_layout("wrap","[grow]") + --layout = new_mig_layout("wrap","[grow]") + horizontal_alignment = "right" + hover_background = int_to_color(0xEEEEEE) } local list_scroll_pane = new_scroll_pane{ view = list_view @@ -96,27 +97,19 @@ list_scroll_pane.scroll_to_right() end -local list_group = new_button_group() - -local function new_list_window_item(text) - local rb = new_radio_button{ - constraints = "grow" - text = text - horizontal_text_position = "left" - horizontal_alignment = "right" - } - list_view.add(rb) - list_group.add(rb) +local function add_list_window_item(item) + list_view.add_element(item) list_scroll_pane.scroll_to_right() - return rb +end +local function remove_list_window_item(item) + list_view.remove_element(item) --or error() end -local function remove_list_window_item(list_window_item) - list_view.remove(list_window_item) - list_group.remove(list_window_item) -end +list_view.add_list_selection_listener( function(item) + item.window.text_area.request_focus() +end ) local black = int_to_color(0x000000) -local blue = int_to_color(0x0000FF) +local dark_blue = int_to_color(0x0000C0) local grey = int_to_color(0x888888) local function new_window(file,document) @@ -158,11 +151,11 @@ end end text_area.set_selection(0) - local list_window_item = new_list_window_item(title) - list_window_item.add_action_listener(function(_) - text_area.request_focus() - end) - --window.list_window_item = list_window_item + local list_window_item = { + text = title + window = window + } + add_list_window_item(list_window_item) local status_bar = new_label{ constraints = "span,growx" text = " " @@ -198,8 +191,7 @@ remove_list_window_item(list_window_item) end) frame.add_window_focus_listener(function() - list_window_item.is_selected = true - list_window_item.scroll_into_view_vertically() + list_view.set_selected_value(list_window_item) end) frame.add_resize_stopped_listener( 200, function() --logger.info(stringify(frame.size)) @@ -222,7 +214,8 @@ s = s.." *" end frame.title = s - list_window_item.foreground_color = is_unedited and black or blue + list_window_item.foreground_color = is_unedited and black or dark_blue + list_view.repaint(list_window_item) end undo_listener() --window.undo_listener = undo_listener -- dont gc