Inconsistent behavior closing comment replies.

Questions, comments and suggestions concerning VintaSoft PDF .NET Plug-in.

Moderator: Alex

Post Reply
IntegraHarlan
Posts: 84
Joined: Fri Jan 24, 2020 3:37 am

Inconsistent behavior closing comment replies.

Post by IntegraHarlan »

Hi,
I have two questions regarding comments.

First Question:
I can create a comment and add several replies.
When I close one of the replies, that replies and all the replies below that reply are closed.
This is expected behavior.
However, if close the comment and re-open the comment, then try to close one of the replies, all of the replies close up to the Comment.
I would expect this behavior to be the same before and after closing and re-opening the comment.
It appears that when a comment and replies are created and one of the replies is closed, The IsOpen property is set to false for the reply that is closed and the replies below that reply. The IsOpen property for the Replies above the one that is closed are left set to true.
When the comment is closed and re-opened, the IsOpen property for all of the replies are set to false when one of the replies is closed.

This is reproducible in the WinfForms Charp PdfEditorDemo by performing the following steps.
  • Add a comment on a document.
    Add several replies. Lets say 5 replies.
    Close and re-open some of the replies. You will see that the reply and the replies below that one are closed, but the replies above it are left open.
    Close the comment. The the comment and all replies are closed.
    Re-open the comment.
    Now close and re-open some of the replies. You will see that all of the replies are closed.
Is this the intended behavior for the comment and replies?
Is there a way that will allow me to close a reply and the sub replies but leave the above replies open after a comment has been closed and re-opened?

Second Question:
I would like to be able to close a comment and retain the Open state of the replies in the comment so that when I re-open the comment the replies will be in the same Open state as they where when I closed the comment.
Currently when I close a comment, The IsOpen property of all of the replies is set to false, so I do not know what state to return them to when I re-open the comment.

Is there a way to do this?
Thanks Harlan
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Inconsistent behavior closing comment replies.

Post by Alex »

Hi Harlan,

The Comment class (https://www.vintasoft.com/docs/vsimagin ... mment.html) has PropertyChanged (https://www.vintasoft.com/docs/vsimagin ... ed_EV.html) and StatesChanged (https://www.vintasoft.com/docs/vsimagin ... ed_EV.html) events.
Please subscribe to the events, monitor comment status and implement necessary logic.

Best regards, Alexander
IntegraHarlan
Posts: 84
Joined: Fri Jan 24, 2020 3:37 am

Re: Inconsistent behavior closing comment replies.

Post by IntegraHarlan »

Thank you for your reply.
Monitoring the Comment status on the PropertyChanged event, does not seem to work for me.
If I am closing a comment, The IsOpen property for all of the replies is set to false before the ProperyChanged event is called for the first time.
I am not able to retain the Open state of the Replies so that when I Open the comment later I do not know the Open state to set them to.
The IsOpen state is set to true for all the replies when opening a comment.

Is there something that I am missing?

Thanks.
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Inconsistent behavior closing comment replies.

Post by Alex »

We analyzed your task and understood that we need make small changes in Comments architecture for solving the task. Changes will be available in version 9.1.0.7, which will be released this week. I will notify you when version 9.1.0.7 is available and provide you an example for solving your task.

Best regards, Alexander
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Inconsistent behavior closing comment replies.

Post by Alex »

Hi Harlan,

Today we released version 9.1.0.7 and now your task can be solved.

For solving the task, please do the following steps:
  • Create custom PDF annotation comment and override logic of PdfAnnotationComment.IsOpen property.

    Code: Select all

    public class MyPdfAnnotationComment : Vintasoft.Imaging.Annotation.Comments.Pdf.PdfAnnotationComment
    {
        public MyPdfAnnotationComment(
            Vintasoft.Imaging.Annotation.Comments.Pdf.PdfAnnotationCommentCollection owner,
            Vintasoft.Imaging.Pdf.Tree.Annotations.PdfMarkupAnnotation source)
            : base(owner, source)
        {
        }
    
        bool? _isOpen;
        public override bool IsOpen
        {
            get
            {
                if (_isOpen == null)
                    _isOpen = base.IsOpen;
                return _isOpen.Value;
            }
            set
            {
                if (IsOpen != value)
                {
                    _isOpen = value;
                    ObjectPropertyChangedEventArgs changedArgs = new ObjectPropertyChangedEventArgs("IsOpen", IsOpen, value);
                    if (Annotation != null && Annotation.PopupAnnotation != null)
                        Annotation.PopupAnnotation.IsOpen = value;
                    if (Annotation is PdfTextAnnotation)
                        ((PdfTextAnnotation)Annotation).IsOpen = value;
                    OnPropertyChanged(changedArgs);
                }
            }
        }
    
        protected override CommentCollection CreateReplyCollection()
        {
            return new MyPdfAnnotationCommentCollection(this);
        }
    }
    
  • Create custom PDF annotation comment collection.

    Code: Select all

    public class MyPdfAnnotationCommentCollection : Vintasoft.Imaging.Annotation.Comments.Pdf.PdfAnnotationCommentCollection
    {
        public MyPdfAnnotationCommentCollection(Vintasoft.Imaging.VintasoftImage image)
            : base(image)
        {
        }
    
        public MyPdfAnnotationCommentCollection(MyPdfAnnotationComment parent)
            : base(parent)
        {
        }
    
        protected override Vintasoft.Imaging.Annotation.Comments.Pdf.PdfAnnotationComment CreateComment(
            Vintasoft.Imaging.Annotation.Comments.Pdf.PdfAnnotationCommentCollection owner,
            Vintasoft.Imaging.Pdf.Tree.Annotations.PdfMarkupAnnotation source)
        {
            return new MyPdfAnnotationComment(owner, source);
        }
    }
    
  • Create custom PDF annotation comment controller of image collection.

    Code: Select all

    public class MyImageCollectionPdfAnnotationCommentController : Vintasoft.Imaging.Annotation.Comments.Pdf.ImageCollectionPdfAnnotationCommentController
    {
        protected override Vintasoft.Imaging.Annotation.Comments.CommentCollection CreateCommentCollection(Vintasoft.Imaging.VintasoftImage image)
        {
            return new MyPdfAnnotationCommentCollection(image);
        }
    }
    
  • Use custom PDF annotation comment controller of image collection in PdfEditorDemo project.
    For doing this change code of InitVisualTools method in MainForm class:

    Code: Select all

    ...
    ImageViewerCommentController commentController = new ImageViewerCommentController(new ImageCollectionPdfAnnotationCommentController());
    ...
    
    to the following code:

    Code: Select all

    ...
    ImageViewerCommentController commentController = new ImageViewerCommentController(new MyImageCollectionPdfAnnotationCommentController());
    ...
    
Best regards, Alexander
IntegraHarlan
Posts: 84
Joined: Fri Jan 24, 2020 3:37 am

Re: Inconsistent behavior closing comment replies.

Post by IntegraHarlan »

Thank you this is now working for me.

Thanks
Harlan
Post Reply