• Login
Community
  • Login

NPP C# plugin - How to get the list of Notepad++'s open files.

Scheduled Pinned Locked Moved Notepad++ & Plugin Development
17 Posts 4 Posters 10.6k 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.
  • C
    Claudia Frank @Alessandro
    last edited by Oct 13, 2017, 10:08 AM

    @Alessandro

    did I suggest to download the c# template from file-upload.net? I don’t think so.
    From the wiki that you refer to

    The Common Plugin Interface
    bool isUnicode()
    A plugin is designed to either work with an ANSI or Unicode build of Notepad++. ANSI plugins must not define this function. Unicode plugins must define it, and it must return true.

    Cheers
    Claudia

    1 Reply Last reply Reply Quote 0
    • S
      Scott Sumner @Alessandro
      last edited by Oct 13, 2017, 11:16 AM

      @Alessandro

      “This ANSI plugin is not compatible with your Unicode Notepad++” What am I doing wrong? Am I using the wrong C# plugin templete?

      You also asked this SAME question in this OTHER thread:
      https://notepad-plus-plus.org/community/topic/14495/npp-c-plugin-template-for-unicode

      Was @dail 's answer in that other thread not correct or insufficient?

      1 Reply Last reply Reply Quote 0
      • A
        Alessandro
        last edited by Oct 13, 2017, 12:54 PM

        I made a lot of confusion, so sorry.

        You didn’t suggest to download the C# template from file-upload.net.
        Reading your kind post I thought it was right place from which download it. I was evidently wrong also because that template doesn’t work ( “This ANSI plugin is not compatible with your Unicode Notepad++” issue).

        Let’s start from the beginning.

        Can you suggest where to get the demo C# template you talked about and where you get the SendMessage example?

        Regards
        Alessandro

        C 1 Reply Last reply Oct 13, 2017, 1:13 PM Reply Quote 1
        • C
          Claudia Frank @Alessandro
          last edited by Oct 13, 2017, 1:13 PM

          @Alessandro

          the plugin template is from kblisted as stated in your other post, to be exact it is from
          https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net
          If you downloaded from this site you should have a Demo Plugin folder which contains the
          demo.cs file which itself has several SendMessage examples.

          The error about unicode and ansi version is coming from notepadd++.
          What it does is, simple explanation, notepad++ loads your plugin dll and is calling
          a dll function called isUnicode(). If this function returns true then npp assumes it is
          a valid unicode plugin. If this function cannot be called, because you didn’t implement it or it returns false, then it throws this error.
          The plugin template has this function already defined within UnmanagedExports.cs.

          Makes this sense to you?

          Cheers
          Claudia

          1 Reply Last reply Reply Quote 0
          • A
            Alessandro
            last edited by Oct 14, 2017, 7:24 PM

            Dear Claudia,

            I want to thank you so much for the precious help you gave me.

            Everything is clear now. Right C# template, right demo project, exactly what I was looking for. The reason of the NPP’s incompatible dll message when NPP stars is now clear.

            I greatly appreciated your patience and the clarity of your explanation thanks to which I fully understood.

            Cheers
            Alessandro

            C 1 Reply Last reply Oct 14, 2017, 7:28 PM Reply Quote 1
            • C
              Claudia Frank @Alessandro
              last edited by Oct 14, 2017, 7:28 PM

              @Alessandro,

              my pleasure!

              Cheers
              Claudia

              1 Reply Last reply Reply Quote 0
              • A
                Alessandro
                last edited by Oct 18, 2017, 9:51 PM

                @Claudia

                Can you explain me why the method saveCurrentSessionDemo present in the Demo NPP C# plugin, even if the Win32.SendMessage return the full path of the file to be saved (i.e. C:\text.txt) the file text.txt is not created. It happens only if the static string sessionFilePath = @“C:\text.txt”" and it doesn’t if *static string sessionFilePath = @“C:\Users\USR1\Desktop\text.txt”.

                Here is the source code of the saveCurrentSessionDemo

                static void saveCurrentSessionDemo()
                {
                string sessionPath = Marshal.PtrToStringUni(Win32.SendMessage(PluginBase.nppData._nppHandle, (uint) NppMsg.NPPM_SAVECURRENTSESSION, 0, sessionFilePath));
                if (!string.IsNullOrEmpty(sessionPath))
                MessageBox.Show(sessionPath, “Saved Session File :”, MessageBoxButtons.OK);
                }

                Regards and thanks in advance
                Alessandro

                C 1 Reply Last reply Oct 18, 2017, 10:15 PM Reply Quote 0
                • C
                  Claudia Frank @Alessandro
                  last edited by Oct 18, 2017, 10:15 PM

                  @Alessandro

                  I’m a little bit confused about what is working and what doesn’t.
                  Are you saying if you specify sessionFilePath = “C:\text.txt” it is working
                  but if you specify sessionFilePath = “C:\Users\USR1\Desktop\text.txt"
                  it does not work?

                  Or is it vice versa?

                  As I’m not a csharp developer I tried this with python and both ways work for me
                  so I have to assume that the path C:\Users\USR1\Desktop does not exist or permissions
                  problems happen.

                  Cheers
                  Claudia

                  1 Reply Last reply Reply Quote 0
                  • A
                    Alessandro
                    last edited by Oct 18, 2017, 10:38 PM

                    You confusion comes from the fact I’m not a native english, sorry.
                    But yes in my case sessionFilePath = “C:\text.txt” doesn’t work. It also for me a matter of permissions. Then the question is Win32.SendMessage doesn’t return a path null or empty as the file ins’t created.

                    Thank you so much.
                    Alessandro

                    C R 2 Replies Last reply Oct 18, 2017, 11:31 PM Reply Quote 0
                    • C
                      Claudia Frank @Alessandro
                      last edited by Claudia Frank Oct 18, 2017, 11:33 PM Oct 18, 2017, 11:31 PM

                      I tried this with python and it is behaving the same. I don’t get an info that the call failed.
                      I did a quick look to the npp source code and it looks like we should get the info

                      	case NPPM_SAVECURRENTSESSION:
                      	{
                      		return (LRESULT)fileSaveSession(0, NULL, reinterpret_cast<const TCHAR *>(lParam));
                      	}
                      

                      and

                      const TCHAR * Notepad_plus::fileSaveSession(size_t nbFile, TCHAR ** fileNames, const TCHAR *sessionFile2save)
                      {
                          if (sessionFile2save)
                          {
                              Session currentSession;
                              if ((nbFile) && (fileNames))
                              {
                                  for (size_t i = 0 ; i < nbFile ; ++i)
                                  {
                                      if (PathFileExists(fileNames[i]))
                                          currentSession._mainViewFiles.push_back(generic_string(fileNames[i]));
                                  }
                              }
                              else
                                  getCurrentOpenedFiles(currentSession);
                      
                              (NppParameters::getInstance())->writeSession(currentSession, sessionFile2save);
                              return sessionFile2save;
                          }
                          return NULL;
                      }
                      

                      In case of success it should return the full path, in case of error NULL.
                      So I assume, this isn’t correctly implemented, either in python and c# plugin pack
                      or npp. Hmm, as I do not have a windows operating system anymore I can hardly test it. Sorry.

                      Cheers
                      Claudia

                      1 Reply Last reply Reply Quote 0
                      • R
                        rinku singh @Alessandro
                        last edited by Dec 15, 2018, 6:14 AM

                        @Alessandro
                        BGuenthner has good answer here for get all open files and current open files include new tab
                        https://sourceforge.net/p/notepad-plus/discussion/482781/thread/90ae2b1a/

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