From 6e1794a27e0dc81a96d585262e7313524b58ddb6 Mon Sep 17 00:00:00 2001 From: George Litvinov Date: Tue, 29 Oct 2019 16:17:08 +0300 Subject: [PATCH] Fixes for link removal macro --- IPHRedaction/Clean.xba | 44 ++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/IPHRedaction/Clean.xba b/IPHRedaction/Clean.xba index e0725e1..9e4ba43 100644 --- a/IPHRedaction/Clean.xba +++ b/IPHRedaction/Clean.xba @@ -1,6 +1,9 @@ -Sub cleanButton +Private Sub markFxFxF +End Sub + +Sub cleanButton Dim description As String Dim statusIndicator as Object statusIndicator = ThisComponent.getCurrentController.statusIndicator @@ -188,7 +191,7 @@ End Function Private Sub disposeAllLinks() Dim SrchAttributes(0) as new com.sun.star.beans.PropertyValue SrchAttributes(0).Name = "CharStyleName" - SrchAttributes(0).Value = "Internet Link" + SrchAttributes(0).Value = "Internet link" Dim ReplAttributes(2) as new com.sun.star.beans.PropertyValue ReplAttributes(0).Name = "HyperlinkTarget" ReplAttributes(0).Value = "" @@ -196,7 +199,7 @@ Private Sub disposeAllLinks() ReplAttributes(1).Value = "" ReplAttributes(2).Name = "CharStyleName" ReplAttributes(2).Value = ThisComponent.getStyleFamilies().getByIndex(0).ElementNames(0) - setAttributesBySearchPattern(searchPattern,SrchAttributes,ReplAttributes) + setAttributesBySearchPattern("",SrchAttributes,ReplAttributes) End Sub Private Sub disposeAllBookmarks() @@ -239,6 +242,8 @@ Private Sub setAttributesBySearchPattern(searchPattern As String, SrchAttributes Dim oTextCursor As Object Dim oViewCursor As Object Dim lineIndent + dim stringValue1 As String + dim stringValue2 As String Dim foundPatterns() As Object document = ThisComponent.CurrentController.Frame dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") @@ -251,15 +256,30 @@ Private Sub setAttributesBySearchPattern(searchPattern As String, SrchAttributes oSearch.SetSearchAttributes(SrchAttributes()) End If oFound = ThisComponent.findFirst(oSearch) + Dim replace As Boolean + Do While Not IsNull(oFound) - For i = LBound(ReplAttributes) To Ubound(ReplAttributes) - ' Globalscope.BasicLibraries.LoadLibrary( "MRILib" ) - ' Mri oFound - If oFound.getPropertySetInfo.hasPropertyByName(ReplAttributes(i).Name) Then - oFound.SetPropertyValue(ReplAttributes(i).Name,ReplAttributes(i).Value) - EndIf - Next i - oFound = ThisComponent.findNext(oFound.End, oSearch) + replace = true + + For j = LBound(SrchAttributes) To Ubound(SrchAttributes) + If oFound.getPropertySetInfo.hasPropertyByName(SrchAttributes(j).Name) Then + stringValue1 = "" & oFound.getPropertyValue(SrchAttributes(j).Name) + stringValue2 = "" & SrchAttributes(j).Value + If stringValue1 <> stringValue2 Then + replace = replace AND False + EndIf + Else + replace = replace AND False + EndIf + Next j + If replace then + For i = LBound(ReplAttributes) To Ubound(ReplAttributes) + If oFound.getPropertySetInfo.hasPropertyByName(ReplAttributes(i).Name) Then + oFound.SetPropertyValue(ReplAttributes(i).Name,ReplAttributes(i).Value) + EndIf + Next i + EndIf + oFound = ThisComponent.findNext(oFound.End, oSearch) Loop End Sub @@ -785,4 +805,4 @@ Private Function getStyleNames(oFamily,bLocalized as Boolean, _ Endif xArray(iUB) = vNextElement End Sub - + \ No newline at end of file