changeset 1904:ad1dc9f103b7

ed status bar
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 15 Apr 2025 16:13:14 -0600
parents b3850e44e037
children f7649b3ebd22
files src/luan/modules/editor/find.luan src/luan/modules/editor/menu.luan src/luan/modules/editor/window.luan
diffstat 3 files changed, 40 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/modules/editor/find.luan	Tue Apr 15 14:08:18 2025 -0600
+++ b/src/luan/modules/editor/find.luan	Tue Apr 15 16:13:14 2025 -0600
@@ -41,12 +41,13 @@
 
 local function make_find_panel(window)
 	local text_area = window.text_area
-	local find_field, replace_field, regex_check_box, output
+	local status_bar = window.status_bar
+	local find_field, replace_field, regex_check_box
 	local function find_match(event)
 		--logger.info("action "..event.action)
 		local s = find_field.text
 		if #s == 0 then
-			output.text = ""
+			status_bar.text = " "
 			return
 		end
 		if not regex_check_box.is_selected then
@@ -56,12 +57,12 @@
 		try
 			matches = get_matches( text_area.text, s )
 		catch e
-			output.text = "Regex error: "..e.get_message()
+			status_bar.text = "Regex error: "..e.get_message()
 			return
 		end
 		local n_matches = #matches
 		if n_matches == 0 then
-			output.text = "0 matches"
+			status_bar.text = "0 matches"
 			return
 		end
 		local action = event.action
@@ -70,26 +71,26 @@
 			for i, match in ipairs(matches) do
 				if match.start >= pos then
 					text_area.set_selection( match.start, match.end_ )
-					output.text = i.." of "..n_matches.." matches"
+					status_bar.text = i.." of "..n_matches.." matches"
 					return
 				end
 			end
 			local match = matches[1]
 			text_area.set_selection( match.start, match.end_ )
-			output.text = "1 of "..n_matches.." matches; wrapped past end"
+			status_bar.text = "1 of "..n_matches.." matches; wrapped past end"
 		elseif action == "previous" then
 			local pos = text_area.get_selection()
 			for i in range(n_matches,1,-1) do
 				local match = matches[i]
 				if match.end_ <= pos then
 					text_area.set_selection( match.start, match.end_ )
-					output.text = i.." of "..n_matches.." matches"
+					status_bar.text = i.." of "..n_matches.." matches"
 					return
 				end
 			end
 			local match = matches[n_matches]
 			text_area.set_selection( match.start, match.end_ )
-			output.text = n_matches.." of "..n_matches.." matches; wrapped past end"
+			status_bar.text = n_matches.." of "..n_matches.." matches; wrapped past end"
 		else
 			error(action)
 		end
@@ -97,7 +98,7 @@
 	local function replace_match(event)
 		local find = find_field.text
 		if #find == 0 then
-			output.text = ""
+			status_bar.text = " "
 			return
 		end
 		local replace = replace_field.text
@@ -109,7 +110,7 @@
 		try
 			r = regex(find)
 		catch e
-			output.text = "Regex error: "..e.get_message()
+			status_bar.text = "Regex error: "..e.get_message()
 			return
 		end
 		local new, n
@@ -129,7 +130,7 @@
 		else
 			error(action)
 		end
-		output.text = n.." replacements"
+		status_bar.text = n.." replacements"
 	end
 	find_field = new_text_field{
 		constraints = "growx"
@@ -146,12 +147,9 @@
 	regex_check_box = new_check_box{
 		text = "Use Regex"
 	}
-	output = new_label{
-		constraints = "span"
-	}
 	local find_panel = new_panel{
 		constraints = "growy 0,growx"
-		layout = new_mig_layout("","[][grow][grow 0]")
+		layout = new_mig_layout("insets 8 16 0 16","[][grow][grow 0]")
 		visible = false
 		children = {
 			new_label{
@@ -202,7 +200,6 @@
 					}
 				}
 			}
-			output
 		}
 	}
 	function window.show_find_panel(visible)
