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="SearchAndReplace" script:language="StarBasic">' *** 4' SearchAndReplace basic script 5' Uses a user interface to search and replace the specified strings 6' 7' author Neil Montgomery 8' created August 12, 2002 9' *** 10 11 12' Main subprocedure to start script 13Sub Main 14 dialogShow() 15End Sub 16 17 18' Global reference to the dialog object 19Dim oDialog as Object 20 21 22' Uses the loadDialog subprocedure to load and execute the dialog box 23Sub dialogShow 24 oDialog = loadDialog("Standard","SearchAndReplaceDialog") 25 oDialog.execute() 26End Sub 27 28 29 30' *** 31' Loads the dialog from the dialog library 32' 33' param Libname the library name where dialog is stored 34' param DialogName the name of the dialog 35' param oLibContainer library container to hold the loaded dialog library (optional) 36' return runtime dialog object 37' *** 38Function loadDialog(Libname as String, DialogName as String, Optional oLibContainer) 39 Dim oLib as Object 40 Dim oLibDialog as Object 41 Dim oRuntimeDialog as Object 42 43 If isMissing(oLibContainer ) then 44 oLibContainer = DialogLibraries 45 End If 46 oLibContainer.loadLibrary(LibName) 47 oLib = oLibContainer.getByName(Libname) 48 oLibDialog = oLib.getByName(DialogName) 49 oRuntimeDialog = createUnoDialog(oLibDialog) 50 loadDialog() = oRuntimeDialog 51End Function 52 53 54 55' *** 56' Creates a connection to the current document. 57' Gets the search and replace keys from the dialog and replaces all 58' instances of the search key with the replace key. 59' 60' *** 61Sub getInfoFromDialog 62 Dim oDocument As Object 63 Dim oSearch As Object 64 Dim oFound As Object 65 Dim oFoundCursor As Object 66 Dim oSearchText as Object 67 Dim oReplaceText as Object 68 69 ' Create a document object for the current document then create text and 70 ' cursor objects 71 oDocument = StarDesktop.ActiveFrame.Controller.Model 72 oSearch = oDocument.createSearchDescriptor 73 74 ' Replace all instances of the search string with the replavce string 75 oSearch.SearchString = getSearchKey() 76 oSearch.ReplaceString = getReplaceKey() 77 oDocument.replaceAll(oSearch) 78End Sub 79 80 81' *** 82' Gets the search key string from the dialog 83' 84' returns string representing the search key 85' *** 86Function getSearchKey() as String 87 Dim sSearch As String 88 89 ' Get the search key from the dialog 90 oSearchText = oDialog.GetControl("SearchKeyTextBox") 91 sSearch = oSearchText.Text 92 getSearchKey = sSearch 93End Function 94 95 96 97' *** 98' Gets the replace key string from the dialog 99' 100' returns string representing the replace key 101' *** 102Function getReplaceKey() as String 103 Dim sReplace As String 104 105 ' Get the replace key from the dialog 106 oReplaceText = oDialog.GetControl("ReplaceKeyTextBox") 107 sReplace = oReplaceText.Text 108 getReplaceKey = sReplace 109End Function</script:module>