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