Apache OpenOffice (AOO) Bugzilla – Issue 98931
macros does not paste text into Notes as in 2.4
Last modified: 2017-05-20 11:17:48 UTC
I make intensive use of macros that inspect the text and in presence of keywords transform the paragraph in Annotation in OO writer 2.4 calling the macro "Trasform_Selected_Text_To_Annotation" will replace the selected text with a Annotation which contains the selected text . in OO writer 3.0 the same macro cuts the text and inserts a Annotation with no text at all , without raise errors or exceptions. ******************************************************* REM ***** BASIC ***** rem define variables dim document as object dim dispatcher as object Sub Trasform_Selected_Text_To_Annotation() Dim oDisp , octl Dim NoArg() Dim nome as String dim textOfAnnotation As String document = ThisComponent.CurrentController.Frame ''' create the DispatcherService dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") ''' Set source doc/currentController/frame/sheet/range. octl = ThisComponent.getCurrentController() '''''copy the current selection to the clipboard. dispatcher.executeDispatch(octl, ".uno:Cut", "", 0, NoArg()) textOfAnnotation = getClipBoard() insertAnnotation(textOfAnnotation) End Sub sub insertAnnotation (textOfAnnotation) dim args2(2) as new com.sun.star.beans.PropertyValue args2(0).Name = "Text" args2(0).Value = textOfAnnotation args2(1).Name = "Author" args2(1).Value = "test" args2(2).Name = "Date" args2(2).Value = "" dispatcher.executeDispatch (document, ".uno:InsertAnnotation", "", 0, args2()) end sub Function getClipBoard() as String Dim oClip, oClipContents, oTypes Dim oConverter, convertedString$ Dim i%, iPlainLoc% iPlainLoc = -1 Dim s$ : s$ = "com.sun.star.datatransfer.clipboard.SystemClipboard" oClip = createUnoService(s$) oConverter = createUnoService("com.sun.star.script.Converter") 'Print "Clipboard name = " & oClip.getName() 'Print "Implemantation name = " & oClip.getImplementationName() oClipContents = oClip.getContents() oTypes = oClipContents.getTransferDataFlavors() Dim msg$, iLoc%, outS msg = "" iLoc = -1 For i=LBound(oTypes) To UBound(oTypes) If oTypes(i).MimeType = "text/plain;charset=utf-16" Then iPlainLoc = i Exit For End If 'msg = msg & "Mime type = " & x(ii).MimeType & " normal = " & _ ' x(ii).HumanPresentableName & Chr$(10) Next If (iPlainLoc >= 0) Then convertedString = oConverter.convertToSimpleType( _ oClipContents.getTransferData(oTypes(iPlainLoc)), _ com.sun.star.uno.TypeClass.STRING) End If getClipBoard = convertedString End Function
Created attachment 59967 [details] in oo writer 3.0 macros does not works as in 2.4
MRU->OS: see attached document. Selected text is not pasted into a Note anymore as it was done in OOo 2.4 by the Macro.
Closed.
Ignore my above "Closed" comment... Wanted to reassign to OS...
I've came across the same bug (3.1 dev OOO3010m40 build 9388), trying to paste text into a new Note using a macro. Behaviour was extremely erratic: worked about one in twenty times, if that, with no apparent logic. This suggests a problem with timing or threads, and - so far - adding a short pause after the Note's creation (.uno:InsertAnnotation) seems to work for me. A simple example: [code] Sub Main dim document as object dim dispatcher as object document = ThisComponent.CurrentController.Frame dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") dispatcher.executeDispatch(document, ".uno:Copy", "", 0, array()) thisComponent.CurrentController.getViewCursor.collapseToStart() dispatcher.executeDispatch(document, ".uno:InsertAnnotation", "", 0, array()) wait 500 dispatcher.executeDispatch(document, ".uno:Paste", "", 0, array()) End Sub [/code] Hope that helps.
Target changed to 3.x
Reset assigne to the default "issues@openoffice.apache.org".