Bug 139991 - Use user-defined default template when opening 0-byte files with OD* extensions
Summary: Use user-defined default template when opening 0-byte files with OD* extensions
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
(earliest affected)
Hardware: All All
: medium enhancement
Assignee: Not Assigned
Whiteboard: target:7.4.0
Depends on:
Reported: 2021-01-29 06:07 UTC by Mike Kaganski
Modified: 2024-01-18 16:20 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Note You need to log in before you can comment on or make changes to this bug.
Description Mike Kaganski 2021-01-29 06:07:41 UTC
After fixing tdf#133661, the documents created using Windows Explorer's ShellNew command follow some LibreOffice settings (language, fonts). However, they still do not honor user-defined default templates (as configured in File->Templates->Manage Templates). This means that the two methods of creating new LibreOffice documents (from within LibreOffice application, and from Explorer's context menu), which from user's PoV should be interchangeable and give identical results, in fact behave differently: the former method does what user told to do, while the latter ignored user default template setting.

With the fix to tdf#123476, LibreOffice now opens 0-byte files with ODT/ODS/etc extensions as empty documents in the corresponding component. This paves a way to implement the missing functionality: process such files to make them use default templates, and then create empty files in Windows ShellNew handler (i.e., drop soffice.* files in C:\Program Files\LibreOffice\share\template\shellnew, and replace "FileName" with "NullFile" in ShellNew registry subkeys [1]).

We should detect that the opened file that uses our native filter is 0-byte file (tools::isEmptyFileUrl) somewhere before the call to SfxObjectShell::DoLoad, and use SfxObjectFactory::GetStandardTemplate to get the default template for the component service. Then we must use the template to initialize the document, but unlike the normal creation of a new document from a template, we must make it have the name and location of the 0-byte file.

I don't have a specific proposal where should this happen, and how to implement the substitution of temporary storage (that is used for newly created files) with the 0-byte file, thus not marking this an easy hack.

[1] https://docs.microsoft.com/en-us/windows/win32/shell/context#extending-the-new-submenu
Comment 1 V Stuart Foote 2021-01-29 13:47:09 UTC
Comment 2 Commit Notification 2022-04-13 13:47:52 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":


tdf#139991: move 0-byte file handling to SfxFrameLoader_Impl::load

It will be available in 7.4.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:

Affected users are encouraged to test the fix and report feedback.