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">' ***
4 ' SearchAndReplace basic script
5 ' Uses a user interface to search and replace the specified strings
7 ' author Neil Montgomery
8 ' created August
12,
2002
12 ' Main subprocedure to start script
18 ' Global reference to the dialog object
22 ' Uses the loadDialog subprocedure to load and execute the dialog box
24 oDialog = loadDialog(
"Standard
",
"SearchAndReplaceDialog
")
31 ' Loads the dialog from the dialog library
33 ' param Libname the library name where dialog is stored
34 ' param DialogName the name of the dialog
35 ' param oLibContainer library container to hold the loaded dialog library (optional)
36 ' return runtime dialog object
38 Function loadDialog(Libname as String, DialogName as String, Optional oLibContainer)
40 Dim oLibDialog as Object
41 Dim oRuntimeDialog as Object
43 If isMissing(oLibContainer ) then
44 oLibContainer = DialogLibraries
46 oLibContainer.loadLibrary(LibName)
47 oLib = oLibContainer.getByName(Libname)
48 oLibDialog = oLib.getByName(DialogName)
49 oRuntimeDialog = createUnoDialog(oLibDialog)
50 loadDialog() = oRuntimeDialog
56 ' Creates a connection to the current document.
57 ' Gets the search and replace keys from the dialog and replaces all
58 ' instances of the search key with the replace key.
62 Dim oDocument As Object
65 Dim oFoundCursor As Object
66 Dim oSearchText as Object
67 Dim oReplaceText as Object
69 ' Create a document object for the current document then create text and
71 oDocument = StarDesktop.ActiveFrame.Controller.Model
72 oSearch = oDocument.createSearchDescriptor
74 ' Replace all instances of the search string with the replavce string
75 oSearch.SearchString = getSearchKey()
76 oSearch.ReplaceString = getReplaceKey()
77 oDocument.replaceAll(oSearch)
82 ' Gets the search key string from the dialog
84 ' returns string representing the search key
86 Function getSearchKey() as String
89 ' Get the search key from the dialog
90 oSearchText = oDialog.GetControl(
"SearchKeyTextBox
")
91 sSearch = oSearchText.Text
92 getSearchKey = sSearch
98 ' Gets the replace key string from the dialog
100 ' returns string representing the replace key
102 Function getReplaceKey() as String
103 Dim sReplace As String
105 ' Get the replace key from the dialog
106 oReplaceText = oDialog.GetControl(
"ReplaceKeyTextBox
")
107 sReplace = oReplaceText.Text
108 getReplaceKey = sReplace
109 End Function
</script:module>