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
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.