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