Forum at OOoForum.orgThe Forum
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Use OOWriter as a Diff-Viewer in TortoiseSVN

Post new topic   Reply to topic Forum Index -> Code Snippets
View previous topic :: View next topic  
Author Message

Joined: 19 Sep 2004
Posts: 1

PostPosted: Sun Sep 19, 2004 4:54 am    Post subject: Use OOWriter as a Diff-Viewer in TortoiseSVN Reply with quote

1.) Create a new module diffViewer in the standard rep. with these subs (only the first 2 are from me. the rest is from this thread:


Sub diff( baseFile )
   ' get rid of the +
   baseFile = Mid(baseFile, 2)
   TextToClipboard( baseFile )
   MsgBox("Use paste to enter the base file.")
End Sub

Sub dispatchCompareDocuments
   rem ----------------------------------------------------------------------
   rem define variables
   dim document   as object
   dim dispatcher as object
   rem ----------------------------------------------------------------------

   document   = ThisComponent.CurrentController.Frame
   dispatcher = createUnoService("")
   dispatcher.executeDispatch(document, ".uno:CompareDocuments", "", 0, Array())
End Sub

' Given a string of text, put that text into the clipboard.
' This works by...
'   1. Invisibly create a new Writer document
'   2. Insert text into that document.
'   3. Select All
'   4. Copy
'   5. Close the invisible writer document.
' So what ends up in the clipboard can be pasted to an external
'  program as Text.  But the clipboard contains additional information
'  about the text, such as whatever default font and style it had in
'  the temporary Writer document.
Sub TextToClipboard( ByVal cText As String )
   oDoc = StarDesktop.loadComponentFromURL( "private:factory/swriter", "_blank", 0,_
      Array( MakePropertyValue( "Hidden", True ) ) )

   ' Get the text of the document.
   oText = oDoc.getText()
   ' Get a cursor that can move over or to any part of the text.
   oCursor = oText.createTextCursor()
   ' Insert text and paragraph breaks into the text, at the cursor position.
   oText.insertString( oCursor, cText, False )
   SelectAll( oDoc )
   ClipboardCopy( oDoc )
   oDoc.close( True )
End Sub

' The MakePropertyValue() function is defined here...
Function MakePropertyValue( Optional cName As String, Optional uValue ) As
   oPropertyValue = createUnoStruct( "" )
   If Not IsMissing( cName ) Then
      oPropertyValue.Name = cName
   If Not IsMissing( uValue ) Then
      oPropertyValue.Value = uValue
   MakePropertyValue() = oPropertyValue
End Function

' Routines from
'    Making the Dispatcher easier to use

Sub ClipboardPaste( oDocumentFrame )
   DocumentDispatch( oDocumentFrame, ".uno:Paste" )
End Sub

Sub ClipboardCopy( oDocumentFrame )
   DocumentDispatch( oDocumentFrame, ".uno:Copy" )
End Sub

Sub ClipboardCut( oDocumentFrame )
   DocumentDispatch( oDocumentFrame, ".uno:Cut" )
End Sub

Sub SelectAll( oDocumentFrame )
   DocumentDispatch( oDocumentFrame, ".uno:SelectAll" )
'   DocumentDispatch( oDocumentFrame, "slot:5723" )
End Sub

' An easy to use Dispatch on an office document.
' Arguments are similar to the args for the
'  interface of
' What makes this so easy to use are two things:
'   1. The fact that the oDocumentFrame parameter can actually accept
'      either the document model or one of its controllers.
'   2. The optional parameters.
' For an example of how simple this routine is to use, see
'  routines such as ClipboardCopy().
' Parameters:
'      oDocumentFrame      -   An office document frame.
'                        But wait!  It could be the document controller
'                         or the document model.  This routine will find
'                         the document frame from either of these.
'      cURL            -   The dispatch URL.
' Optional:
'      cTargetFrameName   -   Defaults to blank.
'      nSearchFlags      -   Defaults to zero.
'      aDispatchArgs      -   Defaults an an empty sequence.
Sub DocumentDispatch( ByVal oDocumentFrame As Object,_
                  ByVal cURL As String,_
                  Optional cTargetFrameName,_
                  Optional nSearchFlags,_
                  Optional aDispatchArgs )
   ' If they gave us the wrong parameter...
   If Not HasUnoInterfaces( oDocumentFrame, "" ) Then
      ' Be sure that we've got the document frame.
      ' Someone might have passed us the document model or one of
      '  its controller's.
      oDocumentFrame = GetDocumentFrame( oDocumentFrame )
   If IsMissing( cTargetFrameName ) Then
      cTargetFrameName = ""
   If IsMissing( nSearchFlags ) Then
      nSearchFlags = 0
   If IsMissing( aDispatchArgs ) Then
      aDispatchArgs = Array()
   oDispatchHelper = createUnoService( "" )
   oDispatchHelper.executeDispatch( oDocumentFrame, cURL, cTargetFrameName, nSearchFlags, aDispatchArgs )
End Sub

' Routines from
'    Document model, controller and frame

' This will always return the document's frame.
' Pass in any one of...
'   * the document's model (subclass of
'   * the document's controller
'   * the document's frame
Function GetDocumentFrame( oDoc As Object ) As Object
   Dim oFrame As Object
   ' If the caller gave us the document model...
   If oDoc.supportsService( "" ) Then
      ' ...then get the controller from that.
      oCtrl = oDoc.getCurrentController()
      ' ...then get the frame from the controller.
      oFrame = oCtrl.getFrame()

   ' If the caller gave us a document controller...
   ElseIf HasUnoInterfaces( oDoc, "" ) Then
      oCtrl = oDoc
      ' ...then get the frame from the controller.
      oFrame = oCtrl.getFrame()
   ' If the caller gave us the document frame...
   ElseIf HasUnoInterfaces( oDoc, "" ) Then
      ' ...thanks!  That's just what we wanted!
      oFrame = oDoc
      ' The caller did not give us what we expected!
      MsgBox( "GetDocumentFrame called with incorrect parameter." )
   GetDocumentFrame() = oFrame
End Function

2) Open TortoiseSVN Settings -> Tab Diff/Merge -> DivProg. -> Advanced...

3) Add a new entry:

extension: sxw
external program:
C:\Programme\OpenOffice.org1.1.1\program\soffice.exe %base %mine macro:///Standard.diffViewer.diff(""+%base)

This is actually quite a croppy workaround. I don't know how to pass the correct argument to the dispatched CompareDocuments. Maybe there are some bugs, too. See it as a basis for further enhancements Smile

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Forum Index -> Code Snippets All times are GMT - 8 Hours
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group