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="Find" script:language="StarBasic">' *** MODULE FIND *** 4 5Dim oDialog AS Object 6Dim document AS Object 7Dim Found(0) As Object 8Dim nPos As Integer 9 10'======================================================= 11' Main 12'------------------------------------------------------- 13' Calls the Find routine to search in fields 14'======================================================= 15Sub Main 16 17 If not IsHelpFile Then 18 msgbox(strErr_NoHelpFile) 19 Exit Sub 20 End If 21 22 BasicLibraries.LoadLibrary("HelpAuthoring") 23 oDialog = LoadDialog("HelpAuthoring", "dlgFind") 24 25 oDoc = StarDesktop.CurrentComponent 26 Enum = oDoc.Text.createEnumeration 27 28 LastSearchTerm = ReadConfig("SearchTerm") 29 If LastSearchTerm <> "" Then 30 oTxtFind = oDialog.GetControl("txtFind") 31 oTxtFind.Text = LastSearchTerm 32 End If 33 34 If oDialog.execute() = 1 Then 35 oTxtFind = oDialog.GetControl("txtFind") 36 sFind = oTxtFind.Text 37 WriteConfig("SearchTerm",sFind) 38 39 Do While Enum.hasMoreElements 40 TE = Enum.nextElement 41 If TE.supportsService("com.sun.star.text.Paragraph") Then 42 TP = TE.createEnumeration 43 While TP.hasmoreElements 44 TPE = TP.nextElement 45 If TPE.supportsService("com.sun.star.text.TextField") Then 46 If Instr(TPE.String, sFind) Then 47 sDim = ubound(Found())+1 48 Redim Preserve Found(sDim) As Object 49 Found(sDim) = TPE.TextField.getAnchor.getText.createTextCursorbyRange(TPE.TextField.getAnchor) 50 End If 51 End If 52 Wend 53 ElseIf TE.supportsService("com.sun.star.text.TextTable") Then 54 CellName = "A1" 55 Cell = TE.getCellByName(CellName) 56 tmpCellEnum = Cell.createEnumeration 57 tmpCellElement = tmpCellEnum.nextElement 58 59 Rows = TE.getRows 60 Cols = TE.getColumns 61 62 For RowIndex = 1 to Rows.getCount() 63 For ColIndex = 1 to Cols.getCount() 64 CellName = Chr(64 + ColIndex) & RowIndex 65 Cell = TE.getCellByName(CellName) 66 CellEnum = Cell.createEnumeration 67 68 Do While CellEnum.hasMoreElements 69 70 CellElement = CellEnum.nextElement 71 72 If CellElement.supportsService("com.sun.star.text.Paragraph") Then 73 TP = CellElement.createEnumeration 74 While TP.hasmoreElements 75 TPE = TP.nextElement 76 If TPE.supportsService("com.sun.star.text.TextField") Then 77 If Instr(TPE.String, sFind) Then 78 sDim = ubound(Found())+1 79 Redim Preserve Found(sDim) As Object 80 Found(sDim) = TPE.TextField.getAnchor.getText.createTextCursorbyRange(TPE.TextField.getAnchor) 81 End If 82 End If 83 Wend 84 EndIf 85 86 Loop 87 88 Next 89 Next 90 91 EndIf 92 Loop 93 94 If ubound(Found()) < 1 Then 95 msgbox "Nothing found" 96 ElseIf ubound(Found()) > 1 Then 97 nPos = 1 98 thiscomponent.getcurrentcontroller.select(Found(1)) 99 oDialog = LoadDialog("HelpAuthoring", "dlgRepeatFind") 100 oPrev = oDialog.GetControl("butPrev") 101 oPrev.Enable = FALSE 102 oDialog.Execute() 103 Else 104 thiscomponent.getcurrentcontroller.select(Found(1)) 105 End If 106 End If 107End Sub 108 109'======================================================= 110' FindNext 111'------------------------------------------------------- 112' Goes to the next search result position. 113'======================================================= 114Sub FindNext 115 If nPos < ubound(Found()) Then 116 nPos = nPos + 1 117 thiscomponent.getcurrentcontroller.select(Found(nPos)) 118 If nPos = ubound(Found()) Then 119 oNext = oDialog.GetControl("butNext") 120 oNext.Enable = FALSE 121 End If 122 If nPos > 1 Then 123 oPrev = oDialog.GetControl("butPrev") 124 oPrev.Enable = TRUE 125 End If 126 End If 127End Sub 128 129'======================================================= 130' FindPrev 131'------------------------------------------------------- 132' Goes to the previous search result position. 133'======================================================= 134Sub FindPrev 135 If nPos > 1 Then 136 nPos = nPos - 1 137 thiscomponent.getcurrentcontroller.select(Found(nPos)) 138 If nPos = 1 Then 139 oPrev = oDialog.GetControl("butPrev") 140 oPrev.Enable = FALSE 141 End If 142 If nPos < ubound(Found()) Then 143 oNext = oDialog.GetControl("butNext") 144 oNext.Enable = TRUE 145 End If 146 End If 147End Sub 148 149</script:module>