| <?xml version="1.0" encoding="UTF-8"?> |
| <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> |
| <!--*********************************************************** |
| * |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| * |
| ***********************************************************--> |
| <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Find" script:language="StarBasic">' *** MODULE FIND *** |
| |
| Dim oDialog AS Object |
| Dim document AS Object |
| Dim Found(0) As Object |
| Dim nPos As Integer |
| |
| '======================================================= |
| ' Main |
| '------------------------------------------------------- |
| ' Calls the Find routine to search in fields |
| '======================================================= |
| Sub Main |
| |
| If not IsHelpFile Then |
| msgbox(strErr_NoHelpFile) |
| Exit Sub |
| End If |
| |
| BasicLibraries.LoadLibrary("HelpAuthoring") |
| oDialog = LoadDialog("HelpAuthoring", "dlgFind") |
| |
| oDoc = StarDesktop.CurrentComponent |
| Enum = oDoc.Text.createEnumeration |
| |
| LastSearchTerm = ReadConfig("SearchTerm") |
| If LastSearchTerm <> "" Then |
| oTxtFind = oDialog.GetControl("txtFind") |
| oTxtFind.Text = LastSearchTerm |
| End If |
| |
| If oDialog.execute() = 1 Then |
| oTxtFind = oDialog.GetControl("txtFind") |
| sFind = oTxtFind.Text |
| WriteConfig("SearchTerm",sFind) |
| |
| Do While Enum.hasMoreElements |
| TE = Enum.nextElement |
| If TE.supportsService("com.sun.star.text.Paragraph") Then |
| TP = TE.createEnumeration |
| While TP.hasmoreElements |
| TPE = TP.nextElement |
| If TPE.supportsService("com.sun.star.text.TextField") Then |
| If Instr(TPE.String, sFind) Then |
| sDim = ubound(Found())+1 |
| Redim Preserve Found(sDim) As Object |
| Found(sDim) = TPE.TextField.getAnchor.getText.createTextCursorbyRange(TPE.TextField.getAnchor) |
| End If |
| End If |
| Wend |
| ElseIf TE.supportsService("com.sun.star.text.TextTable") Then |
| CellName = "A1" |
| Cell = TE.getCellByName(CellName) |
| tmpCellEnum = Cell.createEnumeration |
| tmpCellElement = tmpCellEnum.nextElement |
| |
| Rows = TE.getRows |
| Cols = TE.getColumns |
| |
| For RowIndex = 1 to Rows.getCount() |
| For ColIndex = 1 to Cols.getCount() |
| CellName = Chr(64 + ColIndex) & RowIndex |
| Cell = TE.getCellByName(CellName) |
| CellEnum = Cell.createEnumeration |
| |
| Do While CellEnum.hasMoreElements |
| |
| CellElement = CellEnum.nextElement |
| |
| If CellElement.supportsService("com.sun.star.text.Paragraph") Then |
| TP = CellElement.createEnumeration |
| While TP.hasmoreElements |
| TPE = TP.nextElement |
| If TPE.supportsService("com.sun.star.text.TextField") Then |
| If Instr(TPE.String, sFind) Then |
| sDim = ubound(Found())+1 |
| Redim Preserve Found(sDim) As Object |
| Found(sDim) = TPE.TextField.getAnchor.getText.createTextCursorbyRange(TPE.TextField.getAnchor) |
| End If |
| End If |
| Wend |
| EndIf |
| |
| Loop |
| |
| Next |
| Next |
| |
| EndIf |
| Loop |
| |
| If ubound(Found()) < 1 Then |
| msgbox "Nothing found" |
| ElseIf ubound(Found()) > 1 Then |
| nPos = 1 |
| thiscomponent.getcurrentcontroller.select(Found(1)) |
| oDialog = LoadDialog("HelpAuthoring", "dlgRepeatFind") |
| oPrev = oDialog.GetControl("butPrev") |
| oPrev.Enable = FALSE |
| oDialog.Execute() |
| Else |
| thiscomponent.getcurrentcontroller.select(Found(1)) |
| End If |
| End If |
| End Sub |
| |
| '======================================================= |
| ' FindNext |
| '------------------------------------------------------- |
| ' Goes to the next search result position. |
| '======================================================= |
| Sub FindNext |
| If nPos < ubound(Found()) Then |
| nPos = nPos + 1 |
| thiscomponent.getcurrentcontroller.select(Found(nPos)) |
| If nPos = ubound(Found()) Then |
| oNext = oDialog.GetControl("butNext") |
| oNext.Enable = FALSE |
| End If |
| If nPos > 1 Then |
| oPrev = oDialog.GetControl("butPrev") |
| oPrev.Enable = TRUE |
| End If |
| End If |
| End Sub |
| |
| '======================================================= |
| ' FindPrev |
| '------------------------------------------------------- |
| ' Goes to the previous search result position. |
| '======================================================= |
| Sub FindPrev |
| If nPos > 1 Then |
| nPos = nPos - 1 |
| thiscomponent.getcurrentcontroller.select(Found(nPos)) |
| If nPos = 1 Then |
| oPrev = oDialog.GetControl("butPrev") |
| oPrev.Enable = FALSE |
| End If |
| If nPos < ubound(Found()) Then |
| oNext = oDialog.GetControl("butNext") |
| oNext.Enable = TRUE |
| End If |
| End If |
| End Sub |
| |
| </script:module> |