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