Community
    • Login

    [NEW Plugin] FirstUpper

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    22 Posts 3 Posters 21.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.
    • zkirklandZ
      zkirkland
      last edited by

      I had a project recently that required me to properly capitalize a lot of text that were titles. I created the notepad++ plugin to do just that. Since then I have been adding small fixes and features.

      FirstUpper Notepad++ Plugin

      The plugin checks words in selected text against a list of “forbidden” words that, according to the Chicago Manual of Style, should not be capitalized in a title and capitalizes the first letter of selected words that are not in the list.

      You can also select an option in the menu to capitalize the first letter of the first word of every sentence in a document.

      Comments and Suggestions welcome.

      Thanks for looking!
      Zach

      1 Reply Last reply Reply Quote 0
      • Kasper GraversenK
        Kasper Graversen
        last edited by

        Perhaps you want to have a look at the https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net/releases plugin pack for C#. It provides a lot of convenience methods when interacting with the win32 api. Any comments much appreciated.

        1 Reply Last reply Reply Quote 0
        • Kasper GraversenK
          Kasper Graversen
          last edited by

          Perhaps you want to have a look at the https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net/releases plugin pack for C#. It provides a lot of convenience methods when interacting with the win32 api. Any comments much appreciated.

          Also I would suggest not reading the text out using the stringbuilder since it destroys international letters such as æ,ø,å. The plugin pack properly encodes and decodes strings for you.

          Also remember to use the using() statement around your disposable resources such as file.

          Finally, consider having support for regional selections thereby making it possible to lookup multiple words in one go.

          1 Reply Last reply Reply Quote 1
          • zkirklandZ
            zkirkland
            last edited by

            @Kasper-Graversen

            Thank you for the information!

            When you say “reading the text out using stringbuilder”, do you mean the part of my plugin that uses a stringbuilder ( “allText”) as the container to hold the output from the Win32.SendMessage(currentScint, SciMsg.SCI_GETTEXT, bufSz+1, allText) statement?

            Also, what do you mean by “regional selections”?

            Kasper GraversenK 1 Reply Last reply Reply Quote 0
            • zkirklandZ
              zkirkland
              last edited by

              I am in the process of redoing the git repo. Sorry everyone for any problems or confusion.

              Zach

              1 Reply Last reply Reply Quote 0
              • Kasper GraversenK
                Kasper Graversen @zkirkland
                last edited by

                @zkirkland yes how you read strings into a stringbuilder is not compatible with “foreign” characters. My plugin pack deals with this automatically, you can simply call a method scintillaGateway.GetText() that returns the string

                region select is selections using the alt + left mouse or alt-shift-cursor

                1 Reply Last reply Reply Quote 0
                • zkirklandZ
                  zkirkland
                  last edited by

                  I’m confused. I am trying to initialize a new scintillagateway and it seems the only way I can do this is by

                  IntPtr scintilla = new IntPtr();
                  ScintillaGateway currentScint = new ScintillaGateway(scintilla);
                  

                  Why is it necessary for me to create an IntPtr in order to create a new gateway?

                  Also, you talk about not using StringBuilder objects and part of my code relies on the ability for the StringBuilder object to replace a single character with a new one. Strings cannot do this. In order to avoid using a StringBuilder, it seems I will have to use a character array or something similar.

                  Do you know of a better way?

                  Thanks,
                  Zach

                  1 Reply Last reply Reply Quote 0
                  • zkirklandZ
                    zkirkland
                    last edited by

                    Regarding the IntPtr, forget what I said on that. I realized what I had to do after a little while…lol.

                    IntPtr scintilla = PluginBase.GetCurrentScintilla();
                    ScintillaGateway currentScint = new ScintillaGateway(scintilla);
                    

                    It’s working now that I’ve done that.

                    1 Reply Last reply Reply Quote 0
                    • Kasper GraversenK
                      Kasper Graversen
                      last edited by

                      it is on purpose the gateway does not get the scintilla instance itself… . more complex pluginsmay choose to reuse the same instance, some look up the current scintilla all the time. The little experience I have I often do the later. Also notice that the PluginBase has a factory method you can use if you want to defer the instantiation to eg. specific keys are pressed.

                      regarding the stringbuilder - please explain what you want to do. The ScintillaGateway operates solely on strings and does the encoding to/from Notepad++

                      1 Reply Last reply Reply Quote 0
                      • Kasper GraversenK
                        Kasper Graversen
                        last edited by

                        yes you may need to use a stringbuilder for string manipulation - but getting text from notepad++ and setting text in notepad++ should not be done with a stringbuilder - although you can find plenty examples online that does this… but it does not work with non-US characters.

                        1 Reply Last reply Reply Quote 0
                        • zkirklandZ
                          zkirkland
                          last edited by

                          I’ve updated the plugin with Kasper Graversen’s .NET template and scintilla gateway.

                          • New feature “Capitalize All Markdown Titles”. Supports Setext and Atx style headings.
                          • Fixed the menu option descriptions so they more accurately describe what each option does.

                          I have no way to test international characters so if anyone would like to test that for me, please do! If you test it and you have any ideas as to how to fix any problems with it, let me know!

                          Thanks to Kasper for all of his help.

                          Thank you for looking!
                          Zach

                          1 Reply Last reply Reply Quote 0
                          • guy038G
                            guy038
                            last edited by guy038

                            Hello zkirkland,

                            Many thanks for this new plugin ! Unfortunately, once downloaded from :

                            https://github.com/zkirkland/FirstUpper/tree/master/PluginInstallFiles

                            and the two files FirstUpper.dll andFirstUpperForbiddenWords.txt, installed in the plugins folder, of my N++ configuration, on restarting Notepad++, I got the message boxes :

                            • The first, in French, which says, something like , below :

                              The program or DLLC:_691\plugins\firstUpper.dll is not a valid windows image. Verify with the help of your installation media

                            • The second N++ message, in English, says :

                              %1 is not a valid Win32 application

                              This program is not compatible with the current version of Notepad++

                              Do you want to remove this plugin from plugins directory to prevent this message from the next launch time?


                            Some hints, about these bug :

                            • My operating system is ( still ! ) a Win XP SP3 configuration

                            • My N++ configuration is a local configuration, with the 6.9.1 version of N++

                            • Here is the result of the ? - The debug Info action :

                              Notepad++ v6.9.1
                              Build time : Mar 28 2016 - 19:48:40
                              Path : C:_691\notepad++.exe
                              Admin mode : OFF
                              Local Conf mode : ON
                              OS : Windows XP
                              Plugins : DSpellCheck.dll mimeTools.dll NppConverter.dll NppExport.dll PluginManager.dll

                            • As about the different .NET modules, installed on my system :

                              • Microsoft .NET Compact Frawework 3.5

                              • Microsoft .NET Framework 1.1

                              • Microsoft .NET Framework 1.1 Hotfix ( KB928366 )

                              • Microsoft .NET Framework 2.0 Service Pack 1

                              • Microsoft .NET Framework 2.0 Secrive Pack 1 Language Pack - FRA

                              • Microsoft .NET Framework 3.0 Service Pack 1

                              • Microsoft .NET Framework 3.0 Secrive Pack 1 Language Pack - FRA

                              • Microsoft .NET Framework 3.5

                              • Microsoft .NET Framework 4 Client Profile

                              • Microsoft User - Mode Driver Framework Feature Pack 1.0

                              • Module linguistique Microsoft .NET Framework 3.5 - fra

                            Any idea ?

                            Best Regards,

                            guy038

                            1 Reply Last reply Reply Quote 1
                            • Kasper GraversenK
                              Kasper Graversen
                              last edited by

                              The plugin framework requires dot net 3.5 but can easily be modified back to 2.0 by removing the factory method returning Func <> and changing the project to 2.0. It would be interesting to see if that is the root problem

                              1 Reply Last reply Reply Quote 0
                              • zkirklandZ
                                zkirkland
                                last edited by

                                @Kasper-Graversen: How and where do I remove that factory method returning Func<,>?

                                1 Reply Last reply Reply Quote 0
                                • zkirklandZ
                                  zkirkland
                                  last edited by

                                  @guy038: I created a build (click me!) that uses .NET 2.0 and x86 architecture to see if that helps. Let me know if it works.

                                  Zach

                                  Kasper GraversenK 1 Reply Last reply Reply Quote 0
                                  • guy038G
                                    guy038
                                    last edited by guy038

                                    Hi zkirkland and Kasper,

                                    Thanks for having a glance about it ! Unfortunately, I get the same error windows, with your new FirstUpper.dll ( 43646 bytes ) and its associated text file FirstUpperForbiddenWords.txt :-((

                                    So, I think that we should have a logical attitude !

                                    • First, ask for people, having a Win XP configuration ( There are still some, indeed !! ) to test your plugin. May be, my Win XP system is just bugged !

                                    • As for me, tomorrow, I’ll verify, at work, your two versions of your plugin, both, on a Win XP and a W7 configuration, with local installation of the last 6.9.2 N++ version, without any additional plugin, but yours, of course !

                                    Cheers,

                                    guy038

                                    1 Reply Last reply Reply Quote 1
                                    • Kasper GraversenK
                                      Kasper Graversen @zkirkland
                                      last edited by

                                      @zkirkland seems you found the factory method :)

                                      1 Reply Last reply Reply Quote 0
                                      • guy038G
                                        guy038
                                        last edited by guy038

                                        Hello zkirkland,

                                        Don’t understand what is happening ? Yesterday, I did try your plugin on an other Win XP machine as well as an W7 system. And as I’m, presently, building a W8.1 64b machine for a friend of mine, I just noticed that it did not work, too, on that W8.1 install !

                                        So, I suppose that I certainly, missed something important, but what ?! As you said, I just copy the DLL and the text file in the plugins folder of my local N++ configuration ?! So, what I’m doing wrong ?

                                        Best Regards,

                                        guy038

                                        1 Reply Last reply Reply Quote 0
                                        • Kasper GraversenK
                                          Kasper Graversen
                                          last edited by

                                          @zkirkland maybe you messed around with the namespaces of the exports. If you try the demo app that comes with the pluginpack you can see the exported functions that N++ requires. Then you can check the ones for your plugin

                                          PS C:\src\NotepadPlusPlusPluginPack.Net\Demo Plugin\NppManagedPluginDemo\bin\Debug> & ‘C:\Program Files (x86)\Microsoft
                                          Visual Studio 14.0\VC\bin\dumpbin.exe’ -exports .\Demo.dll
                                          Microsoft ® COFF/PE Dumper Version 14.00.23918.0
                                          Copyright © Microsoft Corporation. All rights reserved.

                                          Dump of file .\Demo.dll

                                          File Type: DLL

                                          Section contains the following exports for \Demo.dll

                                          00000000 characteristics
                                          572B1CF6 time date stamp Thu May  5 12:14:14 2016
                                              0.00 version
                                                 0 ordinal base
                                                 6 number of functions
                                                 6 number of names
                                          
                                          ordinal hint RVA      name
                                          
                                                5    0 0001691E beNotified
                                                2    1 000168EE getFuncsArray
                                                4    2 0001690E getName
                                                0    3 000168CE isUnicode
                                                3    4 000168FE messageProc
                                                1    5 000168DE setInfo
                                          
                                          1 Reply Last reply Reply Quote 0
                                          • zkirklandZ
                                            zkirkland
                                            last edited by

                                            @guy038: I don’t know yet what is wrong. I am sorry. I am new to writing plugins for Notepad++. I will do my best to figure out what is going on.

                                            @Kasper-Graversen: I do not know how to interpret the output on your file nor do I understand how to use that on my own dll. However, you said perhaps I messed around with the namespaces. I did not change any namespaces.

                                            Zach

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