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.
[Solved] Accept or Reject Writer Changes in code?
[Solved] Accept or Reject Writer Changes in code?
Last edited by JeJe on Thu Jan 31, 2019 11:37 pm, edited 2 times in total.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Accept or Reject Writer Changes in code?
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
.uno:AcceptTrackedChange FN_REDLINE_ACCEPT_DIRECT 21837 MTA Accept
But selecting a tracked change and calling doesn't do anything
Code: Select all
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())
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: Accept or Reject Writer Changes in code?
Eventually finding this, I guess not:
https://bugs.documentfoundation.org/sho ... ?id=101977
(at least there is the workaround)
https://bugs.documentfoundation.org/sho ... ?id=101977
(at least there is the workaround)
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Re: [Solved] Accept or Reject Writer Changes in code?
The solution is to use RejectTracedChange or AcceptTracedChange.
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
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())
Code: Select all
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)
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)