Refresh Source Record Auto Titles.fh_lua--[[
@Title: Refresh Source Record Auto Titles
@Type: Standard
@Author: Calico Pie
@Version: 1.0
@Keywords: source, record, title
@LastUpdated: 19 Jan 2023
@Licence: This plugin is copyright (c) 2023 Calico Pie and contributors, and is licensed under the MIT License
which is hereby incorporated by reference (see https://pluginstore.family-historian.co.uk/fh-plugin-licence)
@Description:
This plugin is used to refresh titles for all Source records in the current project that have auto titling enabled.
Auto titling is only (optionally) supported for templated Source records. It normally occurs (if enabled) whenever
changes are made to the fields in the Source record. Use of this plugin is only needed if you make changes to the
Record Title Format in one or more Source Template records, and wish to apply those changes to existing Source records.
On completion, the plugin shows a count of Source records in the project, as well as the number for which auto titling
is enabled, and the number in which the title has in fact been changed as a result of this plugin.
]]
-- << Comment in the next 2 lines if you need to use IUP >>
-- require("iuplua");
-- iup.SetGlobal("CUSTOMQUITMESSAGE","YES");
fhInitialise(7); -- implies users will need version 7 as a minimum; change if that is not the case
-------------------------------------------------------
-- main
-------------------------------------------------------
function main()
local sMsg = "This plugin will refresh the title of all templated Source records in the current project that " ..
"have auto titling enabled.\n\nProceed?"
local sRes = fhMessageBox(sMsg, "MB_OKCANCEL");
if sRes ~= "OK" then
return;
end
local pSrc = fhNewItemPtr();
pSrc:MoveToFirstRecord("SOUR");
local iRecCount = 0;
local iEnabledCount = 0;
local iChangedCount = 0;
local sBefore;
local sAfter;
while (pSrc:IsNotNull()) do
iRecCount = iRecCount + 1;
if fhSrcIsAutoTitleEnabled(pSrc) then
iEnabledCount = iEnabledCount + 1;
sBefore = GetSourceRecordTitle(pSrc);
fhSrcEnableAutoTitle(pSrc, true);
sAfter = GetSourceRecordTitle(pSrc);
if sBefore ~= sAfter then
iChangedCount = iChangedCount + 1;
end
end
pSrc:MoveNext();
end
sMsg = "Refresh has completed.\n\n" ..
"Source records (total): " .. iRecCount .. "\n" ..
"Source records with auto titling enabled: " .. iEnabledCount .. "\n" ..
"Source records where title has been modified: " .. iChangedCount;
fhMessageBox(sMsg);
end
-------------------------------------------------------
-- GetSourceRecordTitle
-------------------------------------------------------
function GetSourceRecordTitle(pSrc)
local sTitle = "";
local pTitle = fhNewItemPtr();
pTitle:MoveTo(pSrc, "~.TITL");
if pTitle:IsNotNull() then
sTitle = fhGetValueAsText(pTitle);
end
return sTitle;
end
-------------------------------------------------------
main();
--[[
@Title: Refresh Source Record Auto Titles
@Type: Standard
@Author: Calico Pie
@Version: 1.0
@Keywords: source, record, title
@LastUpdated: 19 Jan 2023
@Licence: This plugin is copyright (c) 2023 Calico Pie and contributors, and is licensed under the MIT License
which is hereby incorporated by reference (see https://pluginstore.family-historian.co.uk/fh-plugin-licence)
@Description:
This plugin is used to refresh titles for all Source records in the current project that have auto titling enabled.
Auto titling is only (optionally) supported for templated Source records. It normally occurs (if enabled) whenever
changes are made to the fields in the Source record. Use of this plugin is only needed if you make changes to the
Record Title Format in one or more Source Template records, and wish to apply those changes to existing Source records.
On completion, the plugin shows a count of Source records in the project, as well as the number for which auto titling
is enabled, and the number in which the title has in fact been changed as a result of this plugin.
]]
-- << Comment in the next 2 lines if you need to use IUP >>
-- require("iuplua");
-- iup.SetGlobal("CUSTOMQUITMESSAGE","YES");
fhInitialise(7); -- implies users will need version 7 as a minimum; change if that is not the case
-------------------------------------------------------
-- main
-------------------------------------------------------
function main()
local sMsg = "This plugin will refresh the title of all templated Source records in the current project that " ..
"have auto titling enabled.\n\nProceed?"
local sRes = fhMessageBox(sMsg, "MB_OKCANCEL");
if sRes ~= "OK" then
return;
end
local pSrc = fhNewItemPtr();
pSrc:MoveToFirstRecord("SOUR");
local iRecCount = 0;
local iEnabledCount = 0;
local iChangedCount = 0;
local sBefore;
local sAfter;
while (pSrc:IsNotNull()) do
iRecCount = iRecCount + 1;
if fhSrcIsAutoTitleEnabled(pSrc) then
iEnabledCount = iEnabledCount + 1;
sBefore = GetSourceRecordTitle(pSrc);
fhSrcEnableAutoTitle(pSrc, true);
sAfter = GetSourceRecordTitle(pSrc);
if sBefore ~= sAfter then
iChangedCount = iChangedCount + 1;
end
end
pSrc:MoveNext();
end
sMsg = "Refresh has completed.\n\n" ..
"Source records (total): " .. iRecCount .. "\n" ..
"Source records with auto titling enabled: " .. iEnabledCount .. "\n" ..
"Source records where title has been modified: " .. iChangedCount;
fhMessageBox(sMsg);
end
-------------------------------------------------------
-- GetSourceRecordTitle
-------------------------------------------------------
function GetSourceRecordTitle(pSrc)
local sTitle = "";
local pTitle = fhNewItemPtr();
pTitle:MoveTo(pSrc, "~.TITL");
if pTitle:IsNotNull() then
sTitle = fhGetValueAsText(pTitle);
end
return sTitle;
end
-------------------------------------------------------
main();
Source:Refresh-Source-Record-Auto-Titles.fh_lua