1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<!--*********************************************************** 4 * 5 * Licensed to the Apache Software Foundation (ASF) under one 6 * or more contributor license agreements. See the NOTICE file 7 * distributed with this work for additional information 8 * regarding copyright ownership. The ASF licenses this file 9 * to you under the Apache License, Version 2.0 (the 10 * "License"); you may not use this file except in compliance 11 * with the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, 16 * software distributed under the License is distributed on an 17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 * KIND, either express or implied. See the License for the 19 * specific language governing permissions and limitations 20 * under the License. 21 * 22 ***********************************************************--> 23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SearchAndReplace" script:language="StarBasic">' *** 24' SearchAndReplace basic script 25' Uses a user interface to search and replace the specified strings 26' 27' author Neil Montgomery 28' created August 12, 2002 29' *** 30 31 32' Main subprocedure to start script 33Sub Main 34 dialogShow() 35End Sub 36 37 38' Global reference to the dialog object 39Dim oDialog as Object 40 41 42' Uses the loadDialog subprocedure to load and execute the dialog box 43Sub dialogShow 44 oDialog = loadDialog("Standard","SearchAndReplaceDialog") 45 oDialog.execute() 46End Sub 47 48 49 50' *** 51' Loads the dialog from the dialog library 52' 53' param Libname the library name where dialog is stored 54' param DialogName the name of the dialog 55' param oLibContainer library container to hold the loaded dialog library (optional) 56' return runtime dialog object 57' *** 58Function loadDialog(Libname as String, DialogName as String, Optional oLibContainer) 59 Dim oLib as Object 60 Dim oLibDialog as Object 61 Dim oRuntimeDialog as Object 62 63 If isMissing(oLibContainer ) then 64 oLibContainer = DialogLibraries 65 End If 66 oLibContainer.loadLibrary(LibName) 67 oLib = oLibContainer.getByName(Libname) 68 oLibDialog = oLib.getByName(DialogName) 69 oRuntimeDialog = createUnoDialog(oLibDialog) 70 loadDialog() = oRuntimeDialog 71End Function 72 73 74 75' *** 76' Creates a connection to the current document. 77' Gets the search and replace keys from the dialog and replaces all 78' instances of the search key with the replace key. 79' 80' *** 81Sub getInfoFromDialog 82 Dim oDocument As Object 83 Dim oSearch As Object 84 Dim oFound As Object 85 Dim oFoundCursor As Object 86 Dim oSearchText as Object 87 Dim oReplaceText as Object 88 89 ' Create a document object for the current document then create text and 90 ' cursor objects 91 oDocument = StarDesktop.ActiveFrame.Controller.Model 92 oSearch = oDocument.createSearchDescriptor 93 94 ' Replace all instances of the search string with the replavce string 95 oSearch.SearchString = getSearchKey() 96 oSearch.ReplaceString = getReplaceKey() 97 oDocument.replaceAll(oSearch) 98End Sub 99 100 101' *** 102' Gets the search key string from the dialog 103' 104' returns string representing the search key 105' *** 106Function getSearchKey() as String 107 Dim sSearch As String 108 109 ' Get the search key from the dialog 110 oSearchText = oDialog.GetControl("SearchKeyTextBox") 111 sSearch = oSearchText.Text 112 getSearchKey = sSearch 113End Function 114 115 116 117' *** 118' Gets the replace key string from the dialog 119' 120' returns string representing the replace key 121' *** 122Function getReplaceKey() as String 123 Dim sReplace As String 124 125 ' Get the replace key from the dialog 126 oReplaceText = oDialog.GetControl("ReplaceKeyTextBox") 127 sReplace = oReplaceText.Text 128 getReplaceKey = sReplace 129End Function</script:module> 130