From 8644afed0d8e383cf3576c598b2ca76833a74e33 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Mon, 23 May 2016 16:17:18 +1000 Subject: Kate session panel: added support for switch/shutdown session options and fixed up logic where required. Fixed Kate quit process to support correct shutdown. Improved handling of configuration option changes. Some code rework. Signed-off-by: Michele Calgaro --- kate/app/kateapp.cpp | 78 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 16 deletions(-) (limited to 'kate/app/kateapp.cpp') diff --git a/kate/app/kateapp.cpp b/kate/app/kateapp.cpp index aeecc5fac..18251ee09 100644 --- a/kate/app/kateapp.cpp +++ b/kate/app/kateapp.cpp @@ -83,6 +83,8 @@ KateApp::KateApp (TDECmdLineArgs *args) kdDebug()<<"Setting KATE_PID: '"<config(); - kateCfg->setGroup("General"); - if (kateCfg->hasKey("Last Session")) + int startupOption = sessionManager()->getStartupOption(); + if (startupOption == KateSessionManager::STARTUP_NEW) { - // Delete no longer used entry (pre R14.1.0) - kateCfg->deleteEntry("Last Session"); + sessionManager()->newSession(); } - TQString startupOption(kateCfg->readEntry("Startup Session", "manual")); - if (startupOption == "last") + else if (startupOption == KateSessionManager::STARTUP_LAST) { sessionManager()->restoreLastSession(); } - else if (startupOption == "new") - { - sessionManager()->newSession(); - } - else // startupOption == "manual" + else // startupOption == KateSessionManager::STARTUP_MANUAL { KateSessionChooser *chooser = new KateSessionChooser(NULL); int result = chooser->exec(); @@ -308,12 +303,9 @@ bool KateApp::startupKate() void KateApp::shutdownKate(KateMainWindow *win) { - if (!win->queryClose_internal()) + if (!win->queryClose_internal() || !query_session_close()) return; - // Save current session here to make sure all GUI elements are saved correctly - sessionManager()->saveActiveSession(); - // detach the dcopClient dcopClient()->detach(); @@ -324,6 +316,60 @@ void KateApp::shutdownKate(KateMainWindow *win) quit (); } +bool KateApp::query_session_close() +{ + bool saveSessions = false; + int switchOption = m_sessionManager->getSwitchOption(); + if (switchOption == KateSessionManager::SWITCH_SAVE) + { + saveSessions = true; + } + else if (switchOption == KateSessionManager::SWITCH_ASK) + { + KDialogBase *dlg = new KDialogBase(i18n("Save Sessions"), + KDialogBase::Yes | KDialogBase::No | KDialogBase::Cancel, + KDialogBase::Cancel, KDialogBase::Cancel, NULL, NULL, true, false, + KStdGuiItem::save(), KStdGuiItem::del(), KStdGuiItem::cancel()); + bool dontAgain = false; + int res = KMessageBox::createKMessageBox(dlg, TQMessageBox::Warning, + i18n("

Do you want to save the existing sessions?

!!NOTE!!" + "

All existing sessions will be removed " + "if you choose \"Delete\""), TQStringList(), + i18n("Do not ask again"), &dontAgain, KMessageBox::Notify); + if (res == KDialogBase::Cancel) + { + return false; + } + if (dontAgain) + { + if (res == KDialogBase::No) + { + m_sessionManager->setSwitchOption(KateSessionManager::SWITCH_DISCARD); + } + else + { + m_sessionManager->setSwitchOption(KateSessionManager::SWITCH_SAVE); + } + } + if (res == KDialogBase::Yes) + { + saveSessions = true; + } + } + + if (saveSessions) + { + m_sessionManager->saveActiveSession(); + } + m_sessionManager->saveConfig(saveSessions); + return true; +} + +void KateApp::reparse_config() +{ + emit optionsChanged(); +} + KatePluginManager *KateApp::pluginManager() { return m_pluginManager; -- cgit v1.2.1