'#Reference {A3B5C45B-F842-44fc-A5E5-50CED69BA86E}#2.0#0#C:\Program Files\Mindjet\MindManager 6\Mm5WebExport.dll#Mm5webexport 2.0 Type Library
'#Uses "ParameterNames.mmbas"
'#Uses "GlobalUtilities.mmbas"
'#Uses "TOCHandler.cls"

Option Explicit

Sub Main

    Dim addin As Mm5WebExportAddIn
    Dim webex As WebExport
    Dim aPage As Mm5WebExportLib.Page
    Dim oneTOCHandler As TOCHandler

    Set addin = WebExportHelper.WebExportAddIn
    Set webex = addin.ActiveWebExport
    Set oneTOCHandler = New TOCHandler

    Dim count As Long
    Dim i As Long
    Dim template As String
    Dim topicString As String
    Dim bodyString As String
    Dim ParentTopicURL As String
    Dim TextToInsert As String

    Dim oneTopic As Topic
    Dim oneObject As Object

    On Error GoTo ReportError
    
    webex.Trace("Entering SnipNavBrItem.mmbas", 2 )

    Set aPage = webex.ActivePage
    count = aPage.TopicCount

    If aPage.Type = wePageTypeCallout Then

        ' we could show the parent topic for regular topics
        bodyString = ""

    Else

        ' a page should always have topics, but just to make sure
        If (count > 0) Then

            webex.ActiveTopic = aPage.GetTopic(1)

            Set oneTopic = webex.ActiveTopic

            ' List unlinked topic name
            template = webex.ReadFile("SnipNavBrHere.htm")
            topicString = template

            If Not oneTopic.IsCentralTopic Then
                webex.SetParameter("CustomParameter.BreadCrumbTopic", VerifyTopicText(webex,oneTopic))
                webex.SetParameter("CustomParameter.TOCOutlineNumberToWrite", _
                    oneTOCHandler.GetOutlineNumberForTopic(oneTopic, webex.GetParameter("Strings.Show.NumberToLevel")))
            Else
                ' If parent is central topic convert topic text to "Home"
                ' or whatever text the user specified for the home button
                webex.SetParameter("CustomParameter.BreadCrumbTopic", webex.GetParameter("Strings.Navigation.Home"))
                webex.SetParameter("CustomParameter.TOCOutlineNumberToWrite", _
                        oneTOCHandler.GetOutlineNumberForTopic(oneTopic, webex.GetParameter("Strings.Show.NumberToLevel")))
            End If
            
            ' Process all commands and parameters
            ProcessString webex, topicString
            ' Reverse order
            bodyString = topicString + bodyString

            ' Now list back to parent
            Do Until oneTopic.IsCentralTopic 'And Not oneTopic.IsMainTopic

                ' Continue with parent branch - might not exist if topic is a callout!
                Set oneTopic = oneTopic.ParentTopic

                template = webex.ReadFile("SnipNavBrItem.htm")
                topicString = template

                ' Build hyperlink to topic
                If oneTopic.IsCentralTopic = False Then
                    webex.SetParameter("CustomParameter.BreadCrumbTopicURL", webex.PathToUrl(webex.Pages.FindPage(oneTopic).Filename))
                    webex.SetParameter("CustomParameter.BreadCrumbTopic", VerifyTopicText(webex,oneTopic))
                    webex.SetParameter("CustomParameter.TOCOutlineNumberToWrite", _
                            oneTOCHandler.GetOutlineNumberForTopic(oneTopic, webex.GetParameter("Strings.Show.NumberToLevel")))
                Else
                    ' If parent is central topic convert topic text to "Home"
                    ' or whatever text the user specified for the home button
                    webex.SetParameter("CustomParameter.BreadCrumbTopicURL", webex.PathToUrl(webex.Pages.FindPage(oneTopic).Filename))
                    webex.SetParameter("CustomParameter.BreadCrumbTopic", webex.GetParameter("Strings.Navigation.Home"))
                    webex.SetParameter("CustomParameter.TOCOutlineNumberToWrite", _
                            oneTOCHandler.GetOutlineNumberForTopic(oneTopic, webex.GetParameter("Strings.Show.NumberToLevel")))
                End If

                ' Process all commands and parameters
                ProcessString webex, topicString

                ' Reverse order
                bodyString = topicString + bodyString

                ' Check if the loop "got stuck"
                If oneObject Is oneTopic Then
                    Exit Do
                End If

                ' Store last topic processed
                Set oneObject = oneTopic

            Loop

        End If   ' count > 0

    End If    ' regular topic

    ' Write out the result
    webex.PushString( bodyString )
 
    webex.Trace( "Exiting SnipNavBrItem.mmbas", 2 )

    Exit Sub
 
ReportError:
    ProcessError(webex)
    Exit Sub
 
End Sub
