How can we listen comment added, updated and deleted events in custom view?

I want to refresh my custom view once Comment got added or edited or deleted.

Parents
  • Hi ,

    Created new thread and copy/paste your response below.

    ================

    • Hi Harshad,

      You can't subscribe to an event through the Integration API; but you can potentially listen for changes and intuitively deduct when comments are added/removed.

      Start by subscribing to the ActiveDocumentChanged event on the EditorController.

      Then subscribe to the ActiveSegmentChanged, ContentChanged events when active document changes.

      Manage a collection on the document to identify the list of comments associated with each of the segmentPairs (read when the document is loaded).  Call this CollectionA

      Note: when you add a comment to the segment, the content changed event is fired. Understanding this, you would only need to get the current list of comments for the active segment pair and then compare it against a comments for the segment mentioned in CollectionA that you are managing on the document.

      private void ActiveDocument_ContentChanged(object sender, DocumentContentEventArgs e)
      {

      [...]

           var segmentSourceComments = segmentPair.Source.GetComments();
           var segmentTargetComments = segmentPair.Target.GetComments();
           var segmentParagraphComments = segmentPair.GetParagraphUnitProperties().Comments;

          // Compare list of comments listed here against what was initially read in CollectionA
          // Identify what was added or removed
          // if different, do something!
          // update CollectionA with the new list of comments for the SegmentPair (if different)

      [...]

      }

      similarly, perform same check in the ActiveSegmentChanged; to cover cases where the content structure of the segment didn't change; I'd need to check but might be that if the scope of the comment is at the paragraph level, then the ContentChanged is not fired!

      ===================



    Generated Image Alt-Text
    [edited by: Trados AI at 4:05 AM (GMT 0) on 5 Mar 2024]
  • Hi ,

    Thanks for your input.

    Please find point wise reply for given input below.

    #1) ActiveDocument_ContentChanged:-

    • this event only called when we Add  & Delete comment
    • If comment added first time say version 1 then its called, If we add new comment say version 2 then not called. 
    • If we Edit comment then also not called
    • Its also called when we write/remove content to/from Active Segment so its not feasible to have comment logic here

    #2) var segmentSourceComments = segmentPair.Source.GetComments(); AND var segmentTargetComments = segmentPair.Target.GetComments();: 

    • Was not able to find GetComments() method in API
    • In APi we have GetCommentsFromSegment(ISegmentPair segmentPair) but its return comments having Scope as Segment, Its not return comments having Scope as Range.

    #3) var segmentParagraphComments = segmentPair.GetParagraphUnitProperties().Comments;:

    • Always return NULL. I have comments for given segment but its return NULL

    I have managed to get all comments (Scope comment and Range comment). Here ActiveDocument_ContentChanged is called only in few scenarios (i.e. First time Add & Delete) so only half usable ;-)

    Thanks,

    -harshad

  • Hi Harshad,

    yeah, I'd need to do as you're doing now and run through the scenarios/workflows.

    Interesting that the contentChanged event is not fired when you edit a comment within the segment range scope, I would have expected the property change event to fire.

    If I were developing this feature, I'd concentrate on catching all other cases in the ActiveSegmentChanged and perform the same comparison against CollectionA that you are managing on the document to identify changes.

    In the meantime, I have added this to the list of API enhancements to expose an event that permits 3rd party developers to subscribe to comments changed.  I'm not able to give you a time line when these enhancements will be available yet though.

    Thank you for your all input and support,

    P.

  • Hi ,

    Thanks for adding this features in list of API enhancements.Once feature get implemented and become public then how one can know its available?

    Once should able to subscribe  Add_Comment, Delete_Comment, Edit_Comment  of Comment Window. OR only one event say Comment_listener_event where base on ENUM one can able to find its added, deleted or edited.

    Regards,

    -Harshad

Reply Children