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

Option Explicit

Sub Main

    Dim addin As Mm5WebExportAddIn
    Dim webex As WebExport

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

    Dim bodyString As String
    Dim topicString As String
    Dim OutlineItems As String
    Dim styleSheetPath As String

    On Error GoTo ReportError

    webex.Trace("Entering EndExport " + CStr(webex.GetParameter(WeErrorNumber)), 2)

    ' Generate CONTENTS page
    webex.SetParameter("CustomParameter.PageTitle", VerifyTopicText(webex, webex.Document.CentralTopic)) ' set up page title
    webex.SetParameter("CustomParameter.MapName", VerifyTopicText(webex, webex.Document.CentralTopic)) ' page heading text

    bodyString = webex.ReadFile("ToolsCnt.htm")
    topicString = bodyString
    ' Process all commands and parameters
    ProcessString webex, topicString
    bodyString = topicString
   
    ' Write out the result
    webex.WriteFile ("contents.htm", bodyString)

    ' Generate LEGEND page if required
    If webex.GetParameter("Strings.Show.IconLegend") Then
        bodyString = webex.ReadFile("ToolsLg.htm")
        topicString = bodyString
        ' Process all commands and parameters
        ProcessString webex, topicString
        bodyString = topicString
        ' Write out the result
        webex.WriteFile ("legend.htm", bodyString)
    End If

    ' Generate Overview Map page
    'If webex.GetParameter("Strings.Show.OverviewMap") Then
    '   bodyString = webex.ReadFile("ToolsMap.htm")
    '   topicString = bodyString

    '   ' Process all commands and parameters
    '   ProcessString webex, topicString
    '   bodyString = topicString

    '   ' Write out the result
    '   webex.WriteFile ("map.htm", bodyString)

    '   bodyString = webex.ReadFile("ToolsMapCont.htm")
    '   topicString = bodyString

    '   ' Process all commands and parameters
    '   ProcessString webex, topicString
    '   bodyString = topicString

    '   ' Write out the result
    '   webex.WriteFile ("mapContent.htm", bodyString)

    '   bodyString = webex.ReadFile("ToolsMapHd.htm")
    '   topicString = bodyString

    '   ' Process all commands and parameters
    '   ProcessString webex, topicString
    '   bodyString = topicString

    '   ' Write out the result
    '   webex.WriteFile ("mapHeader.htm", bodyString)

        bodyString = webex.ReadFile("PreFooter.htm")
        topicString = bodyString

        ' Process all commands and parameters
        ProcessString webex, topicString
        bodyString = topicString

        ' Write out the result
        webex.WriteFile ("mapFooter.htm", bodyString)
    'End If

    '' Determine whether partial map images should be shown or hidden in the export
    ''If webex.GetParameter("Strings.Show.PartialMaps") = True Then
    'If webex.GetParameter("Strings.Show.SubLinks") = "partmaps" Then
    '   webex.SetParameter("CustomParameter.ShowPartialMapsImage","visible")
    'Else
    '   webex.SetParameter("CustomParameter.ShowPartialMapsImage","none")
    'End If

    ' If there's no pending error
    If webex.IsSuccessful Then

        ' Copy our Resources folder
        webex.CopyDirectory(webex.GetParameter(TdFolderResources))
           
        ' If our CSS file is read-write (i.e. the user will allow us to change it)
        Dim fileAttributes As Long
        Dim fullStyleSheetPath As String
        webex.SetParameter("CustomParameter.ShowPartialMapsImage", "none") ' required for the shared CSS file
        styleSheetPath = webex.GetParameter(TdFolderResources) + "\styles\shared.css"
        fullStyleSheetPath = webex.FullExportFilename(styleSheetPath)
        fileAttributes = GetAttr(fullStyleSheetPath)
        If (fileAttributes And vbReadOnly) = 0 Then
            ' Process our style sheet
            ProcessFile webex, styleSheetPath
        End If

        ' Process any parameters in boxController.js (so it gets the proper "Resources" folder name)
        ' ProcessResourceFile webex, "code\boxController.js"

        ' Copy our linked documents to the Linked Documents folder
        ' webex.CopyLinkedDocuments()

        ' Generate Dynamic Outline Javascript items file
        ' oneDynamicOutlineBuilder.BuildDynamicOutline (webex.ActiveTopic.Document.CentralTopic), webex.GetParameter (TdNavigationDepth)
        ' OutlineItems = webex.GetParameter ("CustomParameter.DynamicOutlineString")
        ' webex.WriteFile(webex.FullExportFilename(webex.GetParameter(TdFolderResources) + "\tree\tree_items.js"), OutlineItems)

    End If

    webex.Trace("Exiting EndExport " + CStr(webex.GetParameter(WeErrorNumber)), 2)

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