'#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"

Option Explicit

Sub Main

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

    Set addin = WebExportHelper.WebExportAddIn
    Set webex = addin.ActiveWebExport

    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 PreBr.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

            If False Then ' List unlinked topic name

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

               If oneTopic.IsCentralTopic Then
                   ' 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"))
               Else
                   webex.SetParameter("CustomParameter.BreadCrumbTopic", VerifyTopicText(webex,oneTopic))
               End If
               
               ' Process all commands and parameters
               ProcessString webex, topicString
               ' Reverse order
               bodyString = topicString + bodyString

            End If

            ' 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("PreBrItem.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))
               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"))
               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 PreBr.mmbas", 2 )

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