Disabled the old session manager and switched permanently to the new one. Lot of functionality still missing.

It is possible to switch sessions from the session panel (either by the activate pushbutton or by executing a listview item).
Kate's session settings are currently not yet supported (last session is saved and restored by default).

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/2/head
Michele Calgaro 10 years ago
parent de91a161b1
commit 099c8a8821

@ -75,7 +75,6 @@ KateApp::KateApp (TDECmdLineArgs *args)
m_pluginManager = new KatePluginManager (TQT_TQOBJECT(this)); m_pluginManager = new KatePluginManager (TQT_TQOBJECT(this));
// session manager up // session manager up
m_oldSessionManager = new OldKateSessionManager (TQT_TQOBJECT(this));
m_sessionManager = KateSessionManager::self(); m_sessionManager = KateSessionManager::self();
// application dcop interface // application dcop interface
@ -109,7 +108,6 @@ KateApp::~KateApp ()
delete m_obj; // cu dcop interface delete m_obj; // cu dcop interface
delete m_pluginManager; // cu plugin manager delete m_pluginManager; // cu plugin manager
delete m_sessionManager; // delete session manager delete m_sessionManager; // delete session manager
delete m_oldSessionManager; // delete session manager
delete m_docManager; // delete document manager. Do this now, or we crash delete m_docManager; // delete document manager. Do this now, or we crash
} }
@ -137,24 +135,22 @@ TQString KateApp::kateVersion (bool fullVersion)
return fullVersion ? TQString ("2.5.%1").arg(KDE::versionMajor()) : TQString ("%1.%2").arg(2.5); return fullVersion ? TQString ("2.5.%1").arg(KDE::versionMajor()) : TQString ("%1.%2").arg(2.5);
} }
void KateApp::restoreKate () void KateApp::restoreKate()
{ {
// restore the nice files ;) we need it // restore the nice files ;) we need it
Kate::Document::setOpenErrorDialogsActivated (false); Kate::Document::setOpenErrorDialogsActivated(false);
// activate again correct session!!! // restore last session
sessionConfig()->setGroup("General"); sessionManager()->restoreLastSession();
TQString lastSession (sessionConfig()->readEntry ("Last Session", "default.katesession")); m_docManager->restoreDocumentList(sessionConfig());
oldSessionManager()->activateSession (new OldKateSession (oldSessionManager(), lastSession, ""), false, false, false);
m_docManager->restoreDocumentList (sessionConfig());
Kate::Document::setOpenErrorDialogsActivated (true); Kate::Document::setOpenErrorDialogsActivated(true);
// restore all windows ;) // restore all windows ;)
for (int n=1; TDEMainWindow::canBeRestored(n); n++) for (int n=1; TDEMainWindow::canBeRestored(n); n++)
newMainWindow(sessionConfig(), TQString ("%1").arg(n)); newMainWindow(sessionConfig(), TQString ("%1").arg(n));
// oh, no mainwindow, create one, should not happen, but make sure ;) // no mainwindow, create one, should not happen, but make sure ;)
if (mainWindows() == 0) if (mainWindows() == 0)
newMainWindow (); newMainWindow ();
@ -167,17 +163,24 @@ bool KateApp::startupKate ()
// user specified session to open // user specified session to open
if (m_args->isSet ("start")) if (m_args->isSet ("start"))
{ {
oldSessionManager()->activateSession (oldSessionManager()->giveSession (TQString::fromLocal8Bit(m_args->getOption("start"))), false, false); // MIKE fixme: need to handle this functionality
sessionManager()->activateSession(
sessionManager()->getSessionIdFromName(TQString::fromLocal8Bit(m_args->getOption("start"))));
} }
else else
{ {
// MIKE: for the time being just open last session.
// FIXME: need to add support for startup session options
sessionManager()->restoreLastSession();
// MIKE fixme: need to handle this functionality
// let the user choose session if possible // let the user choose session if possible
if (!oldSessionManager()->chooseSession ()) /*if (!oldSessionManager()->chooseSession ())
{ {
// we will exit kate now, notify the rest of the world we are done // we will exit kate now, notify the rest of the world we are done
TDEStartupInfo::appStarted (startupId()); TDEStartupInfo::appStarted (startupId());
return false; return false;
} }*/
} }
// oh, no mainwindow, create one, should not happen, but make sure ;) // oh, no mainwindow, create one, should not happen, but make sure ;)
@ -264,12 +267,13 @@ bool KateApp::startupKate ()
return true; return true;
} }
void KateApp::shutdownKate (KateMainWindow *win) void KateApp::shutdownKate(KateMainWindow *win)
{ {
if (!win->queryClose_internal()) if (!win->queryClose_internal())
return; return;
oldSessionManager()->saveActiveSession(true, true); // Save current session here to make sure all GUI elements are saved correctly
sessionManager()->saveActiveSession();
// detach the dcopClient // detach the dcopClient
dcopClient()->detach(); dcopClient()->detach();
@ -291,11 +295,6 @@ KateDocManager *KateApp::documentManager ()
return m_docManager; return m_docManager;
} }
OldKateSessionManager *KateApp::oldSessionManager ()
{
return m_oldSessionManager;
}
KateSessionManager* KateApp::sessionManager() KateSessionManager* KateApp::sessionManager()
{ {
return m_sessionManager; return m_sessionManager;

@ -26,7 +26,6 @@
#include <tqvaluelist.h> #include <tqvaluelist.h>
class OldKateSessionManager;
class KateSessionManager; class KateSessionManager;
class KateAppDCOPIface; class KateAppDCOPIface;
@ -129,7 +128,6 @@ class KDE_EXPORT KateApp : public TDEApplication
* accessor to session manager * accessor to session manager
* @return session manager instance * @return session manager instance
*/ */
OldKateSessionManager *oldSessionManager ();
KateSessionManager *sessionManager(); KateSessionManager *sessionManager();
/** /**
@ -224,7 +222,6 @@ class KDE_EXPORT KateApp : public TDEApplication
/** /**
* session manager * session manager
*/ */
OldKateSessionManager *m_oldSessionManager;
KateSessionManager *m_sessionManager; KateSessionManager *m_sessionManager;

@ -89,16 +89,17 @@ bool KateAppDCOPIface::openInput (TQString text)
return m_app->openInput (text); return m_app->openInput (text);
} }
bool KateAppDCOPIface::activateSession (TQString session) bool KateAppDCOPIface::activateSession(TQString session)
{ {
m_app->oldSessionManager()->activateSession (m_app->oldSessionManager()->giveSession (session)); // MIKE: to fix
// m_app->sessionManager()->activateSession (m_app->oldSessionManager()->giveSession (session));
return true; return true;
} }
const TQString & KateAppDCOPIface::session() const const TQString& KateAppDCOPIface::session() const
{ {
return m_app->oldSessionManager()->activeSession()->sessionName(); return m_app->sessionManager()->getActiveSessionName();
} }
// kate: space-indent on; indent-width 2; replace-tabs on; // kate: space-indent on; indent-width 2; replace-tabs on;

