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