Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions src/library/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,72 @@ function utils.rethrow_placeholder()
return "'" .. rethrow_placeholder .. "'"
end

--[[
% show_notes_dialog

Displays a modal dialog with the contents of finaleplugin.RFTNotes (if present) or finaleplugin.Notes. If neither one is present, no dialog is shown.

@ caption (string) The caption for the dialog. Defaults to plugin name and version.
@ width (number) The width in pixels of the edit control. Defaults to 500.
@ height (number) The height inpixels of the edit control. Defaults to 350.
]]
function utils.show_notes_dialog(caption, width, height)
if not finaleplugin.RTFNotes and not finaleplugin.Notes then
return
end

width = width or 500
height = height or 350

if not caption then
caption = plugindef()
if finaleplugin.Version then
local version = finaleplugin.Version
if string.sub(version, 1, 1) ~= "v" then
version = "v" .. version
end
caption = string.format("%s %s", caption, version)
end
end

local dlg = finale.FCCustomLuaWindow()
dlg:SetTitle(finale.FCString(caption))
local edit_text = dlg:CreateTextEditor(10, 10)
edit_text:SetWidth(width)
edit_text:SetHeight(height)
edit_text:SetUseRichText(finaleplugin.RTFNotes)
edit_text:SetReadOnly(true)
edit_text:SetWordWrap(true)

local ok = dlg:CreateOkButton()

local function dedent(input)
local first_line_indent = input:match("^(%s*)")
local pattern = "\n" .. string.rep(" ", #first_line_indent)
local result = input:gsub(pattern, "\n")

result = result:gsub("^%s+", "")

return result
end

dlg:RegisterInitWindow(
function()
local notes = dedent(finaleplugin.RTFNotes or dedent(finaleplugin.Notes))
local notes_str = finale.FCString(notes)
if edit_text:GetUseRichText() then
edit_text:SetRTFString(notes_str)
else
local edit_font = finale.FCFontInfo()
edit_font.Name = "Arial"
edit_font.Size = 10
edit_text:SetFont(edit_font)
edit_text:SetText(notes_str)
end
edit_text:ResetColors()
ok:SetKeyboardFocus()
end)
dlg:ExecuteModal(nil)
end

return utils