@ -305,8 +305,9 @@ void KateMainWindow::setupActions()
slotWindowActivated (); slotWindowActivated ();
// MIKE to fix and enable again
// session actions // session actions
new TDEAction(i18n("Menu entry Session->New", "&New"), "list-add", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionNew()), actionCollection(), "sessions_new"); /* new TDEAction(i18n("Menu entry Session->New", "&New"), "list-add", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionNew()), actionCollection(), "sessions_new");
new TDEAction(i18n("&Open..."), "document-open", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionOpen()), actionCollection(), "sessions_open"); new TDEAction(i18n("&Open..."), "document-open", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionOpen()), actionCollection(), "sessions_open");
new TDEAction(i18n("&Save"), "document-save", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionSave()), actionCollection(), "sessions_save"); new TDEAction(i18n("&Save"), "document-save", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionSave()), actionCollection(), "sessions_save");
new TDEAction(i18n("Save &As..."), "document-save-as", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionSaveAs()), actionCollection(), "sessions_save_as"); new TDEAction(i18n("Save &As..."), "document-save-as", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionSaveAs()), actionCollection(), "sessions_save_as");
@ -314,6 +315,7 @@ void KateMainWindow::setupActions()
// quick open menu ;) // quick open menu ;)
new OldKateSessionsAction (i18n("&Quick Open"), actionCollection(), "sessions_list"); new OldKateSessionsAction (i18n("&Quick Open"), actionCollection(), "sessions_list");
*/
} }
KateTabWidget *KateMainWindow::tabWidget () KateTabWidget *KateMainWindow::tabWidget ()
@ -370,7 +372,7 @@ bool KateMainWindow::queryClose()
// and save docs if we really close down ! // and save docs if we really close down !
if ( queryClose_internal () ) if ( queryClose_internal () )
{ {
KateApp::self()->oldSessionManager()->saveActiveSession(true, true); KateApp::self()->sessionManager()->saveActiveSession();
// detach the dcopClient // detach the dcopClient
KateApp::self()->dcopClient()->detach(); KateApp::self()->dcopClient()->detach();
@ -824,7 +826,7 @@ void KateMainWindow::updateCaption (Kate::Document *doc)
c = m_viewManager->activeView()->getDoc()->url().prettyURL(); c = m_viewManager->activeView()->getDoc()->url().prettyURL();
} }
TQString sessName = KateApp::self()->oldSessionManager()->activeSession()->sessionName(); TQString sessName = KateApp::self()->sessionManager()->getActiveSessionName();
if ( !sessName.isEmpty() ) if ( !sessName.isEmpty() )
sessName = TQString("%1: ").arg( sessName ); sessName = TQString("%1: ").arg( sessName );
@ -855,10 +857,8 @@ void KateMainWindow::readProperties(TDEConfig *config)
void KateMainWindow::saveGlobalProperties( TDEConfig* sessionConfig ) void KateMainWindow::saveGlobalProperties( TDEConfig* sessionConfig )
{ {
KateDocManager::self()->saveDocumentList (sessionConfig); // MIKE do we still need this code here?
// KateDocManager::self()->saveDocumentList (sessionConfig);
sessionConfig->setGroup("General");
sessionConfig->writeEntry ("Last Session", KateApp::self()->oldSessionManager()->activeSession()->sessionFileRelative());
} }
// kate: space-indent on; indent-width 2; replace-tabs on; // kate: space-indent on; indent-width 2; replace-tabs on;

