annotate src/luan_editor/menu.luan @ 55:77ee3a37475a default tip

paste files
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 27 May 2025 22:31:32 -0600
parents ca5ae0a36db7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
37
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
40
38bc1cdf77c8 add align windows
Franklin Schmidt <fschmidt@gmail.com>
parents: 38
diff changeset
3 local ipairs = Luan.ipairs or error()
37
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local String = require "luan:String.luan"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local to_number = String.to_number or error()
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local new_menu_item = require("luan:swing/Menu_item.luan").new or error()
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local new_check_box_menu_item = require("luan:swing/Check_box_menu_item.luan").new or error()
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local new_menu_bar = require("luan:swing/Menu_bar.luan").new or error()
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Menu = require "luan:swing/Menu.luan"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local new_menu = Menu.new or error()
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local separator = Menu.separator or error()
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local Option_pane = require "luan:swing/Option_pane.luan"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local show_message_dialog = Option_pane.show_message_dialog or error()
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 local show_input_dialog = Option_pane.show_input_dialog or error()
40
38bc1cdf77c8 add align windows
Franklin Schmidt <fschmidt@gmail.com>
parents: 38
diff changeset
15 local Frame = require "luan:swing/Frame.luan"
38bc1cdf77c8 add align windows
Franklin Schmidt <fschmidt@gmail.com>
parents: 38
diff changeset
16 local get_all_frames = Frame.get_all_frames or error()
37
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 local Spell_checker = require "classpath:luan_editor/Spell_checker.luan"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 local spell_check = Spell_checker.spell_check or error()
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 local function action_listener(fn)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 return function(_)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 fn()
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 local function add_menu_bar(window)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 local text_area = window.text_area
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 local document = text_area.document
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 local status_bar = window.status_bar
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 local revert = new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 text = "Revert"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 enabled = window.has_file
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 action_listener = action_listener(window.revert)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 }
48
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
36 local view_file_path = new_menu_item{
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
37 text = "File Path"
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
38 enabled = window.has_file
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
39 action_listener = function(_)
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
40 status_bar.text = window.title()
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
41 end
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
42 }
37
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 local undo = new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 text = "Undo"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 accelerator = "meta Z"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 action_listener = action_listener(document.undo)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 local redo = new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 text = "Redo"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 accelerator = "meta shift Z"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 action_listener = action_listener(document.redo)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 local function update_undo_redo()
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 undo.set_enabled(document.can_undo())
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 redo.set_enabled(document.can_redo())
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 window.update_undo_redo = update_undo_redo -- dont gc
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 update_undo_redo()
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 document.add_undo_listener(update_undo_redo)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 local find_menu_item = new_check_box_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 text = "Find and Replace"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 accelerator = "meta F"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 action_listener = function(event)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 window.show_find_panel(event.source.state)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68 window.find_menu_item = find_menu_item
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
69
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
70 local menu_bar = new_menu_bar{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
71 menus = {
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
72 new_menu{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
73 text = "File"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
74 menu_items = {
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
75 new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
76 text = "New File"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
77 accelerator = "meta N"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
78 action_listener = action_listener(window.new)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
79 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
80 new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
81 text = "Open..."
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
82 accelerator = "meta O"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
83 action_listener = action_listener(window.open)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
84 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
85 new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
86 text = "Save"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
87 accelerator = "meta S"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
88 action_listener = function(_)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
89 if window.save() then
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90 revert.set_enabled(true)
48
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
91 view_file_path.set_enabled(true)
37
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
93 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
94 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
95 new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
96 text = "Print"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
97 action_listener = action_listener(text_area.print)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
98 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
99 revert
55
77ee3a37475a paste files
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
100 new_menu_item{
77ee3a37475a paste files
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
101 text = "Paste File(s)"
77ee3a37475a paste files
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
102 action_listener = function(_)
77ee3a37475a paste files
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
103 if not window.paste_files() then
77ee3a37475a paste files
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
104 show_message_dialog(nil,"No files to paste")
77ee3a37475a paste files
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
105 end
77ee3a37475a paste files
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
106 end
77ee3a37475a paste files
Franklin Schmidt <fschmidt@gmail.com>
parents: 48
diff changeset
107 }
37
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
108 --[[
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
109 new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
110 text = "Test"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
111 action_listener = function(_)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
112 local location = window.frame.location
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
113 location.y = location.y - 20
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
114 window.frame.location = location
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
115 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
116 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
117 ]]
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
118 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
119 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
120 new_menu{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
121 text = "Edit"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
122 menu_items = {
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
123 undo
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
124 redo
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
125 separator
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
126 new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
127 text = "Cut"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
128 accelerator = "meta X"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
129 action_listener = action_listener(text_area.cut)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
130 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
131 new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
132 text = "Copy"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
133 accelerator = "meta C"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
134 action_listener = action_listener(text_area.copy)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
135 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
136 new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
137 text = "Paste"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
138 accelerator = "meta V"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
139 action_listener = action_listener(text_area.paste)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
140 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
141 separator
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
142 new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
143 text = "Indent"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
144 accelerator = "meta CLOSE_BRACKET"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
145 action_listener = action_listener(window.indent)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
146 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
147 new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
148 text = "Unindent"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
149 accelerator = "meta OPEN_BRACKET"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
150 action_listener = action_listener(window.unindent)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
151 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
152 separator
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
153 new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
154 text = "Select All"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
155 accelerator = "meta A"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
156 action_listener = action_listener(text_area.select_all)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
157 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
158 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
159 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
160 new_menu{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
161 text = "Find"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
162 menu_items = {
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
163 find_menu_item
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
164 new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
165 text = "Find Case Insensitive"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
166 action_listener = window.find_case_insensitive
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
167 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
168 new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
169 text = "Convert Leading Tabs to Spaces"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
170 action_listener = window.tabs_to_spaces
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
171 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
172 new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
173 text = "Convert Leading Spaces to Tabs"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
174 action_listener = window.spaces_to_tabs
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
175 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
176 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
177 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
178 new_menu{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
179 text = "View"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
180 menu_items = {
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
181 new_check_box_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
182 text = "Word Wrap"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
183 state = text_area.line_wrap
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
184 action_listener = function(event)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
185 window.set_line_wrap(event.source.state)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
186 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
187 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
188 new_check_box_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
189 text = "Show Whitespace"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
190 accelerator = "meta W"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
191 state = text_area.whitespace_visible
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
192 action_listener = function(event)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
193 window.set_whitespace_visible(event.source.state)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
194 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
195 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
196 new_check_box_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
197 text = "Spell Check"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
198 accelerator = "meta SEMICOLON"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
199 action_listener = function(event)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
200 spell_check(text_area,event.source.state)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
201 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
202 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
203 new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
204 text = "Cursor Column"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
205 accelerator = "meta B"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
206 action_listener = function(_)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
207 status_bar.text = "Cursor Column: "..window.cursor_column()
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
208 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
209 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
210 new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
211 text = "Goto Line"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
212 accelerator = "meta G"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
213 action_listener = function(_)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
214 local input = show_input_dialog( window.frame, "Goto line" )
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
215 if input == nil then
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
216 return
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
217 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
218 local line = to_number(input)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
219 try
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
220 window.goto(line)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
221 status_bar.text = "Went to line "..line
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
222 catch e
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
223 status_bar.text = "Invalid line: "..input
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
224 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
225 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
226 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
227 new_menu_item{
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
228 text = "Tab Size"
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
229 action_listener = function(_)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
230 local input = show_input_dialog( window.frame, "Tab size", text_area.tab_size )
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
231 if input == nil then
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
232 return
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
233 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
234 local size = to_number(input)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
235 try
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
236 window.set_tab_size(size)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
237 status_bar.text = "Set tab size to "..size
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
238 catch e
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
239 status_bar.text = "Invalid tab size: "..input
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
240 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
241 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
242 }
48
Franklin Schmidt <fschmidt@gmail.com>
parents: 41
diff changeset
243 view_file_path
37
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
244 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
245 }
38
8c90e0077cfe add duplicate window
Franklin Schmidt <fschmidt@gmail.com>
parents: 37
diff changeset
246 new_menu{
8c90e0077cfe add duplicate window
Franklin Schmidt <fschmidt@gmail.com>
parents: 37
diff changeset
247 text = "Window"
8c90e0077cfe add duplicate window
Franklin Schmidt <fschmidt@gmail.com>
parents: 37
diff changeset
248 menu_items = {
8c90e0077cfe add duplicate window
Franklin Schmidt <fschmidt@gmail.com>
parents: 37
diff changeset
249 new_menu_item{
8c90e0077cfe add duplicate window
Franklin Schmidt <fschmidt@gmail.com>
parents: 37
diff changeset
250 text = "Duplicate Window"
8c90e0077cfe add duplicate window
Franklin Schmidt <fschmidt@gmail.com>
parents: 37
diff changeset
251 action_listener = action_listener(window.duplicate)
8c90e0077cfe add duplicate window
Franklin Schmidt <fschmidt@gmail.com>
parents: 37
diff changeset
252 }
40
38bc1cdf77c8 add align windows
Franklin Schmidt <fschmidt@gmail.com>
parents: 38
diff changeset
253 new_menu_item{
38bc1cdf77c8 add align windows
Franklin Schmidt <fschmidt@gmail.com>
parents: 38
diff changeset
254 text = "Align Windows"
38bc1cdf77c8 add align windows
Franklin Schmidt <fschmidt@gmail.com>
parents: 38
diff changeset
255 action_listener = function(_)
38bc1cdf77c8 add align windows
Franklin Schmidt <fschmidt@gmail.com>
parents: 38
diff changeset
256 local this_frame = window.frame
38bc1cdf77c8 add align windows
Franklin Schmidt <fschmidt@gmail.com>
parents: 38
diff changeset
257 local location = this_frame.location
38bc1cdf77c8 add align windows
Franklin Schmidt <fschmidt@gmail.com>
parents: 38
diff changeset
258 local size = this_frame.size
38bc1cdf77c8 add align windows
Franklin Schmidt <fschmidt@gmail.com>
parents: 38
diff changeset
259 for _, frame in ipairs(get_all_frames()) do
38bc1cdf77c8 add align windows
Franklin Schmidt <fschmidt@gmail.com>
parents: 38
diff changeset
260 frame.location = location
38bc1cdf77c8 add align windows
Franklin Schmidt <fschmidt@gmail.com>
parents: 38
diff changeset
261 frame.size = size
38bc1cdf77c8 add align windows
Franklin Schmidt <fschmidt@gmail.com>
parents: 38
diff changeset
262 end
38bc1cdf77c8 add align windows
Franklin Schmidt <fschmidt@gmail.com>
parents: 38
diff changeset
263 end
38bc1cdf77c8 add align windows
Franklin Schmidt <fschmidt@gmail.com>
parents: 38
diff changeset
264 }
41
f7e8c1f532c8 start list window
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
265 new_menu_item{
f7e8c1f532c8 start list window
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
266 text = "List Windows"
f7e8c1f532c8 start list window
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
267 accelerator = "meta L"
f7e8c1f532c8 start list window
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
268 action_listener = action_listener(window.show_list_window)
f7e8c1f532c8 start list window
Franklin Schmidt <fschmidt@gmail.com>
parents: 40
diff changeset
269 }
38
8c90e0077cfe add duplicate window
Franklin Schmidt <fschmidt@gmail.com>
parents: 37
diff changeset
270 }
8c90e0077cfe add duplicate window
Franklin Schmidt <fschmidt@gmail.com>
parents: 37
diff changeset
271 }
37
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
272 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
273 }
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
274 window.frame.set_menu_bar(menu_bar)
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
275 end
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
276
b7ff52d45b9a copy from luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
277 return add_menu_bar