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