diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /scripting/examples/basic/SearchAndReplace.xba | |
parent | Initial commit. (diff) | |
download | libreoffice-upstream.tar.xz libreoffice-upstream.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'scripting/examples/basic/SearchAndReplace.xba')
-rw-r--r-- | scripting/examples/basic/SearchAndReplace.xba | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/scripting/examples/basic/SearchAndReplace.xba b/scripting/examples/basic/SearchAndReplace.xba new file mode 100644 index 000000000..24c61d8e9 --- /dev/null +++ b/scripting/examples/basic/SearchAndReplace.xba @@ -0,0 +1,126 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . +--> +<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 replace 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> |