11ecadb57SMathias Bauer<?xml version="1.0" encoding="UTF-8"?>
21ecadb57SMathias Bauer<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*3e02b54dSAndrew Rist<!--***********************************************************
4*3e02b54dSAndrew Rist *
5*3e02b54dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
6*3e02b54dSAndrew Rist * or more contributor license agreements.  See the NOTICE file
7*3e02b54dSAndrew Rist * distributed with this work for additional information
8*3e02b54dSAndrew Rist * regarding copyright ownership.  The ASF licenses this file
9*3e02b54dSAndrew Rist * to you under the Apache License, Version 2.0 (the
10*3e02b54dSAndrew Rist * "License"); you may not use this file except in compliance
11*3e02b54dSAndrew Rist * with the License.  You may obtain a copy of the License at
12*3e02b54dSAndrew Rist *
13*3e02b54dSAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
14*3e02b54dSAndrew Rist *
15*3e02b54dSAndrew Rist * Unless required by applicable law or agreed to in writing,
16*3e02b54dSAndrew Rist * software distributed under the License is distributed on an
17*3e02b54dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*3e02b54dSAndrew Rist * KIND, either express or implied.  See the License for the
19*3e02b54dSAndrew Rist * specific language governing permissions and limitations
20*3e02b54dSAndrew Rist * under the License.
21*3e02b54dSAndrew Rist *
22*3e02b54dSAndrew Rist ***********************************************************-->
231ecadb57SMathias Bauer<script:module xmlns:script="http://openoffice.org/2000/script" script:name="IND" script:language="StarBasic">REM  *****  BASIC  *****
241ecadb57SMathias Bauer
251ecadb57SMathias BauerDim oDialog AS Object
261ecadb57SMathias BauerDim document AS Object
271ecadb57SMathias Bauer
281ecadb57SMathias BauerSub Main
291ecadb57SMathias Bauer
301ecadb57SMathias Bauer	If not IsHelpFile Then
311ecadb57SMathias Bauer		msgbox(strErr_NoHelpFile)
321ecadb57SMathias Bauer		Exit Sub
331ecadb57SMathias Bauer	End If
341ecadb57SMathias Bauer
351ecadb57SMathias Bauer	document = StarDesktop.CurrentComponent
361ecadb57SMathias Bauer
371ecadb57SMathias Bauer	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
381ecadb57SMathias Bauer	oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgIND&quot;)
391ecadb57SMathias Bauer	ocbAddTag = oDialog.GetControl(&quot;cbAddTag&quot;)
401ecadb57SMathias Bauer
411ecadb57SMathias Bauer	&apos; Check if bookmarks are allowed here
421ecadb57SMathias Bauer	If IsInList Then
431ecadb57SMathias Bauer		msgbox &quot;No Bookmarks allowed inside a list.&quot;, 48, &quot;D&apos;oh!&quot;
441ecadb57SMathias Bauer		Exit Sub
451ecadb57SMathias Bauer	End If
461ecadb57SMathias Bauer
471ecadb57SMathias Bauer
481ecadb57SMathias Bauer	nBookmarkType = IsInBookmark
491ecadb57SMathias Bauer	If nBookmarkType = 1 Then &apos; inside INDEX bookmark
501ecadb57SMathias Bauer		ocbAddTag.State = 0
511ecadb57SMathias Bauer	End If
521ecadb57SMathias Bauer
531ecadb57SMathias Bauer	oDialogModel = oDialog.Model
541ecadb57SMathias Bauer
551ecadb57SMathias Bauer	If oDialog.Execute() = 1 Then
561ecadb57SMathias Bauer		&apos; Insert the bookmark construction
571ecadb57SMathias Bauer		olbIND = oDialog.GetControl(&quot;lbIND&quot;)
581ecadb57SMathias Bauer
591ecadb57SMathias Bauer		If nBookmarkType = 0 Then&apos; not in a bookmark, always add parent tags
601ecadb57SMathias Bauer			bmid = CreateID
611ecadb57SMathias Bauer			&apos; now check if we are in a para with text (this wouldn&apos;t be valid)
621ecadb57SMathias Bauer			If Not(ParaIsEmpty) Then
631ecadb57SMathias Bauer				CR
641ecadb57SMathias Bauer			End If
651ecadb57SMathias 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;)
661ecadb57SMathias Bauer
671ecadb57SMathias Bauer			For i=0 to ubound(olbIND.Items)
681ecadb57SMathias Bauer				LF
691ecadb57SMathias Bauer				InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
701ecadb57SMathias Bauer				InsertField(&quot;BOOKMARKVALUE&quot;,olbIND.Items(i))
711ecadb57SMathias Bauer				InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
721ecadb57SMathias Bauer			Next i
731ecadb57SMathias Bauer			LF
741ecadb57SMathias Bauer			InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
751ecadb57SMathias Bauer
761ecadb57SMathias Bauer		ElseIf nBookmarkType = 1 Then &apos; in a correct bookmark type
771ecadb57SMathias Bauer			If ocbAddTag.State = 1 Then
781ecadb57SMathias Bauer				If Not(ParaIsEmpty) Then
791ecadb57SMathias Bauer					CR
801ecadb57SMathias Bauer				End If
811ecadb57SMathias 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;)
821ecadb57SMathias Bauer				For i=0 to ubound(olbIND.Items)
831ecadb57SMathias Bauer					LF
841ecadb57SMathias Bauer					InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
851ecadb57SMathias Bauer					InsertField(&quot;BOOKMARKVALUE&quot;,olbIND.Items(i))
861ecadb57SMathias Bauer					InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
871ecadb57SMathias Bauer				Next i
881ecadb57SMathias Bauer				If ocbAddTag.State = 1 Then
891ecadb57SMathias Bauer					LF
901ecadb57SMathias Bauer					InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
911ecadb57SMathias Bauer				End If
921ecadb57SMathias Bauer			Else
931ecadb57SMathias Bauer				For i=0 to ubound(olbIND.Items)
941ecadb57SMathias Bauer					LF
951ecadb57SMathias Bauer					InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
961ecadb57SMathias Bauer					InsertField(&quot;BOOKMARKVALUE&quot;,olbIND.Items(i))
971ecadb57SMathias Bauer					InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
981ecadb57SMathias Bauer				Next i
991ecadb57SMathias Bauer			End If
1001ecadb57SMathias Bauer		Else	&apos; in a wrong bookmark type
1011ecadb57SMathias Bauer			If Not(ParaIsEmpty) Then
1021ecadb57SMathias Bauer				CR
1031ecadb57SMathias Bauer			End If
1041ecadb57SMathias 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;)
1051ecadb57SMathias Bauer			For i=0 to ubound(olbIND.Items)
1061ecadb57SMathias Bauer				LF
1071ecadb57SMathias Bauer				InsertTag(&quot;BOOKMARKVALUE_&quot;,&quot;&lt;BOOKMARKVALUE&gt;&quot;)
1081ecadb57SMathias Bauer				InsertField(&quot;BOOKMARKVALUE&quot;,olbIND.Items(i))
1091ecadb57SMathias Bauer				InsertTag(&quot;_BOOKMARKVALUE&quot;,&quot;&lt;/BOOKMARKVALUE&gt;&quot;)
1101ecadb57SMathias Bauer			Next i
1111ecadb57SMathias Bauer			LF
1121ecadb57SMathias Bauer			InsertTagCR(&quot;_BOOKMARK&quot;,&quot;&lt;/BOOKMARK&gt;&quot;,&quot;hlp_aux_bookmark&quot;)
1131ecadb57SMathias Bauer		End If
1141ecadb57SMathias Bauer	End If
1151ecadb57SMathias Bauer
1161ecadb57SMathias Bauer	oDialog.dispose
1171ecadb57SMathias Bauer
1181ecadb57SMathias BauerEnd Sub
1191ecadb57SMathias Bauer
1201ecadb57SMathias BauerSub AddKeyStroke(Event As Object)
1211ecadb57SMathias Bauer	Select Case Event.KeyCode
1221ecadb57SMathias Bauer		Case com.sun.star.awt.Key.RETURN
1231ecadb57SMathias Bauer			AddIndexEntry
1241ecadb57SMathias Bauer		Case com.sun.star.awt.Key.SPACE
1251ecadb57SMathias Bauer			AddIndexEntry
1261ecadb57SMathias Bauer	End Select
1271ecadb57SMathias BauerEnd Sub
1281ecadb57SMathias Bauer
1291ecadb57SMathias BauerSub AddIndexEntry
1301ecadb57SMathias Bauer
1311ecadb57SMathias Bauer		oTxtLevel1 = oDialog.GetControl(&quot;txtLevel1&quot;)
1321ecadb57SMathias Bauer		oTxtLevel2 = oDialog.GetControl(&quot;txtLevel2&quot;)
1331ecadb57SMathias Bauer
1341ecadb57SMathias Bauer		If oTxtLevel2.Text &lt;&gt; &quot;&quot; Then
1351ecadb57SMathias Bauer			IndexEntry = oTxtLevel1.Text + &quot;;&quot; + oTxtLevel2.Text
1361ecadb57SMathias Bauer		Else
1371ecadb57SMathias Bauer			IndexEntry = oTxtLevel1.Text
1381ecadb57SMathias Bauer		End If
1391ecadb57SMathias Bauer
1401ecadb57SMathias Bauer		If ((oTxtLevel1.Text = &quot;&quot;) OR (IndexEntry = &quot;&lt;Level 1&gt;;&lt;Level 2&gt;&quot;)) Then
1411ecadb57SMathias Bauer			msgbox &quot;Enter an index entry first.&quot;
1421ecadb57SMathias Bauer		Else
1431ecadb57SMathias Bauer			&apos; Insert the index entry into the list
1441ecadb57SMathias Bauer			olbIND = oDialog.GetControl(&quot;lbIND&quot;)
1451ecadb57SMathias Bauer			olbIND.addItem(IndexEntry,0)
1461ecadb57SMathias Bauer		End If
1471ecadb57SMathias Bauer
1481ecadb57SMathias BauerEnd Sub
1491ecadb57SMathias Bauer
1501ecadb57SMathias BauerSub RemoveKeyStroke(Event As Object)
1511ecadb57SMathias Bauer	Select Case Event.KeyCode
1521ecadb57SMathias Bauer		Case com.sun.star.awt.Key.RETURN
1531ecadb57SMathias Bauer			RemoveIndexEntry
1541ecadb57SMathias Bauer		Case com.sun.star.awt.Key.SPACE
1551ecadb57SMathias Bauer			RemoveIndexEntry
1561ecadb57SMathias Bauer	End Select
1571ecadb57SMathias BauerEnd Sub
1581ecadb57SMathias Bauer
1591ecadb57SMathias Bauer
1601ecadb57SMathias BauerSub RemoveIndexEntry
1611ecadb57SMathias Bauer	olbIND = oDialog.GetControl(&quot;lbIND&quot;)
1621ecadb57SMathias Bauer	ItemsPos = olbIND.getSelectedItemsPos
1631ecadb57SMathias Bauer	For i=0 to ubound(ItemsPos)
1641ecadb57SMathias Bauer		olbIND.removeItems(ItemsPos(i)-i,1)
1651ecadb57SMathias Bauer	Next i
1661ecadb57SMathias BauerEnd Sub
1671ecadb57SMathias Bauer
1681ecadb57SMathias BauerSub KeyPressedAdd(Event As Object)
1691ecadb57SMathias Bauer	Select Case Event.KeyCode
1701ecadb57SMathias Bauer		Case com.sun.star.awt.Key.INSERT
1711ecadb57SMathias Bauer			AddIndexEntry
1721ecadb57SMathias Bauer	End Select
1731ecadb57SMathias BauerEnd Sub
1741ecadb57SMathias Bauer
1751ecadb57SMathias BauerSub KeyPressedRemove(Event As Object)
1761ecadb57SMathias Bauer	Select Case Event.KeyCode
1771ecadb57SMathias Bauer		Case com.sun.star.awt.Key.DELETE
1781ecadb57SMathias Bauer		RemoveIndexEntry
1791ecadb57SMathias Bauer	End Select
1801ecadb57SMathias BauerEnd Sub
181*3e02b54dSAndrew Rist</script:module>
182