void TestCore::initializeNonStatic(Core::Setup mode, const QString& _session) { QString session = _session; if (_session.isEmpty()) { // use a distinct session name for unit test sessions // they are temporary (see below) but still - we want to make sure session = "test-" + qAppName(); } d->initialize( mode, session ); if (_session.isEmpty()) { activeSession()->setTemporary(true); } }
void KateSessionManager::sessionSaveAs() { bool ok = false; QString name = KInputDialog::getText(i18n("Specify New Name for Current Session"), i18n("Session name:"), "", &ok); if(!ok) return; if(name.isEmpty()) { KMessageBox::error(0, i18n("To save a session, you must specify a name."), i18n("Missing Session Name")); return; } activeSession()->create(name, true); saveActiveSession(); }
void KateSessionManager::sessionSave() { // if the active session is valid, just save it :) if(saveActiveSession()) return; bool ok = false; QString name = KInputDialog::getText(i18n("Specify Name for Current Session"), i18n("Session name:"), "", &ok); if(!ok) return; if(name.isEmpty()) { KMessageBox::error(0, i18n("To save a new session, you must specify a name."), i18n("Missing Session Name")); return; } activeSession()->create(name); saveActiveSession(); }
bool KateSessionManager::saveActiveSession(bool tryAsk, bool rememberAsLast) { if(tryAsk) { // app config KConfig *c = KateApp::self()->config(); c->setGroup("General"); QString sesExit(c->readEntry("Session Exit", "save")); if(sesExit == "discard") return true; if(sesExit == "ask") { KDialogBase *dlg = new KDialogBase(i18n("Save Session?"), KDialogBase::Yes | KDialogBase::No, KDialogBase::Yes, KDialogBase::No); bool dontAgain = false; int res = KMessageBox::createKMessageBox(dlg, QMessageBox::Question, i18n("Save current session?"), QStringList(), i18n("Do not ask again"), &dontAgain, KMessageBox::Notify); // remember to not ask again with right setting if(dontAgain) { c->setGroup("General"); if(res == KDialogBase::No) c->writeEntry("Session Exit", "discard"); else c->writeEntry("Session Exit", "save"); } if(res == KDialogBase::No) return true; } } KConfig *sc = activeSession()->configWrite(); if(!sc) return false; KateDocManager::self()->saveDocumentList(sc); sc->setGroup("Open MainWindows"); sc->writeEntry("Count", KateApp::self()->mainWindows()); // save config for all windows around ;) for(unsigned int i = 0; i < KateApp::self()->mainWindows(); ++i) { sc->setGroup(QString("MainWindow%1").arg(i)); KateApp::self()->mainWindow(i)->saveProperties(sc); } sc->sync(); if(rememberAsLast) { KConfig *c = KateApp::self()->config(); c->setGroup("General"); c->writeEntry("Last Session", activeSession()->sessionFileRelative()); c->sync(); } return true; }
void KateSessionManager::activateSession(KateSession::Ptr session, bool closeLast, bool saveLast, bool loadNew) { // don't reload. // ### comparing the pointers directly is b0rk3d :( if(!session->sessionName().isEmpty() && session->sessionName() == m_activeSession->sessionName()) return; // try to close last session if(closeLast) { if(KateApp::self()->activeMainWindow()) { if(!KateApp::self()->activeMainWindow()->queryClose_internal()) return; } } // save last session or not? if(saveLast) saveActiveSession(true); // really close last if(closeLast) { KateDocManager::self()->closeAllDocuments(); } // set the new session m_activeSession = session; if(loadNew) { // open the new session Kate::Document::setOpenErrorDialogsActivated(false); KConfig *sc = activeSession()->configRead(); if(sc) KateApp::self()->documentManager()->restoreDocumentList(sc); // if we have no session config object, try to load the default // (anonymous/unnamed sessions) if(!sc) sc = new KSimpleConfig(sessionsDir() + "/default.katesession"); // window config if(sc) { KConfig *c = KateApp::self()->config(); c->setGroup("General"); if(c->readBoolEntry("Restore Window Configuration", true)) { // a new, named session, read settings of the default session. if(!sc->hasGroup("Open MainWindows")) sc = new KSimpleConfig(sessionsDir() + "/default.katesession"); sc->setGroup("Open MainWindows"); unsigned int wCount = sc->readUnsignedNumEntry("Count", 1); for(unsigned int i = 0; i < wCount; ++i) { if(i >= KateApp::self()->mainWindows()) { KateApp::self()->newMainWindow(sc, QString("MainWindow%1").arg(i)); } else { sc->setGroup(QString("MainWindow%1").arg(i)); KateApp::self()->mainWindow(i)->readProperties(sc); } } if(wCount > 0) { while(wCount < KateApp::self()->mainWindows()) { KateMainWindow *w = KateApp::self()->mainWindow(KateApp::self()->mainWindows() - 1); KateApp::self()->removeMainWindow(w); delete w; } } } } Kate::Document::setOpenErrorDialogsActivated(true); } }