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