Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a -quitOnEmpty command line flag that causes Notepad++ to quit when the last tab is closed. #1923

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions PowerEditor/src/Notepad_plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3254,6 +3254,17 @@ bool Notepad_plus::canHideView(int whichOne)
return canHide;
}

bool Notepad_plus::isEmpty()
{
if (bothActive()) return false;

DocTabView * tabToCheck = (_mainWindowStatus & WindowMainActive) ? &_mainDocTab : &_subDocTab;

Buffer * buf = MainFileManager->getBufferByID(tabToCheck->getBufferByIndex(0));
bool isEmpty = ((tabToCheck->nbItem() == 1) && !buf->isDirty() && buf->isUntitled());
return isEmpty;
}

void Notepad_plus::loadBufferIntoView(BufferID id, int whichOne, bool dontClose)
{
DocTabView * tabToOpen = (whichOne == MAIN_VIEW)?&_mainDocTab:&_subDocTab;
Expand Down
4 changes: 4 additions & 0 deletions PowerEditor/src/Notepad_plus.h
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ friend class FileManager;

bool _sysMenuEntering = false;

// make sure we don't recursively call doClose when closing the last file with -quitOnEmpty
bool _isAttemptingCloseOnQuit = false;

// For FullScreen/PostIt features
VisibleGUIConf _beforeSpecialView;
Expand Down Expand Up @@ -461,6 +463,8 @@ friend class FileManager;

bool canHideView(int whichOne); //true if view can safely be hidden (no open docs etc)

bool isEmpty(); // true if we have 1 view with 1 clean, untitled doc

int switchEditViewTo(int gid); //activate other view (set focus etc)

void docGotoAnotherEditView(FileTransferMode mode); //TransferMode
Expand Down
2 changes: 2 additions & 0 deletions PowerEditor/src/Notepad_plus_Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
if (nppGUI._rememberLastSession && !cmdLineParams->_isNoSession)
_notepad_plus_plus_core.loadLastSession();

nppGUI._quitOnEmpty = cmdLineParams->_quitOnEmpty;

if (not cmdLineParams->_isPreLaunch)
{
if (cmdLineParams->isPointValid())
Expand Down
2 changes: 2 additions & 0 deletions PowerEditor/src/NppBigSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,9 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
//Causing them to show on restart even though they are loaded by session
_lastRecentFileList.setLock(true); //only lock when the session is remembered
}
_isAttemptingCloseOnQuit = true;
bool allClosed = fileCloseAll(false, isSnapshotMode); //try closing files before doing anything else
_isAttemptingCloseOnQuit = false;

if (nppgui._rememberLastSession)
_lastRecentFileList.setLock(false); //only lock when the session is remembered
Expand Down
14 changes: 14 additions & 0 deletions PowerEditor/src/NppIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,10 @@ void Notepad_plus::doClose(BufferID id, int whichOne, bool doDeleteBackup)
if (i == -1)
return;

int numInitialOpenBuffers =
((_mainWindowStatus & WindowMainActive) == WindowMainActive ? _mainDocTab.nbItem() : 0) +
((_mainWindowStatus & WindowSubActive) == WindowSubActive ? _subDocTab.nbItem() : 0);

if (doDeleteBackup)
MainFileManager->deleteCurrentBufferBackup();

Expand Down Expand Up @@ -663,6 +667,16 @@ void Notepad_plus::doClose(BufferID id, int whichOne, bool doDeleteBackup)
}
}
command(IDM_VIEW_REFRESHTABAR);

if (NppParameters::getInstance()->getNppGUI()._quitOnEmpty)
{
// the user closed the last open tab
if (numInitialOpenBuffers == 1 && isEmpty() && !_isAttemptingCloseOnQuit)
{
command(IDM_FILE_EXIT);
}
}

return;
}

Expand Down
2 changes: 2 additions & 0 deletions PowerEditor/src/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ struct CmdLineParams
int _line2go = -1;
int _column2go = -1;
int _pos2go = -1;
bool _quitOnEmpty = false;

POINT _point;
bool _isPointXValid = false;
Expand Down Expand Up @@ -785,6 +786,7 @@ struct NppGUI final
char _rightmostDelimiter = ')';
bool _delimiterSelectionOnEntireDocument = false;
bool _backSlashIsEscapeCharacterForSql = true;
bool _quitOnEmpty = false;


// 0 : do nothing
Expand Down
2 changes: 2 additions & 0 deletions PowerEditor/src/winmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ const TCHAR FLAG_HELP[] = TEXT("--help");
const TCHAR FLAG_ALWAYS_ON_TOP[] = TEXT("-alwaysOnTop");
const TCHAR FLAG_OPENSESSIONFILE[] = TEXT("-openSession");
const TCHAR FLAG_RECURSIVE[] = TEXT("-r");
const TCHAR FLAG_QUIT_ON_EMPTY[] = TEXT("-quitOnEmpty");


static void doException(Notepad_plus_Window & notepad_plus_plus)
Expand Down Expand Up @@ -302,6 +303,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
cmdLineParams._point.x = getNumberFromParam('x', params, cmdLineParams._isPointXValid);
cmdLineParams._point.y = getNumberFromParam('y', params, cmdLineParams._isPointYValid);
cmdLineParams._easterEggName = getEasterEggNameFromParam(params, cmdLineParams._quoteType);
cmdLineParams._quitOnEmpty = isInList(FLAG_QUIT_ON_EMPTY, params);


if (showHelp)
Expand Down