Mercurial Hosting > editor
comparison editor.luan @ 18:fd6d0162e924
start find
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 07 Apr 2025 21:15:38 -0600 |
parents | 273aebbcf90b |
children | ba59fdcf41f3 |
comparison
equal
deleted
inserted
replaced
17:273aebbcf90b | 18:fd6d0162e924 |
---|---|
15 local Swing = require "luan:swing/Swing.luan" | 15 local Swing = require "luan:swing/Swing.luan" |
16 local new_frame = require("luan:swing/Frame.luan").new or error() | 16 local new_frame = require("luan:swing/Frame.luan").new or error() |
17 local new_label = require("luan:swing/Label.luan").new or error() | 17 local new_label = require("luan:swing/Label.luan").new or error() |
18 local new_text_area = require("luan:swing/Text_area.luan").new or error() | 18 local new_text_area = require("luan:swing/Text_area.luan").new or error() |
19 local new_scroll_pane = require("luan:swing/Scroll_pane.luan").new or error() | 19 local new_scroll_pane = require("luan:swing/Scroll_pane.luan").new or error() |
20 local new_text_area_line_numbers = require("luan:swing/TextAreaLineNumbers.luan").new or error() | 20 local new_text_area_line_numbers = require("luan:swing/Text_area_line_numbers.luan").new or error() |
21 local new_menu_bar = require("luan:swing/Menu_bar.luan").new or error() | 21 local new_menu_bar = require("luan:swing/Menu_bar.luan").new or error() |
22 local new_menu = require("luan:swing/Menu.luan").new or error() | 22 local new_menu = require("luan:swing/Menu.luan").new or error() |
23 local new_menu_item = require("luan:swing/Menu_item.luan").new or error() | 23 local new_menu_item = require("luan:swing/Menu_item.luan").new or error() |
24 local new_check_box_menu_item = require("luan:swing/Check_box_menu_item.luan").new or error() | 24 local new_check_box_menu_item = require("luan:swing/Check_box_menu_item.luan").new or error() |
25 local int_to_color = require("luan:swing/Color.luan").int_to_color or error() | 25 local int_to_color = require("luan:swing/Color.luan").int_to_color or error() |
26 local create_empty_border = require("luan:swing/Border.luan").create_empty_border or error() | 26 local Border = require "luan:swing/Border.luan" |
27 local create_empty_border = Border.create_empty_border or error() | |
28 local create_line_border = Border.create_line_border or error() | |
29 local Layout = require "luan:swing/Layout.luan" | |
30 local new_flow_layout = Layout.new_flow_layout or error() | |
31 local new_box_layout = Layout.new_box_layout or error() | |
27 local Option_pane = require "luan:swing/Option_pane.luan" | 32 local Option_pane = require "luan:swing/Option_pane.luan" |
28 local show_message_dialog = Option_pane.show_message_dialog or error() | 33 local show_message_dialog = Option_pane.show_message_dialog or error() |
29 local show_input_dialog = Option_pane.show_input_dialog or error() | 34 local show_input_dialog = Option_pane.show_input_dialog or error() |
35 local new_dialog = require("luan:swing/Dialog.luan").new or error() | |
36 local new_panel = require("luan:swing/Component.luan").new_panel or error() | |
37 local new_button = require("luan:swing/Button.luan").new or error() | |
30 local Logging = require "luan:logging/Logging.luan" | 38 local Logging = require "luan:logging/Logging.luan" |
31 local logger = Logging.logger "editor" | 39 local logger = Logging.logger "editor" |
32 | 40 |
33 | 41 |
34 local new_window | 42 local new_window |
142 select_all.text = "Select All" | 150 select_all.text = "Select All" |
143 select_all.accelerator = "meta A" | 151 select_all.accelerator = "meta A" |
144 select_all.add_action_listener(window.text_area.select_all) | 152 select_all.add_action_listener(window.text_area.select_all) |
145 edit_menu.add(select_all) | 153 edit_menu.add(select_all) |
146 end | 154 end |
155 edit_menu.add_separator() | |
156 do | |
157 local find = new_menu_item() | |
158 find.text = "Find and Replace" | |
159 find.accelerator = "meta F" | |
160 find.add_action_listener(window.show_find_dialog) | |
161 edit_menu.add(find) | |
162 end | |
147 menu_bar.add(edit_menu) | 163 menu_bar.add(edit_menu) |
148 end | 164 end |
149 do | 165 do |
150 local view_menu = new_menu() | 166 local view_menu = new_menu() |
151 view_menu.text = "View" | 167 view_menu.text = "View" |
177 do | 193 do |
178 local goto = new_menu_item() | 194 local goto = new_menu_item() |
179 goto.text = "Goto Line" | 195 goto.text = "Goto Line" |
180 goto.accelerator = "meta G" | 196 goto.accelerator = "meta G" |
181 goto.add_action_listener(function() | 197 goto.add_action_listener(function() |
182 local input = show_input_dialog( window.frame, "Cursor Column: "..window.cursor_column() ) | 198 local input = show_input_dialog( window.frame, "Goto line" ) |
183 --logger.info("input "..input) | 199 --logger.info("input "..input) |
184 local line = input and to_number(input) | 200 local line = input and to_number(input) |
185 if line ~= nil then | 201 if line ~= nil then |
186 window.goto(line) | 202 window.goto(line) |
187 end | 203 end |
189 view_menu.add(goto) | 205 view_menu.add(goto) |
190 end | 206 end |
191 menu_bar.add(view_menu) | 207 menu_bar.add(view_menu) |
192 end | 208 end |
193 return menu_bar | 209 return menu_bar |
210 end | |
211 | |
212 local function make_find_dialog(window) | |
213 local dialog = new_dialog(window.frame) | |
214 local root = dialog.component | |
215 root.set_layout(new_box_layout(root,"y_axis")) | |
216 do | |
217 local buttons = new_panel() | |
218 buttons.set_layout(new_flow_layout("left")) | |
219 --buttons.border = create_empty_border(8,8,8,8) | |
220 buttons.border = create_line_border(int_to_color(0)) | |
221 | |
222 local find_next = new_button() | |
223 find_next.text = "Find Next" | |
224 buttons.add(find_next) | |
225 | |
226 local find_prev = new_button() | |
227 find_prev.text = "Find Previous" | |
228 buttons.add(find_prev) | |
229 | |
230 root.add(buttons) | |
231 end | |
232 dialog.pack() | |
233 local was_shown = false | |
234 function window.show_find_dialog() | |
235 if not was_shown then | |
236 was_shown = true | |
237 dialog.move_into_owner() | |
238 end | |
239 dialog.visible = true | |
240 end | |
194 end | 241 end |
195 | 242 |
196 local n_windows = 0 | 243 local n_windows = 0 |
197 local documents = {} | 244 local documents = {} |
198 | 245 |
330 end | 377 end |
331 function window.goto(line) | 378 function window.goto(line) |
332 local pos = text_area.get_line_start_position(line) | 379 local pos = text_area.get_line_start_position(line) |
333 text_area.set_selection(pos) | 380 text_area.set_selection(pos) |
334 end | 381 end |
382 make_find_dialog(window) | |
335 local menu_bar = make_menu_bar(window) | 383 local menu_bar = make_menu_bar(window) |
336 frame.set_menu_bar(menu_bar) | 384 frame.set_menu_bar(menu_bar) |
337 frame.pack() | 385 frame.pack() |
338 frame.visible = true | 386 frame.visible = true |
339 text_area.request_focus_in_window() | 387 text_area.request_focus_in_window() |