• Login
Community
  • Login

How to get text and/or scintilla handle for background file?

Scheduled Pinned Locked Moved Notepad++ & Plugin Development
28 Posts 5 Posters 2.5k 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.
  • D
    Derek Brown
    last edited by Oct 24, 2020, 8:47 AM

    I fear I may have a pretty difficult problem.

    I’m writing a plugin and I need to get the text of all files when notepad++ open and track their changes. The problem is that when a file is opened it is not the “current Scintilla” when the NPPN_FILEOPENED notification is sent (unless it was the first file opened when you start NPP). Replace across documents also causes problems, background files are obviously not the current Scintilla (in fact, calling NPPM_GETCURRENTSCINTILLA during a multi-document replace seems to return -1 for all documents, even the one currently in view).

    I’ve done a lot of digging around the Scintilla documentation and the NPP source code. I see that Scintilla has a notion of a Document, if I had one of these I could create a new Scintilla (using NPPM_CREATESCINTILLAHANDLE) referencing the background document use that to get the text. NPP does this in some of it’s functions that manipulate files in the background, including the function to load a file. NPP itself has a notion of a Buffer, which contains a reference to the backing Document. During the NPPN_FILEOPENED I can get the Buffer ID for the background document (I also use this to get the filename), but I don’t see anyway to go from a Buffer ID to a Document from the context of a plugin.

    In short, what I need is a way to get the text, or preferably a Scintilla handle, for a background file. Does anyone know how to tackle this problem?

    E 1 Reply Last reply Oct 24, 2020, 11:32 AM Reply Quote 2
    • E
      Ekopalypse @Derek Brown
      last edited by Oct 24, 2020, 11:32 AM

      @Derek-Brown

      If I understand correctly then you are looking for something like this.

      1 Reply Last reply Reply Quote 1
      • D
        Derek Brown
        last edited by Oct 24, 2020, 6:32 PM

        It looks like that only gets the filenames? Unless I am missing something. I want to get the actual data in the files, preferably in the form of a Scintilla handle.

        E 1 Reply Last reply Oct 24, 2020, 9:01 PM Reply Quote 0
        • E
          Ekopalypse @Derek Brown
          last edited by Ekopalypse Oct 24, 2020, 9:02 PM Oct 24, 2020, 9:01 PM

          @Derek-Brown

          It does a bit more, but yes, you do not get the contents of the file.
          But if you have the file name, you can read the content, and once the buffer is activated,
          which is indicated by the buffer ID, you can compare the current text with the text you read initially.
          Or am I missing something?

          1 Reply Last reply Reply Quote 0
          • D
            Derek Brown
            last edited by Derek Brown Oct 24, 2020, 10:31 PM Oct 24, 2020, 10:28 PM

            I’m not sure I follow you. Are you suggesting to use the filename to read the file directly (using Windows APIs or something)? That won’t always work: If session backups are enabled you can have an unsaved new file backed up. When you restart NPP it’s filename will be something like “new 1”, not an actual file on disk (I’m sure the backup file exists somewhere, but the filename does not point you to it). Likewise, if an existing file is unsaved then the contents that are opened when you restart NPP will be different from the contents on disk at the given filename.

            And sure you could compare what you loaded from disk with the contents of the buffer when it becomes active, but then I may as well just wait until the buffer is active to read anything at all. And I could write my plugin this way, but it would be much better and simpler if I could track the state of all buffers whether they were active or not.

            E 1 Reply Last reply Oct 24, 2020, 11:08 PM Reply Quote 0
            • E
              Ekopalypse @Derek Brown
              last edited by Oct 24, 2020, 11:08 PM

              @Derek-Brown

              Afaik, there is no direct way to read the loaded buffers.
              Sorry for the confusion, but I thought this was clear and you are looking for an alternative.

              1 Reply Last reply Reply Quote 1
              • D
                Derek Brown
                last edited by Oct 25, 2020, 4:12 AM

                I’m hoping that someone might know a clever workaround or hack, or that I might have missed something.

                1 Reply Last reply Reply Quote 2
                • K
                  KnIfER
                  last edited by Apr 11, 2021, 3:40 AM

                  Hack? It’s easy to implement in the source code.

                  1 Reply Last reply Reply Quote 0
                  • K
                    KnIfER
                    last edited by Apr 11, 2021, 3:43 AM

                    This post is deleted!
                    P 1 Reply Last reply Apr 11, 2021, 5:41 PM Reply Quote 0
                    • P
                      PeterJones @KnIfER
                      last edited by Apr 11, 2021, 5:41 PM

                      @KnIfER

                      A HTML previewer plugin requires such feature

                      The existing Preview HTML plugin works just fine as is, because expecting that the user saves ancilliary files (like a CSS file accompanying an HTML file) is not an onerus expectation of the user.

                      It’s easy to implement in the source code.

                      Like other regulars on this forum, I am amazed at how often phrases like that are bandied about. If you have the skills to implement such a fix easily, then implement it and provide a Pull Request to get it incorporated; if you have the skills but are unwilling to do the work, then it is your own fault the codebase isn’t updated; if you don’t have the skills, then you are not actually in a position to judge how easy or difficult the task might be.

                      Besides, you have been here long enough to know (or at least long enough to have had opportunity to learn) that if you have a feature request, this forum is not the place to make it official. You can discuss topics here, and we’re happy to answer if we know such a feature already exists or suggest workarounds if they don’t; and it’s a great place for finding out if others think your feature request is a good idea or not; but in the end, if no one has put in an official feature request, as explained in one of this forum’s FAQs, then it’s just discussion and not an official request.

                      K 1 Reply Last reply Apr 13, 2021, 4:58 PM Reply Quote 4
                      • K
                        KnIfER
                        last edited by Apr 13, 2021, 4:55 PM

                        This post is deleted!
                        1 Reply Last reply Reply Quote 0
                        • K
                          KnIfER @PeterJones
                          last edited by Apr 13, 2021, 4:58 PM

                          @PeterJones

                          You words are so long and I can bearly understand all of them. XD

                          Anyway , when I am saying something is easy to achieve, I probably have already achieved such goals or at least some working prototypes, that’s my style.

                          Here is a short video of what it shall look like —— the two “chained updating” demo. In the example, when the shader source file is modified, the web-based shadertory preview updates immediately.

                          Please, don’t let the imagination limit you.

                          A P 2 Replies Last reply Apr 13, 2021, 6:09 PM Reply Quote 0
                          • A
                            Alan Kilborn @KnIfER
                            last edited by Alan Kilborn Apr 13, 2021, 6:09 PM Apr 13, 2021, 6:09 PM

                            @KnIfER said in How to get text and/or scintilla handle for background file?:

                            You words are so long and I can bearly understand all of them.

                            Oh, boy. LOL

                            Here is a short video of what it shall look like

                            Why does anyone care about this?

                            @KnIfER I’ve read a good number of your postings here, as well as on github, and I’m left with, well, a general feeling of confusion about what you are trying to communicate, in pretty much all of your postings.

                            At least @PeterJones writes with a style and length to make his information understandable.

                            K 2 Replies Last reply Apr 13, 2021, 8:23 PM Reply Quote 1
                            • K
                              KnIfER
                              last edited by Apr 13, 2021, 8:22 PM

                              This post is deleted!
                              1 Reply Last reply Reply Quote 0
                              • K
                                KnIfER @Alan Kilborn
                                last edited by Apr 13, 2021, 8:23 PM

                                This post is deleted!
                                1 Reply Last reply Reply Quote 0
                                • K
                                  KnIfER @Alan Kilborn
                                  last edited by Apr 13, 2021, 8:28 PM

                                  @Alan-Kilborn
                                  You are being off-topic for your comments. just leave and dont reply if you don’t like @Derek Brown’s ideas about NotepadPlusplus and scintilla .

                                  Well , I styled my text this time, if you say.

                                  A P 2 Replies Last reply Apr 13, 2021, 8:29 PM Reply Quote 0
                                  • A
                                    Alan Kilborn @KnIfER
                                    last edited by Alan Kilborn Apr 13, 2021, 8:31 PM Apr 13, 2021, 8:29 PM

                                    @KnIfER

                                    Yep, you continue to make zero sense, as far as I can see; anyone else make any sense out of what this person is saying?
                                    It’s a shame because you probably have some good ideas to share.

                                    K 2 Replies Last reply Apr 13, 2021, 8:32 PM Reply Quote -1
                                    • K
                                      KnIfER
                                      last edited by Apr 13, 2021, 8:29 PM

                                      Some alien person:

                                      Why does anyone care about this ( the video )?

                                      This guy has never understood the subject of this article. The video accurately demostrates the possibility of “getting text and/or scintilla handle for background file”.

                                      1 Reply Last reply Reply Quote -1
                                      • K
                                        KnIfER @Alan Kilborn
                                        last edited by Apr 13, 2021, 8:32 PM

                                        This post is deleted!
                                        1 Reply Last reply Reply Quote -1
                                        • K
                                          KnIfER @Alan Kilborn
                                          last edited by Apr 13, 2021, 8:33 PM

                                          @Alan-Kilborn Yep, you continue to reply your none-constructive words; anyone else make any sense out of what this persn and it’s crap?

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