Extended file information (full path) in TitleBar

Shared Libraries
Forum rules
For sharing working examples of macros / scripts. These can be in any script language supported by OpenOffice.org [Basic, Python, Netbean] or as source code files in Java or C# even - but requires the actual source code listing. This section is not for asking questions about writing your own macros.
Post Reply
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Extended file information (full path) in TitleBar

Post by Lupp »

The following code is from a module 'appStart' in my Basic macros Standard library. (location=application)
The two one-liners are assigned to the document events hinted in their names (for the application, not stored to documents).

Code: Select all

Global Const preferredTitleStyle = 1

Sub onViewCreated()
showFileLocationInTitleBar(preferredTitleStyle)
End Sub

Sub onDoumentSavedAs()
showFileLocationInTitleBar(preferredTitleStyle)
End Sub

Sub showFileLocationInTitleBar(Optional pTitleStyle As Long)
REM pTitleStyle for 0: full URL; 1: URL without protocol part; 2: OS style
On Local Error Goto fail
If IsMissing(pTitleStyle) Then pTitleStyle = 1
Dim newTitle As String, url As String 
url = ThisComponent.URL
If url = "" Then Exit Sub REM The document was not yet stored.
Select Case pTitleStyle
  Case 0
    newTitle = url
  Case 1
    newTitle = Split(url, "://")(1)
  Case 2
    newTitle = ConvertFromURL(url)
  Case Else
    newTitle = "" REM Same effect as newTitle = ThisComponent.Title
    REM Nothing implemented.
End Select
If newTitle<>"" Then ThisComponent.Title = newTitle
fail:
End Sub
I wrote the little poem years ago for an answer to a respective question somewere in one of the community sites I contribute to.

Well I actually wrote thousands of lines in "pursuit of happiness" when challenging questions were asked, often well knowing there was no real value in the suggested solution.

I also wrote code (little task-forces) coming from own experiences and needs. Now and then -but not often- I even use parts oft it. The only little piece of Basic code I actualy use every day is the tiny thing posted above. My legacy?

Of course, very similar code for the purpose working as well or even having enhanced power may be published in hundreds of places. Don't know. My apologies if such code already was posted in this forum, and I didn't know.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
karolus
Volunteer
Posts: 1158
Joined: Sat Jul 02, 2011 9:47 am

Re: Extended file information (full path) in TitleBar

Post by karolus »

Hello

@Lupp: Nice Example!

and of course I'd rewrite it in python, assigned to Event 'View created' :

Code: Select all

from pathlib import Path


def more_informative_title(event):
    doc = event.Source
    if doc.URL == "":
        return
    p = Path(doc.URL)
    parts = p.parts 
    limit = min( [ len(parts), 3 ] )
    doc.Title = f"{ Path( *parts[ -limit : ] ) }"
 
Sorry for only 9 lines of code!
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Extended file information (full path) in TitleBar

Post by Lupp »

@karolus
You surely will knock me off the ring one day. This time you may barbecue two spare lines. The (bit of) additional functionality concerning components not previously saved may serve as the mustard. Enjoy.

Code: Select all

Sub onViewCreatedAmputated(pEvent)
Dim URLstruct As New com.sun.star.util.URL, parser, succ
parser = CreateUnoService("com.sun.star.util.URLTransformer")
URLstruct.Complete = pEvent.Source.URL
succ = parser.parseStrict(URLstruct)
If succ Then pEvent.Source.Title = URLstruct.Path & URLstruct.Name
End Sub
The above used service from the AOO/LibO API may not be as well renowned as Python's pathlib, and I therefore didn't use it in the original version.

All the other lines should have added functionality or offered flexibility. Not in every case titlebar manipulation will be the only concern "onViewCreated" or related component events.

Bug tdf#144162 will apply in every case (as long as not fixed) independent of the programming tools used. Sorry.

If you are interested in a serious exchange about preferrable tools for different tasks of programming, you may start with a PM.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
karolus
Volunteer
Posts: 1158
Joined: Sat Jul 02, 2011 9:47 am

Re: Extended file information (full path) in TitleBar

Post by karolus »

Hallo
The one and only reason I've introduced 'pathlib' was:
I want to show only the last 3 Path-parts for Example pi/Documents/example.ods … instead full path /home/pi/Documents/example.ods

you want to see less loc:

Code: Select all

def more_informative_title(event):
    if event.Source.URL == "":
        return
    event.Source.Title = event.Source.URL.rpartition('://')[-1]
nb. The real Text in Titlebar is for example: pi/Downloads/example.ods - LibreOffice Calc'
this is from:

Code: Select all

doc.CurrentController.ComponentWindow.AccessibleContext.AccessibleParent.AccessibleContext.TitledBorderText
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Extended file information (full path) in TitleBar

Post by JeJe »

doc.CurrentController.ComponentWindow.AccessibleContext.AccessibleParent.AccessibleContext.TitledBorderText
doc.CurrentController.frame.title
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
karolus
Volunteer
Posts: 1158
Joined: Sat Jul 02, 2011 9:47 am

Re: Extended file information (full path) in TitleBar

Post by karolus »

JeJe wrote:
doc.CurrentController.ComponentWindow.AccessibleContext.AccessibleParent.AccessibleContext.TitledBorderText
doc.CurrentController.frame.title
blame on me, didnt realize thats not the same as 'doc.Title'
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
Post Reply