1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<!--*********************************************************** 4 * 5 * Licensed to the Apache Software Foundation (ASF) under one 6 * or more contributor license agreements. See the NOTICE file 7 * distributed with this work for additional information 8 * regarding copyright ownership. The ASF licenses this file 9 * to you under the Apache License, Version 2.0 (the 10 * "License"); you may not use this file except in compliance 11 * with the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, 16 * software distributed under the License is distributed on an 17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 * KIND, either express or implied. See the License for the 19 * specific language governing permissions and limitations 20 * under the License. 21 * 22 ***********************************************************--> 23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="TOC" script:language="StarBasic">REM ***** BASIC ***** 24 25Dim oDialog AS Object 26Dim document AS Object 27 28Sub Main 29 document = StarDesktop.CurrentComponent 30 31 BasicLibraries.LoadLibrary("HelpAuthoring") 32 oDialog = LoadDialog("HelpAuthoring", "dlgTOC") 33 oDialogModel = oDialog.Model 34 35 ocbAddTag = oDialog.GetControl("cbAddTag") 36 37 ' Check if bookmarks are allowed here 38 If IsInList Then 39 msgbox "No Bookmarks allowed inside a list.", 48, "D'oh!" 40 Exit Sub 41 End If 42 43 nBookmarkType = IsInBookmark 44 If nBookmarkType = 3 Then ' inside TOC bookmark 45 ocbAddTag.State = 0 46 End If 47 48 If oDialog.Execute() = 1 Then 49 ' Insert the bookmark construction 50 olbTOC = oDialog.GetControl("lbTOC") 51 52 If nBookmarkType = 0 Then' not in a bookmark, always add parent tags 53 bmid = CreateID 54 ' now check if we are in a para with text (this wouldn't be valid) 55 If Not(ParaIsEmpty) Then 56 CR 57 End If 58 InsertTag("BOOKMARK_","<BOOKMARK branch=""contents"" id=""bm_id" + bmid + """>","hlp_aux_bookmark") 59 For i=0 to ubound(olbTOC.Items) 60 LF 61 InsertTag("BOOKMARKVALUE_","<BOOKMARKVALUE>") 62 InsertField("BOOKMARKVALUE",olbTOC.Items(i)) 63 InsertTag("_BOOKMARKVALUE","</BOOKMARKVALUE>") 64 Next i 65 LF 66 InsertTagCR("_BOOKMARK","</BOOKMARK>","hlp_aux_bookmark") 67 68 ElseIf nBookmarkType = 3 Then ' correct bookmark type 69 If ocbAddTag.State = 1 Then 70 bmid = CreateID 71 ' now check if we are in a para with text (this wouldn't be valid) 72 If Not(ParaIsEmpty) Then 73 CR 74 End If 75 InsertTag("BOOKMARK_","<BOOKMARK branch=""contents"" id=""bm_id" + bmid + """>","hlp_aux_bookmark") 76 End If 77 For i=0 to ubound(olbTOC.Items) 78 LF 79 InsertTag("BOOKMARKVALUE_","<BOOKMARKVALUE>") 80 InsertField("BOOKMARKVALUE",olbTOC.Items(i)) 81 InsertTag("_BOOKMARKVALUE","</BOOKMARKVALUE>") 82 Next i 83 If ocbAddTag.State = 1 Then 84 LF 85 InsertTagCR("_BOOKMARK","</BOOKMARK>","hlp_aux_bookmark") 86 End If 87 Else ' wrong bookmark type 88 bmid = CreateID 89 ' now check if we are in a para with text (this wouldn't be valid) 90 If Not(ParaIsEmpty) Then 91 CR 92 End If 93 InsertTag("BOOKMARK_","<BOOKMARK branch=""contents"" id=""bm_id" + bmid + """>","hlp_aux_bookmark") 94 For i=0 to ubound(olbTOC.Items) 95 LF 96 InsertTag("BOOKMARKVALUE_","<BOOKMARKVALUE>") 97 InsertField("BOOKMARKVALUE",olbTOC.Items(i)) 98 InsertTag("_BOOKMARKVALUE","</BOOKMARKVALUE>") 99 Next i 100 LF 101 InsertTagCR("_BOOKMARK","</BOOKMARK>","hlp_aux_bookmark") 102 End If 103 104 End If 105 oDialog.dispose 106 107End Sub 108 109Sub RemoveKeyStroke(Event As Object) 110 Select Case Event.KeyCode 111 Case com.sun.star.awt.Key.RETURN 112 RemoveIndexEntry 113 Case com.sun.star.awt.Key.SPACE 114 RemoveIndexEntry 115 End Select 116End Sub 117 118 119Sub RemoveTOCEntry 120 olbTOC = oDialog.GetControl("lbTOC") 121 ItemsPos = olbTOC.getSelectedItemsPos 122 For i=0 to ubound(ItemsPos) 123 olbTOC.removeItems(ItemsPos(i)-i,1) 124 Next i 125End Sub 126 127Sub KeyPressedRemove(Event As Object) 128 Select Case Event.KeyCode 129 Case com.sun.star.awt.Key.DELETE 130 RemoveTOCEntry 131 End Select 132End Sub 133 134Sub AddKeyStroke(Event As Object) 135 Select Case Event.KeyCode 136 Case com.sun.star.awt.Key.RETURN 137 AddTOCEntry 138 Case com.sun.star.awt.Key.SPACE 139 AddTOCEntry 140 End Select 141End Sub 142 143Sub AddTOCEntry 144 oTxtTOC = oDialog.GetControl("txtTOC") 145 If (oTxtTOC.Text = "") Then 146 msgbox "Enter a TOC entry first." 147 Else 148 ' Insert the index entry into the list 149 olbTOC = oDialog.GetControl("lbTOC") 150 olbTOC.addItem(oTxtTOC.Text,0) 151 End If 152 153End Sub 154 155 156</script:module> 157