changeset 44:779ea6d9d8fb default tip

list window work
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 19 May 2025 14:53:41 -0600 (2 hours ago)
parents 48c35fdccb31
children
files src/luan_editor/window.luan
diffstat 1 files changed, 37 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan_editor/window.luan	Sun May 18 18:47:32 2025 -0600
+++ b/src/luan_editor/window.luan	Mon May 19 14:53:41 2025 -0600
@@ -23,6 +23,7 @@
 local make_find_panel = require "classpath:luan_editor/find.luan"
 local add_menu_bar = require "classpath:luan_editor/menu.luan"
 local Swing = require "luan:swing/Swing.luan"
+local run_later = Swing.run_later or error()
 local File_chooser = require "luan:swing/File_chooser.luan"
 local choose_file = File_chooser.awt_choose_file or error()
 local Option_pane = require "luan:swing/Option_pane.luan"
@@ -64,16 +65,23 @@
 
 local list_view = new_panel{
 	--layout = new_mig_layout("insets 0,wrap,fill")
-	layout = new_mig_layout("wrap,debug","[grow]")
+	layout = new_mig_layout("wrap","[grow]")
 }
 local list_scroll_pane = new_scroll_pane{
 	view = list_view
 }
 local list_window = new_dialog{
-	preferred_size = { width=200, height=400 }
+	--preferred_size = { width=200, height=400 }
+	size = { width=200, height=400 }
+	--maximum_size = { width=200, height=400 }
 	content_pane = list_scroll_pane
 	focusable_window_state = false
 }
+local function show_list_window()
+	list_window.visible = true
+	list_scroll_pane.scroll_to_right()
+end
+
 local list_group = new_button_group()
 
 local function new_list_window_item(text)
@@ -86,16 +94,19 @@
 	list_view.add(rb)
 	list_group.add(rb)
 	list_scroll_pane.scroll_to_right()
-	list_window.pack()
+	list_window.validate()
 	return rb
 end
 local function remove_list_window_item(list_window_item)
 	list_view.remove(list_window_item)
 	list_group.remove(list_window_item)
-	list_window.pack()
-	list_window.repaint()
+	list_window.validate()
 end
 
+local black = int_to_color(0x000000)
+local blue = int_to_color(0x0000FF)
+local grey = int_to_color(0x888888)
+
 local function new_window(file,document)
 	local window = {}
 	if file == nil or not file.exists() then
@@ -135,6 +146,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 status_bar = new_label{
 		constraints = "span,growx"
 		text = " "
@@ -152,7 +168,7 @@
 					view = text_area
 					row_header_view = new_text_area_line_numbers{
 						text_area = text_area
-						foreground_color = int_to_color(0x888888)
+						foreground_color = grey
 						border = create_empty_border(0,8,0,8)
 					}
 				}
@@ -167,10 +183,11 @@
 		if n_windows == 0 then
 			Luan.exit()
 		end
-		remove_list_window_item(window.list_window_item)
+		remove_list_window_item(list_window_item)
 	end)
 	frame.add_window_focus_listener(function()
-		window.list_window_item.is_selected = true
+		list_window_item.is_selected = true
+		list_window_item.scroll_into_view_vertically()
 	end)
 	frame.add_resize_stopped_listener( 200, function()
 		--logger.info(stringify(frame.size))
@@ -182,21 +199,22 @@
 		config.location = frame.location
 		save_config()
 	end)
-	local function set_title()
+	local function undo_listener()
+		local is_unedited = text_area.document.is_unedited()
+		if window.is_unedited == is_unedited then
+			return
+		end
+		window.is_unedited = is_unedited
 		local s = title
-		if not text_area.document.is_unedited() then
+		if not is_unedited then
 			s = s.." *"
 		end
 		frame.title = s
+		list_window_item.foreground_color = is_unedited and black or blue
 	end
-	set_title()
-	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
-	window.set_title = set_title  -- dont gc
-	text_area.document.add_undo_listener(set_title)
+	undo_listener()
+	--window.undo_listener = undo_listener  -- dont gc
+	text_area.document.add_undo_listener(undo_listener)
 	window.new = new_window
 	function window.open()
 		local new_file = choose_file{
@@ -310,10 +328,7 @@
 		local new = new_window(file,text_area.document)
 		new.text_area.set_selection( text_area.get_selection() )
 	end
-	function window.show_list_window()
-		list_window.visible = true
-		list_scroll_pane.scroll_to_right()
-	end
+	window.show_list_window = show_list_window
 	add_menu_bar(window)
 	frame.pack()
 	if config.location ~= nil then