• Login
Community
  • Login

Pythonscript: Is there a way to detect changes in bookmarks?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
pythonscriptbookmarksbookmarkcallbackplugin
7 Posts 3 Posters 429 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K
    kiyn
    last edited by Apr 27, 2021, 1:58 PM

    My need is to detect any addition or removal of bookmarks.

    The closest I have found is the callback SCINTILLANOTIFICATION.MARGINCLICK, which works fine if you edit bookmarks from the left margin, but cannot detect if they are edited in any other way (shortcuts, macros, toolbar, menu, plugin GUI).

    Any kind of suggestions or help will be greatly appreciated.
    Thanks

    A D 2 Replies Last reply Apr 27, 2021, 2:04 PM Reply Quote 0
    • A
      Alan Kilborn @kiyn
      last edited by Apr 27, 2021, 2:04 PM

      @kiyn

      I don’t think you’re going to be able to get anything like a “notification” about this. Meaning that you would likely have to resort to a “polling” approach, where you examine every line in a file as to whether it current has or doesn’t have a bookmark. This is probably not the answer you wanted. :-(

      A 1 Reply Last reply Apr 27, 2021, 9:05 PM Reply Quote 1
      • D
        dail @kiyn
        last edited by Apr 27, 2021, 8:29 PM

        @kiyn

        You can catch the SCN_MODIFIED notification and check for the SC_MOD_CHANGEMARKER flag.

        1 Reply Last reply Reply Quote 6
        • A
          Alan Kilborn @Alan Kilborn
          last edited by Alan Kilborn Apr 27, 2021, 9:06 PM Apr 27, 2021, 9:05 PM

          @Alan-Kilborn said in Pythonscript: Is there a way to detect changes in bookmarks?:

          I don’t think you’re going to be able to get anything like a “notification” about this

          @dail said:

          You can catch the SCN_MODIFIED notification and check for the SC_MOD_CHANGEMARKER flag.

          I love to be wrong, especially when we get increased functionality from my wrongness. :-)

          Here’s a PS demo of what dail expressed above:

          # -*- coding: utf-8 -*-
          
          from Npp import editor, SCINTILLANOTIFICATION, MODIFICATIONFLAGS
          
          def callback_sci_MODIFIED(args):
              if args['modificationType'] & MODIFICATIONFLAGS.CHANGEMARKER:
                  line = editor.lineFromPosition(args['position'])
                  print('bookmark placed/removed on line {}'.format(line + 1))
          editor.callback(callback_sci_MODIFIED, [SCINTILLANOTIFICATION.MODIFIED])
          
          1 Reply Last reply Reply Quote 5
          • A
            Alan Kilborn
            last edited by Apr 27, 2021, 9:18 PM

            I guess we can refine it a bit more, in order to tell a placement from a removal:

            # -*- coding: utf-8 -*-
            
            from Npp import editor, SCINTILLANOTIFICATION, MODIFICATIONFLAGS
            
            MARK_BOOKMARK = 24  # from N++ source code
            
            def callback_sci_MODIFIED(args):
                if args['modificationType'] & MODIFICATIONFLAGS.CHANGEMARKER:
                    line = editor.lineFromPosition(args['position'])
                    if editor.markerGet(line) & (1 << MARK_BOOKMARK):
                        print('bookmark placed on line {}'.format(line + 1))
                    else:
                        print('bookmark removed on line {}'.format(line + 1))
            editor.callback(callback_sci_MODIFIED, [SCINTILLANOTIFICATION.MODIFIED])
            
            1 Reply Last reply Reply Quote 6
            • K
              kiyn
              last edited by Apr 28, 2021, 7:03 PM

              That’s exactly what I was hoping for.
              I would never have succeeded by myself.
              Thanks a lot to both of you!

              1 Reply Last reply Reply Quote 2
              • A
                Alan Kilborn
                last edited by Dec 20, 2022, 10:52 PM

                The marker ID used for bookmarks changed in Notepad++ 8.4.6 (and later). It is now 20, instead of 24. So, all references to 24 in this thread and/or its script(s), should be changed to 20.

                1 Reply Last reply Reply Quote 4
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors