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