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