ExecuteSearch versus createSearchDescriptor

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
NorthTexasOldMan
Posts: 18
Joined: Thu Jan 16, 2014 2:22 am

ExecuteSearch versus createSearchDescriptor

Post by NorthTexasOldMan »

If I record a macro in Writer I can limit the search to selected text.

args1(0).Name = "SearchItem.SearchFlags"
args1(0).Value = 6144
dispatcher.executeDispatch(doc, ".uno:ExecuteSearch", "", 0, args1())

However createsearchdescriptor will not recognize searchflags=6144

I'm confused because executeSearch will find
args1(0).Name = "SearchItem.SearchString"
args1(0).Value = "Find this"
and
createsearchdescriptor will also find SearchString="Find this"

Can createsearchdescriptor search only selected text?
Open Office 3.4.1 on Windows 7
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: ExecuteSearch versus createSearchDescriptor

Post by Villeroy »

Don't waste your time with all this bullshit. It's not worth it. menu:Edit>Find&Replace (Ctrl+F) is the way to go when using this office suite.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
birnbacs
Posts: 1
Joined: Tue Oct 12, 2021 9:51 am

Re: ExecuteSearch versus createSearchDescriptor

Post by birnbacs »

That's a sorry answer. OO find function is bad enough as it is, any attempt to make it more useable through macros should be encouraged.

@NorthTexasOldMan: try searchflags=2048
OpenOffice 7.1.3.2 on Mac OS X 10.15.7
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: ExecuteSearch versus createSearchDescriptor

Post by JeJe »

birnbacs - the searchdescriptor in OO doesn't have a searchflags property.

I could be wrong but I think the dispatch helper has to be used for a find in a selection... though you can use compareRegionEnds/starts to go through a search result and see if its in a selection/range
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: ExecuteSearch versus createSearchDescriptor

Post by JeJe »

For a find all in a selection you can try something like this:

Temporarily apply a property to the selection(s) that you don't use... such as charflash... then search for that property and your other attributes, then remove the charflash.

Code: Select all




sels= thiscomponent.currentcontroller.selection

for i = 0 to sels.count -1
sels(i).charflash= true
next

'insert your find all code here - include the charflash property.

for i = 0 to sels.count -1
sels(i).charflash= false
next


Edit: some small mods
Edit2: simplified, don't seem to need temporary array of sel ranges.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2779
Joined: Wed Mar 09, 2016 2:40 pm

Re: ExecuteSearch versus createSearchDescriptor

Post by JeJe »

Slightly more rigorous to find and restore any existing text with charflash:

Code: Select all


sub FindAllInSelection
	Dim SrchAttributes(0) as new com.sun.star.beans.PropertyValue
	dim doc,sels,find,flashfind,i as long
	
	doc = thiscomponent
	sels= doc.currentcontroller.selection
	find = Doc.createSearchDescriptor
	SrchAttributes(C).NAME = "CharFlash"
	SrchAttributes(C).VALUE = true
	Find.SetSearchAttributes(SrchAttributes())
	flashfind= doc.findall(find)

	if flashfind.count >0 then
		for i = 0 to flashfind.count -1
			flashfind(i).charflash = false
		next
	end if

	for i = 0 to sels.count -1
		sels(i).charflash= true
	next

'insert your find all code here - include the charflash property.

	for i = 0 to sels.count -1
		sels(i).charflash= false
	next

	if flashfind.count >0 then
		for i = 0 to flashfind.count -1
			flashfind(i).charflash = true
		next
	end if
end sub


Edit: oops... added clearing existing charflash if any
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Lupp
Volunteer
Posts: 3548
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: ExecuteSearch versus createSearchDescriptor

Post by Lupp »

birnbacs wrote:That's a sorry answer. OO find function is bad enough as it is, any attempt to make it more useable through macros should be encouraged.
@NorthTexasOldMan: try searchflags=2048
1. The original question by NorthTexasOldMan was posted 2014-07-20. The questioners last visit to the forum was 2014-08-02 20:38.

2. OpenOffice (OO) is a name not used by LibreOffice for (assumed) legal reasons. It's used by Apache for their branch of the software. Your Signature is telling you are using a recent version of LibreOffice.

3. With Ctrl+F you may open the FindBar with its limited functionality. To get the dialog for the much more powerful Find&Replace tool, you can use (in LibO) Ctrl+H by default. Using this dialog you get all the available options. No "macros" needed - except for very special reoccurring tasks, probably.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
Post Reply