Mercurial Hosting > editor
diff editor.luan @ 29:01b8a25b38aa
work
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 13 Apr 2025 12:25:57 -0600 |
parents | bdb8754f1211 |
children | 8e32ad89c2a1 |
line wrap: on
line diff
--- a/editor.luan Fri Apr 11 21:41:26 2025 -0600 +++ b/editor.luan Sun Apr 13 12:25:57 2025 -0600 @@ -52,7 +52,7 @@ end end -local function make_menu_bar(window) +local function add_menu_bar(window) local document = window.text_area.document local revert = new_menu_item{ text = "Revert" @@ -77,7 +77,7 @@ update_undo_redo() document.add_undo_listener(update_undo_redo) - return new_menu_bar{ + local menu_bar = new_menu_bar{ menus = { new_menu{ text = "File" @@ -145,10 +145,12 @@ action_listener = action_listener(window.text_area.select_all) } separator - new_menu_item{ + new_check_box_menu_item{ text = "Find and Replace" accelerator = "meta F" - action_listener = action_listener(window.show_find_dialog) + action_listener = function(event) + window.show_find_panel(event.source.state) + end } } } @@ -189,6 +191,7 @@ } } } + window.frame.set_menu_bar(menu_bar) end local function get_matches(text,s) @@ -209,7 +212,7 @@ return matches end -local function make_find_dialog(window) +local function make_find_panel(window) local text_area = window.text_area local find_field, output local function find_match(event) @@ -256,62 +259,63 @@ end end find_field = new_text_field{ - constraints = "wrap,growx" + constraints = "growx" columns = 20 action = "next" action_listener = find_match } output = new_label{ - constraints = "span,grow" + constraints = "span" text = "testing" } - local dialog = new_dialog{ - owner_frame = window.frame - content_pane = new_panel{ - layout = new_mig_layout("","[][grow]") - children = { - new_label{ - constraints = "right" - text = "Find:" - } - find_field - new_label{ - constraints = "right" - text = "Replace:" - } - new_text_field{ - constraints = "wrap,growx" - columns = 20 - } - new_panel{ - constraints = "span,wrap" - layout = new_mig_layout("insets 0") - children = { - new_button{ - text = "Find Next" - action = "next" - action_listener = find_match - } - new_button{ - text = "Find Previous" - action = "previous" - action_listener = find_match - } + local find_panel = new_panel{ + constraints = "growy 0,growx" + layout = new_mig_layout("","[][grow][grow 0]") + visible = false + children = { + new_label{ + constraints = "right" + text = "Find:" + } + find_field + new_panel{ + constraints = "wrap" + layout = new_mig_layout("insets 0") + children = { + new_button{ + text = "Find Next" + action = "next" + action_listener = find_match + } + new_button{ + text = "Find Previous" + action = "previous" + action_listener = find_match } } - output + } + new_label{ + constraints = "right" + text = "Replace:" } + new_text_field{ + constraints = "growx" + columns = 20 + } + new_button{ + constraints = "wrap" + text = "Replace" + } + output } } - dialog.pack() - local was_shown = false - function window.show_find_dialog() - if not was_shown then - was_shown = true - dialog.move_into_owner() + function window.show_find_panel(visible) + find_panel.visible = visible + if visible then + find_field.request_focus_in_window() end - dialog.visible = true end + return find_panel end local n_windows = 0 @@ -321,13 +325,10 @@ local window = {} window.has_file = file~=nil and file.is_file() local text_area = new_text_area{ - rows = 10 - columns = 20 wrap_style_word = true line_wrap = true tab_size = 4 font = { family="Monospaced", size=13 } - border = create_empty_border(0,4,0,4) } window.text_area = text_area local title = file and file.canonical().to_string() or "new" @@ -344,14 +345,22 @@ end end text_area.set_selection(0) + local find_panel = make_find_panel(window) local frame = new_frame{ - content_pane = new_scroll_pane{ - view = text_area - border = no_border - row_header_view = new_text_area_line_numbers{ - text_area = text_area - foreground_color = int_to_color(0x888888) - border = create_empty_border(0,8,0,8) + preferred_size = { width=700, height=700 } + content_pane = new_panel{ + layout = new_mig_layout("insets 0,wrap,fill,hidemode 3","","[][grow 0]") + children = { + new_scroll_pane{ + constraints = "grow" + view = text_area + row_header_view = new_text_area_line_numbers{ + text_area = text_area + foreground_color = int_to_color(0x888888) + border = create_empty_border(0,8,0,8) + } + } + find_panel } } } @@ -459,24 +468,13 @@ local pos = text_area.get_line_start_position(line) text_area.set_selection(pos) end - make_find_dialog(window) - local menu_bar = make_menu_bar(window) - frame.set_menu_bar(menu_bar) + add_menu_bar(window) frame.pack() frame.visible = true text_area.request_focus_in_window() n_windows = n_windows + 1 end ---[[ -for _, laf in ipairs(Swing.get_installed_look_and_feels()) do - logger.info(laf) -end -]] ---logger.info(Swing.get_look_and_feel()) -Swing.ui_manager_put("control",int_to_color(0xedeff2)) -Swing.set_look_and_feel("javax.swing.plaf.nimbus.NimbusLookAndFeel") - Swing.run(function() local args = Luan.arg if #args == 0 then