Menu

Writing plugin in C#, basic questions.

2012-09-07
2015-01-12
  • Mikhail Konvisar

    Hi all.
    Need your help in writing plugin.

    It should do the following:
    1. On file open, N++ fires this plugin, or on button press in N++, doesn't really matters.
    2. Plugin, runs through the opened file, through each line in this file, and matches each line to regex pattern.
    3.1. If line didn't match the pattern, plugin does nothing.
    3.2. If line matches the pattern, plugin highlights this line with some color.

    ===========================================================================
    4. If user right clicks on highlited line, plugin, is connecting to database and displays a comment for this line.
    5. User can add comment or edit existing comment for any line, in this case plugin connects to db, adds or edits this comment, many users should be able to add/edit/remove comments.

    Does anybody know if such plugin already exists?
    If not, could you please help in writing it?

    Questions are:
    - How to automatically start plugin on file open in N++
    - How to start plugin on button press in N++, from menu.
    - How to highlight a line of text in N++, or how to add some pictogram at the beginning of line, so user could see there is a comment available for this line?

    Thanks in advance!

     
  • Adrian

    Adrian - 2012-11-18

    I am trying to get started on a C# plugin. To start I have downloaded NppPlugin.NET.v0.5 then compiled and built it with Microsoft Visual Studio Express 2012 for Windows Desktop, Version 11.0.50727.42. First, when I do a "Rebuild solution" I get the error "The system cannot find the file specified" with no clues as to which file. See the output below.

    But, the Demo.dll file is created. Copyied this file into the "C:\Program Files (x86)\Notepad++\plugins" directory and ran Notepad++ version 6.2. Get a pop-up with it first line saying "This ANSI plugin is not compatible with tour Unicode Notepad++." Checked the source files and find that file "C:\Adrian\VS\NppPlugin.NET.v0.5\Demo Plugin\NppManagedPluginDemo\UnmanagedExports.cs" contains the lines:

    namespace NppPluginNET
    {
    class UnmanagedExports
    {
    [DllExport(CallingConvention=CallingConvention.Cdecl)]
    static bool isUnicode()
    {
    return true;
    }

    From what I have read, the above should mean it is not an ANSI plugin.

    Would like to know what I have done wrong.
    Regards
    Adrian

    1>------ Rebuild All started: Project: NppManagedPluginDemo.VS2010, Configuration: Debug Any CPU ------
    1> NppManagedPluginDemo.VS2010 -> C:\Adrian\VS\NppPlugin.NET.v0.5\Demo Plugin\NppManagedPluginDemo\bin\Debug\Demo.dll
    1> ILDasm: calling 'ildasm.exe' with /quoteallnames /unicode /nobar /linenum "/out:C:\Users\Adrian_2\AppData\Local\Temp\tmpAB1F\Demo.il" "C:\Adrian\VS\NppPlugin.NET.v0.5\Demo Plugin\NppManagedPluginDemo\bin\Debug\Demo.dll"
    1>C:\Adrian\VS\NppPlugin.NET.v0.5\Demo Plugin\NppManagedPluginDemo\DllExport\NppPlugin.DllExport.targets(8,5): error : The system cannot find the file specified
    ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

     
  • Adrian

    Adrian - 2012-11-25

    I have been looking, without success, for a simple unicode plugin for Notepad++ that is written in C# that I can use as a guide to understanding what is right and what is wrong with the C# template I downloaded previously. Would appreciate a link to the source code for a simple C# plugin.
    Thanks
    Adrian

     
  • Adrian

    Adrian - 2012-12-03

    In the two weeks since my first post here, there have been about 90 views of this thread. So there is a lot of interest in it. But no one has been able to provide any help.

    After several years as a user of Notepad++ I wanted to increase my knowledge of the editor and of C# by adding a small feature that I would like to use.

    The documentation of Notepad++ and its plugins says that they can be written in C#. As this is the plugin forum for Notepad++ I assumed that it was the place to look for help on this topic. Perhaps the readers of this forum can direct me to somewhere that can help.

    Regards
    Adrian

     
  • Shaleen Mishra

    Shaleen Mishra - 2012-12-04

    Hey Adrian, I recently started developing a plugin using C# template. Not published it yet as it is still not final, but should be enough for you to get started. Drop me a note on shaleen.mishra@gmail.com and i will revert with the source if you think that might help.

     
  • Adrian

    Adrian - 2012-12-09

    Shaleen has been kind enough to send me a copy of her files. After studying them and doing some more investigation I found why I had had the problems. One of the last stages in the build of a C# plugin invokes the "ildasm.exe" program, which is part of Visual Studio. Unfortunately, the Visual Studio 2012 Express installer does not add the directory with ildasm.exe to the path. The error message I quoted, above, must be complaining that the executable can not be found on the path.

    I added the directory "c:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools" to the path. Then both the NPP C# demo and Shaleen's code compile successfully. Both work when their DLLs are added to the Notepad++ plugin directory.

    Question: Is adding the directory to the path the best solution? Is there some better way of making Visual Studio 2012 find ildasm.exe?
    Regards
    Adrian

     
  • Chris McGrath

    Chris McGrath - 2014-12-14

    Has anyone figured out how to stop using .NET 3.5 and use 4/4.5?

     
    • Shaleen Mishra

      Shaleen Mishra - 2014-12-15

      Well, target framework under plugin project properties can be changed to
      whichever version you want to build with...doesn't that work for ypu?

      -Shaleen
      On Dec 14, 2014 11:15 AM, "Chris McGrath" cpmcgrath1@users.sf.net wrote:

      Has anyone figured out how to stop using .NET 3.5 and use 4/4.5?

      Writing plugin in C#, basic questions.
      https://sourceforge.net/p/notepad-plus/discussion/482781/thread/389e300c/?limit=25#ce5f


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/notepad-plus/discussion/482781/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       
      • Chris McGrath

        Chris McGrath - 2015-01-12

        Hi Shaleen,
        Sorry for the late reply. When I change the version to 4.0 or 4.5, the extension crashes with the useful, "Unknown exception". The Title of the message box says "PluginsManager::runPluginCommand Exception"

         
  • Chris McGrath

    Chris McGrath - 2015-01-12

    Here's an interesting one,
    When I call

    [DllImport("user32")]
    public static extern IntPtr SendMessage(IntPtr hWnd, SciMsg Msg, int wParam, [MarshalAs(UnmanagedType.LPStr)] StringBuilder lParam);

    Unicode glyphs are returned as three characters. For my extension, this is a big problem. I tried changing the UnmanagedType to LPWStr but that returned gibberish. Any Advice?