From 6abc4939de7074b337bf11c37b9d0046ef415a20 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Tue, 6 Nov 2007 19:23:42 +0000 Subject: [PATCH] accidently closing a window with one session in it, no big deal. maybe annoying, but that's all. closing a window with 10 active sesssions in it and it just disappearing ... no good. that's why every (ewll behaved) tabbed app asks for confirmation in these cases. konsole in kde3 did it too. now, to set up those tabs again ... *sigh* svn path=/trunk/KDE/kdebase/apps/konsole/; revision=733577 --- src/MainWindow.cpp | 38 +++++++++++++++++++++++++++++++++++++- src/MainWindow.h | 8 ++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index eb712b79c..88f249139 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -27,15 +27,18 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include #include -#include +#include +#include #include #include @@ -46,6 +49,7 @@ #include "SessionController.h" #include "ProfileList.h" #include "ManageProfilesDialog.h" +#include "Session.h" #include "ViewManager.h" #include "ViewSplitter.h" @@ -279,6 +283,38 @@ void MainWindow::newWindow() emit newWindowRequest( _defaultProfile , activeSessionDir() ); } +bool MainWindow::queryClose() +{ + if (kapp->sessionSaving() || + _viewManager->viewProperties().count() < 2) + return true; + + int res = KMessageBox::warningYesNoCancel(this, + i18n("You have multiple terminal sessions open in this window, are you sure you want to quit?"), + i18n("Really Quit?"), + KStandardGuiItem::quit(), + KGuiItem(i18n("Close current sesion"), "tab-close"), + KStandardGuiItem::cancel(), + "CloseAllSessions"); + + switch (res) { + case KMessageBox::Yes: + return true; + break; + case KMessageBox::No: + if (_pluggedController && _pluggedController->session()) { + _pluggedController->session()->close(); + } + return false; + break; + case KMessageBox::Cancel: + return false; + break; + } + + return true; +} + void MainWindow::showShortcutsDialog() { KShortcutsDialog::configure( actionCollection() , diff --git a/src/MainWindow.h b/src/MainWindow.h index 41300b1ea..0fd4b9fa3 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -120,6 +120,14 @@ class MainWindow : public KXmlGuiWindow void newWindowRequest(const QString& key, const QString& directory); + /** + * Emitted by the main window to request the current session to close. + */ + void closeActiveSessionRequest(); + + protected: + bool queryClose(); + private slots: void newTab(); void newWindow();