Feature Request: CTRL+W exits np when only 1 file open

fr33man
2014-06-16
2014-06-28
  • fr33man

    fr33man - 2014-06-16

    Web browsers have great feature: when CTRL+W in single tabbed window is pressed, it closes the window. I also think it does not make sense to actualy execute "close & new" command in npp+ with CTRL+W in single tabbed window, which happens now if only one tab is opened.

    I use mouse hotkey binding to either close tabs or exit program with mouse button. The problem is, with mouse hotkey binding software I cannot detect if there is only one tab open in tabbed interface to switch key to ALT+F4 to close window. So I have to chose between CTRL+W or ALT+F4, instead to merge both features in CTRL+W hotkey, which would also close np++ window if there is only single file opened.

    Please either implement this feature or provide at least option to close application in case CTRL+W is pressed when only one tab is opened. Thanks.

     
  • Loreia2

    Loreia2 - 2014-06-16

    Hi fr33man,

    install PythonScript plugin (from Plugin manager), create a new scipt, copy/paste below code in it. You can create button on toolbar or assign a shortcut to execute this script, I guess you should use CTRL+W.

    Regards,
    Loreia

    ~~~~~~~~~~~~~~~~~~~~~~~~~
    if len(notepad.getFiles()) > 1:
    notepad.close()
    else:
    notepad.menuCommand(MENUCOMMAND.FILE_EXIT)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~

     
  • fr33man

    fr33man - 2014-06-17

    It does not work. If I use sys.exit() instead of menuCommand, then notepad++ hangs itself.

     
  • Loreia2

    Loreia2 - 2014-06-18

    Hi,

    code works for me without issues.
    Can you describe what goes wrong for you?

    Regards,
    Loreia

     
  • fr33man

    fr33man - 2014-06-20

    If I use your code, then notepad++ does not exit when there is only single tab opened.

    If I change the line
    notepad.menuCommand(MENUCOMMAND.FILE_EXIT)
    with
    sys.exit()
    then np++ hangs when script is executed when only one tab opened.

     
  • fr33man

    fr33man - 2014-06-20

    I have version 6.6.6. And you?

     
  • fr33man

    fr33man - 2014-06-26

    Any feedback? I am willing to donate for this feature.

     
  • Loreia2

    Loreia2 - 2014-06-26

    Hi fr33man,

    thanks for the remainder, I am using a custom version which is based on some older version. I just downloaded latest 6.6.7 ZIP version, tried there and indeed it doesn't work. It closes a file, but not the application.

    I will check what is going on and post an updated version during the day.
    As for donation, here is my offer: if I provide a working script, you pay any amount to either:
    a) Linux Mint project: http://linuxmint.com/donors.php
    b) Krita fundraiser: https://www.kickstarter.com/projects/krita/krita-open-source-digital-painting-accelerate-deve

    Regards,
    Loreia

     
  • Loreia2

    Loreia2 - 2014-06-26

    Hi,

    it looks like new version is reporting invisible buffers, here is a modified script that takes into account these buffers:

    ~~~~~~~~~~~~~~~~~~~~~~
    files = notepad.getFiles()

    console.write("files: " + str(notepad.getFiles()) + "\n")
    console.write("view: " + str(notepad.getCurrentView()) + "\n")

    if len(files) == 1:
    notepad.menuCommand(MENUCOMMAND.FILE_EXIT)
    elif len(files) == 2 and \ files[0][0].startswith("new ") and files[0][2] == 0 and files[0][3] == 0 and \ files[1][0].startswith("new ") and files[1][2] == 0 and files[1][3] == 1:
    notepad.menuCommand(MENUCOMMAND.FILE_EXIT)
    else:
    notepad.close()
    ~~~~~~~~~~~~~~~~~~~~~~~

    Can you test this and provide feedback here?

    Regards,
    Loreia

     
  • fr33man

    fr33man - 2014-06-27

    It works. I simplified it to:

    if len(notepad.getFiles()) <= 2:
    notepad.menuCommand(MENUCOMMAND.FILE_EXIT)
    else:
    notepad.close()

    However, I hoped that somebody would get this integrated in np++ binary, without the need to use plugin and possibly update the script later when design of np++ changes.

    Nevertheless, I will donate. Thanks.

     
  • Loreia2

    Loreia2 - 2014-06-28

    Hi fr33man,

    your version will work with just one view active, but you might have a legit case where two files are open in different views. If such scenario is not important to you, your version will work just fine.

    Anyway, I agree that this might be an interesting option to include in main application.

    Regards,
    Loreia

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks