diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2015-10-23 17:59:00 +0700 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2015-10-23 17:59:00 +0700 |
commit | de91a161b1555bca58c4c30c6367dcc38750ca17 (patch) | |
tree | ec3ebc67b5391bc395a365ca13f267593eb4f9df /kate/app/katesession.cpp | |
parent | f0f642f6b23b9a38727944a6db194bf4d16f0377 (diff) | |
download | tdebase-de91a161b1555bca58c4c30c6367dcc38750ca17.tar.gz tdebase-de91a161b1555bca58c4c30c6367dcc38750ca17.zip |
Populated session panel. Now able to switch session within the new panel.
*** NOTE *** In this commit both the old and new session managers are active,
therefore funny things occasionally happen. Then won't be the case from the
next commit since the old session manager will be disabled.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'kate/app/katesession.cpp')
-rw-r--r-- | kate/app/katesession.cpp | 68 |
1 files changed, 54 insertions, 14 deletions
diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index a6547393a..c66c171cf 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -48,6 +48,9 @@ #include <unistd.h> #include <time.h> +// FIXME general: need to keep doc list and current session's m_documents in synchro +// all the time (doc open, doc closed, doc renamed) + // String constants namespace { @@ -65,6 +68,7 @@ namespace const char *KSM_DIR = "kate/sessions"; const char *KSM_FILE = "sessions.list"; const char *KSM_SESSIONS_COUNT = "Sessions count"; + const char *KSM_ACTIVE_SESSION_ID = "Active session id"; const char *KSM_SESSIONS_LIST = "Sessions list"; } @@ -125,10 +129,7 @@ KateSession::KateSession(const TQString &sessionName, const TQString &filename, { m_sessionName = i18n(KS_UNNAMED); } - if (m_docCount == 0) - { - m_documents.clear(); - } + // FIXME: needs to make sure doc list and m_documents are in synchro here } //------------------------------------ @@ -153,12 +154,6 @@ void KateSession::setSessionName(const TQString &sessionName) //------------------------------------ void KateSession::setReadOnly(bool readOnly) { - if (!m_readOnly && readOnly) - { - // When a session is turned read only, make sure the current - // status is first saved to disk - save(); - } m_readOnly = readOnly; if (m_config) { @@ -167,7 +162,7 @@ void KateSession::setReadOnly(bool readOnly) } //------------------------------------ -void KateSession::save() +void KateSession::save(bool saveDocList) { if (m_readOnly) return; @@ -196,6 +191,7 @@ void KateSession::save() { m_config = new KSimpleConfig(m_filename); } + if (m_config->hasGroup(KS_GENERAL)) { m_config->deleteGroup(KS_GENERAL); @@ -214,11 +210,27 @@ void KateSession::save() { m_config->writeEntry(TQString("URL_%1").arg(i), m_documents[i]); } + if (saveDocList) + { + KateDocManager::self()->saveDocumentList(m_config); + } m_config->sync(); } //------------------------------------ +void KateSession::activate() +{ + KateDocManager::self()->closeAllDocuments(); + Kate::Document::setOpenErrorDialogsActivated(false); + if (m_config) + { + KateApp::self()->documentManager()->restoreDocumentList(m_config); + } + Kate::Document::setOpenErrorDialogsActivated(true); +} + +//------------------------------------ KateSessionManager *KateSessionManager::ksm_instance = NULL; //------------------------------------ @@ -234,7 +246,7 @@ KateSessionManager* KateSessionManager::self() //------------------------------------ KateSessionManager::KateSessionManager() : m_baseDir(locateLocal("data", KSM_DIR)+"/"), m_configFile(m_baseDir + KSM_FILE), - m_sessionsCount(0), m_sessions(), m_config(NULL) + m_sessionsCount(0), m_activeSessionId(-1), m_sessions(), m_config(NULL) { m_sessions.setAutoDelete(true); @@ -244,6 +256,7 @@ KateSessionManager::KateSessionManager() : m_config = new KSimpleConfig(m_configFile); m_config->setGroup(KSM_SESSIONS_LIST); m_sessionsCount = m_config->readNumEntry(KSM_SESSIONS_COUNT, 0); + m_activeSessionId = m_config->readNumEntry(KSM_ACTIVE_SESSION_ID, -1); for (int i=0; i<m_sessionsCount; ++i) { TQString urlStr = m_config->readEntry(TQString("URL_%1").arg(i)); @@ -265,6 +278,11 @@ KateSessionManager::KateSessionManager() : } } m_sessionsCount = static_cast<int>(m_sessions.count()); + if (m_activeSessionId < 0 || m_activeSessionId >= m_sessionsCount) + { + m_activeSessionId = 0; // Invalid active session was detected. Use first in the list + } + m_sessions[m_activeSessionId]->activate(); } //------------------------------------ @@ -294,15 +312,37 @@ void KateSessionManager::saveConfig() } m_config->setGroup(KSM_SESSIONS_LIST); m_config->writeEntry(KSM_SESSIONS_COUNT, m_sessionsCount); + m_config->writeEntry(KSM_ACTIVE_SESSION_ID, m_activeSessionId); for (int i=0; i<m_sessionsCount; ++i) { // Save the session first, to make sure a new session has an associated file - m_sessions[i]->save(); + m_sessions[i]->save(i == m_activeSessionId); m_config->writeEntry(TQString("URL_%1").arg(i), m_sessions[i]->getSessionFilename()); } m_config->sync(); } +//------------------------------------ +bool KateSessionManager::activateSession(int sessionId, bool saveCurr) +{ + if (sessionId == m_activeSessionId) + { + return true; + } + + // First check if all documents can be closed safely + if (KateApp::self()->activeMainWindow()) + { + if (!KateApp::self()->activeMainWindow()->queryClose_internal()) + return false; + } + + m_sessions[m_activeSessionId]->save(true); + m_sessions[sessionId]->activate(); + m_activeSessionId = sessionId; + return true; +} + @@ -485,7 +525,7 @@ OldKateSessionManager::~OldKateSessionManager() OldKateSessionManager *OldKateSessionManager::self() { - return KateApp::self()->sessionManager (); + return KateApp::self()->oldSessionManager (); } void OldKateSessionManager::dirty (const TQString &) |