Hi Mathias,

Alle 16:50, martedì 5 settembre 2006, Mathias Bauer ha scritto:
> Cor Nouws wrote:
> > Hi *,
> >
> > In order to force/advice the saving of certain documents on a specified
> > location, I prepared some macro's, looking at the documents state, name
> > and such, and opening the save-dialog.
> > Then I assigned the macro's to Save(-As) with Tools|Customisation|Events
> > in order that a click on the 'floppy' or File|Save triggers my macro.
> >
> > However, it appears (2.0.3, on XP, 2.0.2 on Madrake) that my code is
> > triggered áfter the regular Save(-As) actions :-\
>
> Yes and no. Your code will be triggered right after the dialog is closed
> but before the real saving starts. These events are means to perform
> actions on the document before they get saved, not as a hook to replace
> the built-in UI code.
>
> > What am I supposed to do to actually replace those?
>
> This is what DispatchInterceptors are for. Unfortunately you can't
> implement them in Basic. Replacing dispatch actions triggered by the UI
> with macros is currently not supported. Sounds like a good idea though.

Although an "official" support is actually missing, with a "creative" ;-) use 
of the createUnoListener() function it's possible to intercept dispatches and 
replace dispatch actions with your arbitrary basic code.

See for example the demo code below:
(please, restore lines broken from the mailer before your test)

REM  *****  BASIC  *****

Option Explicit

Global oDispatchInterceptor
Global oSlaveDispatchProvider
Global oMasterDispatchProvider
Global oFrame
Global bDebug As Boolean

Dim oCopyDispatch

'_______________________________________________________________________________________________________________________
Sub RegisterInterceptor
  oFrame = ThisComponent.currentController.Frame
  oDispatchInterceptor = CreateUnoListener("ThisFrame_", _
    "com.sun.star.frame.XDispatchProviderInterceptor")
  oFrame.registerDispatchProviderInterceptor(oDispatchInterceptor)
End Sub
  

'_______________________________________________________________________________________________________________________
Sub ReleaseInterceptor()
On Error Resume Next
  oFrame.releaseDispatchProviderInterceptor(oDispatchInterceptor)
End Sub


'_______________________________________________________________________________________________________________________
Function ThisFrame_queryDispatch ( oUrl, _
  sTargetFrameName As String, lSearchFlags As Long ) As Variant
  
Dim oDisp
Dim sUrl As String

  'slot protocol causes OOo crash...
  if oUrl.Protocol = "slot:" Then
    Exit Function
  End If
  
  If bDebug Then
    Print oUrl.complete
  End If
  
  'do your dispatch management here:
  Select Case oUrl.complete
  
    Case ".uno:Copy" 
      oDisp = GetCopyDispatch 'replace the original dispatch
    Case ".uno:Paste" 
      oDisp = GetCopyDispatch 'replace the original dispatch
    Case ".uno:Save" 
      oDisp = GetCopyDispatch 'replace the original dispatch
    Case ".uno:Undo"
      oDisp = GetCopyDispatch 'replace the original dispatch
    'Case ".uno:blabla"
      'do something
    Case Else
      oDisp = _
      oSlaveDispatchProvider.queryDispatch( oUrl, sTargetFrameName, 
lSearchFlags )
      
  End Select
  
  ThisFrame_queryDispatch = oDisp

End Function


'_______________________________________________________________________________________________________________________
Function ThisFrame_queryDispatches ( mDispatches ) As Variant
  'ThisFrame_queryDispatches = mDispatches()
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
  bDebug = Not bDebug
End Sub

'_______________________________________________________________________________________________________________________
Function GetCopyDispatch()
  If Not IsNull(oCopyDispatch) Then
    oCopyDispatch = _
      CreateUnoListener("MyCustom_", "com.sun.star.frame.XDispatch")
  End If
  
  GetCopyDispatch = oCopyDispatch

End Function

'_______________________________________________________________________________________________________________________
Sub MyCustom_dispatch(URL, Arguments)
  Select Case URL.complete
    Case ".uno:Copy" 
      MsgBox "Sorry, the original " & URL.complete & _
        " dispatch was stolen from Paolo M.", 48
      
    Case ".uno:Paste" 
      ThisComponent.CurrentSelection(0).String = _
        "**** ARBITRARY CLIPBOARD CONTENT PROVIDED BY PAOLO M. ****"
    Case ".uno:Save" 
      MsgBox "Sorry, the original " & URL.complete & _
        " dispatch was stolen from Paolo M.", 48
      
    Case ".uno:Undo"
      MsgBox "Undo What????!!!???", 16

    Case Else

  End Select
End Sub

'_______________________________________________________________________________________________________________________
Sub MyCustom_addStatusListener(Control, URL)
End Sub

'_______________________________________________________________________________________________________________________
Sub MyCustom_removeStatusListener (Control, URL)
End Sub

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to