Reply to topic  [ 9 posts ] 
Converting comments to inline comments 
Author Message

Joined: 2007-10-21 14:59:09
Posts: 272
Hi,

I wonder if someone knows how to program such a macro: one that converts each comment to an inline comment of this type:

This is the referring text [This is the comment I added to this text, PT].

Author's abbreviation would be optional; automatic highlight (optional) would be very highly appreciated.

Uh, and the other way round (from inline comments to NW comment) would also be nice...

(Sooner or later, I'll learn how to program...)

Cheers,
Paolo


2010-10-18 09:40:05
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Hi Paolo, here's a macro for you:
Code:
Select Document Start
$count = 0

While true
   # move to the next comment, detecting if no more comments
   $previousSelection = TextSelection.active
   Menu 'Go to Next Comment'
   $selection = TextSelection.active
   If $selection.range == $previousSelection.range
      Break
   End
   
   # save the comment, remove it, and place it inline
   $comment = Read Selection
   Menu 'Remove Comments in Selection'
   Select End
   Type Text ' [['
   Insert Attributed Text $comment
   Menu 'Highlight:Yellow'
   Select End
   Menu 'Highlight:Remove Highlight Attribute'
   Type Text ']]'
   $count += 1
End

Prompt "Converted $count comments to be inline."

It doesn't insert the initials of the authors, which I don't think is currently possible, but it does highlight the comments. You'll notice I used double brackets to [[surround]] the comments, so that the inverse macro doesn't slurp up all bracketed text. But perhaps that's not necessary for you.

Here's the inverse:
Code:
Select Document Start
$count = 0

# scan for comments enclosed in double brackets
While Find Next ' \[\[(?<comment>.+?)\]\]', 'E$'
   # delete the inline comment and add back in the normal comment
   Delete
   Menu 'Add Comment'
   Insert Attributed Text $comment
   # remove highlight
   Menu 'Highlight:Remove Highlight Attribute'
   Menu 'Paragraph Style:Comment'
   $count += 1
End

Prompt "Found and converted $count inline comments."

There is one possibly significant limitation: the revived comments will all be marked as if they had been created by the current author (ie: the author running the macro).


2010-10-18 12:28:05
Profile WWW
User avatar

Joined: 2007-01-17 03:25:42
Posts: 729
The second macro does not work for me. Inline comments are just deleted..


2010-10-19 00:33:01
Profile

Joined: 2007-10-21 14:59:09
Posts: 272
I'll try these macros later today. In the meantime, thank you very much Martin, these promise to be real time-savers. Good idea to avoid using square brackets. I could eventually replace the double square brackets with a brace.

Paolo


2010-10-19 01:04:16
Profile

Joined: 2007-10-21 14:59:09
Posts: 272
OK, tested both macros (after adapting them to the Italian version). They seem to work fine.

I'll post both the English and the Italian version in the Macro forum.

Thank you Martin!

Paolo


2010-10-19 01:28:10
Profile
User avatar

Joined: 2007-01-17 03:25:42
Posts: 729
Hamid wrote:
The second macro does not work for me. Inline comments are just deleted..

That was in Draft View.

In Page View the macro works fine.


2010-10-19 06:14:43
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Hamid wrote:
Hamid wrote:
The second macro does not work for me. Inline comments are just deleted..

That was in Draft View.

In Page View the macro works fine.

That's odd, that shouldn't make a difference. I just tested it and you're right, the macro doesn't work in Draft view. For some reason the "Add Comment" macro command doesn't move the focus/selection to the comment area in Draft View. I'll have a look at fixing this.

Here's a revised macro that functions both in Draft View or Page View:
Code:
Select Document Start
$count = 0

# scan for comments enclosed in double brackets
While Find Next ' \[\[(?<comment>.+?)\]\]', 'E$'
   # delete the inline comment and add back in the normal comment
   Delete
   Menu 'Add Comment'

   # in Draft View the Add Comment command doesn't move focus to the comment area; fix that
   $selection = TextSelection.active
   If 'comment' != $selection.text.documentContentType
      Menu 'Go to Comment Text'
   End

   # insert comment text and remove highlight
   Insert Attributed Text $comment
   Menu 'Highlight:Remove Highlight Attribute'
   Menu 'Paragraph Style:Comment'
   
   $count += 1
End

Prompt "Found and converted $count inline comments."


2010-10-19 13:20:28
Profile WWW

Joined: 2007-10-21 14:59:09
Posts: 272
Martin, may I ask you to move this discussion to the Macro forum? I would prefer to avoid duplicates, and I did the mistake to start it in the wrong one.

Thanx, Paolo


2010-10-20 04:53:08
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Sounds like a good idea to me- topic moved, thanks Paolo.


2010-10-20 12:42:26
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 9 posts ] 

Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software