• Login
Community
  • Login

[Need Help] npp c++ plugin

Scheduled Pinned Locked Moved Notepad++ & Plugin Development
c++ plugin
12 Posts 3 Posters 1.3k 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.
  • L
    Long TV
    last edited by Feb 8, 2022, 3:48 PM

    Hello everyone
    I am making a npp plugin base on c++ template, the functionality is that getting the selected text from txt file, decode it then show the result in a separated panel.

    can anyone help with some code demo for 2 actions below?

    • get the selected text from a txt
    • show the string to a separated panel as the find’s result.

    I am very new in c++ and npp plugin, so any help is much appreciated.
    thank you for visiting here!

    A P 2 Replies Last reply Feb 8, 2022, 3:51 PM Reply Quote 0
    • A
      Alan Kilborn @Long TV
      last edited by Alan Kilborn Feb 8, 2022, 3:53 PM Feb 8, 2022, 3:51 PM

      I am making a npp plugin base on c++ template

      To be specific, which C++ template are you referring to?

      I am very new in c++ and npp plugin

      If you are new to both, are you sure you want to tackle this?

      I’d advise starting with something “simpler”, like maybe a scripting plugin.

      L 1 Reply Last reply Feb 8, 2022, 3:57 PM Reply Quote 3
      • P
        PeterJones @Long TV
        last edited by Feb 8, 2022, 3:53 PM

        @long-tv ,

        Getting selected text from the editor is done using the Scintilla message SCI_GETSELTEXT

        Creating a panel and writing text into that panel is not something I know how to do (I haven’t actually written a plugin). But maybe you could look at the source for PythonScript or NppConsole which make console windows, so presumably show how to write text into there, or maybe the NppFTP which will write statuses into one of its windows…

        A L 2 Replies Last reply Feb 8, 2022, 3:56 PM Reply Quote 3
        • A
          Alan Kilborn @PeterJones
          last edited by Feb 8, 2022, 3:56 PM

          @peterjones said in [Need Help] npp c++ plugin:

          Creating a panel and writing text into that panel is not something I know how to do (I haven’t actually written a plugin).

          Me, neither – the scripting plugins are just THAT good that writing a true plugin seems like too much trouble.

          BTW, @Long-TV , you have seen this section of the N++ user manual, right?: https://npp-user-manual.org/docs/plugin-communication/

          L 1 Reply Last reply Feb 8, 2022, 4:06 PM Reply Quote 2
          • L
            Long TV @Alan Kilborn
            last edited by Feb 8, 2022, 3:57 PM

            @alan-kilborn
            I got the template here https://github.com/npp-plugins/plugintemplate
            I am learning c++ now, so I chosed c++ to make the plugin.

            1 Reply Last reply Reply Quote 0
            • L
              Long TV @PeterJones
              last edited by Feb 8, 2022, 4:01 PM

              @peterjones
              thank you for suggestion… I will look for PythonScript for code sample.

              1 Reply Last reply Reply Quote 0
              • L
                Long TV @Alan Kilborn
                last edited by Feb 8, 2022, 4:06 PM

                BTW, @Long-TV , you have seen this section of the N++ user manual, right?: https://npp-user-manual.org/docs/plugin-communication/

                I have read it and did some practice code. but it too many… I just need 2 actions I mentioned.

                P 1 Reply Last reply Feb 8, 2022, 4:17 PM Reply Quote 0
                • P
                  PeterJones @Long TV
                  last edited by PeterJones Feb 8, 2022, 4:28 PM Feb 8, 2022, 4:17 PM

                  @long-tv said in [Need Help] npp c++ plugin:

                  I have read it and did some practice code. but it too many… I just need 2 actions I mentioned.

                  I gave you the Scintilla message for grabbing selected text. If you don’t know how to send that message to Scintilla, your problems go deeper, and you probably need to start with a C++ project that isn’t as complicated as a plugin.

                  And as far as creating a window/panel inside Notepad++ and writing text into it: that’s a much more complicated task, and isn’t just “one” action from the “just need 2 actions” you mentioned. It is a large series of steps which you will have to learn how to do – and we cannot be expected to spoonfeed such things – because that would be us writing the plugin for you (and because not all of us even know how to create that window; it’s a more complicated task, though I thought the c++ plugin template including a “docking window” example in a subfolder… so I would start there).

                  But honestly, as Alan suggested, if you wanted to learn the PythonScript plugin (rather than using its source code as an example of how to implement something), and use that plugin that to write and run a script in Notepad++ environment, then you could leverage the development-time-saving features built into a solution like the PythonScript plugin. For example:

                  from Npp import * 
                  console.show()
                  selected_text = editor.getSelText()
                  console.write(selected_text+"\n")
                  

                  That script will do everything you described you wanted your plugin to do. In 4 lines of code.

                  As Alan says, using a scripting plugin rather than having to deal with all the overhead of writing a full plugin is a definite timesaver. Unless you are doing something computationally expensive, or something that’s trying to change the styles of large documents, it’s usually best to just stick with that.

                  –
                  edited: added more details on the adding a window task

                  L A 2 Replies Last reply Feb 8, 2022, 4:28 PM Reply Quote 3
                  • L
                    Long TV @PeterJones
                    last edited by Feb 8, 2022, 4:28 PM

                    @peterjones
                    thank you for your advice!

                    1 Reply Last reply Reply Quote 0
                    • A
                      Alan Kilborn @PeterJones
                      last edited by Feb 8, 2022, 4:30 PM

                      @peterjones said in [Need Help] npp c++ plugin:

                      That script will do everything you described you wanted your plugin to do

                      Well… scripting plugins would NOT be great if you have to have a “docking panel” or similar kind of “fancy” output presentation.

                      P 1 Reply Last reply Feb 8, 2022, 4:43 PM Reply Quote 2
                      • P
                        PeterJones @Alan Kilborn
                        last edited by Feb 8, 2022, 4:43 PM

                        @alan-kilborn ,

                        Well, the PythonScript console is a docking panel of sorts, and could be used for outputting such data, as long as the OP just wants a simple text output, and doesn’t care about fancy formatting.

                        A 1 Reply Last reply Feb 8, 2022, 6:59 PM Reply Quote 2
                        • A
                          Alan Kilborn @PeterJones
                          last edited by Feb 8, 2022, 6:59 PM

                          @peterjones said in [Need Help] npp c++ plugin:

                          Well, the PythonScript console is a docking panel of sorts, and could be used for outputting such data, as long as the OP just wants a simple text output, and doesn’t care about fancy formatting.

                          All true, but I think the OP is going for something more sophisticated.

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