Page 1 of 1

[Solved] Can I merge sidebar comments into main text?

PostPosted: Wed May 20, 2020 11:43 pm
by linter
so, i've got this doc that has a bunch of comments in the righthand sidebar with dotted-lines connecting them to the main text. but it's all incredibly confusing to me. i don't know what goes with what. it'd be much easier if the comments were placed right in the text where appropriate, maybe in a different color, if necessary.

is that possible? i'm working on something that has to be done in a hurry and i'm afraid i don't have time to learn a whole new way of doing things. perhaps later, but not now.

what do you think?

Re: can i merge sidebar comments into main text?

PostPosted: Thu May 21, 2020 12:50 am
by JeJe
You can create a character style with a background color for this.

The following macro will create a character style called "CommentStyle" with a yellow background, and copy the text of the comments into the document in that style.

TO BE SAFE MAKE A COPY OF YOUR DOCUMENT FIRST BEFORE RUNNING.

Code: Select all   Expand viewCollapse view

cs = thiscomponent.stylefamilies.getbyname("CharacterStyles")
ss=thiscomponent.createinstance("com.sun.star.style.CharacterStyle")
ss.charbackcolor =  rgb(255,255,20)
cs.insertbyname("CommentStyle",ss)

en =thiscomponent.textfields.createenumeration
tc = thiscomponent.text.createtextcursorbyrange(thiscomponent.text.start)
do until en.hasmoreelements = false
ff= en.nextelement
anch= ff.anchor
tc.gotorange(anch.end,false)
tc.string =ff.textrange.text.string
tc.charstylename = "CommentStyle"
loop



Re: can i merge sidebar comments into main text?

PostPosted: Thu May 21, 2020 2:35 am
by linter
thank you for that. it'll merge the comments into the text, right?

now all i have to do is figure out macros!

Re: can i merge sidebar comments into main text?

PostPosted: Thu May 21, 2020 7:44 am
by JeJe
You have an ancient version of OO according to your signature. All I can do is go through what to do on my more up to date version as I don't have that old version. It may or may not be the same

Make a copy of your document, close all your others and open that.

Go to Tools menu/Macros/Organise Macros/Openoffice basic

In the dialog that pops up select the name of your document from the left side listbox and click the "New" button.

A popup box will ask you for the name of a module - just click on Okay.

You'll be taken to the macro area for your document where you'll find this:


REM ***** BASIC *****

Sub Main

End Sub


Copy and past the macro code I wrote above in between the sub main and end sub so it looks like this

Code: Select all   Expand viewCollapse view
REM  *****  BASIC  *****

Sub Main
cs = thiscomponent.stylefamilies.getbyname("CharacterStyles")
ss=thiscomponent.createinstance("com.sun.star.style.CharacterStyle")
ss.charbackcolor =  rgb(255,255,20)
cs.insertbyname("CommentStyle",ss)

en =thiscomponent.textfields.createenumeration
tc = thiscomponent.text.createtextcursorbyrange(thiscomponent.text.start)
do until en.hasmoreelements = false
ff= en.nextelement
anch= ff.anchor
tc.gotorange(anch.end,false)
tc.string =ff.textrange.text.string
tc.charstylename = "CommentStyle"
loop
End Sub






When that's done press F5 to run the macro and see if the result is what you want.

Re: Can I merge sidebar comments into main text?

PostPosted: Thu May 21, 2020 12:42 pm
by JeJe
Slightly improved version makes sure the textfields are all comments in case you have other ones in the document:

Code: Select all   Expand viewCollapse view

cs = thiscomponent.stylefamilies.getbyname("CharacterStyles")
if cs.hasbyname("CommentStyle") = false then
ss=thiscomponent.createinstance("com.sun.star.style.CharacterStyle")
ss.charbackcolor =  rgb(255,255,20)
cs.insertbyname("CommentStyle",ss)
end if

en =thiscomponent.textfields.createenumeration
tc = thiscomponent.text.createtextcursorbyrange(thiscomponent.text.start)
do until en.hasmoreelements = false
ff= en.nextelement
if ff.supportsService("com.sun.star.text.TextField.Annotation") then
anch= ff.anchor
tc.gotorange(anch.end,false)
tc.string =ff.textrange.text.string
tc.charstylename = "CommentStyle"
end if
loop


Re: Can I merge sidebar comments into main text?

PostPosted: Thu May 21, 2020 2:06 pm
by linter
good golly that worked perfectly. what a life saver. i can't thank you enough. thank you!!!!

Re: Can I merge sidebar comments into main text?

PostPosted: Thu May 21, 2020 2:18 pm
by JeJe
If you want to change the color or hide/show them you just have to change the properties of the character style.