@@ -218,7 +215,7 @@
 		find_field.text = "(?i)\Q\E"
 		find_field.set_selection(7)
 		find_field.request_focus_in_window()
-		output.text = [[Put search text between "\Q" and "\E"]]
+		status_bar.text = [[Put search text between "\Q" and "\E"]]
 	end
 	function window.tabs_to_spaces(_)
 		find_panel.visible = true
@@ -227,7 +224,7 @@
 		find_field.text = [[(?m)^(\t*)\t]]
 		local spaces = repeated( " ", text_area.tab_size )
 		replace_field.text = "$1"..spaces
-		output.text = [[Do "Replace All" until 0 replacements]]
+		status_bar.text = [[Do "Replace All" until 0 replacements]]
 	end
 	function window.spaces_to_tabs(_)
 		find_panel.visible = true
@@ -236,7 +233,7 @@
 		local tab_size = text_area.tab_size
 		find_field.text = `%>(?m)^(( {<%=tab_size%>})*) {<%=tab_size%>}<%`
 		replace_field.text = "$1\t"
-		output.text = [[Do "Replace All" until 0 replacements]]
+		status_bar.text = [[Do "Replace All" until 0 replacements]]
 	end
 	return find_panel
 end
--- a/src/luan/modules/editor/menu.luan	Tue Apr 15 14:08:18 2025 -0600
+++ b/src/luan/modules/editor/menu.luan	Tue Apr 15 16:13:14 2025 -0600
@@ -21,6 +21,7 @@
 
 local function add_menu_bar(window)
 	local document = window.text_area.document
+	local status_bar = window.status_bar
 	local revert = new_menu_item{
 		text = "Revert"
 		enabled = window.has_file
@@ -155,9 +156,10 @@
 						end
 					}
 					new_menu_item{
-						text = "Show Cursor Column"
+						text = "Cursor Column"
+						accelerator = "meta B"
 						action_listener = function(_)
-							show_message_dialog( window.frame, "Cursor Column: "..window.cursor_column() )
+							status_bar.text = "Cursor Column: "..window.cursor_column()
 						end
 					}
 					new_menu_item{
@@ -165,10 +167,19 @@
 						accelerator = "meta G"
 						action_listener = function(_)
 							local input = show_input_dialog( window.frame, "Goto line" )
-							local line = input and to_number(input)
+							if input == nil then
+								return
+							end
+							local line = to_number(input)
 							if line ~= nil then
-								window.goto(line)
+								try
+									window.goto(line)
+									status_bar.text = "Went to line "..line
+									return
+								catch e
+								end
 							end
+							status_bar.text = "Invalid line: "..input
 						end
 					}
 				}
--- a/src/luan/modules/editor/window.luan	Tue Apr 15 14:08:18 2025 -0600
+++ b/src/luan/modules/editor/window.luan	Tue Apr 15 16:13:14 2025 -0600
@@ -16,6 +16,7 @@
 local int_to_color = require("luan:swing/Color.luan").int_to_color or error()
 local Border = require "luan:swing/Border.luan"
 local create_empty_border = Border.create_empty_border or error()
+local new_label = require("luan:swing/Label.luan").new or error()
 local make_find_panel = require "luan:editor/find.luan"
 local add_menu_bar = require "luan:editor/menu.luan"
 
@@ -47,6 +48,12 @@
 		end
 	end
 	text_area.set_selection(0)
+	local status_bar = new_label{
+		--constraints = "span"
+		text = " "
+		border = create_empty_border(2,16,4,16)
+	}
+	window.status_bar = status_bar
 	local find_panel = make_find_panel(window)
 	local frame = new_frame{
 		preferred_size = { width=700, height=700 }
@@ -63,6 +70,7 @@
 					}
 				}
 				find_panel
+				status_bar
 			}
 		}
 	}
@@ -117,6 +125,7 @@
 		text_area.text = text
 		text_area.set_selection(min(selection,#text+1))
 		text_area.document.set_unedited()
+		status_bar.text = "Reverted"
 	end
 	local function selection_lines()
 		local start_seletion, end_selection = text_area.get_selection()