I want to prevent the user from saving on top of the original file.
Setting to read-only is not an option since the user needs to run my macro which creates a folder on our server and saves the file there.
I need help with the code to stop the Save action, see placeholder " ' some code here to stop the Save"
' can't make the file Read-Only, otherwise the SaveToServer macro won't run
' this macro runs on event Save, prevents user from Saving over original file
Sub ProtectOriginalFile
Dim oDoc as Object 'prob don't need this
oDoc = ThisComponent 'prob don't need this
If Filename = "retail.ods" Then
MsgBox ("Save to Quotes folder first!!", MB_OK + MB_ICONEXCLAMATION,"Warning")
' some code here to stop the Save
Exit Sub
End If
End Sub
Function Filename
Dim url as new com.sun.star.util.URL
Dim srv, bSuccess as Boolean
sURL = thiscomponent.getURL()
srv = createUnoService("com.sun.star.util.URLTransformer")
url.Complete = sURL
srv.parseStrict(url)
Filename = url.Name
End Function
Last edited by bartjeman on Wed Nov 06, 2019 6:17 pm, edited 1 time in total.
Tips:
Use the Template file format (.ots). When the user opens a template file, it will lost the URL where it was loaded-in from. It will be appeared as "Untitled1". The user (if he/she not know the file name and URL) can not save the modified document back to the original place accidentally.
Use a prepared Icon (link) for opening the Template. Then the user will not see even the file name... (yes, he/she can edit the link, if he/she WANT anyway to see the URL .)
Last edited by Zizi64 on Wed Nov 06, 2019 12:31 pm, edited 1 time in total.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
REM Author: Paolo Mantovani
REM Modifed: Andrew Pitonyak
Option Explicit
Global oDispatchInterceptor
Global oSlaveDispatchProvider
Global oMasterDispatchProvider
Global oFrame
Global bDebug As Boolean
'________________________________________________________
Sub RegisterInterceptor
Dim oFrame : oFrame = ThisComponent.currentController.Frame
Dim s$ : s = "com.sun.star.frame.XDispatchProviderInterceptor"
oDispatchInterceptor = CreateUnoListener("ThisFrame_", s)
oFrame.registerDispatchProviderInterceptor(oDispatchInterceptor)
End Sub
'________________________________________________________
Sub ReleaseInterceptor()
On Error Resume Next
oFrame.releaseDispatchProviderInterceptor(oDispatchInterceptor)
End Sub
'________________________________________________________
Function ThisFrame_queryDispatch ( oUrl As Object, _
sTargetFrameName As String, lFlags As Long ) As Variant
Dim oDisp
Dim s$
'the slot protocol causes ooo crash...
If oUrl.protocol = "slot:" Then
Exit Function
End If
If bDebug Then
Print oUrl.complete, sTargetFrameName, lFlags
End If
s = sTargetFrameName
oDisp = oSlaveDispatchProvider.queryDispatch( oUrl, s, lFlags )
'do your management here
Select Case oUrl.complete
Case ".uno:Save" 'disable the save command
Exit Function
'Case "..."
'...
Case Else
' do nothing
End Select
ThisFrame_queryDispatch = oDisp
End Function
'________________________________________________________
Function ThisFrame_queryDispatches ( mDispArray ) As Variant
ThisFrame_queryDispatches = mDispArray
End Function
'________________________________________________________
Function ThisFrame_getSlaveDispatchProvider ( ) As Variant
ThisFrame_getSlaveDispatchProvider = oSlaveDispatchProvider
End Function
'________________________________________________________
Sub ThisFrame_setSlaveDispatchProvider ( oSDP )
oSlaveDispatchProvider = oSDP
End Sub
'________________________________________________________
Function ThisFrame_getMasterDispatchProvider ( ) As Variant
ThisFrame_getMasterDispatchProvider = oMasterDispatchProvider
End Function
'________________________________________________________
Sub ThisFrame_setMasterDispatchProvider ( oMDP )
oMasterDispatchProvider = oMDP
End Sub
'________________________________________________________
Sub ToggleDebug()
'be carefull! you will have a debug message
' for each dispatch....
bDebug = Not bDebug
End Sub
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
You can also just disable the Save Button by pretending the file hasn't changed:
Code: Select all Expand view
ThisComponent.setModified(False)
Note:
The Save function (the toolbar button and the menu item) is active in the newer versions of the LibreOffice even if the document has not changed.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
You can also just disable the Save Button by pretending the file hasn't changed:
Code: Select all Expand view
ThisComponent.setModified(False)
Note:
The Save function (the toolbar button and the menu item) is active in the newer versions of the LibreOffice even if the document has not changed.
oh, you're right. Thank you! Fortunately the OP can make usage of the template solution.