Wait for 1 sec after document load as events doesn't work well.

This commit is contained in:
Georgy Litvinov 2021-01-15 20:03:04 +01:00
parent e929de14f0
commit 31ae769470
2 changed files with 48 additions and 4 deletions

View file

@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Clean" script:language="StarBasic">Sub mark74
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Clean" script:language="StarBasic">Sub mark75
End Sub
Dim DocumentLoaded as Boolean
Sub cleanButton
Dim config As Object
config = initRedactionConfiguration()
@ -160,7 +162,7 @@ End Sub
Private Sub quietCleaning
Dim description As String
Dim statusIndicator As Object
DocumentLoaded = false
saveDocument
saveAsDocAndBackToODT
statusIndicator = ThisComponent.getCurrentController.statusIndicator
@ -205,6 +207,20 @@ Private Sub quietCleaning
MsgBox getTranslation(&quot;cleaningFinished&quot;)
End Sub
&apos;Sub RegisterListener (ThisComponent)
&apos; oListener = CreateUnoListener( &quot;DocumentListener_&quot;,&quot;com.sun.star.document.XEventListener&quot; )
&apos; ThisComponent.com_sun_star_document_XEventBroadcaster_addEventListener( oListener )
&apos;End Sub
&apos;Sub DocumentListener_notifyEvent( o as object )
&apos; If o.EventName = &quot;OnLoad&quot; Then
&apos; DocumentLoaded = true
&apos; EndIf
&apos;end sub
&apos;Sub DocumentListener_disposing()
&apos;End Sub
Private Sub removeFirstElementPageBreak
Dim enum1 As Object
Dim enum1Element As Object
@ -715,11 +731,24 @@ End Sub
Private Sub saveAndreload()
Dim document As Object
Dim dispatcher As Object
&apos;Dim timeOut As Long
&apos;timeOut = 0
&apos;DocumentLoaded = false
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
dispatcher.executeDispatch(document, &quot;.uno:Save&quot;, &quot;&quot;, 0, Array())
dispatcher.executeDispatch(document, &quot;.uno:Reload&quot;, &quot;&quot;, 0, Array())
Wait 1000
&apos;RegisterListener (ThisComponent)
&apos;Do while DocumentLoaded = false
&apos; Wait 300
&apos; timeOut = timeOut + 300
&apos; If timeOut &gt; 30000 Then
&apos; MsgBox &quot;Time out&quot;
&apos; Exit sub
&apos; EndIf
&apos;Loop
&apos;DocumentLoaded = false
End Sub
@ -1810,6 +1839,10 @@ sub saveAsDocAndBackToODT
Dim path As String
Dim tmpName As String
Dim oldName As String
&apos;Dim timeOut As Long
&apos;timeOut = 0
&apos;DocumentLoaded = false
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
oldName = ThisComponent.getURL()
@ -1825,6 +1858,17 @@ sub saveAsDocAndBackToODT
args1(1).Value = &quot;writer8&quot;
dispatcher.executeDispatch(document, &quot;.uno:SaveAs&quot;, &quot;&quot;, 0, args1())
dispatcher.executeDispatch(document, &quot;.uno:Reload&quot;, &quot;&quot;, 0, Array())
&apos;RegisterListener (ThisComponent)
&apos;Do while DocumentLoaded = false
&apos; Wait 300
&apos; timeOut = timeOut + 300
&apos; If timeOut &gt; 30000 Then
&apos; MsgBox &quot;Time out&quot;
&apos; Exit sub
&apos; EndIf
&apos;Loop
&apos;DocumentLoaded = false
If FileExists(tmpName) Then
Kill(tmpName)
End If

View file

@ -199,4 +199,4 @@ End Sub
End If
getFileURLDialog = &quot;&quot;
End Function
</script:module>
</script:module>