1
1
function plugindef ()
2
2
finaleplugin .RequireDocument = true -- Load Text Metrics crashes Finale (and doesn't work) if no document is open
3
- finaleplugin .MinJWLuaVersion = 0.68
3
+ finaleplugin .MinJWLuaVersion = 0.71
4
4
return " 0--text_editor_control.lua"
5
5
end
6
6
@@ -41,7 +41,7 @@ print(edit_text:GetControlID())
41
41
local tabstop_width = calc_tab_width (edit_font , 4 )
42
42
edit_text :SetTabstopWidth (tabstop_width )
43
43
edit_text :SetAutomaticEditing (true )
44
- dlg :RegisterHandleControlEvent (edit_text , function (control )
44
+ dlg :RegisterHandleControlEvent (edit_text , function (_control )
45
45
-- local finale.FCString = control:CreateEnigmaString()
46
46
-- print("Got Enigma String: "..finale.FCString.LuaString)
47
47
end )
@@ -53,7 +53,7 @@ local non_bmp_text = [[𝒜𝓈 𝒸𝒽
53
53
𝓊𝓃𝓈𝑒
54
54
𝓉𝓈 𝒾𝓃 𝓉𝒽𝑒 𝓋𝒶𝓈𝓉 𝒾𝓃𝓉𝓸 𝓉𝒽𝑒 𝓊𝓃𝓀𝓃𝑜𝓌𝓃
55
55
𝒾𝓈 𝒶 𝒷𝑒𝒶𝓊𝓉𝒾𝒻𝓊𝓁 𝓂𝒶𝑔𝒾𝒸 𝑜𝒻 𝒸𝒽𝒶𝓇𝒶𝒸𝓉𝑒𝓇𝓈.]]
56
- local long_line_text = " This is a test. Now is the time for a very long string to come to the aid and comfort of their friends and enemies to create a very, very long string."
56
+ local long_line_text = " This is a test. Now is the time for a very long string to come to the aid and comfort of their friends and enemies to create a very, very long string." -- luacheck: ignore
57
57
local rtf_text = [[ {\rtf1\ansi
58
58
This is some {\b bold} text.
59
59
This is some {\i italic} text.
@@ -80,40 +80,41 @@ dlg:RegisterHandleControlEvent(enabler, function(control)
80
80
end )
81
81
local visifier = dlg :CreateButton (90 , 200 )
82
82
visifier :SetText (finale .FCString (" Visible" ))
83
- dlg :RegisterHandleControlEvent (visifier , function (control )
83
+ dlg :RegisterHandleControlEvent (visifier , function (_control )
84
84
edit_text :SetVisible (not edit_text :GetVisible ())
85
85
enabler :SetVisible (not enabler :GetVisible ())
86
86
edit_text :SetKeyboardFocus ()
87
87
end )
88
88
local readonly = dlg :CreateButton (170 , 200 )
89
89
readonly :SetText (finale .FCString (" Readonly" ))
90
- dlg :RegisterHandleControlEvent (readonly , function (control )
90
+ dlg :RegisterHandleControlEvent (readonly , function (_control )
91
91
edit_text :SetReadOnly (not edit_text :GetReadOnly ())
92
92
edit_text :SetKeyboardFocus ()
93
93
end )
94
94
local sizer = dlg :CreateButton (250 , 200 )
95
95
sizer :SetText (finale .FCString (" Size" ))
96
- dlg :RegisterHandleControlEvent (sizer , function (control )
97
- if not glob_size then glob_size = 10 end
98
- glob_size = glob_size * 1.25
99
- edit_text :SetFontSizeForSelection (glob_size )
96
+ local size_incrementer
97
+ dlg :RegisterHandleControlEvent (sizer , function (_control )
98
+ if not size_incrementer then size_incrementer = 10 end
99
+ size_incrementer = size_incrementer * 1.25
100
+ edit_text :SetFontSizeForSelection (size_incrementer )
100
101
end )
101
102
local copier = dlg :CreateButton (330 , 200 )
102
103
copier :SetText (finale .FCString (" Copy" ))
103
- dlg :RegisterHandleControlEvent (copier , function (control )
104
+ dlg :RegisterHandleControlEvent (copier , function (_control )
104
105
edit_text :TextToClipboard ()
105
106
end )
106
107
local replacer = dlg :CreateButton (10 , 225 )
107
108
replacer :SetText (finale .FCString (" Replace" ))
108
- dlg :RegisterHandleControlEvent (replacer , function (control )
109
+ dlg :RegisterHandleControlEvent (replacer , function (_control )
109
110
if not edit_text :ReplaceSelectedText (finale .FCString (" *** replaced\n text ***" )) then
110
111
print (" ReplaceSelectedText failed because no selected text." )
111
112
end
112
113
edit_text :SetKeyboardFocus ()
113
114
end )
114
115
local restorer = dlg :CreateButton (90 , 225 )
115
116
restorer :SetText (finale .FCString (" Restore" ))
116
- dlg :RegisterHandleControlEvent (restorer , function (control )
117
+ dlg :RegisterHandleControlEvent (restorer , function (_control )
117
118
-- local vers1 = finale.FCVerseLyricsText()
118
119
-- if not vers1:Load(1) then print("lyrics load failed") end
119
120
-- local versstr = vers1:CreateString()
@@ -125,21 +126,21 @@ dlg:RegisterHandleControlEvent(restorer, function(control)
125
126
end )
126
127
local inserter = dlg :CreateButton (170 , 225 )
127
128
inserter :SetText (finale .FCString (" Insert" ))
128
- dlg :RegisterHandleControlEvent (inserter , function (control )
129
+ dlg :RegisterHandleControlEvent (inserter , function (_control )
129
130
edit_text :InsertTextAtCursor (finale .FCString (" *** inserted text ***" ))
130
131
edit_text :SetKeyboardFocus ()
131
132
end )
132
133
local selectall = dlg :CreateButton (250 , 225 )
133
134
selectall :SetText (finale .FCString (" SelAll" ))
134
- dlg :RegisterHandleControlEvent (selectall , function (control )
135
+ dlg :RegisterHandleControlEvent (selectall , function (_control )
135
136
local range = finale .FCRange ()
136
137
edit_text :GetTotalTextRange (range )
137
138
edit_text :SetSelection (range )
138
139
edit_text :SetKeyboardFocus ()
139
140
end )
140
141
local tabber = dlg :CreateButton (10 , 250 )
141
142
tabber :SetText (finale .FCString (" Tabs" ))
142
- dlg :RegisterHandleControlEvent (tabber , function (control )
143
+ dlg :RegisterHandleControlEvent (tabber , function (_control )
143
144
tabstop_width = tabstop_width - 12
144
145
if tabstop_width < 12 then
145
146
tabstop_width = 12
@@ -171,7 +172,7 @@ dlg:RegisterHandleControlEvent(italicer, function(control)
171
172
local locinfo = dlg :CreateButton (330 , 250 )
172
173
locinfo :SetText (finale .FCString (" Loc." ))
173
174
locinfo :SetWidth (70 )
174
- dlg :RegisterHandleControlEvent (locinfo , function (control )
175
+ dlg :RegisterHandleControlEvent (locinfo , function (_control )
175
176
local selrange = finale .FCRange ()
176
177
edit_text :GetSelection (selrange )
177
178
local posrange = finale .FCRange ()
@@ -195,7 +196,7 @@ wordonly:SetWidth(70)
195
196
local igncase = dlg :CreateCheckbox (250 , 275 )
196
197
igncase :SetText (finale .FCString (" Ign Case" ))
197
198
igncase :SetWidth (70 )
198
- dlg :RegisterHandleControlEvent (finder , function (control )
199
+ dlg :RegisterHandleControlEvent (finder , function (_control )
199
200
local str = finale .FCString ()
200
201
findtext :GetText (str )
201
202
local options = 0
@@ -223,26 +224,44 @@ dlg:RegisterHandleControlEvent(finder, function(control)
223
224
local dumper = dlg :CreateButton (330 , 275 )
224
225
dumper :SetText (finale .FCString (" DumpText" ))
225
226
dumper :SetWidth (70 )
226
- dlg :RegisterHandleControlEvent (dumper , function (control )
227
+ dlg :RegisterHandleControlEvent (dumper , function (_control )
227
228
local range = finale .FCRange ()
228
- if not edit_text :GetSelection (range ) then
229
+ edit_text :GetSelection (range )
230
+ if range .Length == 0 then
229
231
edit_text :GetTotalTextRange (range )
230
232
end
233
+ local raw_string = finale .FCString ()
234
+ edit_text :GetTextInRange (raw_string , range )
235
+ print (" Got Raw String: " .. raw_string .LuaString )
236
+ local utf16_string = finale .FCString ()
237
+ local i = range .Start
238
+ while (i < range .End ) do
239
+ local next_char = edit_text :CreateCharacterAtIndex (i )
240
+ if not next_char then
241
+ print (" GetCharacterAtIndex failed" )
242
+ break
243
+ end
244
+ utf16_string :AppendString (next_char )
245
+ i = i + next_char .Length
246
+ end
247
+ if utf16_string .Length > 0 then
248
+ print (" Got Utf16 String: " .. utf16_string .LuaString )
249
+ end
231
250
local fcstr = edit_text :CreateEnigmaString (range )
232
251
print (" Got Enigma String: " .. fcstr .LuaString )
233
252
end )
234
253
local colorizer = dlg :CreateButton (10 , 300 )
235
254
colorizer :SetText (finale .FCString (" Sel2Red" ))
236
255
colorizer :SetWidth (90 )
237
- dlg :RegisterHandleControlEvent (colorizer , function (control )
256
+ dlg :RegisterHandleControlEvent (colorizer , function (_control )
238
257
local range = finale .FCRange ()
239
258
edit_text :GetSelection (range )
240
259
edit_text :SetTextColorInRange (247 , 0 , 0 , range )
241
260
end )
242
261
local find2color = dlg :CreateButton (110 , 300 )
243
262
find2color :SetText (finale .FCString (" Find2Green" ))
244
263
find2color :SetWidth (90 )
245
- dlg :RegisterHandleControlEvent (find2color , function (control )
264
+ dlg :RegisterHandleControlEvent (find2color , function (_control )
246
265
local str = finale .FCString ()
247
266
findtext :GetText (str )
248
267
local options = 0
@@ -264,7 +283,7 @@ dlg:RegisterHandleControlEvent(find2color, function(control)
264
283
local colorreporter = dlg :CreateButton (210 , 300 )
265
284
colorreporter :SetText (finale .FCString (" Color Starts" ))
266
285
colorreporter :SetWidth (90 )
267
- dlg :RegisterHandleControlEvent (colorreporter , function (control )
286
+ dlg :RegisterHandleControlEvent (colorreporter , function (_control )
268
287
local ranges = edit_text :CreateTextColorChanges ()
269
288
if not ranges then
270
289
print (" No colors returned." )
@@ -281,7 +300,7 @@ dlg:RegisterHandleControlEvent(colorreporter, function(control)
281
300
end )
282
301
local colorreverter = dlg :CreateButton (310 , 300 )
283
302
colorreverter :SetText (finale .FCString (" Default" ))
284
- dlg :RegisterHandleControlEvent (colorreverter , function (control )
303
+ dlg :RegisterHandleControlEvent (colorreverter , function (_control )
285
304
edit_text :SetFont (finale .FCFontInfo (" Arial" , 12 ))
286
305
-- local range = finale.FCRange()
287
306
-- edit_text:GetTotalTextRange(range)
@@ -296,11 +315,10 @@ curr_sel:SetWidth(200)
296
315
dlg :RegisterTextSelectionChanged (function (control )
297
316
local fstr = finale .FCString ()
298
317
control :GetSelectedText (fstr ) -- if no selection, fstr is unchanged and empty
299
- local seltext = fstr .LuaString
300
- -- print("Selected Text: "..seltext)
318
+ -- print("Selected Text: "..fstr.LuaString)
301
319
curr_sel :SetText (fstr )
302
320
end )
303
- local ok = dlg :CreateOkButton ()
321
+ dlg :CreateOkButton ()
304
322
dlg :RegisterInitWindow (function ()
305
323
if init_with_rtf then
306
324
edit_text :SetFont (finale .FCFontInfo (" Arial" , 12 ))
0 commit comments