[Solved] Accept or Reject Writer Changes in code?

Creating a macro - Writing a Script - Using the API

[Solved] Accept or Reject Writer Changes in code?

Postby JeJe » Thu Jan 31, 2019 3:03 pm

Anyone know how to Accept or reject changes in Writer using code?

I've searched hard and can't find a proper way. There is a workaround - replace the redline content with the same content with changes not being recorded - so I can do it but clumsily.

https://www.openoffice.org/api/docs/com ... etRedlines
https://www.openoffice.org/api/docs/com ... dline.html
https://www.openoffice.org/api/docs/com ... rtion.html

The macro record just gives code to show the dialog... not what's called when the Accept or Reject buttons are pressed.

The redlines are accessible through thiscomponent.getredlines
MRI gives the following:

Properties

(Name) (Value Type) (Value) (Info.) (Attr.) (Handle)
Count long 0 Pseud Read_Only
ElementType type com.sun.star.beans.XPropertySet Pseud Read_Only
ImplementationId []byte -SEQUENCE- Pseud Read_Only
ImplementationName string SwXRedlines Pseud Read_Only
SupportedServiceNames []string -SEQUENCE- Pseud Read_Only
Types []type -Sequence- Pseud Read_Only



Methods


(Name) (Arguments) (Return Type) (DeclaringClass) (Exceptions)
acquire () void .uno.XInterface
createEnumeration () .container.XEnumeration .container.XEnumerationAccess .uno.RuntimeException
getByIndex ( [in] long Index ) any .container.XIndexAccess .lang.IndexOutOfBoundsException, .lang.WrappedTargetException
getCount () long .container.XIndexAccess
getElementType () type .container.XElementAccess .uno.RuntimeException
getImplementationId () []byte .lang.XTypeProvider .uno.RuntimeException
getImplementationName () string .lang.XServiceInfo .uno.RuntimeException
getSupportedServiceNames () []string .lang.XServiceInfo .uno.RuntimeException
getTypes () []type .lang.XTypeProvider .uno.RuntimeException
hasElements () boolean .container.XElementAccess .uno.RuntimeException
queryAdapter () .uno.XAdapter .uno.XWeak .uno.RuntimeException
queryInterface ( [in] type aType ) any .uno.XInterface .uno.RuntimeException
release () void .uno.XInterface
supportsService ( [in] string ServiceName ) boolean .lang.XServiceInfo .uno.RuntimeException




Services
com.sun.star.lang.XServiceInfo interface is not supported.








Edit: there's no dispose as there is for tables.
Last edited by JeJe on Thu Jan 31, 2019 11:37 pm, edited 2 times in total.
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 508
Joined: Wed Mar 09, 2016 2:40 pm

Re: Accept or Reject Writer Changes in code?

Postby JeJe » Thu Jan 31, 2019 3:56 pm

this is on the list of dispatch calls

.uno:AcceptTrackedChange FN_REDLINE_ACCEPT_DIRECT 21837 MTA Accept

But selecting a tracked change and calling doesn't do anything

Code: Select all   Expand viewCollapse view

dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Accept"
args1(0).Value = false 'or true
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:AcceptTrackedChange", "", 0, args1())

Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 508
Joined: Wed Mar 09, 2016 2:40 pm

Re: Accept or Reject Writer Changes in code?

Postby JeJe » Thu Jan 31, 2019 9:15 pm

Eventually finding this, I guess not:

https://bugs.documentfoundation.org/sho ... ?id=101977

(at least there is the workaround)
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 508
Joined: Wed Mar 09, 2016 2:40 pm

Re: [Solved] Accept or Reject Writer Changes in code?

Postby JeJe » Fri Feb 01, 2019 2:21 am

The solution is to use RejectTracedChange or AcceptTracedChange.

Code: Select all   Expand viewCollapse view
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue

args1(0).Name = "RejectTracedChange"
'args1(0).Name = "AcceptTracedChange"
args1(0).Value = true

'dispatcher.executeDispatch(document, ".uno:AcceptTracedChange", "", 0, args1())
dispatcher.executeDispatch(document, ".uno:RejectTracedChange", "", 0, args1())


In order to work the Redline has to be selected carefully - the selection produced by the Accept or Reject changes dialog doesn't work, nor does just using redlinestart and RedLineend - the selection needs to go left 1 before redlinestart. That was causing me a lot of confusion.

Code: Select all   Expand viewCollapse view

dim ovc
ovc = thiscomponent.currentcontroller.viewcursor
oRedline = thiscomponent.getredlines.getbyindex(0)
ovc.goToRange(oRedline.redlinestart,false)
oVC.goleft(1,false) 'THIS IS NEEDED
ovc.goToRange(oRedline.RedLineend,true)


Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 508
Joined: Wed Mar 09, 2016 2:40 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 5 guests