REM ***** BASIC ***** Dim oDialog AS Object Dim document AS Object Sub Main document = StarDesktop.CurrentComponent BasicLibraries.LoadLibrary("HelpAuthoring") oDialog = LoadDialog("HelpAuthoring", "dlgTOC") oDialogModel = oDialog.Model ocbAddTag = oDialog.GetControl("cbAddTag") ' Check if bookmarks are allowed here If IsInList Then msgbox "No Bookmarks allowed inside a list.", 48, "D'oh!" Exit Sub End If nBookmarkType = IsInBookmark If nBookmarkType = 3 Then ' inside TOC bookmark ocbAddTag.State = 0 End If If oDialog.Execute() = 1 Then ' Insert the bookmark construction olbTOC = oDialog.GetControl("lbTOC") If nBookmarkType = 0 Then' not in a bookmark, always add parent tags bmid = CreateID ' now check if we are in a para with text (this wouldn't be valid) If Not(ParaIsEmpty) Then CR End If InsertTag("BOOKMARK_","<BOOKMARK branch=""contents"" id=""bm_id" + bmid + """>","hlp_aux_bookmark") For i=0 to ubound(olbTOC.Items) LF InsertTag("BOOKMARKVALUE_","<BOOKMARKVALUE>") InsertField("BOOKMARKVALUE",olbTOC.Items(i)) InsertTag("_BOOKMARKVALUE","</BOOKMARKVALUE>") Next i LF InsertTagCR("_BOOKMARK","</BOOKMARK>","hlp_aux_bookmark") ElseIf nBookmarkType = 3 Then ' correct bookmark type If ocbAddTag.State = 1 Then bmid = CreateID ' now check if we are in a para with text (this wouldn't be valid) If Not(ParaIsEmpty) Then CR End If InsertTag("BOOKMARK_","<BOOKMARK branch=""contents"" id=""bm_id" + bmid + """>","hlp_aux_bookmark") End If For i=0 to ubound(olbTOC.Items) LF InsertTag("BOOKMARKVALUE_","<BOOKMARKVALUE>") InsertField("BOOKMARKVALUE",olbTOC.Items(i)) InsertTag("_BOOKMARKVALUE","</BOOKMARKVALUE>") Next i If ocbAddTag.State = 1 Then LF InsertTagCR("_BOOKMARK","</BOOKMARK>","hlp_aux_bookmark") End If Else ' wrong bookmark type bmid = CreateID ' now check if we are in a para with text (this wouldn't be valid) If Not(ParaIsEmpty) Then CR End If InsertTag("BOOKMARK_","<BOOKMARK branch=""contents"" id=""bm_id" + bmid + """>","hlp_aux_bookmark") For i=0 to ubound(olbTOC.Items) LF InsertTag("BOOKMARKVALUE_","<BOOKMARKVALUE>") InsertField("BOOKMARKVALUE",olbTOC.Items(i)) InsertTag("_BOOKMARKVALUE","</BOOKMARKVALUE>") Next i LF InsertTagCR("_BOOKMARK","</BOOKMARK>","hlp_aux_bookmark") End If End If oDialog.dispose End Sub Sub RemoveKeyStroke(Event As Object) Select Case Event.KeyCode Case com.sun.star.awt.Key.RETURN RemoveIndexEntry Case com.sun.star.awt.Key.SPACE RemoveIndexEntry End Select End Sub Sub RemoveTOCEntry olbTOC = oDialog.GetControl("lbTOC") ItemsPos = olbTOC.getSelectedItemsPos For i=0 to ubound(ItemsPos) olbTOC.removeItems(ItemsPos(i)-i,1) Next i End Sub Sub KeyPressedRemove(Event As Object) Select Case Event.KeyCode Case com.sun.star.awt.Key.DELETE RemoveTOCEntry End Select End Sub Sub AddKeyStroke(Event As Object) Select Case Event.KeyCode Case com.sun.star.awt.Key.RETURN AddTOCEntry Case com.sun.star.awt.Key.SPACE AddTOCEntry End Select End Sub Sub AddTOCEntry oTxtTOC = oDialog.GetControl("txtTOC") If (oTxtTOC.Text = "") Then msgbox "Enter a TOC entry first." Else ' Insert the index entry into the list olbTOC = oDialog.GetControl("lbTOC") olbTOC.addItem(oTxtTOC.Text,0) End If End Sub