-
Notifications
You must be signed in to change notification settings - Fork 3
/
ZtMainStory.cls
319 lines (206 loc) · 10.8 KB
/
ZtMainStory.cls
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "ZtMainStory"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Implements ZtIStory
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Class ZtMainStory.
' It extends ZtStory for captions and bibliography.
'
' Zotero Tools.
' This software is under Revised ('New') BSD license.
' Copyright © 2019, Olaf Ahrens. All rights reserved.
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Private variables.
Private pvtConfig As ZtConfig
Private pvtMessageDisplay As ZtIMessageDisplayable
Private pvtProgress As ZtProgress
Private pvtDocument As ZtDocument
Private pvtRange As Word.Range
Private pvtStory As ZtStory
Private pvtBibliography As ZtBibliography
Private pvtCaptions() As ZtCaption
Private pvtCaptionsCt As Integer
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Constructor.
Private Sub Class_Initialize()
Set pvtStory = New ZtStory
Set pvtBibliography = New ZtBibliography
pvtCaptionsCt = -1
End Sub
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Private interface procedures and properties directing to Friend procedures and properties below.
Private Sub ZtIStory_Initialize(ByVal valConfig As ZtConfig, ByVal valMessageDisplay As ZtIMessageDisplayable, ByVal valProgress As ZtProgress, _
ByVal valDocument As ZtDocument, ByVal valRange As Word.Range)
Me.Initialize valConfig, valMessageDisplay, valProgress, valDocument, valRange
End Sub
Private Property Get ZtIStory_CanHoldCitations() As Boolean
ZtIStory_CanHoldCitations = Me.CanHoldCitations
End Property
Private Sub ZtIStory_KeepCitationGroups(ByRef refCitationGroupsOffset As Integer)
Me.KeepCitationGroups refCitationGroupsOffset
End Sub
Private Function ZtIStory_RemoveInternalLinking() As ZtFMessageType
ZtIStory_RemoveInternalLinking = Me.RemoveInternalLinking
End Function
Private Function ZtIStory_SetInternalLinking() As ZtFMessageType
ZtIStory_SetInternalLinking = Me.SetInternalLinking
End Function
Private Function ZtIStory_AdjustPunctuation(ByRef refAffectedCt As Integer, ByRef refNotAffectedCt As Integer, ByRef refNotCorrectedCt As Integer) As ZtFMessageType
ZtIStory_AdjustPunctuation = Me.AdjustPunctuation(refAffectedCt, refNotAffectedCt, refNotCorrectedCt)
End Function
Private Sub ZtIStory_ResolveCitationGroups(ByRef refAffectedCt As Integer)
Me.ResolveCitationGroups refAffectedCt
End Sub
Private Sub ZtIStory_UpdateAllFields()
Me.UpdateAllFields
End Sub
Private Property Get ZtIStory_Range() As Word.Range
Set ZtIStory_Range = Me.Range
End Property
Private Property Get ZtIStory_Document() As ZtDocument
Set ZtIStory_Document = Me.Document
End Property
Private Sub ZtIStory_JoinCitationGroups(ByRef refAffectedCt As Integer, ByRef refNotAffectedCt As Integer, Optional ByVal valRange As Word.Range = Nothing)
Me.JoinCitationGroups refAffectedCt, refNotAffectedCt, valRange
End Sub
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Friend procedures and properties.
Friend Sub Initialize(ByVal valConfig As ZtConfig, ByVal valMessageDisplay As ZtIMessageDisplayable, ByVal valProgress As ZtProgress, _
ByVal valDocument As ZtDocument, ByVal valRange As Word.Range)
Set pvtConfig = valConfig
Set pvtMessageDisplay = valMessageDisplay
Set pvtProgress = valProgress
Set pvtDocument = valDocument
Set pvtRange = valRange
pvtStory.Initialize pvtConfig, pvtMessageDisplay, pvtProgress, pvtDocument, pvtRange
End Sub
Friend Property Get CanHoldCitations() As Boolean
CanHoldCitations = pvtStory.CanHoldCitations
End Property
Friend Sub KeepCitationGroups(ByRef refCitationGroupsOffset As Integer)
pvtStory.KeepCitationGroups refCitationGroupsOffset
End Sub
Friend Function RemoveInternalLinking() As ZtFMessageType
Dim locResult As ZtFMessageType
locResult = pvtStory.RemoveInternalLinking()
If locResult = MessageOk Then
locResult = pvtBibliography.Initialize(pvtConfig, pvtMessageDisplay, pvtProgress, Me)
If locResult = MessageOk Then
' Delete 'Cited on page n' text.
locResult = pvtBibliography.RemoveCitedOnPage
End If
End If
RemoveInternalLinking = locResult
End Function
Friend Function SetInternalLinking() As ZtFMessageType
SetInternalLinking = pvtStory.SetInternalLinking()
End Function
Friend Function AdjustPunctuation(ByRef refAffectedCt As Integer, ByRef refNotAffectedCt As Integer, ByRef refNotCorrectedCt As Integer) As ZtFMessageType
AdjustPunctuation = pvtStory.AdjustPunctuation(refAffectedCt, refNotAffectedCt, refNotCorrectedCt)
End Function
Friend Sub ResolveCitationGroups(ByRef refAffectedCt As Integer)
pvtStory.ResolveCitationGroups refAffectedCt
End Sub
Friend Sub UpdateAllFields()
Dim locToc As Word.TableOfContents
Dim locTof As Word.TableOfFigures
' Update tables. We do this first so that they contain all necessary entries and so extend to their final number of pages.
For Each locToc In pvtDocument.TablesOfContents
locToc.Update
Next
For Each locTof In pvtDocument.TablesOfFigures
locTof.Update
Next
pvtStory.UpdateAllFields
End Sub
Friend Property Get Range() As Word.Range
Set Range = pvtRange
End Property
Friend Property Get Document() As ZtDocument
Set Document = pvtDocument
End Property
Friend Sub JoinCitationGroups(ByRef refAffectedCt As Integer, ByRef refNotAffectedCt As Integer, Optional ByVal valRange As Word.Range = Nothing)
pvtStory.JoinCitationGroups refAffectedCt, refNotAffectedCt, valRange
End Sub
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Extending ZtStory procedures and properties.
Friend Property Get Bibliography() As ZtBibliography
Set Bibliography = pvtBibliography
End Property
Friend Function SetBibliographyBookmarks() As ZtFMessageType
Dim locResult As ZtFMessageType
pvtProgress.SetStep 1
locResult = pvtBibliography.Initialize(pvtConfig, pvtMessageDisplay, pvtProgress, Me)
pvtProgress.SetSubstep
If locResult = MessageOk Then
locResult = pvtBibliography.SetBookmarks
End If
SetBibliographyBookmarks = locResult
End Function
Friend Function SetBibliographyLinking() As ZtFMessageType
SetBibliographyLinking = pvtBibliography.SetInternalLinking
End Function
Friend Function SetBibliographyWebLinks() As ZtFMessageType
Dim locResult As ZtFMessageType
locResult = pvtBibliography.Initialize(pvtConfig, pvtMessageDisplay, pvtProgress, Me)
If locResult = MessageOk Then
locResult = pvtBibliography.SetWebLinks
End If
SetBibliographyWebLinks = locResult
End Function
Friend Sub GetCaptions(ByRef refCaptions() As ZtCaption)
refCaptions = pvtCaptions
End Sub
Friend Sub KeepCaptions()
Dim locCaptionRange As Word.Range
Dim locPreviousCaptionStart As Long
If pvtCaptionsCt = -1 Then
pvtProgress.SetToRunningMode
pvtProgress.SetStep
pvtCaptionsCt = 0
' Null-caption for all citations before first caption (in the introduction etc).
pvtCaptionFactory "?", "?", 0
' Real captions.
Set locCaptionRange = pvtDocument.GoingTo(wdGoToHeading, wdGoToFirst)
Do Until locPreviousCaptionStart = locCaptionRange.Start
With locCaptionRange
If .Paragraphs(1).Range.ListParagraphs.Count = 1 Then
If .ListFormat.ListLevelNumber <= pvtConfig.User.BackwardLinkingStyle.MaxCaptionLevel Then
pvtCaptionFactory .ListFormat.ListString, .Paragraphs(1).Range.Text, .Start
End If
End If
locPreviousCaptionStart = .Start
pvtProgress.SetSubstep
Set locCaptionRange = .GoToNext(wdGoToHeading)
End With
Loop
pvtProgress.SetToNormalMode
If pvtCaptionsCt = 1 Then
pvtMessageDisplay.Show "I couldn't find any caption." & vbNewLine & vbNewLine & _
"Please, ensure that you have used Word's build-in formatting for heading levels 1 to 9 in your document.", _
MessageExclamation + MessageCancel
End If
End If
End Sub
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
' Private procedures and properties.
Private Sub pvtCaptionFactory(ByVal valNr As String, ByVal valText As String, ByVal valStart As Long)
ReDim Preserve pvtCaptions(pvtCaptionsCt)
Set pvtCaptions(pvtCaptionsCt) = New ZtCaption
pvtCaptions(pvtCaptionsCt).Initialize pvtConfig, valNr, valText, valStart
pvtCaptionsCt = pvtCaptionsCt + 1
End Sub
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *