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