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="IND" 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
10*1ecadb57SMathias Bauer	If not IsHelpFile Then
11*1ecadb57SMathias Bauer		msgbox(strErr_NoHelpFile)
12*1ecadb57SMathias Bauer		Exit Sub
13*1ecadb57SMathias Bauer	End If
14*1ecadb57SMathias Bauer
15*1ecadb57SMathias Bauer	document = StarDesktop.CurrentComponent
16*1ecadb57SMathias Bauer
17*1ecadb57SMathias Bauer	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
18*1ecadb57SMathias Bauer	oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgIND&quot;)
19*1ecadb57SMathias Bauer	ocbAddTag = oDialog.GetControl(&quot;cbAddTag&quot;)
20*1ecadb57SMathias Bauer
21*1ecadb57SMathias Bauer	&apos; Check if bookmarks are allowed here
22*1ecadb57SMathias Bauer	If IsInList Then
23*1ecadb57SMathias Bauer		msgbox &quot;No Bookmarks allowed inside a list.&quot;, 48, &quot;D&apos;oh!&quot;
24*1ecadb57SMathias Bauer		Exit Sub
25*1ecadb57SMathias Bauer	End If
26*1ecadb57SMathias Bauer
27*1ecadb57SMathias Bauer
28*1ecadb57SMathias Bauer	nBookmarkType = IsInBookmark
29*1ecadb57SMathias Bauer	If nBookmarkType = 1 Then &apos; inside INDEX bookmark
30*1ecadb57SMathias Bauer		ocbAddTag.State = 0
31*1ecadb57SMathias Bauer	End If
32*1ecadb57SMathias Bauer
33*1ecadb57SMathias Bauer	oDialogModel = oDialog.Model
34*1ecadb57SMathias Bauer
35*1ecadb57SMathias Bauer	If oDialog.Execute() = 1 Then
36*1ecadb57SMathias Bauer		&apos; Insert the bookmark construction
37*1ecadb57SMathias Bauer		olbIND = oDialog.GetControl(&quot;lbIND&quot;)
38*1ecadb57SMathias Bauer
39*1ecadb57SMathias Bauer		If nBookmarkType = 0 Then&apos; not in a bookmark, always add parent tags
40*1ecadb57SMathias Bauer			bmid = CreateID
41*1ecadb57SMathias Bauer			&apos; now check if we are in a para with text (this wouldn&apos;t be valid)
42*1ecadb57SMathias Bauer			If Not(ParaIsEmpty) Then
43*1ecadb57SMathias Bauer				CR
44*1ecadb57SMathias Bauer			End If
45*1ecadb57SMathias Bauer			InsertTag(&quot;BOOKMARK_&quot;,&quot;&lt;BOOKMARK branch=&quot;&quot;index&quot;&quot; id=&quot;&quot;bm_id&quot; + bmid + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
46*1ecadb57SMathias Bauer
47*1ecadb57SMathias Bauer			For i=0 to ubound(olbIND.Items)
48*1ecadb57SMathias Bauer				LF
49*1ecadb57SMathias Bauer				InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
50*1ecadb57SMathias Bauer				InsertField(&quot;BOOKMARKVALUE&quot;,olbIND.Items(i))
51*1ecadb57SMathias Bauer				InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
52*1ecadb57SMathias Bauer			Next i
53*1ecadb57SMathias Bauer			LF
54*1ecadb57SMathias Bauer			InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
55*1ecadb57SMathias Bauer
56*1ecadb57SMathias Bauer		ElseIf nBookmarkType = 1 Then &apos; in a correct bookmark type
57*1ecadb57SMathias Bauer			If ocbAddTag.State = 1 Then
58*1ecadb57SMathias Bauer				If Not(ParaIsEmpty) Then
59*1ecadb57SMathias Bauer					CR
60*1ecadb57SMathias Bauer				End If
61*1ecadb57SMathias Bauer				InsertTag(&quot;BOOKMARK_&quot;,&quot;&lt;BOOKMARK branch=&quot;&quot;index&quot;&quot; id=&quot;&quot;bm_id&quot; + bmid + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
62*1ecadb57SMathias Bauer				For i=0 to ubound(olbIND.Items)
63*1ecadb57SMathias Bauer					LF
64*1ecadb57SMathias Bauer					InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
65*1ecadb57SMathias Bauer					InsertField(&quot;BOOKMARKVALUE&quot;,olbIND.Items(i))
66*1ecadb57SMathias Bauer					InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
67*1ecadb57SMathias Bauer				Next i
68*1ecadb57SMathias Bauer				If ocbAddTag.State = 1 Then
69*1ecadb57SMathias Bauer					LF
70*1ecadb57SMathias Bauer					InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
71*1ecadb57SMathias Bauer				End If
72*1ecadb57SMathias Bauer			Else
73*1ecadb57SMathias Bauer				For i=0 to ubound(olbIND.Items)
74*1ecadb57SMathias Bauer					LF
75*1ecadb57SMathias Bauer					InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
76*1ecadb57SMathias Bauer					InsertField(&quot;BOOKMARKVALUE&quot;,olbIND.Items(i))
77*1ecadb57SMathias Bauer					InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
78*1ecadb57SMathias Bauer				Next i
79*1ecadb57SMathias Bauer			End If
80*1ecadb57SMathias Bauer		Else	&apos; in a wrong bookmark type
81*1ecadb57SMathias Bauer			If Not(ParaIsEmpty) Then
82*1ecadb57SMathias Bauer				CR
83*1ecadb57SMathias Bauer			End If
84*1ecadb57SMathias Bauer			InsertTag(&quot;BOOKMARK_&quot;,&quot;&lt;BOOKMARK branch=&quot;&quot;index&quot;&quot; id=&quot;&quot;bm_id&quot; + bmid + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
85*1ecadb57SMathias Bauer			For i=0 to ubound(olbIND.Items)
86*1ecadb57SMathias Bauer				LF
87*1ecadb57SMathias Bauer				InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
88*1ecadb57SMathias Bauer				InsertField(&quot;BOOKMARKVALUE&quot;,olbIND.Items(i))
89*1ecadb57SMathias Bauer				InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
90*1ecadb57SMathias Bauer			Next i
91*1ecadb57SMathias Bauer			LF
92*1ecadb57SMathias Bauer			InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
93*1ecadb57SMathias Bauer		End If
94*1ecadb57SMathias Bauer	End If
95*1ecadb57SMathias Bauer
96*1ecadb57SMathias Bauer	oDialog.dispose
97*1ecadb57SMathias Bauer
98*1ecadb57SMathias BauerEnd Sub
99*1ecadb57SMathias Bauer
100*1ecadb57SMathias BauerSub AddKeyStroke(Event As Object)
101*1ecadb57SMathias Bauer	Select Case Event.KeyCode
102*1ecadb57SMathias Bauer		Case com.sun.star.awt.Key.RETURN
103*1ecadb57SMathias Bauer			AddIndexEntry
104*1ecadb57SMathias Bauer		Case com.sun.star.awt.Key.SPACE
105*1ecadb57SMathias Bauer			AddIndexEntry
106*1ecadb57SMathias Bauer	End Select
107*1ecadb57SMathias BauerEnd Sub
108*1ecadb57SMathias Bauer
109*1ecadb57SMathias BauerSub AddIndexEntry
110*1ecadb57SMathias Bauer
111*1ecadb57SMathias Bauer		oTxtLevel1 = oDialog.GetControl(&quot;txtLevel1&quot;)
112*1ecadb57SMathias Bauer		oTxtLevel2 = oDialog.GetControl(&quot;txtLevel2&quot;)
113*1ecadb57SMathias Bauer
114*1ecadb57SMathias Bauer		If oTxtLevel2.Text &lt;&gt; &quot;&quot; Then
115*1ecadb57SMathias Bauer			IndexEntry = oTxtLevel1.Text + &quot;;&quot; + oTxtLevel2.Text
116*1ecadb57SMathias Bauer		Else
117*1ecadb57SMathias Bauer			IndexEntry = oTxtLevel1.Text
118*1ecadb57SMathias Bauer		End If
119*1ecadb57SMathias Bauer
120*1ecadb57SMathias Bauer		If ((oTxtLevel1.Text = &quot;&quot;) OR (IndexEntry = &quot;&lt;Level 1&gt;;&lt;Level 2&gt;&quot;)) Then
121*1ecadb57SMathias Bauer			msgbox &quot;Enter an index entry first.&quot;
122*1ecadb57SMathias Bauer		Else
123*1ecadb57SMathias Bauer			&apos; Insert the index entry into the list
124*1ecadb57SMathias Bauer			olbIND = oDialog.GetControl(&quot;lbIND&quot;)
125*1ecadb57SMathias Bauer			olbIND.addItem(IndexEntry,0)
126*1ecadb57SMathias Bauer		End If
127*1ecadb57SMathias Bauer
128*1ecadb57SMathias BauerEnd Sub
129*1ecadb57SMathias Bauer
130*1ecadb57SMathias BauerSub RemoveKeyStroke(Event As Object)
131*1ecadb57SMathias Bauer	Select Case Event.KeyCode
132*1ecadb57SMathias Bauer		Case com.sun.star.awt.Key.RETURN
133*1ecadb57SMathias Bauer			RemoveIndexEntry
134*1ecadb57SMathias Bauer		Case com.sun.star.awt.Key.SPACE
135*1ecadb57SMathias Bauer			RemoveIndexEntry
136*1ecadb57SMathias Bauer	End Select
137*1ecadb57SMathias BauerEnd Sub
138*1ecadb57SMathias Bauer
139*1ecadb57SMathias Bauer
140*1ecadb57SMathias BauerSub RemoveIndexEntry
141*1ecadb57SMathias Bauer	olbIND = oDialog.GetControl(&quot;lbIND&quot;)
142*1ecadb57SMathias Bauer	ItemsPos = olbIND.getSelectedItemsPos
143*1ecadb57SMathias Bauer	For i=0 to ubound(ItemsPos)
144*1ecadb57SMathias Bauer		olbIND.removeItems(ItemsPos(i)-i,1)
145*1ecadb57SMathias Bauer	Next i
146*1ecadb57SMathias BauerEnd Sub
147*1ecadb57SMathias Bauer
148*1ecadb57SMathias BauerSub KeyPressedAdd(Event As Object)
149*1ecadb57SMathias Bauer	Select Case Event.KeyCode
150*1ecadb57SMathias Bauer		Case com.sun.star.awt.Key.INSERT
151*1ecadb57SMathias Bauer			AddIndexEntry
152*1ecadb57SMathias Bauer	End Select
153*1ecadb57SMathias BauerEnd Sub
154*1ecadb57SMathias Bauer
155*1ecadb57SMathias BauerSub KeyPressedRemove(Event As Object)
156*1ecadb57SMathias Bauer	Select Case Event.KeyCode
157*1ecadb57SMathias Bauer		Case com.sun.star.awt.Key.DELETE
158*1ecadb57SMathias Bauer		RemoveIndexEntry
159*1ecadb57SMathias Bauer	End Select
160*1ecadb57SMathias BauerEnd Sub
161*1ecadb57SMathias Bauer</script:module>