@ -50,6 +50,7 @@
// FIXME general: need to keep doc list and current session's m_documents in synchro // FIXME general: need to keep doc list and current session's m_documents in synchro
// all the time (doc open, doc closed, doc renamed) // all the time (doc open, doc closed, doc renamed)
// FIXME add code to handle the various options in Configure Kate -> Application -> Sessions
// String constants // String constants
namespace namespace
@ -63,6 +64,7 @@ namespace
const char *KS_OPENDOC = "Open Documents"; const char *KS_OPENDOC = "Open Documents";
const char *KS_READONLY = "ReadOnly"; const char *KS_READONLY = "ReadOnly";
const char *KS_UNNAMED = "Unnamed"; const char *KS_UNNAMED = "Unnamed";
const char *KS_OPEN_MAINWINDOWS = "Open MainWindows";
// Kate session manager // Kate session manager
const char *KSM_DIR = "kate/sessions"; const char *KSM_DIR = "kate/sessions";
@ -162,14 +164,14 @@ void KateSession::setReadOnly(bool readOnly)
} }
//------------------------------------ //------------------------------------
void KateSession::save(bool saveDocList) void KateSession::save(bool saveGUIInfo)
{ {
if (m_readOnly) if (m_readOnly)
return; return;
// create a new session filename if needed
if (!m_isFullName) if (!m_isFullName)
{ {
// create a new session filename
int s = time(0); int s = time(0);
TQCString tname; TQCString tname;
TQString tmpName; TQString tmpName;
@ -187,6 +189,7 @@ void KateSession::save(bool saveDocList)
} }
} }
// save session config info
if (!m_config) if (!m_config)
{ {
m_config = new KSimpleConfig(m_filename); m_config = new KSimpleConfig(m_filename);
@ -210,9 +213,20 @@ void KateSession::save(bool saveDocList)
{ {
m_config->writeEntry(TQString("URL_%1").arg(i), m_documents[i]); m_config->writeEntry(TQString("URL_%1").arg(i), m_documents[i]);
} }
if (saveDocList)
// save GUI elements info
if (saveGUIInfo)
{ {
KateDocManager::self()->saveDocumentList(m_config); KateDocManager::self()->saveDocumentList(m_config);
// save main windows info
int mwCount = KateApp::self()->mainWindows();
m_config->setGroup(KS_OPEN_MAINWINDOWS);
m_config->writeEntry(KS_COUNT, mwCount);
for (int i=0; i<mwCount; ++i)
{
m_config->setGroup(TQString("MainWindow%1").arg(i));
KateApp::self()->mainWindow(i)->saveProperties(m_config);
}
} }
m_config->sync(); m_config->sync();
@ -221,12 +235,35 @@ void KateSession::save(bool saveDocList)
//------------------------------------ //------------------------------------
void KateSession::activate() void KateSession::activate()
{ {
KateDocManager::self()->closeAllDocuments(); if (KateDocManager::self()->documents() > 0)
{
KateDocManager::self()->closeAllDocuments();
}
Kate::Document::setOpenErrorDialogsActivated(false); Kate::Document::setOpenErrorDialogsActivated(false);
if (m_config) if (m_config)
{ {
KateApp::self()->documentManager()->restoreDocumentList(m_config); KateApp::self()->documentManager()->restoreDocumentList(m_config);
} }
// load main windows info, if it exists
if (m_config && m_config->hasGroup(KS_OPEN_MAINWINDOWS))
{
m_config->setGroup(KS_OPEN_MAINWINDOWS);
int mwCount = m_config->readUnsignedNumEntry(KS_COUNT, 1);
for (int i=0; i<mwCount; ++i)
{
if (i >= KateApp::self()->mainWindows())
{
KateApp::self()->newMainWindow(m_config, TQString("MainWindow%1").arg(i));
}
else
{
m_config->setGroup(TQString("MainWindow%1").arg(i));
KateApp::self()->mainWindow(i)->readProperties(m_config);
}
}
}
Kate::Document::setOpenErrorDialogsActivated(true); Kate::Document::setOpenErrorDialogsActivated(true);
} }
@ -246,7 +283,7 @@ KateSessionManager* KateSessionManager::self()
//------------------------------------ //------------------------------------
KateSessionManager::KateSessionManager() : KateSessionManager::KateSessionManager() :
m_baseDir(locateLocal("data", KSM_DIR)+"/"), m_configFile(m_baseDir + KSM_FILE), m_baseDir(locateLocal("data", KSM_DIR)+"/"), m_configFile(m_baseDir + KSM_FILE),
m_sessionsCount(0), m_activeSessionId(-1), m_sessions(), m_config(NULL) m_sessionsCount(0), m_activeSessionId(0), m_firstActivation(true), m_sessions(), m_config(NULL)
{ {
m_sessions.setAutoDelete(true); m_sessions.setAutoDelete(true);
@ -256,7 +293,8 @@ KateSessionManager::KateSessionManager() :
m_config = new KSimpleConfig(m_configFile); m_config = new KSimpleConfig(m_configFile);
m_config->setGroup(KSM_SESSIONS_LIST); m_config->setGroup(KSM_SESSIONS_LIST);
m_sessionsCount = m_config->readNumEntry(KSM_SESSIONS_COUNT, 0); m_sessionsCount = m_config->readNumEntry(KSM_SESSIONS_COUNT, 0);
m_activeSessionId = m_config->readNumEntry(KSM_ACTIVE_SESSION_ID, -1); //FIXME : if m_sessionsCount == 0, create session list from existing session files
m_activeSessionId = m_config->readNumEntry(KSM_ACTIVE_SESSION_ID, 0);
for (int i=0; i<m_sessionsCount; ++i) for (int i=0; i<m_sessionsCount; ++i)
{ {
TQString urlStr = m_config->readEntry(TQString("URL_%1").arg(i)); TQString urlStr = m_config->readEntry(TQString("URL_%1").arg(i));
@ -278,11 +316,18 @@ KateSessionManager::KateSessionManager() :
} }
} }
m_sessionsCount = static_cast<int>(m_sessions.count()); m_sessionsCount = static_cast<int>(m_sessions.count());
if (m_sessionsCount == 0) // In the worst case, there is no valid session at all
{
m_sessions.append(new KateSession(TQString::null, m_baseDir, false));
++m_sessionsCount;
}
if (m_activeSessionId < 0 || m_activeSessionId >= m_sessionsCount) if (m_activeSessionId < 0 || m_activeSessionId >= m_sessionsCount)
{ {
m_activeSessionId = 0; // Invalid active session was detected. Use first in the list m_activeSessionId = 0; // Invalid active session was detected. Use first in the list
} }
m_sessions[m_activeSessionId]->activate(); //NOTE do not activate any session in the KateSessionManager costructor
// since Kate's main window may not be ready yet. The initial session
// will be activated by KateApp::startupKate() or void KateApp::restoreKate()
} }
//------------------------------------ //------------------------------------
@ -316,34 +361,71 @@ void KateSessionManager::saveConfig()
for (int i=0; i<m_sessionsCount; ++i) for (int i=0; i<m_sessionsCount; ++i)
{ {
// Save the session first, to make sure a new session has an associated file // Save the session first, to make sure a new session has an associated file
m_sessions[i]->save(i == m_activeSessionId); m_sessions[i]->save(false);
m_config->writeEntry(TQString("URL_%1").arg(i), m_sessions[i]->getSessionFilename()); m_config->writeEntry(TQString("URL_%1").arg(i), m_sessions[i]->getSessionFilename());
} }
m_config->sync(); m_config->sync();
} }
//------------------------------------
int KateSessionManager::getSessionIdFromName(const TQString &name)
{
if (name.isEmpty())
return KateSessionManager::INVALID_SESSION;
for (int i=0; i<m_sessionsCount; ++i)
{
if (m_sessions[i]->getSessionName() == name)
return i;
}
return KateSessionManager::INVALID_SESSION;
}
//------------------------------------ //------------------------------------
bool KateSessionManager::activateSession(int sessionId, bool saveCurr) bool KateSessionManager::activateSession(int sessionId, bool saveCurr)
{ {
if (sessionId == m_activeSessionId) if (sessionId < 0)
{
return false;
}
if (!m_firstActivation && sessionId == m_activeSessionId)
{ {
return true; return true;
} }
// First check if all documents can be closed safely if (!m_firstActivation)
if (KateApp::self()->activeMainWindow())
{ {
if (!KateApp::self()->activeMainWindow()->queryClose_internal()) // Do this only if a session has already been activated earlier,
return false; if (KateApp::self()->activeMainWindow())
{
// First check if all documents can be closed safely
if (!KateApp::self()->activeMainWindow()->queryClose_internal())
return false;
}
if (saveCurr)
{
m_sessions[m_activeSessionId]->save(true);
}
} }
m_sessions[m_activeSessionId]->save(true);
m_sessions[sessionId]->activate(); m_sessions[sessionId]->activate();
m_activeSessionId = sessionId; m_activeSessionId = sessionId;
m_firstActivation = false;
return true; return true;
} }
//------------------------------------
bool KateSessionManager::restoreLastSession()
{
if (!m_firstActivation)
{
return false;
}
// NOTE: m_activeSessionId contains the id of the last active session
return activateSession(m_activeSessionId, false);
}
@ -525,7 +607,7 @@ OldKateSessionManager::~OldKateSessionManager()
OldKateSessionManager *OldKateSessionManager::self() OldKateSessionManager *OldKateSessionManager::self()
{ {
return KateApp::self()->oldSessionManager (); return (OldKateSessionManager*)KateApp::self()->sessionManager();
} }
void OldKateSessionManager::dirty (const TQString &) void OldKateSessionManager::dirty (const TQString &)

