Added a -quitOnEmpty command line flag
closes #1923, Fixes #1006 -quitOnEmpty command line flag makes Notepad++ to quit when the last tab is closed. Useful for people who use Notead++ for things like editing Git commit messages (using -multiInst -notabbar -nosession), and want to signal they are done editing by closing the tab with Ctrl-W instead of Alt-F4.pull/2141/head
parent
27d80432d8
commit
8b0f5165d2
|
@ -3266,6 +3266,17 @@ bool Notepad_plus::canHideView(int whichOne)
|
||||||
return canHide;
|
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)
|
void Notepad_plus::loadBufferIntoView(BufferID id, int whichOne, bool dontClose)
|
||||||
{
|
{
|
||||||
DocTabView * tabToOpen = (whichOne == MAIN_VIEW)?&_mainDocTab:&_subDocTab;
|
DocTabView * tabToOpen = (whichOne == MAIN_VIEW)?&_mainDocTab:&_subDocTab;
|
||||||
|
|
|
@ -364,6 +364,8 @@ private:
|
||||||
|
|
||||||
bool _sysMenuEntering = false;
|
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
|
// For FullScreen/PostIt features
|
||||||
VisibleGUIConf _beforeSpecialView;
|
VisibleGUIConf _beforeSpecialView;
|
||||||
|
@ -464,6 +466,8 @@ private:
|
||||||
|
|
||||||
bool canHideView(int whichOne); //true if view can safely be hidden (no open docs etc)
|
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)
|
int switchEditViewTo(int gid); //activate other view (set focus etc)
|
||||||
|
|
||||||
void docGotoAnotherEditView(FileTransferMode mode); //TransferMode
|
void docGotoAnotherEditView(FileTransferMode mode); //TransferMode
|
||||||
|
|
|
@ -176,6 +176,8 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
|
||||||
if (nppGUI._rememberLastSession && !cmdLineParams->_isNoSession)
|
if (nppGUI._rememberLastSession && !cmdLineParams->_isNoSession)
|
||||||
_notepad_plus_plus_core.loadLastSession();
|
_notepad_plus_plus_core.loadLastSession();
|
||||||
|
|
||||||
|
nppGUI._quitOnEmpty = cmdLineParams->_quitOnEmpty;
|
||||||
|
|
||||||
if (not cmdLineParams->_isPreLaunch)
|
if (not cmdLineParams->_isPreLaunch)
|
||||||
{
|
{
|
||||||
if (cmdLineParams->isPointValid())
|
if (cmdLineParams->isPointValid())
|
||||||
|
|
|
@ -1646,7 +1646,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
|
//Causing them to show on restart even though they are loaded by session
|
||||||
_lastRecentFileList.setLock(true); //only lock when the session is remembered
|
_lastRecentFileList.setLock(true); //only lock when the session is remembered
|
||||||
}
|
}
|
||||||
|
_isAttemptingCloseOnQuit = true;
|
||||||
bool allClosed = fileCloseAll(false, isSnapshotMode); //try closing files before doing anything else
|
bool allClosed = fileCloseAll(false, isSnapshotMode); //try closing files before doing anything else
|
||||||
|
_isAttemptingCloseOnQuit = false;
|
||||||
|
|
||||||
if (nppgui._rememberLastSession)
|
if (nppgui._rememberLastSession)
|
||||||
_lastRecentFileList.setLock(false); //only lock when the session is remembered
|
_lastRecentFileList.setLock(false); //only lock when the session is remembered
|
||||||
|
|
|
@ -599,6 +599,10 @@ void Notepad_plus::doClose(BufferID id, int whichOne, bool doDeleteBackup)
|
||||||
if (i == -1)
|
if (i == -1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
size_t numInitialOpenBuffers =
|
||||||
|
((_mainWindowStatus & WindowMainActive) == WindowMainActive ? _mainDocTab.nbItem() : 0) +
|
||||||
|
((_mainWindowStatus & WindowSubActive) == WindowSubActive ? _subDocTab.nbItem() : 0);
|
||||||
|
|
||||||
if (doDeleteBackup)
|
if (doDeleteBackup)
|
||||||
MainFileManager->deleteCurrentBufferBackup();
|
MainFileManager->deleteCurrentBufferBackup();
|
||||||
|
|
||||||
|
@ -675,6 +679,16 @@ void Notepad_plus::doClose(BufferID id, int whichOne, bool doDeleteBackup)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
command(IDM_VIEW_REFRESHTABAR);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,6 +183,7 @@ struct CmdLineParams
|
||||||
int _line2go = -1;
|
int _line2go = -1;
|
||||||
int _column2go = -1;
|
int _column2go = -1;
|
||||||
int _pos2go = -1;
|
int _pos2go = -1;
|
||||||
|
bool _quitOnEmpty = false;
|
||||||
|
|
||||||
POINT _point;
|
POINT _point;
|
||||||
bool _isPointXValid = false;
|
bool _isPointXValid = false;
|
||||||
|
@ -755,6 +756,7 @@ struct NppGUI final
|
||||||
char _rightmostDelimiter = ')';
|
char _rightmostDelimiter = ')';
|
||||||
bool _delimiterSelectionOnEntireDocument = false;
|
bool _delimiterSelectionOnEntireDocument = false;
|
||||||
bool _backSlashIsEscapeCharacterForSql = true;
|
bool _backSlashIsEscapeCharacterForSql = true;
|
||||||
|
bool _quitOnEmpty = false;
|
||||||
|
|
||||||
|
|
||||||
// 0 : do nothing
|
// 0 : do nothing
|
||||||
|
|
|
@ -240,6 +240,7 @@ const TCHAR FLAG_HELP[] = TEXT("--help");
|
||||||
const TCHAR FLAG_ALWAYS_ON_TOP[] = TEXT("-alwaysOnTop");
|
const TCHAR FLAG_ALWAYS_ON_TOP[] = TEXT("-alwaysOnTop");
|
||||||
const TCHAR FLAG_OPENSESSIONFILE[] = TEXT("-openSession");
|
const TCHAR FLAG_OPENSESSIONFILE[] = TEXT("-openSession");
|
||||||
const TCHAR FLAG_RECURSIVE[] = TEXT("-r");
|
const TCHAR FLAG_RECURSIVE[] = TEXT("-r");
|
||||||
|
const TCHAR FLAG_QUIT_ON_EMPTY[] = TEXT("-quitOnEmpty");
|
||||||
|
|
||||||
|
|
||||||
static void doException(Notepad_plus_Window & notepad_plus_plus)
|
static void doException(Notepad_plus_Window & notepad_plus_plus)
|
||||||
|
@ -304,6 +305,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
|
||||||
cmdLineParams._point.x = getNumberFromParam('x', params, cmdLineParams._isPointXValid);
|
cmdLineParams._point.x = getNumberFromParam('x', params, cmdLineParams._isPointXValid);
|
||||||
cmdLineParams._point.y = getNumberFromParam('y', params, cmdLineParams._isPointYValid);
|
cmdLineParams._point.y = getNumberFromParam('y', params, cmdLineParams._isPointYValid);
|
||||||
cmdLineParams._easterEggName = getEasterEggNameFromParam(params, cmdLineParams._quoteType);
|
cmdLineParams._easterEggName = getEasterEggNameFromParam(params, cmdLineParams._quoteType);
|
||||||
|
cmdLineParams._quitOnEmpty = isInList(FLAG_QUIT_ON_EMPTY, params);
|
||||||
|
|
||||||
|
|
||||||
if (showHelp)
|
if (showHelp)
|
||||||
|
|
Loading…
Reference in New Issue