1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"SearchAndReplace" script:
language=
"StarBasic">' ***
21 ' SearchAndReplace basic script
22 ' Uses a user interface to search and replace the specified strings
24 ' author Neil Montgomery
25 ' created August
12,
2002
29 ' Main subprocedure to start script
35 ' Global reference to the dialog object
39 ' Uses the loadDialog subprocedure to load and execute the dialog box
41 oDialog = loadDialog(
"Standard
",
"SearchAndReplaceDialog
")
48 ' Loads the dialog from the dialog library
50 ' param Libname the library name where dialog is stored
51 ' param DialogName the name of the dialog
52 ' param oLibContainer library container to hold the loaded dialog library (optional)
53 ' return runtime dialog object
55 Function loadDialog(Libname as String, DialogName as String, Optional oLibContainer)
57 Dim oLibDialog as Object
58 Dim oRuntimeDialog as Object
60 If isMissing(oLibContainer ) then
61 oLibContainer = DialogLibraries
63 oLibContainer.loadLibrary(LibName)
64 oLib = oLibContainer.getByName(Libname)
65 oLibDialog = oLib.getByName(DialogName)
66 oRuntimeDialog = createUnoDialog(oLibDialog)
67 loadDialog() = oRuntimeDialog
73 ' Creates a connection to the current document.
74 ' Gets the search and replace keys from the dialog and replaces all
75 ' instances of the search key with the replace key.
79 Dim oDocument As Object
82 Dim oFoundCursor As Object
83 Dim oSearchText as Object
84 Dim oReplaceText as Object
86 ' Create a document object for the current document then create text and
88 oDocument = StarDesktop.ActiveFrame.Controller.Model
89 oSearch = oDocument.createSearchDescriptor
91 ' Replace all instances of the search string with the replace string
92 oSearch.SearchString = getSearchKey()
93 oSearch.ReplaceString = getReplaceKey()
94 oDocument.replaceAll(oSearch)
99 ' Gets the search key string from the dialog
101 ' returns string representing the search key
103 Function getSearchKey() as String
104 Dim sSearch As String
106 ' Get the search key from the dialog
107 oSearchText = oDialog.GetControl(
"SearchKeyTextBox
")
108 sSearch = oSearchText.Text
109 getSearchKey = sSearch
115 ' Gets the replace key string from the dialog
117 ' returns string representing the replace key
119 Function getReplaceKey() as String
120 Dim sReplace As String
122 ' Get the replace key from the dialog
123 oReplaceText = oDialog.GetControl(
"ReplaceKeyTextBox
")
124 sReplace = oReplaceText.Text
125 getReplaceKey = sReplace
126 End Function
</script:module>