Ao subcountlabel.mmbas

From ActivityOwnerWiki
Jump to: navigation, search
'ao_subcountlabel  20May09  http://creativecommons.org/licenses/by-nc-nd/3.0/  http://activityowner.com
'add/remove a text label to each topic denoting how many topics are below it
Sub Main
	If MsgBox("Do you want to add child counts?",vbYesNo)=vbYes Then
		subcount(ActiveDocument.CentralTopic)
	Else
		subcountremove
	End If
End Sub
Function subcount(ByRef t As Topic) As Integer
	Dim st As Topic
	subcount=1
	For Each st In t.AllSubTopics
		subcount=subcount+subcount(st)
	Next
	If subcount>1 Then t.TextLabels.AddTextLabel(Str(subcount-1)&" children")
End Function
Sub subcountremove
	Dim t As Topic
	Dim l As TextLabel
	For Each t In ActiveDocument.Range(mmRangeAllTopics)
		If t.TextLabels.Count>0 Then
			For Each l In t.TextLabels
				If InStr(l.Name,"children")>0 Then
					l.Delete
				End If
			Next
		End If
	Next
End Sub