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">&apos; ***
24&apos; SearchAndReplace basic script
25&apos; Uses a user interface to search and replace the specified strings
26&apos;
27&apos; author        Neil Montgomery
28&apos; created       August 12, 2002
29&apos; ***
30
31
32&apos; Main subprocedure to start script
33Sub Main
34 dialogShow()
35End Sub
36
37
38&apos; Global reference to the dialog object
39Dim oDialog as Object
40
41
42&apos; Uses the loadDialog subprocedure to load and execute the dialog box
43Sub dialogShow
44 oDialog = loadDialog(&quot;Standard&quot;,&quot;SearchAndReplaceDialog&quot;)
45 oDialog.execute()
46End Sub
47
48
49
50&apos; ***
51&apos; Loads the dialog from the dialog library
52&apos;
53&apos; param Libname         the library name where dialog is stored
54&apos; param  DialogName     the name of the dialog
55&apos; param         oLibContainer   library container to hold the loaded dialog library (optional)
56&apos; return        runtime dialog object
57&apos; ***
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&apos; ***
76&apos; Creates a connection to the current document.
77&apos; Gets the search and replace keys from the dialog and replaces all
78&apos; instances of the search key with the replace key.
79&apos;
80&apos; ***
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 &apos; Create a document object for the current document then create text and
90 &apos; cursor objects
91 oDocument = StarDesktop.ActiveFrame.Controller.Model
92 oSearch = oDocument.createSearchDescriptor
93
94 &apos; 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&apos; ***
102&apos; Gets the search key string from the dialog
103&apos;
104&apos; returns	string 		representing the search key
105&apos; ***
106Function getSearchKey() as String
107 Dim sSearch As String
108
109 &apos; Get the search key from the dialog
110 oSearchText = oDialog.GetControl(&quot;SearchKeyTextBox&quot;)
111 sSearch = oSearchText.Text
112 getSearchKey = sSearch
113End Function
114
115
116
117&apos; ***
118&apos; Gets the replace key string from the dialog
119&apos;
120&apos; returns 	string		representing the replace key
121&apos; ***
122Function getReplaceKey() as String
123 Dim sReplace As String
124
125 &apos; Get the replace key from the dialog
126 oReplaceText = oDialog.GetControl(&quot;ReplaceKeyTextBox&quot;)
127 sReplace = oReplaceText.Text
128 getReplaceKey = sReplace
129End Function</script:module>
130