2012-04-27 80 views
6

我正在使用記事本++幾個月,並通過了所有設置,但無法找到一種方法在關閉最後一個選項卡時關閉npp。它總是會啓動一個新的空文檔。當關閉最後一個文檔時關閉記事本++

任何想法如何使npp在關閉最後一個文檔時關閉?

回答

0

notepad ++是一個MDI表單應用程序,就像MS OFFICE一樣,關閉子MDI表單不會影響主應用程序,所以,除非重建nodepad ++的源代碼,否則我認爲這是不知道的。

2

如果您熟悉Python,則可以嘗試使用Python Script插件進行N ++。 您將爲文檔關閉事件設置回調腳本。在它內部對所有打開的文檔進行一些迭代,當剩下的只剩下1個文本時,則終止N ++。

就我個人而言,我將按鍵「Alt + x」映射到「退出」記事本++,這更容易抓圖,然後通常工作的「Alt + F4」。

/EDIT

其實我挺喜歡你的想法,所以我趕緊嘗試過自己。 花了20分鐘才弄明白。下面是一個完整的解決方案:

  1. 安裝插件的Python腳本(以上鍊接)
  2. 轉到插件>的Python>配置和改變初始化模式從LAZYATSARTUP
  3. 打開「... \ Notepad ++ \ plugins \ Pyth onScript \腳本\ startup.py「,地點在之後它的結束代碼:Seems like the code tags don't work below a numbered list, so click me to see the code
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]) 
+0

它有一個錯誤 - 當沒有保存的文檔打開 - 只打開(一個&&空&&沒有改變)文檔 - 它不工作 – msangel 2013-05-20 00:52:44

3

這完全是基於UFO的代碼。只有當你關閉最後一個文檔時它才起作用,不管它是否新建,它都不會凍結npp。

爲了簡潔起見,這裏如下再次步驟:

  1. 安裝Python腳本插件
  2. 插件>的Python腳本>從LAZY配置變化初始化模式ATSARTUP
  3. 打開... \ Notepad ++ \ plugins \ PythonScript \ scripts \ startup.py並在其末尾放置下面的代碼。
  4. 保存並重新啓動Npp以加載腳本。

    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]) 
    
2

記事本++最新的更新包括關閉最後一個標籤後關閉應用程序的功能。

要更新Notepad ++,請進入?>更新Notepad ++並遵循安裝嚮導。

更新完成後,您可以在設置>首選項菜單中選擇「退出關閉最後一個選項卡」(在選項卡欄輸入組下)。

+0

從Notepad ++ v7.5.3起,使用startup.py和PythonScript有一些問題用作Git編輯器。如果一個文件通過PythonScript關閉,那麼它似乎掛起了Git進程。記事本++實例在外觀上看起來是封閉的,但根據Process Explorer保持不變。 使用@ Sebastian的建議爲我工作。 – blitzvergnugen 2018-01-02 19:02:34