@ -31,6 +31,8 @@
#include <tqvaluelist.h> #include <tqvaluelist.h>
#include <tqstringlist.h> #include <tqstringlist.h>
class KateViewSpace;
class OldKateSessionManager; // Michele - to be removed with OldKateSession class OldKateSessionManager; // Michele - to be removed with OldKateSession
class KDirWatch; class KDirWatch;
@ -41,68 +43,76 @@ class TQCheckBox;
class KateSession class KateSession
{ {
public: public:
/** /**
* create a new session and read the config from fileName if it exists * create a new session and read the config from fileName if it exists
* @param sessionName session name * @param sessionName session name
* @param fileName file where session config is saved to/restored from * @param fileName file where session config is saved to/restored from
* @param isFullName true -> filename is a full filename, used to load/save the session configuration * @param isFullName true -> filename is a full filename, used to load/save the session configuration
* false -> filename is a folder name. This is used for new unsaved sessions * false -> filename is a folder name. This is used for new unsaved sessions
* to inject the location where the configuration file should be saved * to inject the location where the configuration file should be saved
*/ */
KateSession(const TQString &sessionName, const TQString &fileName, bool isFullName); KateSession(const TQString &sessionName, const TQString &fileName, bool isFullName);
/** /**
* Destructor * Destructor
*/ */
~KateSession(); ~KateSession();
/** /**
* @return the session name * @return the session name
*/ */
const TQString& getSessionName() const { return m_sessionName; } const TQString& getSessionName() const { return m_sessionName; }
/** /**
* Set the new session name * Set the new session name
* @param sessionName the new session name * @param sessionName the new session name
*/ */
void setSessionName(const TQString &sessionName); void setSessionName(const TQString &sessionName);
/** /**
* @return whether the session is read only or not * @return whether the session is read only or not
*/ */
bool isReadOnly() const { return m_readOnly; } bool isReadOnly() const { return m_readOnly; }
/** /**
* Set session read only status * Set session read only status
* @param readOnly if true, the session config can not be saved to file * @param readOnly if true, the session config can not be saved to file
*/ */
void setReadOnly(bool readOnly); void setReadOnly(bool readOnly);
/** /**
* @return the session filename * @return the session filename
*/ */
const TQString& getSessionFilename() const { return m_filename; } const TQString& getSessionFilename() const { return m_filename; }
/** /**
* Save session info * Save session info
* @param saveDocList if true, save also the information about the documents currently open * @param saveGUIInfo if true, save also the information about the GUI elements
*/ */
void save(bool saveDocList); void save(bool saveGUIInfo);
/** /**
* Activate the session * Activate the session
*/ */
void activate(); void activate();
private: private:
TQString m_sessionName;
TQString m_filename; friend class KateViewSpace;
bool m_isFullName; // true -> m_filename is a full filename /**
// false -> m_filename is a folder name. * @return the session config object
bool m_readOnly; */
int m_docCount; // number of documents in the session TDEConfig* getConfig() { return m_config; }
TQStringList m_documents; // document URLs
KSimpleConfig *m_config; // session config
TQString m_sessionName;
TQString m_filename;
bool m_isFullName; // true -> m_filename is a full filename
// false -> m_filename is a folder name.
bool m_readOnly;
int m_docCount; // number of documents in the session
TQStringList m_documents; // document URLs
KSimpleConfig *m_config; // session config
}; };
@ -110,56 +120,88 @@ class KateSession
//------------------------------------ //------------------------------------
class KateSessionManager class KateSessionManager
{ {
public: public:
/** enum
* get a pointer to the unique KateSessionManager instance. {
* If the manager does not exist yet, create it. INVALID_SESSION = -1
*/ };
static KateSessionManager* self();
/** /**
* Destructor * get a pointer to the unique KateSessionManager instance.
*/ * If the manager does not exist yet, create it.
~KateSessionManager(); */
static KateSessionManager* self();
/** /**
* Save session manager info * Destructor
*/ */
void saveConfig(); ~KateSessionManager();
/** /**
* @return the active session id * Save session manager info
*/ */
int getActiveSessionId() const { return m_activeSessionId; } void saveConfig();
/** /**
* @return a reference to the active session * @return the active session id
*/ */
KateSession* getActiveSession() { return m_sessions[m_activeSessionId]; } int getActiveSessionId() const { return m_activeSessionId; }
/**
* @return the active session name
*/
const TQString& getActiveSessionName() /*FIXME const*/ { return m_sessions[m_activeSessionId]->getSessionName(); }
/**
* @return a reference to the active session
*/
KateSession* getActiveSession() { return m_sessions[m_activeSessionId]; }
/**
* @return a reference to the sessions list
*/
TQPtrList<KateSession>& getSessionsList() { return m_sessions; }
/** /**
* @return a reference to the sessions list * Returns the session id of the first session whose name matches the
* provided one
* @param name the session name to look for
* @return the session id of the matching session if it is found,
* otherwise KateSessionManager::INVALID_SESSION.
*/ */
TQPtrList<KateSession>& getSessionsList() { return m_sessions; } int getSessionIdFromName(const TQString &name);
/**
* Activates the selected session.
* @param sessionId the id of the session to activate
* @param saveCurr if true, save the current session before activating the new one
* @return whether the session was activated or not
*/
bool activateSession(int sessionId, bool saveCurr = true);
/** /**
* Activates the selected session. * Restore the last saved session. Can only be used before
* @param sessionId the id of the session to activate * any other session has been activated, i.e. on Kate's startup
* @param saveCurr if true, save the current session before activating the new one
* @return whether the session was activated or not * @return whether the session was activated or not
*/ */
bool activateSession(int sessionId, bool saveCurr = true); bool restoreLastSession();
private: /**
KateSessionManager(); * Saves the active session
*/
void saveActiveSession() { m_sessions[m_activeSessionId]->save(true); }
private:
KateSessionManager();
TQString m_baseDir; // folder where session files are stored TQString m_baseDir; // folder where session files are stored
TQString m_configFile; // file where the session list config is stored TQString m_configFile; // file where the session list config is stored
int m_sessionsCount; // number of sessions int m_sessionsCount; // number of sessions
int m_activeSessionId; // index of the active session int m_activeSessionId; // index of the active session
TQPtrList<KateSession> m_sessions; // session list bool m_firstActivation; // true until at least one session has been activated
KSimpleConfig *m_config; // session manager config TQPtrList<KateSession> m_sessions; // session list
KSimpleConfig *m_config; // session manager config
static KateSessionManager *ksm_instance; // the only KateSessionManager instance static KateSessionManager *ksm_instance; // the only KateSessionManager instance
}; };
@ -173,380 +215,382 @@ class KateSessionManager
//------------------------------------ //------------------------------------
class OldKateSession : public TDEShared class OldKateSession : public TDEShared
{ {
public: public:
/** /**
* Define a Shared-Pointer type * Define a Shared-Pointer type
*/ */
typedef TDESharedPtr<OldKateSession> Ptr; typedef TDESharedPtr<OldKateSession> Ptr;
public: public:
/** /**
* create a session from given file * create a session from given file
* @param fileName session filename, relative * @param fileName session filename, relative
* @param name session name * @param name session name
* @param manager pointer to the manager * @param manager pointer to the manager
*/ */
OldKateSession (OldKateSessionManager *manager, const TQString &fileName, const TQString &name); OldKateSession ( OldKateSessionManager *manager, const TQString &fileName, const TQString &name );
/** /**
* init the session object, after construction or create * init the session object, after construction or create
*/ */
void init (); void init ();
/** /**
* destruct me * destruct me
*/ */
~OldKateSession (); ~OldKateSession ();
/** /**
* session filename, absolute, calculated out of relative filename + session dir * session filename, absolute, calculated out of relative filename + session dir
* @return absolute path to session file * @return absolute path to session file
*/ */
TQString sessionFile () const; TQString sessionFile () const;
/** /**
* relative session filename * relative session filename
* @return relative filename for this session * @return relative filename for this session
*/ */
const TQString &sessionFileRelative () const { return m_sessionFileRel; } const TQString &sessionFileRelative () const { return m_sessionFileRel; }
/** /**
* session name * session name
* @return name for this session * @return name for this session
*/ */
const TQString &sessionName () const { return m_sessionName; } const TQString &sessionName () const { return m_sessionName; }
/** /**
* is this a valid session? if not, don't use any session if this is * is this a valid session? if not, don't use any session if this is
* the active one * the active one
*/ */
bool isNew () const { return m_sessionName.isEmpty(); } bool isNew () const { return m_sessionName.isEmpty(); }
/** /**
* create the session file, if not existing * create the session file, if not existing
* @param name name for this session * @param name name for this session
* @param force force to create new file * @param force force to create new file
* @return true if created, false if no creation needed * @return true if created, false if no creation needed
*/ */
bool create (const TQString &name, bool force = false); bool create ( const TQString &name, bool force = false );
/** /**
* rename this session * rename this session
* @param name new name * @param name new name
* @return success * @return success
*/ */
bool rename (const TQString &name); bool rename ( const TQString &name );
/** /**
* config to read * config to read
* on first access, will create the config object, delete will be done automagic * on first access, will create the config object, delete will be done automagic
* return 0 if we have no file to read config from atm * return 0 if we have no file to read config from atm
* @return config to read from * @return config to read from
*/ */
TDEConfig *configRead (); TDEConfig *configRead ();
/** /**
* config to write * config to write
* on first access, will create the config object, delete will be done automagic * on first access, will create the config object, delete will be done automagic
* return 0 if we have no file to write config to atm * return 0 if we have no file to write config to atm
* @return config to write from * @return config to write from
*/ */
TDEConfig *configWrite (); TDEConfig *configWrite ();
/** /**
* count of documents in this session * count of documents in this session
* @return documents count * @return documents count
*/ */
unsigned int documents () const { return m_documents; } unsigned int documents () const { return m_documents; }
private: private:
/** /**
* session filename, in local location we can write to * session filename, in local location we can write to
* relative filename to the session dirs :) * relative filename to the session dirs :)
*/ */
TQString m_sessionFileRel; TQString m_sessionFileRel;
/** /**
* session name, extracted from the file, to display to the user * session name, extracted from the file, to display to the user
*/ */
TQString m_sessionName; TQString m_sessionName;
/** /**
* number of document of this session * number of document of this session
*/ */
unsigned int m_documents; unsigned int m_documents;
/** /**
* OldKateSessionMananger * OldKateSessionMananger
*/ */
OldKateSessionManager *m_manager; OldKateSessionManager *m_manager;
/** /**
* simpleconfig to read from * simpleconfig to read from
*/ */
KSimpleConfig *m_readConfig; KSimpleConfig *m_readConfig;
/** /**
* simpleconfig to write to * simpleconfig to write to
*/ */
KSimpleConfig *m_writeConfig; KSimpleConfig *m_writeConfig;
}; };
typedef TQValueList<OldKateSession::Ptr> OldKateSessionList; typedef TQValueList<OldKateSession::Ptr> OldKateSessionList;
class OldKateSessionManager : public TQObject class OldKateSessionManager : public TQObject
{ {
Q_OBJECT Q_OBJECT
public: public:
OldKateSessionManager(TQObject *parent); OldKateSessionManager ( TQObject *parent );
~OldKateSessionManager(); ~OldKateSessionManager();
/** /**
* allow access to this :) * allow access to this :)
* @return instance of the session manager * @return instance of the session manager
*/ */
static OldKateSessionManager *self(); static OldKateSessionManager *self();
/** /**
* allow access to the session list * allow access to the session list
* kept up to date by watching the dir * kept up to date by watching the dir
*/ */
inline OldKateSessionList & sessionList () { updateSessionList (); return m_sessionList; } inline OldKateSessionList & sessionList () { updateSessionList (); return m_sessionList; }
/** /**
* activate a session * activate a session
* first, it will look if a session with this name exists in list * first, it will look if a session with this name exists in list
* if yes, it will use this session, else it will create a new session file * if yes, it will use this session, else it will create a new session file
* @param session session to activate * @param session session to activate
* @param closeLast try to close last session or not? * @param closeLast try to close last session or not?
* @param saveLast try to save last session or not? * @param saveLast try to save last session or not?
* @param loadNew load new session stuff? * @param loadNew load new session stuff?
*/ */
void activateSession (OldKateSession::Ptr session, bool closeLast = true, bool saveLast = true, bool loadNew = true); void activateSession ( OldKateSession::Ptr session, bool closeLast = true, bool saveLast = true, bool loadNew = true );
/** /**
* create a new session * create a new session
* @param name session name * @param name session name
*/ */
OldKateSession::Ptr createSession (const TQString &name); OldKateSession::Ptr createSession ( const TQString &name );
/** /**
* return session with given name * return session with given name
* if no existing session matches, create new one with this name * if no existing session matches, create new one with this name
* @param name session name * @param name session name
*/ */
OldKateSession::Ptr giveSession (const TQString &name); OldKateSession::Ptr giveSession ( const TQString &name );
/** /**
* save current session * save current session
* for sessions without filename: save nothing * for sessions without filename: save nothing
* @param tryAsk should we ask user if needed? * @param tryAsk should we ask user if needed?
* @param rememberAsLast remember this session as last used? * @param rememberAsLast remember this session as last used?
* @return success * @return success
*/ */
bool saveActiveSession (bool tryAsk = false, bool rememberAsLast = false); bool saveActiveSession ( bool tryAsk = false, bool rememberAsLast = false );
/** /**
* return the current active session * return the current active session
* sessionFile == empty means we have no session around for this instance of kate * sessionFile == empty means we have no session around for this instance of kate
* @return session active atm * @return session active atm
*/ */
inline OldKateSession::Ptr activeSession () { return m_activeSession; } inline OldKateSession::Ptr activeSession () { return m_activeSession; }
/** /**
* session dir * session dir
* @return global session dir * @return global session dir
*/ */
inline const TQString &sessionsDir () const { return m_sessionsDir; } inline const TQString &sessionsDir () const { return m_sessionsDir; }
/** /**
* initial session chooser, on app start * initial session chooser, on app start
* @return success, if false, app should exit * @return success, if false, app should exit
*/ */
bool chooseSession (); bool chooseSession ();
public slots: public slots:
/** /**
* try to start a new session * try to start a new session
* asks user first for name * asks user first for name
*/ */
void sessionNew (); void sessionNew ();
/** /**
* try to open a existing session * try to open a existing session
*/ */
void sessionOpen (); void sessionOpen ();
/** /**
* try to save current session * try to save current session
*/ */
void sessionSave (); void sessionSave ();
/** /**
* try to save as current session * try to save as current session
*/ */
void sessionSaveAs (); void sessionSaveAs ();
/** /**
* show dialog to manage our sessions * show dialog to manage our sessions
*/ */
void sessionManage (); void sessionManage ();
private slots: private slots:
void dirty (const TQString &path); void dirty ( const TQString &path );
public: public:
/** /**
* trigger update of session list * trigger update of session list
*/ */
void updateSessionList (); void updateSessionList ();
private: private:
/** /**
* absolute path to dir in home dir where to store the sessions * absolute path to dir in home dir where to store the sessions
*/ */
TQString m_sessionsDir; TQString m_sessionsDir;
/** /**
* list of current available sessions * list of current available sessions
*/ */
OldKateSessionList m_sessionList; OldKateSessionList m_sessionList;
/** /**
* current active session * current active session
*/ */
OldKateSession::Ptr m_activeSession; OldKateSession::Ptr m_activeSession;
}; };
class OldKateSessionChooser : public KDialogBase class OldKateSessionChooser : public KDialogBase
{ {
Q_OBJECT Q_OBJECT
public: public:
OldKateSessionChooser (TQWidget *parent, const TQString &lastSession); OldKateSessionChooser ( TQWidget *parent, const TQString &lastSession );
~OldKateSessionChooser (); ~OldKateSessionChooser ();
OldKateSession::Ptr selectedSession (); OldKateSession::Ptr selectedSession ();
bool reopenLastSession (); bool reopenLastSession ();
enum { enum
resultQuit = TQDialog::Rejected, {
resultOpen, resultQuit = TQDialog::Rejected,
resultNew, resultOpen,
resultNone resultNew,
}; resultNone
};
protected slots: protected slots:
/** /**
* open session * open session
*/ */
void slotUser1 (); void slotUser1 ();
/** /**
* new session * new session
*/ */
void slotUser2 (); void slotUser2 ();
/** /**
* quit kate * quit kate
*/ */
void slotUser3 (); void slotUser3 ();
/** /**
* selection has changed * selection has changed
*/ */
void selectionChanged (); void selectionChanged ();
private: private:
TDEListView *m_sessions; TDEListView *m_sessions;
TQCheckBox *m_useLast; TQCheckBox *m_useLast;
}; };
class OldKateSessionOpenDialog : public KDialogBase class OldKateSessionOpenDialog : public KDialogBase
{ {
Q_OBJECT Q_OBJECT
public: public:
OldKateSessionOpenDialog (TQWidget *parent); OldKateSessionOpenDialog ( TQWidget *parent );
~OldKateSessionOpenDialog (); ~OldKateSessionOpenDialog ();
OldKateSession::Ptr selectedSession (); OldKateSession::Ptr selectedSession ();
enum { enum
resultOk, {
resultCancel resultOk,
}; resultCancel
};
protected slots: protected slots:
/** /**
* cancel pressed * cancel pressed
*/ */
void slotUser1 (); void slotUser1 ();
/** /**
* ok pressed * ok pressed
*/ */
void slotUser2 (); void slotUser2 ();
private: private:
TDEListView *m_sessions; TDEListView *m_sessions;
}; };
class OldKateSessionManageDialog : public KDialogBase class OldKateSessionManageDialog : public KDialogBase
{ {
Q_OBJECT Q_OBJECT
public:
OldKateSessionManageDialog (TQWidget *parent);
~OldKateSessionManageDialog ();
protected slots: public:
/** OldKateSessionManageDialog ( TQWidget *parent );
* close pressed ~OldKateSessionManageDialog ();
*/
void slotUser1 ();
/** protected slots:
* selection has changed /**
*/ * close pressed
void selectionChanged (); */
void slotUser1 ();
/** /**
* try to rename session * selection has changed
*/ */
void rename (); void selectionChanged ();
/** /**
* try to delete session * try to rename session
*/ */
void del (); void rename ();
private: /**
/** * try to delete session
* update our list */
*/ void del ();
void updateSessionList ();
private: private:
TDEListView *m_sessions; /**
KPushButton *m_rename; * update our list
KPushButton *m_del; */
void updateSessionList ();
private:
TDEListView *m_sessions;
KPushButton *m_rename;
KPushButton *m_del;
}; };
class OldKateSessionsAction : public TDEActionMenu class OldKateSessionsAction : public TDEActionMenu
{ {
Q_OBJECT Q_OBJECT
public: public:
OldKateSessionsAction(const TQString& text, TQObject* parent = 0, const char* name = 0); OldKateSessionsAction ( const TQString& text, TQObject* parent = 0, const char* name = 0 );
~OldKateSessionsAction (){;}; ~OldKateSessionsAction () {;};
public slots: public slots:
void slotAboutToShow(); void slotAboutToShow();
void openSession (int i); void openSession ( int i );
}; };
#endif #endif

@ -62,7 +62,8 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager *
m_listview->setColumnAlignment(2, TQt::AlignCenter); m_listview->setColumnAlignment(2, TQt::AlignCenter);
m_listview->setMinimumWidth(m_listview->sizeHint().width()); m_listview->setMinimumWidth(m_listview->sizeHint().width());
m_listview->setSorting(-1); m_listview->setSorting(-1);
//m_listview->setRootIsDecorated(true); // to enable after inserting doc list //m_listview->setRootIsDecorated(true); // MIKE to enable after inserting doc list
connect(m_listview, TQT_SIGNAL(executed(TQListViewItem*)), TQT_SLOT(itemExecuted(TQListViewItem*)));
TQPtrList<KateSession>& sessions = m_sessionManager->getSessionsList(); TQPtrList<KateSession>& sessions = m_sessionManager->getSessionsList();
for (int idx = sessions.count()-1; idx >= 0; --idx) for (int idx = sessions.count()-1; idx >= 0; --idx)
@ -210,3 +211,16 @@ void KateSessionPanel::sessionMoveDown()
{ {
//TODO //TODO
} }
void KateSessionPanel::itemExecuted(TQListViewItem *item)
{
if (!item)
return;
// First level items are sessions. Executing one, will switch to that session
if (!item->parent())
{
sessionActivate();
return;
}
}

