Issue 98931

Summary: macros does not paste text into Notes as in 2.4
Product: Writer Reporter: l_allemano <luigi.allemano>
Component: programmingAssignee: AOO issues mailing list <issues>
Status: CONFIRMED --- QA Contact:
Severity: Trivial    
Priority: P3 CC: issues, michael.ruess
Version: OOo 3.0   
Target Milestone: ---   
Hardware: All   
OS: Windows XP   
Issue Type: DEFECT Latest Confirmation in: ---
Developer Difficulty: ---
Attachments:
Description Flags
in oo writer 3.0 macros does not works as in 2.4 none

Description l_allemano 2009-02-05 17:34:42 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
Comment 1 l_allemano 2009-02-05 17:37:56 UTC
Created attachment 59967 [details]
in oo writer 3.0 macros does not works as in 2.4
Comment 2 michael.ruess 2009-02-12 15:24:47 UTC
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.
Comment 3 michael.ruess 2009-02-12 15:49:33 UTC
Closed.
Comment 4 michael.ruess 2009-02-13 14:03:32 UTC
Ignore my above "Closed" comment...
Wanted to reassign to OS...
Comment 5 jurf 2009-05-23 14:06:43 UTC
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.
Comment 6 Oliver Specht 2009-09-30 09:32:10 UTC
Target changed to 3.x
Comment 7 Marcus 2017-05-20 11:17:48 UTC
Reset assigne to the default "issues@openoffice.apache.org".