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 8 years ago
parent de91a161b1
commit 099c8a8821

@ -75,7 +75,6 @@ KateApp::KateApp (TDECmdLineArgs *args)
m_pluginManager = new KatePluginManager (TQT_TQOBJECT(this));
// session manager up
m_oldSessionManager = new OldKateSessionManager (TQT_TQOBJECT(this));
m_sessionManager = KateSessionManager::self();
// application dcop interface
@ -109,7 +108,6 @@ KateApp::~KateApp ()
delete m_obj; // cu dcop interface
delete m_pluginManager; // cu plugin 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
}
@ -137,24 +135,22 @@ TQString KateApp::kateVersion (bool fullVersion)
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
Kate::Document::setOpenErrorDialogsActivated (false);
Kate::Document::setOpenErrorDialogsActivated(false);
// activate again correct session!!!
sessionConfig()->setGroup("General");
TQString lastSession (sessionConfig()->readEntry ("Last Session", "default.katesession"));
oldSessionManager()->activateSession (new OldKateSession (oldSessionManager(), lastSession, ""), false, false, false);
m_docManager->restoreDocumentList (sessionConfig());
// restore last session
sessionManager()->restoreLastSession();
m_docManager->restoreDocumentList(sessionConfig());
Kate::Document::setOpenErrorDialogsActivated (true);
Kate::Document::setOpenErrorDialogsActivated(true);
// restore all windows ;)
for (int n=1; TDEMainWindow::canBeRestored(n); 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)
newMainWindow ();
@ -167,17 +163,24 @@ bool KateApp::startupKate ()
// user specified session to open
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
{
// 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
if (!oldSessionManager()->chooseSession ())
/*if (!oldSessionManager()->chooseSession ())
{
// we will exit kate now, notify the rest of the world we are done
TDEStartupInfo::appStarted (startupId());
return false;
}
}*/
}
// oh, no mainwindow, create one, should not happen, but make sure ;)
@ -264,12 +267,13 @@ bool KateApp::startupKate ()
return true;
}
void KateApp::shutdownKate (KateMainWindow *win)
void KateApp::shutdownKate(KateMainWindow *win)
{
if (!win->queryClose_internal())
return;
oldSessionManager()->saveActiveSession(true, true);
// Save current session here to make sure all GUI elements are saved correctly
sessionManager()->saveActiveSession();
// detach the dcopClient
dcopClient()->detach();
@ -291,11 +295,6 @@ KateDocManager *KateApp::documentManager ()
return m_docManager;
}
OldKateSessionManager *KateApp::oldSessionManager ()
{
return m_oldSessionManager;
}
KateSessionManager* KateApp::sessionManager()
{
return m_sessionManager;

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

@ -89,16 +89,17 @@ bool KateAppDCOPIface::openInput (TQString 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;
}
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;

@ -305,8 +305,9 @@ void KateMainWindow::setupActions()
slotWindowActivated ();
// MIKE to fix and enable again
// 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("&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");
@ -314,6 +315,7 @@ void KateMainWindow::setupActions()
// quick open menu ;)
new OldKateSessionsAction (i18n("&Quick Open"), actionCollection(), "sessions_list");
*/
}
KateTabWidget *KateMainWindow::tabWidget ()
@ -370,7 +372,7 @@ bool KateMainWindow::queryClose()
// and save docs if we really close down !
if ( queryClose_internal () )
{
KateApp::self()->oldSessionManager()->saveActiveSession(true, true);
KateApp::self()->sessionManager()->saveActiveSession();
// detach the dcopClient
KateApp::self()->dcopClient()->detach();
@ -824,7 +826,7 @@ void KateMainWindow::updateCaption (Kate::Document *doc)
c = m_viewManager->activeView()->getDoc()->url().prettyURL();
}
TQString sessName = KateApp::self()->oldSessionManager()->activeSession()->sessionName();
TQString sessName = KateApp::self()->sessionManager()->getActiveSessionName();
if ( !sessName.isEmpty() )
sessName = TQString("%1: ").arg( sessName );
@ -855,10 +857,8 @@ void KateMainWindow::readProperties(TDEConfig *config)
void KateMainWindow::saveGlobalProperties( TDEConfig* sessionConfig )
{
KateDocManager::self()->saveDocumentList (sessionConfig);
sessionConfig->setGroup("General");
sessionConfig->writeEntry ("Last Session", KateApp::self()->oldSessionManager()->activeSession()->sessionFileRelative());
// MIKE do we still need this code here?
// KateDocManager::self()->saveDocumentList (sessionConfig);
}
// 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
// all the time (doc open, doc closed, doc renamed)
// FIXME add code to handle the various options in Configure Kate -> Application -> Sessions
// String constants
namespace
@ -63,6 +64,7 @@ namespace
const char *KS_OPENDOC = "Open Documents";
const char *KS_READONLY = "ReadOnly";
const char *KS_UNNAMED = "Unnamed";
const char *KS_OPEN_MAINWINDOWS = "Open MainWindows";
// Kate session manager
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)
return;
// create a new session filename if needed
if (!m_isFullName)
{
// create a new session filename
int s = time(0);
TQCString tname;
TQString tmpName;
@ -187,6 +189,7 @@ void KateSession::save(bool saveDocList)
}
}
// save session config info
if (!m_config)
{
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]);
}
if (saveDocList)
// save GUI elements info
if (saveGUIInfo)
{
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();
@ -221,12 +235,35 @@ void KateSession::save(bool saveDocList)
//------------------------------------
void KateSession::activate()
{
if (KateDocManager::self()->documents() > 0)
{
KateDocManager::self()->closeAllDocuments();
}
Kate::Document::setOpenErrorDialogsActivated(false);
if (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);
}
@ -246,7 +283,7 @@ KateSessionManager* KateSessionManager::self()
//------------------------------------
KateSessionManager::KateSessionManager() :
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);
@ -256,7 +293,8 @@ 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);
//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)
{
TQString urlStr = m_config->readEntry(TQString("URL_%1").arg(i));
@ -278,11 +316,18 @@ KateSessionManager::KateSessionManager() :
}
}
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)
{
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)
{
// 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->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)
{
if (sessionId == m_activeSessionId)
if (sessionId < 0)
{
return false;
}
if (!m_firstActivation && sessionId == m_activeSessionId)
{
return true;
}
// First check if all documents can be closed safely
if (!m_firstActivation)
{
// Do this only if a session has already been activated earlier,
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[sessionId]->activate();
m_activeSessionId = sessionId;
m_firstActivation = false;
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()
{
return KateApp::self()->oldSessionManager ();
return (OldKateSessionManager*)KateApp::self()->sessionManager();
}
void OldKateSessionManager::dirty (const TQString &)

@ -31,6 +31,8 @@
#include <tqvaluelist.h>
#include <tqstringlist.h>
class KateViewSpace;
class OldKateSessionManager; // Michele - to be removed with OldKateSession
class KDirWatch;
@ -85,9 +87,9 @@ class KateSession
/**
* 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
@ -95,6 +97,14 @@ class KateSession
void activate();
private:
friend class KateViewSpace;
/**
* @return the session config object
*/
TDEConfig* getConfig() { return m_config; }
TQString m_sessionName;
TQString m_filename;
bool m_isFullName; // true -> m_filename is a full filename
@ -112,6 +122,11 @@ class KateSessionManager
{
public:
enum
{
INVALID_SESSION = -1
};
/**
* get a pointer to the unique KateSessionManager instance.
* If the manager does not exist yet, create it.
@ -133,6 +148,11 @@ class KateSessionManager
*/
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
*/
@ -143,6 +163,15 @@ class KateSessionManager
*/
TQPtrList<KateSession>& getSessionsList() { return m_sessions; }
/**
* 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.
*/
int getSessionIdFromName(const TQString &name);
/**
* Activates the selected session.
* @param sessionId the id of the session to activate
@ -151,6 +180,18 @@ class KateSessionManager
*/
bool activateSession(int sessionId, bool saveCurr = true);
/**
* Restore the last saved session. Can only be used before
* any other session has been activated, i.e. on Kate's startup
* @return whether the session was activated or not
*/
bool restoreLastSession();
/**
* Saves the active session
*/
void saveActiveSession() { m_sessions[m_activeSessionId]->save(true); }
private:
KateSessionManager();
@ -158,6 +199,7 @@ class KateSessionManager
TQString m_configFile; // file where the session list config is stored
int m_sessionsCount; // number of sessions
int m_activeSessionId; // index of the active session
bool m_firstActivation; // true until at least one session has been activated
TQPtrList<KateSession> m_sessions; // session list
KSimpleConfig *m_config; // session manager config
@ -186,7 +228,7 @@ class OldKateSession : public TDEShared
* @param name session name
* @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
@ -228,14 +270,14 @@ class OldKateSession : public TDEShared
* @param force force to create new file
* @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
* @param name new name
* @return success
*/
bool rename (const TQString &name);
bool rename ( const TQString &name );
/**
* config to read
@ -299,7 +341,7 @@ class OldKateSessionManager : public TQObject
Q_OBJECT
public:
OldKateSessionManager(TQObject *parent);
OldKateSessionManager ( TQObject *parent );
~OldKateSessionManager();
/**
@ -323,20 +365,20 @@ class OldKateSessionManager : public TQObject
* @param saveLast try to save last session or not?
* @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
* @param name session name
*/
OldKateSession::Ptr createSession (const TQString &name);
OldKateSession::Ptr createSession ( const TQString &name );
/**
* return session with given name
* if no existing session matches, create new one with this name
* @param name session name
*/
OldKateSession::Ptr giveSession (const TQString &name);
OldKateSession::Ptr giveSession ( const TQString &name );
/**
* save current session
@ -345,7 +387,7 @@ class OldKateSessionManager : public TQObject
* @param rememberAsLast remember this session as last used?
* @return success
*/
bool saveActiveSession (bool tryAsk = false, bool rememberAsLast = false);
bool saveActiveSession ( bool tryAsk = false, bool rememberAsLast = false );
/**
* return the current active session
@ -394,7 +436,7 @@ class OldKateSessionManager : public TQObject
void sessionManage ();
private slots:
void dirty (const TQString &path);
void dirty ( const TQString &path );
public:
/**
@ -424,14 +466,15 @@ class OldKateSessionChooser : public KDialogBase
Q_OBJECT
public:
OldKateSessionChooser (TQWidget *parent, const TQString &lastSession);
OldKateSessionChooser ( TQWidget *parent, const TQString &lastSession );
~OldKateSessionChooser ();
OldKateSession::Ptr selectedSession ();
bool reopenLastSession ();
enum {
enum
{
resultQuit = TQDialog::Rejected,
resultOpen,
resultNew,
@ -469,12 +512,13 @@ class OldKateSessionOpenDialog : public KDialogBase
Q_OBJECT
public:
OldKateSessionOpenDialog (TQWidget *parent);
OldKateSessionOpenDialog ( TQWidget *parent );
~OldKateSessionOpenDialog ();
OldKateSession::Ptr selectedSession ();
enum {
enum
{
resultOk,
resultCancel
};
@ -499,7 +543,7 @@ class OldKateSessionManageDialog : public KDialogBase
Q_OBJECT
public:
OldKateSessionManageDialog (TQWidget *parent);
OldKateSessionManageDialog ( TQWidget *parent );
~OldKateSessionManageDialog ();
protected slots:
@ -540,13 +584,13 @@ class OldKateSessionsAction : public TDEActionMenu
Q_OBJECT
public:
OldKateSessionsAction(const TQString& text, TQObject* parent = 0, const char* name = 0);
~OldKateSessionsAction (){;};
OldKateSessionsAction ( const TQString& text, TQObject* parent = 0, const char* name = 0 );
~OldKateSessionsAction () {;};
public slots:
void slotAboutToShow();
void openSession (int i);
void openSession ( int i );
};
#endif

@ -62,7 +62,8 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager *
m_listview->setColumnAlignment(2, TQt::AlignCenter);
m_listview->setMinimumWidth(m_listview->sizeHint().width());
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();
for (int idx = sessions.count()-1; idx >= 0; --idx)
@ -210,3 +211,16 @@ void KateSessionPanel::sessionMoveDown()
{
//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 sessionMoveUp();
void sessionMoveDown();
void itemExecuted(TQListViewItem *item);
private:
void setup_toolbar();

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

Loading…
Cancel
Save