@ -74,6 +74,7 @@ class KateSessionPanel : public TQVBox
void sessionToggleReadOnly(); void sessionToggleReadOnly();
void sessionMoveUp(); void sessionMoveUp();
void sessionMoveDown(); void sessionMoveDown();
void itemExecuted(TQListViewItem *item);
private: private:
void setup_toolbar(); void setup_toolbar();

@ -110,15 +110,16 @@ void KateViewSpace::addView(Kate::View* v, bool show)
if ( !m_group.isEmpty() ) if ( !m_group.isEmpty() )
{ {
TQString fn = v->getDoc()->url().prettyURL(); TQString fn = v->getDoc()->url().prettyURL();
if ( ! fn.isEmpty() ) if (!fn.isEmpty())
{ {
TQString vgroup = TQString("%1 %2").arg(m_group).arg(fn); TQString vgroup = TQString("%1 %2").arg(m_group).arg(fn);
OldKateSession::Ptr as = OldKateSessionManager::self()->activeSession (); KateSession *as = KateSessionManager::self()->getActiveSession();
if ( as->configRead() && as->configRead()->hasGroup( vgroup ) ) TDEConfig *asCfg = as->getConfig();
if (asCfg && asCfg->hasGroup(vgroup))
{ {
as->configRead()->setGroup( vgroup ); asCfg->setGroup(vgroup);
v->readSessionConfig ( as->configRead() ); v->readSessionConfig(asCfg);
} }
} }
} }

Loading…
Cancel
Save