A developer
A developer

Reputation: 13

How to change the document name via UNO?

I use UNO from Java to control LibreOffice (5.3).
How do I change the document name displayed in the window title bar?

So far I tried to use XDocumentProperties, but it only sets the title in the document's embedded properties and not in the window title:

// Sets only meta data, not the window title.
XDocumentPropertiesSupplier xDocumentPropertiesSupplier = UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, openedDocument);
XDocumentProperties xDocumentProperties = xDocumentPropertiesSupplier.getDocumentProperties();
xDocumentProperties.setTitle(retrievedFile.name);

Upvotes: 0

Views: 153

Answers (1)

Jim K
Jim K

Reputation: 13790

Normally, simply call storeAsURL from XStorable.

However, for special cases such as streaming, you may want to use XDocumentProperties. Call setTitle() as in the following C++ code from https://forum.openoffice.org/en/forum/viewtopic.php?f=25&t=70156.

Reference<XModel> xModel(xComponent, UNO_QUERY);
Reference<XTitle> xTitle(xModel, UNO_QUERY);
xTitle->setTitle(constOUString("Title"));

EDIT:

Here is the XTitle code from your rejected edit.

XTitle xTitle = UnoRuntime.queryInterface(XTitle.class, xComponent /* e.g. from xComponentLoader.loadComponentFromURL(...) */);
xTitle.setTitle("Title");

Note: As the reviewers wrote, this should have been added in comments or a separate answer, not an edit. It is almost never a good idea to edit someone else's code on this site. However, it is perfectly acceptable to answer your own question.

Upvotes: 1

Related Questions