xref: /AOO41X/main/helpauthoring/HelpAuthoring/TOC.xba (revision 66d002e8364738f4240879a2942fc03d856dcbe7)
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="TOC" script:language="StarBasic">REM  *****  BASIC  *****
4
5Dim oDialog AS Object
6Dim document AS Object
7
8Sub Main
9    document = StarDesktop.CurrentComponent
10
11    BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
12    oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgTOC&quot;)
13    oDialogModel = oDialog.Model
14
15    ocbAddTag = oDialog.GetControl(&quot;cbAddTag&quot;)
16
17    &apos; Check if bookmarks are allowed here
18    If IsInList Then
19        msgbox &quot;No Bookmarks allowed inside a list.&quot;, 48, &quot;D&apos;oh!&quot;
20        Exit Sub
21    End If
22
23    nBookmarkType = IsInBookmark
24    If nBookmarkType = 3 Then &apos; inside TOC bookmark
25        ocbAddTag.State = 0
26    End If
27
28    If oDialog.Execute() = 1 Then
29        &apos; Insert the bookmark construction
30        olbTOC = oDialog.GetControl(&quot;lbTOC&quot;)
31
32        If nBookmarkType = 0 Then&apos; not in a bookmark, always add parent tags
33            bmid = CreateID
34            &apos; now check if we are in a para with text (this wouldn&apos;t be valid)
35            If Not(ParaIsEmpty) Then
36                CR
37            End If
38            InsertTag(&quot;BOOKMARK_&quot;,&quot;&lt;BOOKMARK branch=&quot;&quot;contents&quot;&quot; id=&quot;&quot;bm_id&quot; + bmid + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
39            For i=0 to ubound(olbTOC.Items)
40                LF
41                InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
42                InsertField(&quot;BOOKMARKVALUE&quot;,olbTOC.Items(i))
43                InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
44            Next i
45            LF
46            InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
47
48        ElseIf nBookmarkType = 3 Then &apos; correct bookmark type
49            If ocbAddTag.State = 1 Then
50                bmid = CreateID
51                &apos; now check if we are in a para with text (this wouldn&apos;t be valid)
52                If Not(ParaIsEmpty) Then
53                    CR
54                End If
55                InsertTag(&quot;BOOKMARK_&quot;,&quot;&lt;BOOKMARK branch=&quot;&quot;contents&quot;&quot; id=&quot;&quot;bm_id&quot; + bmid + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
56            End If
57            For i=0 to ubound(olbTOC.Items)
58                LF
59                InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
60                InsertField(&quot;BOOKMARKVALUE&quot;,olbTOC.Items(i))
61                InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
62            Next i
63            If ocbAddTag.State = 1 Then
64                LF
65                InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
66            End If
67        Else    &apos; wrong bookmark type
68            bmid = CreateID
69            &apos; now check if we are in a para with text (this wouldn&apos;t be valid)
70            If Not(ParaIsEmpty) Then
71                CR
72            End If
73            InsertTag(&quot;BOOKMARK_&quot;,&quot;&lt;BOOKMARK branch=&quot;&quot;contents&quot;&quot; id=&quot;&quot;bm_id&quot; + bmid + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
74            For i=0 to ubound(olbTOC.Items)
75                LF
76                InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
77                InsertField(&quot;BOOKMARKVALUE&quot;,olbTOC.Items(i))
78                InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
79            Next i
80            LF
81            InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
82        End If
83
84    End If
85    oDialog.dispose
86
87End Sub
88
89Sub RemoveKeyStroke(Event As Object)
90    Select Case Event.KeyCode
91        Case com.sun.star.awt.Key.RETURN
92            RemoveIndexEntry
93        Case com.sun.star.awt.Key.SPACE
94            RemoveIndexEntry
95    End Select
96End Sub
97
98
99Sub RemoveTOCEntry
100    olbTOC = oDialog.GetControl(&quot;lbTOC&quot;)
101    ItemsPos = olbTOC.getSelectedItemsPos
102    For i=0 to ubound(ItemsPos)
103        olbTOC.removeItems(ItemsPos(i)-i,1)
104    Next i
105End Sub
106
107Sub KeyPressedRemove(Event As Object)
108    Select Case Event.KeyCode
109        Case com.sun.star.awt.Key.DELETE
110        RemoveTOCEntry
111    End Select
112End Sub
113
114Sub AddKeyStroke(Event As Object)
115    Select Case Event.KeyCode
116        Case com.sun.star.awt.Key.RETURN
117            AddTOCEntry
118        Case com.sun.star.awt.Key.SPACE
119            AddTOCEntry
120    End Select
121End Sub
122
123Sub AddTOCEntry
124        oTxtTOC = oDialog.GetControl(&quot;txtTOC&quot;)
125        If (oTxtTOC.Text = &quot;&quot;) Then
126            msgbox &quot;Enter a TOC entry first.&quot;
127        Else
128            &apos; Insert the index entry into the list
129            olbTOC = oDialog.GetControl(&quot;lbTOC&quot;)
130            olbTOC.addItem(oTxtTOC.Text,0)
131        End If
132
133End Sub
134
135
136</script:module>