From 2675b2147b5ccc7782535e5f662847768bb8b442 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Fri, 19 Feb 2016 22:04:40 +0700 Subject: Added support for Kate startup options and for "New session" functionality. Signed-off-by: Michele Calgaro --- doc/kate/fundamentals.docbook | 16 +-- kate/app/kateapp.cpp | 83 ++++++++--- kate/app/kateappIface.cpp | 6 +- kate/app/katemainwindow.cpp | 4 +- kate/app/katesession.cpp | 310 ++++++++++++++++++------------------------ kate/app/katesession.h | 152 +++++++++++++-------- kate/app/katesessionpanel.cpp | 56 +++++--- kate/app/katesessionpanel.h | 3 + 8 files changed, 347 insertions(+), 283 deletions(-) diff --git a/doc/kate/fundamentals.docbook b/doc/kate/fundamentals.docbook index c42614a71..507fc6032 100644 --- a/doc/kate/fundamentals.docbook +++ b/doc/kate/fundamentals.docbook @@ -156,11 +156,10 @@ Shows license information. name -Starts kate with the session name. The session is created -if it does not exist already. If a &kate; instance running the specified session -exists, the specified files are loaded in that instance. When used with the - option, an instance running this session will be used as -well. +Starts &kate; with the session name. If the session does not exist, +the user is prompted whether to start a new session or not.

+If a &kate; instance running the specified session already exists, the specified files are +loaded in that instance. @@ -170,7 +169,7 @@ well. URL -Causes &kate; to use and existing instance if there is one. If you want all +Causes &kate; to use an existing instance if there is one. If you want all documents to open in one kate instance, you can add this option to the default command in your &tde; application configuration, as well as create a shell alias in your command intepreter if it supports that. @@ -307,7 +306,7 @@ flexibility. In this section we'll look at three items: -Toggles the Documents on and off. If the Documents/Filesystem Browser side bar +Toggles the Documents on and off. If the Documents/Filesystem Browser side bar window is not open, &kate; will open the side bar window. @@ -523,7 +522,8 @@ session chooser, the specified session is loaded prior to the files specified on the command line. To open files from the command line in a new, unnamed session, configure kate to start a new session per default in the session page of the configuration dialog or use with an empty string: -''. +'' (you will be prompted whether to create a new session +or not). Since &kate; 2.5.1 the PID of the current instance is exported to the environment variable KATE_PID. When opening files diff --git a/kate/app/kateapp.cpp b/kate/app/kateapp.cpp index f6089cb75..8793569fa 100644 --- a/kate/app/kateapp.cpp +++ b/kate/app/kateapp.cpp @@ -158,29 +158,78 @@ void KateApp::restoreKate() // TDEStartupInfo::setNewStartupId( activeMainWindow(), startupId()); } -bool KateApp::startupKate () +bool KateApp::startupKate() { - // user specified session to open - if (m_args->isSet ("start")) + if (m_args->isSet("start")) { - // MIKE fixme: need to handle this functionality - sessionManager()->activateSession( - sessionManager()->getSessionIdFromName(TQString::fromLocal8Bit(m_args->getOption("start")))); + // the user has specified the session to open + TQCString sessName = m_args->getOption("start"); + int sessId = sessionManager()->getSessionIdFromName(sessName); + if (sessId != KateSessionManager::INVALID_SESSION) + { + sessionManager()->activateSession(sessId); + } + else + { + int msgres = KMessageBox::warningYesNo(0, i18n("

The session '%1' could not be found." + "

