Closing Notepad ++ when closing the last document

I have been using notepad ++ for a couple of months now and have been looking through all the settings, but cannot find a way to close npp when I close the last tab. It always launches a new blank document.

Any ideas how I can get npp to close the closing of the last document?

+6
source share
4 answers

This is entirely based on ufo code. Just that it works when you close the last document, whether it is new or not, and it does not delay npp.

For brevity, the steps are repeated here again:

  • Install Python Script Plugin
  • In plugins> Python Script> Change configuration Initialization mode from LAZY to ATSARTUP
  • Open ... \ Notepad ++ \ plugins \ PythonScript \ scripts \ startup.py and put the following code at the end.
  • Save and restart Npp to load the script.

    from threading import Timer def shutdownNppOnLastFileClosed(args): def closeNpp(): notepad.menuCommand(MENUCOMMAND.FILE_EXIT) files = notepad.getFiles() if len(files) == 2: t = Timer(0.1, closeNpp) t.start() notepad.callback(shutdownNppOnLastFileClosed, [NOTIFICATION.FILEBEFORECLOSE]) 
+3
source

If you are familiar with Python, you can try the Python Script plugin for N ++. You must set a script callback for the closed document. Inside, it performs some iteration through all open documents, and when there is only 1 left, without text in it, then complete N ++.

Personally, I have mapped the Alt + x keys to Exit Notepad ++, which is easier to engrave than Alt + F4 usually works.

/ EDIT

I really liked your idea, so I quickly tried it. It took ~ 20 minutes to figure this out. Here's the complete solution:

 def shutdownNppOnLastFileClosed(args): import os files = notepad.getFiles() # there are always at least 2 'buffers' open in N++ if len(files) == 2: currentBufferID = notepad.getCurrentBufferID() for (filename, bufferID, index, view) in files: if os.path.exists(filename): break notepad.activateBufferID(bufferID) if editor.getLength() > 0: break # TODO: just to be on the safe side - if we # reached here, we actually should also check # if the 2 left empty buffers are not unsaved, # but I couldn't find a way to do that. else: # following 'menuCommand' looks cleaner than # the 'sys.exit' but it currently deadlocks N++: #notepad.menuCommand(MENUCOMMAND.FILE_EXIT) sys.exit(0) notepad.activateBufferID(currentBufferID) notepad.callback(shutdownNppOnLastFileClosed, [NOTIFICATION.FILECLOSED]) 
+2
source

The latest Notepad ++ update includes the functionality to close the application after closing the last tab.

To update Notepad ++, go to? > Update Notepad ++ and follow the instructions of the installation wizard.

When the update is completed, you will have an option in the menu "Settings"> "Settings" to "Exit to close the last tab" (in the input group of the Tab tab).

+2
source

notepad ++ is an MDI form application, such as MS OFFICE, closing an MDI form for a child will not affect the main application, so I think this is not an idea if you do not restore the source nodepad ++.

0
source

Source: https://habr.com/ru/post/914281/


All Articles