Navigation

    Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    Howto close current file / editor witout savequestion

    Plugin Development
    3
    10
    77
    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.
    • MarioRosi
      MarioRosi last edited by

      Hello,

      i programming a litle plugin on C#.

      How can i close the current file / editor without question for save changing?

      regards Mario

      Ekopalypse Alan Kilborn 2 Replies Last reply Reply Quote 1
      • Ekopalypse
        Ekopalypse @MarioRosi last edited by

        @MarioRosi

        do you want to discard the changes or to always save it?

        1 Reply Last reply Reply Quote 1
        • Alan Kilborn
          Alan Kilborn @MarioRosi last edited by

          @MarioRosi

          Being a Pythonscript programmer, and having wanted to do the same type of thing in the past, I didn’t really find that it is possible in P.S., but maybe with a true plugin it IS possible?

          Anyway, what I do in a P.S. is, since you are discarding changes anyway, is execute repetitive “undo” operations until you get the file back to an unmodified state. Then it can be closed without Notepad++ prompting for anything.

          Of course, if you want to save the changes, what I do via P.S. is a “save” and then the “close” on the file. There should be something mimicing that for true plugins.

          1 Reply Last reply Reply Quote 1
          • Ekopalypse
            Ekopalypse last edited by

            @Alan-Kilborn said in Howto close current file / editor witout savequestion:

            Anyway, what I do in a P.S. is, since you are discarding changes anyway, is execute repetitive “undo” operations until you get the file back to an unmodified state.

            Maybe I’m wrong but shouldn’t this work to discard the changes?

            editor.setSavePoint()
            notepad.close()
            
            Alan Kilborn 1 Reply Last reply Reply Quote 1
            • Alan Kilborn
              Alan Kilborn @Ekopalypse last edited by

              @Ekopalypse

              editor.setSavePoint()

              Never noticed that one; I’ll have to give it a try! :-)

              1 Reply Last reply Reply Quote 1
              • MarioRosi
                MarioRosi last edited by

                Hello,

                @Ekopalypse

                do you want to discard the changes or to always save it?

                yes i want discard all changes and close only the file, not the notepad.

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

                  @MarioRosi

                  Then I would say use the c# equivalent messages to my pythonscript example.

                  1 Reply Last reply Reply Quote 0
                  • MarioRosi
                    MarioRosi last edited by

                    @Ekopalypse

                    IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());
                    editor.SetSavePoint();
                    

                    works and set the document ans unchanged.

                    but how close the document “notepad.close” dosnt exist.

                    1 Reply Last reply Reply Quote 1
                    • Ekopalypse
                      Ekopalypse last edited by Ekopalypse

                      Oh, ok - you need to use SendMessage and menuCommand enums.
                      From python this is like

                      def close(self) -> None:    # done
                          ''' Closes the currently active document '''
                          self.menuCommand(MENUCOMMAND.FILE_CLOSE)
                      
                      def menuCommand(self, commandID: int) -> None:   # done
                          ''' Runs a Notepad++ menu command - just pass the commandID '''
                          self.__npp_send(NPPM_MENUCOMMAND, 0, commandID)
                      
                      def __npp_send(self, message: int, wparam: int=0, lparam: int=0) -> int:  # done
                          ''' internal function used to send npp messages to npp '''
                          result = user32.SendMessageW(self.hwnd, message, wparam, lparam)
                          return result
                      

                      WM_USER = 1024
                      NPPMSG = WM_USER + 1000
                      NPPM_MENUCOMMAND = NPPMSG + 48

                      IDM = 40000
                      FILE = IDM + 1000
                      FILE_NEW = FILE + 1
                      FILE_OPEN = FILE + 2
                      FILE_CLOSE = FILE + 3

                      MENUCOMMAND.FILE_CLOSE = IDM + FILE +3

                      self.hwnd is the handle from npp that you get via setInfo callback

                      1 Reply Last reply Reply Quote 2
                      • MarioRosi
                        MarioRosi last edited by

                        @ all

                        i have found a solution:

                        IScintillaGateway editor = new ScintillaGateway(PluginBase.GetCurrentScintilla());
                        editor.SetSavePoint();
                        Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_MENUCOMMAND, 0, NppMenuCmd.IDM_FILE_CLOSE);
                        

                        work wit current tab.
                        thanks for inspiration

                        1 Reply Last reply Reply Quote 3
                        • First post
                          Last post
                        Copyright © 2014 NodeBB Forums | Contributors