Do you want to start a new session?").arg(sessName), + i18n("Session not found!")); + if (msgres == KMessageBox::Yes) + { + sessionManager()->newSession(TQString::null, true); + } + else + { + // Kate will exit now and notify it is done + TDEStartupInfo::appStarted(startupId()); + return false; + } + } } 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 ()) + // check Kate session startup options + TDEConfig *kateCfg = KateApp::self()->config(); + kateCfg->setGroup("General"); + if (kateCfg->hasKey("Last Session")) { - // we will exit kate now, notify the rest of the world we are done - TDEStartupInfo::appStarted (startupId()); - return false; - }*/ + // Delete no longer used entry (pre R14.1.0) + kateCfg->deleteEntry("Last Session"); + } + TQString startupOption(kateCfg->readEntry("Startup Session", "manual")); + if (startupOption == "last") + { + sessionManager()->restoreLastSession(); + } + else if (startupOption == "new") + { + sessionManager()->newSession(TQString::null, true); + } + else // startupOption == "manual" + { + KateSessionChooser *chooser = new KateSessionChooser(NULL); + int result = chooser->exec(); + switch (result) + { + case KateSessionChooser::RESULT_OPEN_NEW: + sessionManager()->newSession(TQString::null, true); + break; + + case KateSessionChooser::RESULT_OPEN_EXISTING: + if (!m_sessionManager->activateSession(chooser->getSelectedSessionId())) + { + // Open a new session in case of error + sessionManager()->newSession(TQString::null, true); + } + break; + + default: // KateSessionChooser::RESULT_QUIT_KATE: + // Kate will exit now and notify it is done + TDEStartupInfo::appStarted(startupId()); + return false; + break; + } + } } // oh, no mainwindow, create one, should not happen, but make sure ;) diff --git a/kate/app/kateappIface.cpp b/kate/app/kateappIface.cpp index 3ce9229b4..bc06f1b78 100644 --- a/kate/app/kateappIface.cpp +++ b/kate/app/kateappIface.cpp @@ -23,6 +23,8 @@ #include "katedocmanager.h" #include "katemainwindow.h" +// FIXME: review Kate's DCOP interface for session management when the new session code is ready + KateAppDCOPIface::KateAppDCOPIface (KateApp *app) : DCOPObject ("KateApplication") , m_app (app) { @@ -91,9 +93,7 @@ bool KateAppDCOPIface::openInput (TQString text) bool KateAppDCOPIface::activateSession(TQString session) { -// MIKE: to fix -// m_app->sessionManager()->activateSession (m_app->oldSessionManager()->giveSession (session)); - + m_app->sessionManager()->activateSession(m_app->sessionManager()->getSessionIdFromName(session)); return true; } diff --git a/kate/app/katemainwindow.cpp b/kate/app/katemainwindow.cpp index 527dbdc9c..19a76ee27 100644 --- a/kate/app/katemainwindow.cpp +++ b/kate/app/katemainwindow.cpp @@ -305,7 +305,7 @@ void KateMainWindow::setupActions() slotWindowActivated (); -// MIKE to fix and enable again +// FIXME 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("&Open..."), "document-open", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionOpen()), actionCollection(), "sessions_open"); @@ -857,7 +857,7 @@ void KateMainWindow::readProperties(TDEConfig *config) void KateMainWindow::saveGlobalProperties( TDEConfig* sessionConfig ) { -// MIKE do we still need this code here? +// FIXME do we still need this code here? // KateDocManager::self()->saveDocumentList (sessionConfig); } diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index adee747d0..4437d7166 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -17,7 +17,6 @@ */ #include "katesession.h" -#include "katesession.moc" #include "kateapp.h" #include "katemainwindow.h" @@ -74,6 +73,7 @@ namespace const char *KSM_SESSIONS_LIST = "Sessions list"; } +//BEGIN Kate session KateSession::KateSession(const TQString &sessionName, const TQString &filename, bool isFullName) : m_sessionName(sessionName), m_filename(filename), m_isFullName(isFullName), m_readOnly(false), m_docCount(0), m_documents(), m_config(NULL) @@ -167,7 +167,9 @@ void KateSession::setReadOnly(bool readOnly) void KateSession::save(bool saveGUIInfo) { if (m_readOnly) + { return; + } // create a new session filename if needed if (!m_isFullName) @@ -252,7 +254,7 @@ void KateSession::activate() int mwCount = m_config->readUnsignedNumEntry(KS_COUNT, 1); for (int i=0; i= KateApp::self()->mainWindows()) + if (i >= (int)KateApp::self()->mainWindows()) { KateApp::self()->newMainWindow(m_config, TQString("MainWindow%1").arg(i)); } @@ -267,6 +269,9 @@ void KateSession::activate() Kate::Document::setOpenErrorDialogsActivated(true); } +//END Kate session + +//BEGIN KateSessionManager //------------------------------------ KateSessionManager *KateSessionManager::ksm_instance = NULL; @@ -345,6 +350,12 @@ KateSessionManager::~KateSessionManager() } //------------------------------------ +// FIXME Unnamed sessions should not be saved by default, to allow users who do not bother +// about sessions to open-use-close Kate seemlessly. +// FIXME An option need to be added to Configure Kate -> Sessions to allow Kate to ask about +// saving unnamed sessions before closing the current session. Default value is off as per +// point above. + void KateSessionManager::saveConfig() { if (!m_config) @@ -378,18 +389,20 @@ int KateSessionManager::getSessionIdFromName(const TQString &name) if (m_sessions[i]->getSessionName() == name) return i; } - + return KateSessionManager::INVALID_SESSION; } //------------------------------------ +//FIXME: after a session switch, the session name on Kate window title bar displays +//the previously activated session bool KateSessionManager::activateSession(int sessionId, bool saveCurr) { if (sessionId < 0) { return false; } - + if (!m_firstActivation && sessionId == m_activeSessionId) { return true; @@ -410,12 +423,28 @@ bool KateSessionManager::activateSession(int sessionId, bool saveCurr) } } - m_sessions[sessionId]->activate(); + int oldSessionId = m_activeSessionId; m_activeSessionId = sessionId; + m_sessions[sessionId]->activate(); m_firstActivation = false; + emit sessionActivated(m_activeSessionId, oldSessionId); return true; } +//------------------------------------ +int KateSessionManager::newSession(const TQString &sessionName, bool activate) +{ + m_sessions.append(new KateSession(sessionName, m_baseDir, false)); + ++m_sessionsCount; + int newSessionId = m_sessionsCount - 1; + emit sessionCreated(newSessionId); + if (activate) + { + activateSession(newSessionId, true); + } + return newSessionId; +} + //------------------------------------ bool KateSessionManager::restoreLastSession() { @@ -427,6 +456,99 @@ bool KateSessionManager::restoreLastSession() return activateSession(m_activeSessionId, false); } +//------------------------------------------- +void KateSessionManager::slotNewSession() +{ + // FIXME: allow the user to enter a session name first + // FIXME: allow the user to specify whether to switch to the new session or not + newSession(TQString::null, true); +} + +//END KateSessionManager + +//BEGIN KateSessionChooser +//------------------------------------------- +KateSessionChooser::KateSessionChooser(TQWidget *parent) + : KDialogBase(parent, "", true, i18n("Session Chooser"), + KDialogBase::User1 | KDialogBase::User2 | KDialogBase::User3, KDialogBase::User2, + true, KStdGuiItem::quit(), KGuiItem(i18n("Open Session"), "document-open"), + KGuiItem(i18n("New Session"), "document-new")), m_sessionList(NULL), m_columnSessionId(0) +{ + TQHBox *page = new TQHBox(this); + page->setMinimumSize(400, 200); + setMainWidget(page); + + TQHBox *hb = new TQHBox(page); + hb->setSpacing(KDialog::spacingHint()); + + TQLabel *label = new TQLabel(hb); + label->setPixmap(UserIcon("sessionchooser")); + label->setFrameStyle (TQFrame::Panel | TQFrame::Sunken); + + TQVBox *vb = new TQVBox(hb); + vb->setSpacing (KDialog::spacingHint()); + + m_sessionList = new TDEListView(vb); + m_sessionList->addColumn(i18n("Session Name")); + m_columnSessionId = m_sessionList->addColumn("Session Id", 0); // Non visible column + m_sessionList->header()->setResizeEnabled(false, m_columnSessionId); + m_sessionList->addColumn(i18n("Open Documents")); + m_sessionList->setSelectionMode(TQListView::Single); + m_sessionList->setAllColumnsShowFocus(true); + m_sessionList->setSorting(-1); + m_sessionList->setResizeMode(TQListView::LastColumn); + + connect (m_sessionList, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(slotSelectionChanged())); + connect (m_sessionList, TQT_SIGNAL(executed(TQListViewItem*)), this, TQT_SLOT(slotUser2())); + + TQPtrList& sessions = KateSessionManager::self()->getSessionsList(); + for (int idx = sessions.count()-1; idx >= 0; --idx) + { + new TDEListViewItem(m_sessionList, sessions[idx]->getSessionName(), TQString("%1").arg(idx), + TQString("%1").arg(sessions[idx]->getDocCount())); + } + + setResult(RESULT_NO_OP); + slotSelectionChanged(); // update button status +} + +//------------------------------------------- +int KateSessionChooser::getSelectedSessionId() +{ + TQListViewItem *selectedItem = m_sessionList->selectedItem(); + if (!selectedItem) + return KateSessionManager::INVALID_SESSION; + + return selectedItem->text(m_columnSessionId).toInt(); +} + +//------------------------------------------- +void KateSessionChooser::slotUser1() +{ + done(RESULT_QUIT_KATE); +} + +//------------------------------------------- +void KateSessionChooser::slotUser2() +{ + done(RESULT_OPEN_EXISTING); +} + +//------------------------------------------- +void KateSessionChooser::slotUser3() +{ + done(RESULT_OPEN_NEW); +} + +//------------------------------------------- +void KateSessionChooser::slotSelectionChanged() +{ + enableButton(KDialogBase::User2, m_sessionList->selectedItem()); +} + +//END KateSessionChooser + + @@ -817,95 +939,12 @@ bool OldKateSessionManager::saveActiveSession (bool tryAsk, bool rememberAsLast) { TDEConfig *c = KateApp::self()->config(); c->setGroup("General"); - c->writeEntry ("Last Session", activeSession()->sessionFileRelative()); c->sync (); } return true; } -bool OldKateSessionManager::chooseSession () -{ - bool success = true; - - // app config - TDEConfig *c = KateApp::self()->config(); - c->setGroup("General"); - - // get last used session, default to default session - TQString lastSession (c->readEntry ("Last Session", "default.katesession")); - TQString sesStart (c->readEntry ("Startup Session", "manual")); - - // uhh, just open last used session, show no chooser - if (sesStart == "last") - { - activateSession (new OldKateSession (this, lastSession, ""), false, false); - return success; - } - - // start with empty new session - if (sesStart == "new") - { - activateSession (new OldKateSession (this, "", ""), false, false); - return success; - } - - OldKateSessionChooser *chooser = new OldKateSessionChooser (0, lastSession); - - bool retry = true; - int res = 0; - while (retry) - { - res = chooser->exec (); - - switch (res) - { - case OldKateSessionChooser::resultOpen: - { - OldKateSession::Ptr s = chooser->selectedSession (); - - if (!s) - { - KMessageBox::error (chooser, i18n("No session selected to open."), i18n ("No Session Selected")); - break; - } - - activateSession (s, false, false); - retry = false; - break; - } - - // exit the app lateron - case OldKateSessionChooser::resultQuit: - success = false; - retry = false; - break; - - default: - activateSession (new OldKateSession (this, "", ""), false, false); - retry = false; - break; - } - } - - // write back our nice boolean :) - if (success && chooser->reopenLastSession ()) - { - c->setGroup("General"); - - if (res == OldKateSessionChooser::resultOpen) - c->writeEntry ("Startup Session", "last"); - else if (res == OldKateSessionChooser::resultNew) - c->writeEntry ("Startup Session", "new"); - - c->sync (); - } - - delete chooser; - - return success; -} - void OldKateSessionManager::sessionNew () { activateSession (new OldKateSession (this, "", "")); @@ -998,98 +1037,6 @@ class OldKateSessionChooserItem : public TQListViewItem OldKateSession::Ptr session; }; -OldKateSessionChooser::OldKateSessionChooser (TQWidget *parent, const TQString &lastSession) - : KDialogBase ( parent - , "" - , true - , i18n ("Session Chooser") - , KDialogBase::User1 | KDialogBase::User2 | KDialogBase::User3 - , KDialogBase::User2 - , true - , KStdGuiItem::quit () - , KGuiItem (i18n ("Open Session"), "document-open") - , KGuiItem (i18n ("New Session"), "document-new") - ) -{ - TQHBox *page = new TQHBox (this); - page->setMinimumSize (400, 200); - setMainWidget(page); - - TQHBox *hb = new TQHBox (page); - hb->setSpacing (KDialog::spacingHint()); - - TQLabel *label = new TQLabel (hb); - label->setPixmap (UserIcon("sessionchooser")); - label->setFrameStyle (TQFrame::Panel | TQFrame::Sunken); - - TQVBox *vb = new TQVBox (hb); - vb->setSpacing (KDialog::spacingHint()); - - m_sessions = new TDEListView (vb); - m_sessions->addColumn (i18n("Session Name")); - m_sessions->addColumn (i18n("Open Documents")); - m_sessions->setResizeMode (TQListView::AllColumns); - m_sessions->setSelectionMode (TQListView::Single); - m_sessions->setAllColumnsShowFocus (true); - - connect (m_sessions, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(selectionChanged())); - connect (m_sessions, TQT_SIGNAL(doubleClicked(TQListViewItem *, const TQPoint &, int)), this, TQT_SLOT(slotUser2())); - - OldKateSessionList &slist (OldKateSessionManager::self()->sessionList()); - for (unsigned int i=0; i < slist.count(); ++i) - { - OldKateSessionChooserItem *item = new OldKateSessionChooserItem (m_sessions, slist[i]); - - if (slist[i]->sessionFileRelative() == lastSession) - m_sessions->setSelected (item, true); - } - - m_useLast = new TQCheckBox (i18n ("&Always use this choice"), vb); - - setResult (resultNone); - - // trigger action update - selectionChanged (); -} - -OldKateSessionChooser::~OldKateSessionChooser () -{ -} - -OldKateSession::Ptr OldKateSessionChooser::selectedSession () -{ - OldKateSessionChooserItem *item = (OldKateSessionChooserItem *) m_sessions->selectedItem (); - - if (!item) - return 0; - - return item->session; -} - -bool OldKateSessionChooser::reopenLastSession () -{ - return m_useLast->isChecked (); -} - -void OldKateSessionChooser::slotUser2 () -{ - done (resultOpen); -} - -void OldKateSessionChooser::slotUser3 () -{ - done (resultNew); -} - -void OldKateSessionChooser::slotUser1 () -{ - done (resultQuit); -} - -void OldKateSessionChooser::selectionChanged () -{ - enableButton (KDialogBase::User2, m_sessions->selectedItem ()); -} //END CHOOSER DIALOG @@ -1304,4 +1251,7 @@ void OldKateSessionsAction::openSession (int i) OldKateSessionManager::self()->activateSession(slist[(uint)i]); } + +#include "katesession.moc" + // kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off; diff --git a/kate/app/katesession.h b/kate/app/katesession.h index 67fb6dc20..ff6b3c0fa 100644 --- a/kate/app/katesession.h +++ b/kate/app/katesession.h @@ -41,6 +41,7 @@ class KPushButton; class TQCheckBox; +//BEGIN KateSession class KateSession { public: @@ -85,6 +86,11 @@ class KateSession */ const TQString& getSessionFilename() const { return m_filename; } + /** + * @return the number of documents in the session + */ + int getDocCount() const { return m_docCount; } + /** * Save session info * @param saveGUIInfo if true, save also the information about the GUI elements @@ -116,17 +122,29 @@ class KateSession }; - +//END KateSession + +//BEGIN KateSessionManager +//FIXME (advanced) +//There should be only one session manager regardless of how many instances of Kate are running. +//Changes should propagate to all session panels. Different Kate instances should run different +//sessions. If the user switches to a session already opened in another Kate instance, the current +//session should be saved and then the focus switched to the other instance. +//This would allow a safe use of multiple Kate instances without overwriting session information +//among them. Currently the last instance to be closed will overwrite the information previously +//saved by other Kate instances. //------------------------------------ -class KateSessionManager +class KateSessionManager : public TQObject { + Q_OBJECT + public: enum { INVALID_SESSION = -1 }; - + /** * get a pointer to the unique KateSessionManager instance. * If the manager does not exist yet, create it. @@ -158,14 +176,10 @@ class KateSessionManager */ KateSession* getActiveSession() { return m_sessions[m_activeSessionId]; } - /** - * @return a reference to the sessions list - */ - TQPtrList& getSessionsList() { return m_sessions; } - /** - * Returns the session id of the first session whose name matches the - * provided one + * Return the session id of the first session whose name matches the + * provided one. In case multiple sessions share the same name, + * the id of the first one found will be returned. * @param name the session name to look for * @return the session id of the matching session if it is found, * otherwise KateSessionManager::INVALID_SESSION. @@ -173,13 +187,26 @@ class KateSessionManager int getSessionIdFromName(const TQString &name); /** - * Activates the selected session. + * @return a reference to the sessions list + */ + TQPtrList& getSessionsList() { return m_sessions; } + + /** + * Activate 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); + /** + * Create a new session and activate it if required + * @param sessionName new session name + * @param activate if true, activate the new session after creation + * @return the id of the newly created session + */ + int newSession(const TQString &sessionName = TQString::null, bool activate = true); + /** * Restore the last saved session. Can only be used before * any other session has been activated, i.e. on Kate's startup @@ -192,6 +219,28 @@ class KateSessionManager */ void saveActiveSession() { m_sessions[m_activeSessionId]->save(true); } + signals: + /** + * Emitted once a session has been activated + * @param newSessionId the id of the previous active session + * @param oldSessionId the id of the new active session + */ + void sessionActivated(int newSessionId, int oldSessionId); + + /** + * Emitted once a session has been created + * @param newSessionId the id of the new session + */ + void sessionCreated(int newSessionId); + + + public slots: + /** + * Slot to create a new session + */ + void slotNewSession(); + + private: KateSessionManager(); @@ -206,6 +255,42 @@ class KateSessionManager static KateSessionManager *ksm_instance; // the only KateSessionManager instance }; +//END KateSessionManager + +//BEGIN KateSessionChooser +//------------------------------------ +class KateSessionChooser : public KDialogBase +{ + Q_OBJECT + + public: + enum Result + { + RESULT_NO_OP = TQDialog::Rejected, + RESULT_OPEN_EXISTING, + RESULT_OPEN_NEW, + RESULT_QUIT_KATE + }; + + KateSessionChooser(TQWidget *parent); + KateSessionChooser() {} + + int getSelectedSessionId(); //return the session id of the selected session + + protected slots: + + void slotUser1(); // open existing session + void slotUser2(); // open new session + void slotUser3(); // quit kate + void slotSelectionChanged(); // list selection has changed + + protected: + TDEListView *m_sessionList; + int m_columnSessionId; +}; + +//BEGIN KateSessionChooser + @@ -461,51 +546,6 @@ class OldKateSessionManager : public TQObject OldKateSession::Ptr m_activeSession; }; -class OldKateSessionChooser : public KDialogBase -{ - Q_OBJECT - - public: - OldKateSessionChooser ( TQWidget *parent, const TQString &lastSession ); - ~OldKateSessionChooser (); - - OldKateSession::Ptr selectedSession (); - - bool reopenLastSession (); - - enum - { - resultQuit = TQDialog::Rejected, - resultOpen, - resultNew, - resultNone - }; - - protected slots: - /** - * open session - */ - void slotUser1 (); - - /** - * new session - */ - void slotUser2 (); - - /** - * quit kate - */ - void slotUser3 (); - - /** - * selection has changed - */ - void selectionChanged (); - - private: - TDEListView *m_sessions; - TQCheckBox *m_useLast; -}; class OldKateSessionOpenDialog : public KDialogBase { diff --git a/kate/app/katesessionpanel.cpp b/kate/app/katesessionpanel.cpp index 7bb61a308..2e8c12945 100644 --- a/kate/app/katesessionpanel.cpp +++ b/kate/app/katesessionpanel.cpp @@ -57,13 +57,16 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager * m_listview = new TDEListView(this); m_listview->header()->hide(); m_listview->addColumn("Session name"); - m_columnSessionId = m_listview->addColumn("Session id", 0); + m_columnSessionId = m_listview->addColumn("Session id", 50); + m_listview->header()->setResizeEnabled(false, m_columnSessionId); 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); // MIKE to enable after inserting doc list - connect(m_listview, TQT_SIGNAL(executed(TQListViewItem*)), TQT_SLOT(itemExecuted(TQListViewItem*))); + //m_listview->setRootIsDecorated(true); // FIXME to enable after inserting doc list + connect(m_listview, TQT_SIGNAL(executed(TQListViewItem*)), this, TQT_SLOT(itemExecuted(TQListViewItem*))); + connect(m_sessionManager, TQT_SIGNAL(sessionActivated(int, int)), this, TQT_SLOT(slotSessionActivated(int, int))); + connect(m_sessionManager, TQT_SIGNAL(sessionCreated(int)), this, TQT_SLOT(slotSessionCreated(int))); TQPtrList& sessions = m_sessionManager->getSessionsList(); for (int idx = sessions.count()-1; idx >= 0; --idx) @@ -94,12 +97,13 @@ void KateSessionPanel::setup_toolbar() //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"); + TQT_TQOBJECT(m_sessionManager), TQT_SLOT(slotNewSession()), + m_actionCollection, "session_new"); a->setWhatsThis(i18n("Create a new session.")); a->plug(m_toolbar); - +/* a = new TDEAction(i18n("Save"), SmallIcon("document-save"), 0, TQT_TQOBJECT(this), TQT_SLOT(saveSession()), m_actionCollection, "session_save"); a->setWhatsThis(i18n("Save the current session.")); @@ -175,22 +179,14 @@ void KateSessionPanel::deleteSession() void KateSessionPanel::sessionActivate() { TQListViewItem *newSessionItem = m_listview->selectedItem(); - int currSessionId = m_sessionManager->getActiveSessionId(); if (!newSessionItem) return; + + int currSessionId = m_sessionManager->getActiveSessionId(); 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")); + m_sessionManager->activateSession(newSessionId); } } @@ -224,3 +220,29 @@ void KateSessionPanel::itemExecuted(TQListViewItem *item) return; } } + +//------------------------------------------- +void KateSessionPanel::slotSessionActivated(int newSessionId, int oldSessionId) +{ + // Move the active session marker + TQListViewItem *item = m_listview->firstChild(); + for (int idx = 0; idx < oldSessionId; ++idx) + { + item = item->nextSibling(); + } + item->setPixmap(m_columnPixmap, TQPixmap()); + + item = m_listview->firstChild(); + for (int idx = 0; idx < newSessionId; ++idx) + { + item = item->nextSibling(); + } + item->setPixmap(m_columnPixmap, SmallIcon("ok")); + m_listview->setSelected(item, true); +} + +void KateSessionPanel::slotSessionCreated(int newSessionId) +{ + TQPtrList& sessions = m_sessionManager->getSessionsList(); + new TDEListViewItem(m_listview, m_listview->lastItem(), sessions[newSessionId]->getSessionName(), TQString("%1").arg(newSessionId)); +} diff --git a/kate/app/katesessionpanel.h b/kate/app/katesessionpanel.h index d3baddcb4..a33535755 100644 --- a/kate/app/katesessionpanel.h +++ b/kate/app/katesessionpanel.h @@ -76,6 +76,9 @@ class KateSessionPanel : public TQVBox void sessionMoveDown(); void itemExecuted(TQListViewItem *item); + void slotSessionActivated(int newSessionId, int oldSessionId); + void slotSessionCreated(int newSessionId); + private: void setup_toolbar(); -- cgit v1.2.3