Page 1 of 1

Synchronous API equivalent for executeDispatch(.uno:UpdateAl

Posted: Sat Dec 29, 2018 6:54 am
by Jambunathan K
I am looking for a Synchronous API equivalent for executeDispatch(.uno:UpdateAll).

Context:

I produce ODT documents by running an Emacs Org-mode document (a plaintext markup format like Markdown). The document so produced is then passed through a Basic Macro via a command line. This macro does exactly what Tools->Update->Update All does. Passing the document through a macro ensures that (pagenos in) TOC of the ODT document is up to date.

The macro is invoked via command line as below
soffice --norestore --invisible --headless macro:///OrgMode.Utilities.Reload(file:///home/kjambunathan/Downloads/test.odt)
and

OrgMode.Utilities.Reload is a just a shim over
executeDispatch(..., ".uno:UpdateAll", "", 0, Array())
Problem:

When working with large documents, the above "UpdateAll" fails. This is probably because the macro's Subroutine exits even before the executeDispatch has finished its work. I have read through the forums, and one of the suggested workarounds for this problem is to add a wait after a dispatch. I am not comfortable with this workaround, I would prefer a macro (Basic, Python or Java whatever) that would __guarantee__ me that the fields are up to date before the shell command exits.

So, Can someone help me with Synchronous API equivalent for executeDispatch(.uno:UpdateAll).

Re: Synchronous API equivalent for executeDispatch(.uno:Upda

Posted: Sat Dec 29, 2018 12:04 pm
by Villeroy
doc.updateAll() updates all external links but I'm not sure if this is the only thing you want to update because the user interface command updates all links, fields, indexes, tables of contents, and page formatting in the current document. I'm not familiar with Writer and finding adequate API methods is a nightmare even though I'm very familiar with my object inspector and the general concepts of this API.

Re: Synchronous API equivalent for executeDispatch(.uno:Upda

Posted: Sat Dec 29, 2018 1:21 pm
by Villeroy
oDocumentIndexes = ThisComponent.getDocumentIndexes() returns a collection of indices ( TOC, table index, picture index). Each one seems to have an update() method.

Re: Synchronous API equivalent for executeDispatch(.uno:Upda

Posted: Sat Dec 29, 2018 4:02 pm
by Jambunathan K
Villeroy wrote:doc.updateAll() updates all external links but I'm not sure if this is the only thing you want to update because the user interface command updates all links, fields, indexes, tables of contents, and page formatting in the current document.
My little research suggests that .uno:UpdateAll maps to FN_UPDATE_ALL. (See https://wiki.openoffice.org/wiki/Framew ... x_Commands)

And FN_UPDATE_ALL does precisely this https://github.com/LibreOffice/core/blo ... h.cxx#L667.

One of the things that FN_UPDATE_ALL does is to do FN_UPDATE_FIELDS (See https://github.com/LibreOffice/core/blo ... h.cxx#L645)

FN_UPDATE_FIELDS does
rSh.SwViewShell::UpdateFields(true);
SwViewShell::UpdateFields is documented here https://docs.libreoffice.org/sw/html/cl ... 9f931c059a and it does exactly this https://docs.libreoffice.org/sw/html/vi ... tml#l00655.

Now, I have trouble mapping
GetDoc()->getIDocumentFieldsAccess().UpdateFields(bCloseDB);
to something that could be done starting with an SwXTextDocument object (See https://docs.libreoffice.org/sw/html/cl ... ument.html)

[At this point, I realized that I was too deep in a rabbit hole, abandoned further pursuit and posted my query]

---------------
Villeroy wrote: I'm not familiar with Writer and finding adequate API methods is a nightmare even though I'm very familiar with my object inspector and the general concepts of this API.
I believe you are refering to the XRay tool (See https://wiki.openoffice.org/wiki/Extens ... #Xray_tool). I have the XRay tool and I am comfortable using it. I have also looked at the Andrew's Macro document (See http://www.openoffice.org/documentation ... wMacro.odt). Despite all these efforts, I am a bit stuck with this specific problem--the problem of asynchronous dispatch). I was hoping that someone here would have a quick answer for it.