[Solved] Display Full Path to Document in LibreOffice Window Title
Posted: Wed Sep 06, 2023 2:39 am
I've been struggling with this for over 12 hours and I finally got a macro that works. I got the code for this from Lupp's entry in How to view ‘full path’ of open document?
So working from there the code I ended up with is. (EDIT: Do not use this code it doesn't work well. I have given new code that works below.):
It works after a fashion. However, Lupp notes the following:
I think what is happening is that when the macro gets to the line u = ThisComponent.URL The value of 'u' is always an empty string (if I can put it that way) and hence the Window Title doesn't end up showing the full path to the file.
Does anyone know how to fix this? I do have a working macro but having to Reload the document after it has been saved is a bit of hassle. I want to avoid having to do a Reload, if that is possible. (I hope I am making my meaning clear.)
So working from there the code I ended up with is. (EDIT: Do not use this code it doesn't work well. I have given new code that works below.):
Code: Select all
REM ***** BASIC *****
Sub onViewCreated()
showFileLocationInTitleBarSystemStyle(True)
End Sub
Sub onDocumentSavedAs()
showFileLocationInTitleBarSystemStyle(True)
End Sub
Sub showFileLocationInTitleBarSystemStyle()
u = ThisComponent.URL
If u = "" Then Exit Sub REM The document was not yet stored.
ThisComponent.Title = ConvertFromUrl(u)
End Sub
Sub Main
End Sub
When I assign the relevant two sub-routines of the macro to the 'events' noted above (in red bold and underlined) they don't work as I think Lupp intended. To get them to work I have to manually (after "saving the document as") do a File > Reload and then the full path to the newly saved document works.
Edit: After some additional considerations, and rgearding specific effects occurring during the debugging of any Basic code, I would dissuade from assigning the macro to Activate document. I assigned it instead to View created and to Document has been saved as as well. So far this works as I like it.
I think what is happening is that when the macro gets to the line u = ThisComponent.URL The value of 'u' is always an empty string (if I can put it that way) and hence the Window Title doesn't end up showing the full path to the file.
Does anyone know how to fix this? I do have a working macro but having to Reload the document after it has been saved is a bit of hassle. I want to avoid having to do a Reload, if that is possible. (I hope I am making my meaning clear.)