• Login
Community
  • Login

Howto close current file / editor witout savequestion

Scheduled Pinned Locked Moved Notepad++ & Plugin Development
10 Posts 3 Posters 792 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.
  • M
    MarioRosi
    last edited by Mar 6, 2020, 7:29 PM

    Hello,

    i programming a litle plugin on C#.

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

    regards Mario

    E A 2 Replies Last reply Mar 6, 2020, 7:44 PM Reply Quote 1
    • E
      Ekopalypse @MarioRosi
      last edited by Mar 6, 2020, 7:44 PM

      @MarioRosi

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

      1 Reply Last reply Reply Quote 1
      • A
        Alan Kilborn @MarioRosi
        last edited by Mar 6, 2020, 7:45 PM

        @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
        • E
          Ekopalypse
          last edited by Mar 6, 2020, 7:49 PM

          @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()
          
          A 1 Reply Last reply Mar 6, 2020, 7:50 PM Reply Quote 1
          • A
            Alan Kilborn @Ekopalypse
            last edited by Mar 6, 2020, 7:50 PM

            @Ekopalypse

            editor.setSavePoint()

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

            1 Reply Last reply Reply Quote 1
            • M
              MarioRosi
              last edited by Mar 6, 2020, 8:40 PM

              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.

              E 1 Reply Last reply Mar 6, 2020, 8:55 PM Reply Quote 0
              • E
                Ekopalypse @MarioRosi
                last edited by Mar 6, 2020, 8:55 PM

                @MarioRosi

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

                1 Reply Last reply Reply Quote 0
                • M
                  MarioRosi
                  last edited by Mar 6, 2020, 8:58 PM

                  @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
                  • E
                    Ekopalypse
                    last edited by Ekopalypse Mar 6, 2020, 9:06 PM Mar 6, 2020, 9:05 PM

                    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
                    • M
                      MarioRosi
                      last edited by Mar 6, 2020, 9:06 PM

                      @ 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
                      4 out of 10
                      • First post
                        4/10
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors