summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--kate/app/kateapp.cpp32
-rw-r--r--kate/app/kateapp.h8
-rw-r--r--kate/app/kateappIface.cpp4
-rw-r--r--kate/app/katemainwindow.cpp6
-rw-r--r--kate/app/katesession.cpp68
-rw-r--r--kate/app/katesession.h37
-rw-r--r--kate/app/katesessionpanel.cpp65
-rw-r--r--kate/app/katesessionpanel.h9
8 files changed, 165 insertions, 64 deletions
diff --git a/kate/app/kateapp.cpp b/kate/app/kateapp.cpp
index 2f54a8e23..2ff68ed1a 100644
--- a/kate/app/kateapp.cpp
+++ b/kate/app/kateapp.cpp
@@ -75,7 +75,8 @@ KateApp::KateApp (TDECmdLineArgs *args)
m_pluginManager = new KatePluginManager (TQT_TQOBJECT(this));
// session manager up
- m_sessionManager = new OldKateSessionManager (TQT_TQOBJECT(this));
+ m_oldSessionManager = new OldKateSessionManager (TQT_TQOBJECT(this));
+ m_sessionManager = KateSessionManager::self();
// application dcop interface
m_obj = new KateAppDCOPIface (this);
@@ -105,14 +106,11 @@ KateApp::KateApp (TDECmdLineArgs *args)
KateApp::~KateApp ()
{
- // cu dcop interface
- delete m_obj;
-
- // cu plugin manager
- delete m_pluginManager;
-
- // delete this now, or we crash
- delete m_docManager;
+ 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
}
KateApp *KateApp::self ()
@@ -147,8 +145,7 @@ void KateApp::restoreKate ()
// activate again correct session!!!
sessionConfig()->setGroup("General");
TQString lastSession (sessionConfig()->readEntry ("Last Session", "default.katesession"));
- sessionManager()->activateSession (new OldKateSession (sessionManager(), lastSession, ""), false, false, false);
-
+ oldSessionManager()->activateSession (new OldKateSession (oldSessionManager(), lastSession, ""), false, false, false);
m_docManager->restoreDocumentList (sessionConfig());
Kate::Document::setOpenErrorDialogsActivated (true);
@@ -170,12 +167,12 @@ bool KateApp::startupKate ()
// user specified session to open
if (m_args->isSet ("start"))
{
- sessionManager()->activateSession (sessionManager()->giveSession (TQString::fromLocal8Bit(m_args->getOption("start"))), false, false);
+ oldSessionManager()->activateSession (oldSessionManager()->giveSession (TQString::fromLocal8Bit(m_args->getOption("start"))), false, false);
}
else
{
// let the user choose session if possible
- if (!sessionManager()->chooseSession ())
+ if (!oldSessionManager()->chooseSession ())
{
// we will exit kate now, notify the rest of the world we are done
TDEStartupInfo::appStarted (startupId());
@@ -272,7 +269,7 @@ void KateApp::shutdownKate (KateMainWindow *win)
if (!win->queryClose_internal())
return;
- sessionManager()->saveActiveSession(true, true);
+ oldSessionManager()->saveActiveSession(true, true);
// detach the dcopClient
dcopClient()->detach();
@@ -294,7 +291,12 @@ KateDocManager *KateApp::documentManager ()
return m_docManager;
}
-OldKateSessionManager *KateApp::sessionManager ()
+OldKateSessionManager *KateApp::oldSessionManager ()
+{
+ return m_oldSessionManager;
+}
+
+KateSessionManager* KateApp::sessionManager()
{
return m_sessionManager;
}
diff --git a/kate/app/kateapp.h b/kate/app/kateapp.h
index 2b6c1e2cd..73b9553ee 100644
--- a/kate/app/kateapp.h
+++ b/kate/app/kateapp.h
@@ -27,6 +27,7 @@
#include <tqvaluelist.h>
class OldKateSessionManager;
+class KateSessionManager;
class KateAppDCOPIface;
namespace Kate {
@@ -128,7 +129,8 @@ class KDE_EXPORT KateApp : public TDEApplication
* accessor to session manager
* @return session manager instance
*/
- OldKateSessionManager *sessionManager ();
+ OldKateSessionManager *oldSessionManager ();
+ KateSessionManager *sessionManager();
/**
* window management
@@ -222,7 +224,9 @@ class KDE_EXPORT KateApp : public TDEApplication
/**
* session manager
*/
- OldKateSessionManager *m_sessionManager;
+ OldKateSessionManager *m_oldSessionManager;
+ KateSessionManager *m_sessionManager;
+
/**
* known main windows
diff --git a/kate/app/kateappIface.cpp b/kate/app/kateappIface.cpp
index 259e48b89..57f0b63d1 100644
--- a/kate/app/kateappIface.cpp
+++ b/kate/app/kateappIface.cpp
@@ -91,14 +91,14 @@ bool KateAppDCOPIface::openInput (TQString text)
bool KateAppDCOPIface::activateSession (TQString session)
{
- m_app->sessionManager()->activateSession (m_app->sessionManager()->giveSession (session));
+ m_app->oldSessionManager()->activateSession (m_app->oldSessionManager()->giveSession (session));
return true;
}
const TQString & KateAppDCOPIface::session() const
{
- return m_app->sessionManager()->activeSession()->sessionName();
+ return m_app->oldSessionManager()->activeSession()->sessionName();
}
// kate: space-indent on; indent-width 2; replace-tabs on;
diff --git a/kate/app/katemainwindow.cpp b/kate/app/katemainwindow.cpp
index 794e1a777..1546c575b 100644
--- a/kate/app/katemainwindow.cpp
+++ b/kate/app/katemainwindow.cpp
@@ -370,7 +370,7 @@ bool KateMainWindow::queryClose()
// and save docs if we really close down !
if ( queryClose_internal () )
{
- KateApp::self()->sessionManager()->saveActiveSession(true, true);
+ KateApp::self()->oldSessionManager()->saveActiveSession(true, true);
// detach the dcopClient
KateApp::self()->dcopClient()->detach();
@@ -824,7 +824,7 @@ void KateMainWindow::updateCaption (Kate::Document *doc)
c = m_viewManager->activeView()->getDoc()->url().prettyURL();
}
- TQString sessName = KateApp::self()->sessionManager()->activeSession()->sessionName();
+ TQString sessName = KateApp::self()->oldSessionManager()->activeSession()->sessionName();
if ( !sessName.isEmpty() )
sessName = TQString("%1: ").arg( sessName );
@@ -858,7 +858,7 @@ void KateMainWindow::saveGlobalProperties( TDEConfig* sessionConfig )
KateDocManager::self()->saveDocumentList (sessionConfig);
sessionConfig->setGroup("General");
- sessionConfig->writeEntry ("Last Session", KateApp::self()->sessionManager()->activeSession()->sessionFileRelative());
+ sessionConfig->writeEntry ("Last Session", KateApp::self()->oldSessionManager()->activeSession()->sessionFileRelative());
}
// kate: space-indent on; indent-width 2; replace-tabs on;
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 &)
diff --git a/kate/app/katesession.h b/kate/app/katesession.h
index 81a4a77c5..3904f9f0f 100644
--- a/kate/app/katesession.h
+++ b/kate/app/katesession.h
@@ -59,7 +59,7 @@ class KateSession
~KateSession();
/**
- * Returns the session name
+ * @return the session name
*/
const TQString& getSessionName() const { return m_sessionName; }
/**
@@ -69,7 +69,7 @@ class KateSession
void setSessionName(const TQString &sessionName);
/**
- * Returns whether the session is read only or not
+ * @return whether the session is read only or not
*/
bool isReadOnly() const { return m_readOnly; }
/**
@@ -79,16 +79,20 @@ class KateSession
void setReadOnly(bool readOnly);
/**
- * Returns the session filename
+ * @return the session filename
*/
const TQString& getSessionFilename() const { return m_filename; }
/**
* Save session info
- * @return true if the session config is saved, false otherwise
+ * @param saveDocList if true, save also the information about the documents currently open
*/
- void save();
+ void save(bool saveDocList);
+ /**
+ * Activate the session
+ */
+ void activate();
private:
TQString m_sessionName;
@@ -124,6 +128,28 @@ class KateSessionManager
*/
void saveConfig();
+ /**
+ * @return the active session id
+ */
+ int getActiveSessionId() const { return m_activeSessionId; }
+
+ /**
+ * @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; }
+
+ /**
+ * 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);
private:
KateSessionManager();
@@ -131,6 +157,7 @@ class KateSessionManager
TQString m_baseDir; // folder where session files are stored
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
TQPtrList<KateSession> m_sessions; // session list
KSimpleConfig *m_config; // session manager config
diff --git a/kate/app/katesessionpanel.cpp b/kate/app/katesessionpanel.cpp
index e852a9eee..93bca5d06 100644
--- a/kate/app/katesessionpanel.cpp
+++ b/kate/app/katesessionpanel.cpp
@@ -25,6 +25,7 @@
#include <kiconloader.h>
#include <tdelocale.h>
+#include <tqlistview.h>
void KateSessionPanelToolBarParent::setToolBar(TDEToolBar *tbar)
@@ -46,23 +47,41 @@ void KateSessionPanelToolBarParent::resizeEvent (TQResizeEvent*)
KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager *viewManager,
TQWidget *parent, const char *name)
: TQVBox(parent, name), m_mainWin(mainWindow), m_viewManager(viewManager),
- m_sessionManager(OldKateSessionManager::self()), m_actionCollection(new TDEActionCollection(this))
+ m_sessionManager(KateSessionManager::self()), m_actionCollection(new TDEActionCollection(this)),
+ m_columnSessionId(0), m_columnPixmap(0)
{
// Toolbar
setup_toolbar();
// Listview
m_listview = new TDEListView(this);
- m_listview->setRootIsDecorated(true);
- m_listview->setSorting(-1);
+ m_listview->header()->hide();
+ m_listview->addColumn("Session name");
+ m_columnSessionId = m_listview->addColumn("Session id", 0);
+ m_columnPixmap = m_listview->addColumn("Pixmap", 24);
+ 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
+
+ TQPtrList<KateSession>& sessions = m_sessionManager->getSessionsList();
+ for (int idx = sessions.count()-1; idx >= 0; --idx)
+ {
+ new TDEListViewItem(m_listview, sessions[idx]->getSessionName(), TQString("%1").arg(idx));
+ if (idx == m_sessionManager->getActiveSessionId())
+ {
+ m_listview->setSelected(m_listview->firstChild(), true);
+ m_listview->firstChild()->setPixmap(m_columnPixmap, SmallIcon("ok"));
+ }
+ }
+
}
//-------------------------------------------
void KateSessionPanel::setup_toolbar()
{
// Toolbar widget and frame
- KateSessionPanelToolBarParent *tbarParent=new KateSessionPanelToolBarParent(this);
+ KateSessionPanelToolBarParent *tbarParent = new KateSessionPanelToolBarParent(this);
m_toolbar = new TDEToolBar(tbarParent, "Kate Session Panel Toolbar", true);
tbarParent->setToolBar(m_toolbar);
m_toolbar->setMovingEnabled(false);
@@ -71,8 +90,10 @@ void KateSessionPanel::setup_toolbar()
m_toolbar->setIconSize(16);
m_toolbar->setEnableContextMenu(false);
+//FIXME : uncomment and activate as long as the new session manager gets fixed
// Toolbar actions
TDEAction *a;
+/*
a = new TDEAction(i18n("New"), SmallIcon("list-add"), 0,
TQT_TQOBJECT(m_sessionManager), TQT_SLOT(sessionNew()), m_actionCollection, "session_new");
a->setWhatsThis(i18n("Create a new session."));
@@ -99,12 +120,12 @@ void KateSessionPanel::setup_toolbar()
a->plug(m_toolbar);
m_toolbar->insertLineSeparator();
-
+*/
a = new TDEAction(i18n("Activate"), SmallIcon("forward"), 0,
TQT_TQOBJECT(this), TQT_SLOT(sessionActivate()), m_actionCollection, "session_activate");
a->setWhatsThis(i18n("Activate the selected session."));
a->plug(m_toolbar);
-
+/*
TDEToggleAction *tglA = new TDEToggleAction(i18n("Toggle read only"), SmallIcon("encrypted"), 0,
TQT_TQOBJECT(this), TQT_SLOT(sessionToggleReadOnly()), m_actionCollection, "session_toggle_read_only");
tglA->setWhatsThis(i18n("Toggle read only status for the selected session.<p>"
@@ -122,18 +143,7 @@ void KateSessionPanel::setup_toolbar()
TQT_TQOBJECT(this), TQT_SLOT(sessionMoveDown()), m_actionCollection, "session_move_down");
a->setWhatsThis(i18n("Move down the selected session."));
a->plug(m_toolbar);
-
- m_toolbar->insertLineSeparator();
-
- a = new TDEAction(i18n("Open"), SmallIcon("document-open"), 0,
- TQT_TQOBJECT(m_sessionManager), TQT_SLOT(sessionOpen()), m_actionCollection, "session_open");
- a->setWhatsThis(i18n("Switch to another session chosen from a list of existing ones."));
- a->plug(m_toolbar);
-
- a = new TDEAction(i18n("Manage"), SmallIcon("view_choose"), 0,
- TQT_TQOBJECT(m_sessionManager), TQT_SLOT(sessionManage()), m_actionCollection, "session_manage");
- a->setWhatsThis(i18n("Manage existing sessions."));
- a->plug(m_toolbar);
+*/
}
//-------------------------------------------
@@ -163,7 +173,24 @@ void KateSessionPanel::deleteSession()
//-------------------------------------------
void KateSessionPanel::sessionActivate()
{
-//TODO
+ TQListViewItem *newSessionItem = m_listview->selectedItem();
+ int currSessionId = m_sessionManager->getActiveSessionId();
+ if (!newSessionItem)
+ return;
+ int newSessionId = newSessionItem->text(m_columnSessionId).toInt();
+ if (newSessionId != currSessionId)
+ {
+ if (!m_sessionManager->activateSession(newSessionId))
+ return;
+
+ TQListViewItem *item = m_listview->firstChild();
+ for (int idx = 0; idx < currSessionId; ++idx)
+ {
+ item = item->nextSibling();
+ }
+ item->setPixmap(m_columnPixmap, TQPixmap());
+ newSessionItem->setPixmap(m_columnPixmap, SmallIcon("ok"));
+ }
}
//-------------------------------------------
diff --git a/kate/app/katesessionpanel.h b/kate/app/katesessionpanel.h
index bbbba6f14..71120b7e1 100644
--- a/kate/app/katesessionpanel.h
+++ b/kate/app/katesessionpanel.h
@@ -33,7 +33,7 @@
class KateMainWindow;
class KateViewManager;
-class OldKateSessionManager;
+class KateSessionManager;
class TDEActionCollection;
@@ -80,11 +80,12 @@ class KateSessionPanel : public TQVBox
KateMainWindow *m_mainWin;
KateViewManager *m_viewManager;
- OldKateSessionManager *m_sessionManager;
+ KateSessionManager *m_sessionManager;
TDEActionCollection *m_actionCollection;
-
- TDEToolBar *m_toolbar;
+ TDEToolBar *m_toolbar;
TDEListView *m_listview;
+ int m_columnSessionId;
+ int m_columnPixmap;
};