Community
    • Login

    How to create a C# plugin?

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    plugins
    29 Posts 7 Posters 1.7k 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.
    • Alan KilbornA
      Alan Kilborn @scampsd
      last edited by

      @scampsd said:

      an easier way to work with lines of text in the editor.

      I think you need to spend some time getting more familiar with the editor API, i.e., the Scintilla documentation (a portion of which was linked to earlier). It has everything you’ll need.

      PeterJonesP 1 Reply Last reply Reply Quote 3
      • Mark OlsonM
        Mark Olson @scampsd
        last edited by Mark Olson

        @scampsd

        I’m obviously capable to calculate the start and length

        Be careful! Notepad++ uses UTF-8 to encode its buffers so you need to use JsonParser.ExtraUTF8Bytes and JsonParser.ExtraUTF8BytesBetween if you want to convert between indices in your C# strings and positions in the document.

        EDIT: this is only necessary if your plugin will be running on files that contain non-ASCII characters.

        CoisesC 1 Reply Last reply Reply Quote 1
        • PeterJonesP
          PeterJones @Alan Kilborn
          last edited by

          @Alan-Kilborn said in How to create a C# plugin?:

          I think you need to spend some time getting more familiar with the editor API, i.e., the Scintilla documentation (a portion of which was linked to earlier). It has everything you’ll need.

          While that is good advice, for someone just getting started, it’s knowing where to look in that rather big document, or the right search terms, that is the difficulty.

          For example, I’m not sure it’s natural to me to look in the “Information” section to find the commands that convert between position and line, and whether to search for line start or start line or start of line or start of the line. (And of course, a search for line or start alone finds way too many to help narrow things down.) (And yes, I did intentionally pick those examples to throw @scampsd a bone to help narrow down the search range for solving the immediate problem.)

          Even as someone who has done a lot of interacting with Scintilla through the PythonScript interface, I can find it difficult to find the right command that I’m looking for, because I use the wrong term, or I don’t go to the right subsection to find the right group of commands to be able to find the one I’m looking for.

          Alan KilbornA 1 Reply Last reply Reply Quote 2
          • CoisesC
            Coises @Mark Olson
            last edited by Coises

            @Mark-Olson said in How to create a C# plugin?:

            Notepad++ uses UTF-8 to encode its buffers

            I don’t know C# or the C# interface, so this might not be relevant there, but in general, Notepad++ may work with Scintilla using UTF-8 or “ANSI” — ANSI being the system default Windows ANSI code page. SCI_GETCODEPAGE tells you which it is; in Notepad++ it is always either CP_ACP or CP_UTF8. (Defined, for example, here.)

            I’m not sure how that translates to the C# functions you mentioned, but there are non-ASCII characters (128 of them, different ones for each code page) that can still be represented in ANSI mode. Like any ANSI character, they take up one position in Scintilla, not the number of positions the corresponding UTF-8 character would require.

            rdipardoR 1 Reply Last reply Reply Quote 3
            • rdipardoR
              rdipardo @Coises
              last edited by rdipardo

              @Coises said in How to create a C# plugin?:

              I’m not sure how that translates to the C# functions you mentioned, but there are non-ASCII characters (128 of them, different ones for each code page) that can still be represented in ANSI mode.

              See how my .NET Core template wraps all of Scintilla’s text manipulation APIs in a private method that takes account of the document’s encoding (which may be single-byte ASCII), converting to a properly encoded byte array before the window procedure call. (Note: CodePage is the name of an interface property, which .NET Framework apparently supports, since the class library is multi-targeted.)

              1 Reply Last reply Reply Quote 2
              • Alan KilbornA
                Alan Kilborn @PeterJones
                last edited by

                I said:

                I think you need to spend some time getting more familiar with the editor API, i.e., the Scintilla documentation (a portion of which was linked to earlier). It has everything you’ll need.

                @PeterJones said:

                While that is good advice, for someone just getting started, it’s knowing where to look in that rather big document, or the right search terms, that is the difficulty.


                I said what I said because I was feeling like this topic was heading in the direction of potentially a lot of spoon-feeding. Everyone should spend time with the documentation when they’re using something new, and ask detailed questions when those questions are really needed.

                1 Reply Last reply Reply Quote 2
                • EkopalypseE
                  Ekopalypse @scampsd
                  last edited by

                  @scampsd

                  Another possibility would be to use the internal search engine of Npp and thus avoid the encoding problem.
                  This means using SCI_SEARCHINTARGET with a corresponding regular expression in a loop and then SCI_GETTARGETSTART and SCI_GETTARGETEND to determine the positions. SCI_GETTARGETEND then becomes the next start position for SCI_SEARCHINTARGET …

                  S 1 Reply Last reply Reply Quote 0
                  • S
                    scampsd @Ekopalypse
                    last edited by

                    @Ekopalypse : Let me start by thanking all of you for the wonderful support I’m getting from you guys.

                    At this moment I’m at the stage that I’m having the following pieces of source code:

                    int iAmountOfLines = Npp.editor.GetLineCount();
                    for (int i = 0 ; i < iAmountOfLines; i++)
                    {
                        string strCurrentLine = Npp.editor.GetLine(i);
                        if (strCurrentLine.IndexOf(Txt_Trace) != -1)
                        {
                            Npp.editor.SetIndicatorCurrent(0); // Trace
                            Npp.editor.IndicatorFillRange(Npp.editor.GetLineEndPosition(i) - strCurrentLine.Length, Npp.editor.GetLineEndPosition(i));
                        }
                    

                    The “if”-clause is being repeated for all log levels, and it is currently giving the following output (not correct, but very promising 😀):
                    7bb5e778-de0d-4fb5-b4eb-d8a5b1574d2d-image.png

                    When seeing that, you might wonder how I have configured the corresponding colours. Well, me too 😥. Let me show you what I mean: this is what I see when I open the corresponding configuration form:

                    3de2b277-db29-4a8d-9f4a-00a70eb3d058-image.png

                    “But Dominique, you didn’t configure your colours?”

                    Well, I did, but I forgot two things:

                    1. Using the already configured colours while re-opening the configuration form, I’ll take care of that.
                    2. Saving the already configured colours in registry, in order to avoid needing to re-configure the whole thing every time I perform a test.

                    About that last part, I have the simple question: “Where?”.

                    For your information, this is what my registry looks like at “HKey_Local_Machine\SOFTWARE”:

                    340add9b-e8ce-4f00-8c6e-5fb880ee01f2-image.png

                    You might notice two things:

                    1. There is another tool (Mozilla), having its plugins configured around that place.
                    2. There are no Notepad++ plugins being configured around that place. (Although I have some Notepad++ plugins I’ve used before)

                    Can anybody confirm if I’m at the right spot for saving Notepad++ plugin configurations? If not, what’s a place which is better suited?

                    Thanks in advance (again)

                    EkopalypseE 1 Reply Last reply Reply Quote 1
                    • EkopalypseE
                      Ekopalypse @scampsd
                      last edited by

                      @scampsd

                      Although the registry is actually the Windows standard, I would personally avoid it and rather use the plugin config directory. Can be determined via NPPM_GETPLUGINSCONFIGDIR.
                      However, I would create a subdirectory with the plugin name and add a json, xml, toml … file there.

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