Page 1 of 1

[Solved] Function for Search Bar (Ctrl+F)

Posted: Sat Mar 03, 2018 10:56 am
by linuxyz
Hi!
I've found the function to display the search dialog (triggered by Ctrl+H), it's

Code: Select all

.uno:SearchDialog
like in :

Code: Select all

dispatcher.executeDispatch(document, ".uno:SearchDialog", "", 0, Array())
But I haven't found the function to display the search bar, at the bottom (triggered by Ctrl+F), Does it exist?

Thanks a lot in advance!

Re: Function for Search Bar (Ctrl+F)

Posted: Sat Mar 03, 2018 11:34 am
by Zizi64
But I haven't found the function to display the search bar, at the bottom (triggered by Ctrl+F), Does it exist?

Thanks a lot in advance!
openoffice 4.1.5-1 on Linux Arch

Are you using the LibreOffice?

Re: Function for Search Bar (Ctrl+F)

Posted: Sat Mar 03, 2018 12:57 pm
by Villeroy
Run this against some spreadsheet document. It generates a new spreadsheet with all availlable spreadsheet dispatches. Can be used with any other type of frame as well.

Code: Select all

Sub fetchDispatchInformation()
REM dump current frame's "ConfigurableDispatchInformation" into a new spreadsheet as hyperlinks
REM if the current frame happens to be a spreadsheet frame, you can test the hyperlinks
  Dim oCurrentController As Variant
  Dim oFrame As Variant
  Dim oConfigurableDispatchInformation As Variant
  Dim oConfigurableDispatchInformation2 As Variant
  Dim oConfigurableDispatchInformation3 As Variant

  oCurrentController = ThisComponent.getCurrentController()
  oFrame = oCurrentController.getFrame()
	oDoc = StarDesktop.loadComponentFromURL("private:factory/scalc","_blank",0,Array())
	sh = oDoc.Sheets.getByIndex(0)
	c = 0

on error goto exitErr
do
  oConfigurableDispatchInformation = oFrame.getConfigurableDispatchInformation(c)
	for each p in oConfigurableDispatchInformation
		sh.getCellByPosition(c,r).setFormula("=HYPERLINK("""& p.Command &""")")
		r = r +1
	next p
  c = c +1
  r = 0
loop
exitErr:
End Sub
Made with a little help from my friend: [Tutorial] Introduction into object inspection with MRI

Re: Function for Search Bar (Ctrl+F)

Posted: Sat Mar 03, 2018 1:46 pm
by Villeroy
It is vnd.sun.star.findbar:FocusToFindbar
I found it in <profile>/config/soffice.cfg/modules/scalc/menubar/menubar.xml

Re: Function for Search Bar (Ctrl+F)

Posted: Sat Mar 03, 2018 6:50 pm
by linuxyz
Thanks a lot! I'm almost there though... How do you call it in the script?
I've tried :

Code: Select all

dispatcher = createUnoService("com.sun.star.frame.DispatchHelper", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:FocusToFindbar", "", 0, Array())
But that's not the right thing evidently... I'm still very new to macro script, sorry.

Re: Function for Search Bar (Ctrl+F)

Posted: Sat Mar 03, 2018 8:30 pm
by Villeroy
The url is "vnd.sun.star.findbar:FocusToFindbar".

Re: Function for Search Bar (Ctrl+F)

Posted: Sat Mar 03, 2018 10:27 pm
by linuxyz
Sorry, I didn't changed that.
I've tried:

Code: Select all

dim dispatcher as object
dim document as object
document = ThisComponent.CurrentController.Frame

dispatcher = createUnoService("vnd.sun.star.findbar", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:FocusToFindbar", "", 0, Array())
But I get for the last line:

Code: Select all

"object variable not set
how do I call this function?

Re: Function for Search Bar (Ctrl+F)

Posted: Sun Mar 04, 2018 9:34 am
by Zizi64
Please upload the full code of the subroutine (or a sample ODF file with the embedded macro).


Are you using the "Option explicit" at the begin of the Module?
If the answer is Yes, then you need declare the variable Array() too.


How to get the dispacher:

Code: Select all

dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

Re: Function for Search Bar (Ctrl+F)

Posted: Sun Mar 04, 2018 11:43 am
by linuxyz
Phew! Eventually I've got it right!
Thanks @Zizi64 and @Villeroy for the help.

Here's the code working:

Code: Select all

Sub test_findbar
dim document as object
dim dispatcher as object

dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, "vnd.sun.star.findbar:FocusToFindbar", "", 0, Array())
End Sub

Re: [SOLVED] Function for Search Bar (Ctrl+F)

Posted: Sun Mar 04, 2018 12:27 pm
by RoryOF

Re: [SOLVED] Function for Search Bar (Ctrl+F)

Posted: Sun Mar 04, 2018 12:53 pm
by linuxyz
Nobody answered there (I've tried the mailing list too, without success). I could have deleted the post there but I thought it better not deleting it for future users...

Re: [Solved] Function for Search Bar (Ctrl+F)

Posted: Sun Mar 04, 2018 6:00 pm
by Hagar Delest
Of course this discussion should be kept since you got your help here. This is indeed expected to be a knowledge database.