-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList All Citations for a Source.fh_lua
224 lines (209 loc) · 7.67 KB
/
List All Citations for a Source.fh_lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
--[[
@title: List All Citations for a Source
@author: Jane Taubman
@lastupdated: May 2012
@version: 1.5
@description:
Find all the citations to a Source and list
* Record
* Fact
* Entry Date
* Where within source
* Text From Source
V1.5 Added Columns for the note and the quality assessment to the result set.
V1.4 Add a description field for the Field Type and re-arrange the columns so item shows before citation.
V1.3 Reduced the number of times the progress bar is updated and added warning for very large numbers of links
V1.2 Updated the Progress Bar to the latest code and added a more detailed Progress Message
V1.1 Added Progress Bar and Citation Column.
]]
function quickCount(tag)
local ptr = fhNewItemPtr()
local count = 0
ptr:MoveToFirstRecord(tag)
while ptr:IsNotNull() do
count = count + 1
ptr:MoveNext()
end
return count
end
function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
-------------------------------------------------------------- DoItems
function DoItems(strTag,ptrSource,tblRecTypes,action)
-- strTag: Tag of Item being searched for
-- action: function to perform
-- Loop through Record Types
local step = 0
local step2 = 0
local interval = 0
local count = 0
local ptr = fhNewItemPtr()
local recordPtr = fhNewItemPtr()
local ptrCmpSource = fhNewItemPtr()
for i,strRecType in ipairs(tblRecTypes) do
count = quickCount(strRecType)
interval = round(count / 100)
step = (1 / count) * interval
step2 = 0
ProgressDisplay:Reset()
ptr:MoveToFirstRecord(strRecType)
while ptr:IsNotNull() do
if fhGetTag(ptr) == strTag then
action(ptr,ptrSource)
end
recordPtr:MoveToRecordItem(ptr)
if recordPtr:IsSame(ptr) then
step2 = step2 + 1
if step2 == interval then
ProgressDisplay.Step(step)
ProgressDisplay.SetMessage(strRecType..' '..fhGetRecordId(recordPtr)..' Found: '..#tblRecord)
step2 = 0
end
end
if ProgressDisplay.Cancel() then
break
end
ptr:MoveNextSpecial()
end
end
end
--------------------------------------------------------------- Pointer Description
function ptrDescription(ptr)
local strDesc = ''
local strTag = fhGetTag(ptr)
if not(fhHasParentItem(ptr)) then
strDesc = 'Record ('..fhGetTag(ptr)..')'
else
local strTitle = string.match(fhGetDisplayText(ptr),'([%a%w%s]*):')
if not(strTitle) then
strTitle = string.match(fhGetDisplayText(ptr),'(%a*)')
end
strDesc = strTitle..' ('..strTag..')'
end
return strDesc
end
--------------------------------------------------------------- CheckForSource
function CheckForSource(ptr,ptrSource)
local ptrRecord = fhNewItemPtr()
local ptrLink = fhNewItemPtr()
local ptrWork = fhNewItemPtr()
ptrLink = fhGetValueAsLink(ptr)
if ptrLink:IsSame(ptrSource) then
-- Matching Record Found Add to Tables.
-- Get "Owning Record"
ptrRecord:MoveToRecordItem(ptr)
table.insert(tblRecord,ptrRecord:Clone())
-- Parent Item (Fact)
ptrWork:MoveToParentItem(ptr)
table.insert(tblFact,ptrWork:Clone())
table.insert(tblGetDisplay,ptrDescription(ptrWork))
-- Where within Source
ptrWork:MoveTo(ptr,'~.PAGE')
table.insert(tblWhereWithinSource,ptrWork:Clone())
-- Entry Date
ptrWork:MoveTo(ptr,'~.DATA.DATE')
table.insert(tblEntryDate,ptrWork:Clone())
-- Text From Source
ptrWork:MoveTo(ptr,'~.DATA.TEXT')
table.insert(tblTextFromSource,ptrWork:Clone())
ptrWork:MoveTo(ptr,'~.QUAY')
table.insert(tblQual,ptrWork:Clone())
ptrWork:MoveTo(ptr,'~.NOTE2')
table.insert(tblNote,ptrWork:Clone())
table.insert(tblCitation,ptr:Clone())
end
end
----------------------------------------------------------------- Progress Display
ProgressDisplay = {
Start = function(strTitle,intMax) -- Create and start the Progress Display window controls
cancelflag = false
local cancelbutton = iup.button{ title="Cancel", size="50x20",
action = function()
cancelflag = true -- Signal that Cancel button was pressed
return iup.CLOSE
end
}
gaugeProgress = iup.progressbar{ expand="YES", max=intMax } -- Set progress bar maximum range
messageline = iup.label{ title=" ", expand="YES", alignment="ACENTER" }
dlgProgress = iup.dialog{ title=strTitle, size="QUARTER", dialogframe="YES", -- Remove Windows minimize/maximize menu
iup.vbox{ alignment="ACENTER", gap="10",
messageline,
gaugeProgress,
cancelbutton
}
}
dlgProgress.close_cb = cancelbutton.action -- Windows Close button acts as Cancel button
dlgProgress:showxy(iup.CENTER, iup.CENTER) -- Show the Progress Display dialogue window
end,
SetMessage = function(strMessage) -- Set the progress message
messageline.title = strMessage
end,
Step = function(iStep) -- Step the Progress Bar forward
gaugeProgress.value = gaugeProgress.value + iStep
local val = tonumber(gaugeProgress.value)
local max = tonumber(gaugeProgress.max)
if val > max then
gaugeProgress.value = 0
end
iup.LoopStep()
end,
Reset = function() -- Reset progress bar
gaugeProgress.value = 0
end,
Cancel = function() -- Check if Cancel button pressed
return cancelflag
end,
Close = function() -- Close the dialogue window
dlgProgress:destroy()
end
}
----------------------------------------------------------------------------------- Main Code
-- Create Tables for Result Set
tblRecord = {}
tblFact = {}
tblEntryDate = {}
tblWhereWithinSource = {}
tblTextFromSource = {}
tblCitation = {}
tblGetDisplay = {}
tblQual = {}
tblNote = {}
-- Prompt for Source
tblSource = fhPromptUserForRecordSel('SOUR',1)
if #tblSource == 0 then
else
local iCitations = fhCallBuiltInFunction('LinksTo',tblSource[1])
if iCitations > 1000 then
btnValue = fhMessageBox('The number of Citations for '..fhGetDisplayText(tblSource[1])..' is very large '..iCitations..' and the results may take some time to display once the search is complete','MB_OKCANCEL','MB_ICONEXCLAMATION')
if btnValue == 'Cancel' then
return
end
end
if iCitations == 0 then
btnValue = fhMessageBox('There are no Citations for '..fhGetDisplayText(tblSource[1]),'MB_OK','MB_ICONEXCLAMATION')
return
end
ProgressDisplay.Start('Searching for Citations matching: '..fhGetDisplayText(tblSource[1]))
-- DoItems looking for Tag = SOUR for the Record selected, in 2 record types, and calling CheckForSource
DoItems('SOUR',tblSource[1],{'INDI','FAM','OBJ','NOTE'},CheckForSource)
ProgressDisplay.Close()
if ProgressDisplay.Cancel() then
return
end
if #tblRecord > 0 then
-- Output Tables built to Results Window
fhOutputResultSetColumn("Record", "item", tblRecord, #tblRecord, 180, "align_left")
fhOutputResultSetColumn("Item", "item", tblFact, #tblFact, 180, "align_left")
fhOutputResultSetColumn("Description", "text", tblGetDisplay, #tblFact, 100, "align_left")
fhOutputResultSetColumn("Citation", "item",tblCitation , #tblRecord, 80, "align_left")
fhOutputResultSetColumn("Entry Date", "item", tblEntryDate, #tblEntryDate, 80, "align_left")
fhOutputResultSetColumn("Where Within Source", "item", tblWhereWithinSource, #tblWhereWithinSource, 180, "align_left")
fhOutputResultSetColumn("Text From Source", "item",tblTextFromSource , #tblTextFromSource, 180, "align_left")
fhOutputResultSetColumn("Quality", "item",tblQual , #tblQual, 80, "align_left")
fhOutputResultSetColumn("Citation Note", "item",tblNote , #tblNote, 180, "align_left")
else
fhMessageBox('No Citations Found')
end
end