diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index 17218d2b1..1ab43c420 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -91,7 +91,6 @@ KateSession::KateSession(const TQString &sessionName, const TQString &filename, } // Read only m_readOnly = m_config->readBoolEntry(KS_READONLY, false); - m_config->setReadOnly(m_readOnly); // Document list if (m_config->hasGroup(KS_DOCLIST)) { @@ -149,19 +148,9 @@ void KateSession::setSessionName(const TQString &sessionName) } //------------------------------------ -void KateSession::setReadOnly(bool readOnly) +void KateSession::save(bool saveGUIInfo, bool setReadOnly) { - m_readOnly = readOnly; - if (m_config) - { - m_config->setReadOnly(m_readOnly); - } -} - -//------------------------------------ -void KateSession::save(bool saveGUIInfo) -{ - if (m_readOnly) + if (m_readOnly && !setReadOnly) { return; } @@ -349,7 +338,6 @@ KateSessionManager::~KateSessionManager() // 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) @@ -372,6 +360,17 @@ void KateSessionManager::saveConfig() m_config->sync(); } +//------------------------------------ +KateSession* KateSessionManager::getSessionFromId(int sessionId) +{ + if (sessionId < 0 || sessionId >= (int)m_sessions.count()) + { + return NULL; + } + + return m_sessions[sessionId]; +} + //------------------------------------ int KateSessionManager::getSessionIdFromName(const TQString &name) { @@ -447,6 +446,17 @@ bool KateSessionManager::restoreLastSession() return activateSession(m_activeSessionId, false); } +//------------------------------------------- +void KateSessionManager::saveSession(int sessionId) +{ + if (sessionId < 0 || sessionId >= (int)m_sessions.count()) + { + return; + } + m_sessions[sessionId]->save(sessionId == m_activeSessionId); + emit sessionSaved(sessionId); +} + //------------------------------------------- bool KateSessionManager::deleteSession(int sessionId) { @@ -551,6 +561,19 @@ void KateSessionManager::renameSession(int sessionId, const TQString &newSession m_sessions[sessionId]->setSessionName(newSessionName); } + +//------------------------------------------- +void KateSessionManager::setSessionReadOnlyStatus(int sessionId, bool readOnly) +{ + if (sessionId < 0 || sessionId >= (int)m_sessions.count()) + { + return; + } + + m_sessions[sessionId]->setReadOnly(readOnly); + // Session is saved one last time when making it read only + m_sessions[sessionId]->save(sessionId == m_activeSessionId, true); +} //END KateSessionManager diff --git a/kate/app/katesession.h b/kate/app/katesession.h index 077ad1fda..3351db150 100644 --- a/kate/app/katesession.h +++ b/kate/app/katesession.h @@ -42,6 +42,9 @@ class TQCheckBox; //BEGIN KateSession +/** + * An object representing a Kate's session. + */ class KateSession { public: @@ -65,6 +68,7 @@ class KateSession * @return the session name */ const TQString& getSessionName() const { return m_sessionName; } + /** * Set the new session name * @param sessionName the new session name @@ -75,11 +79,12 @@ class KateSession * @return whether the session is read only or not */ bool isReadOnly() const { return m_readOnly; } + /** * Set session read only status - * @param readOnly if true, the session config can not be saved to file + * @param readOnly if true, the session status can not be modified */ - void setReadOnly(bool readOnly); + void setReadOnly(bool readOnly) { m_readOnly = readOnly; } /** * @return the session filename if available, otherwise the null string @@ -94,21 +99,24 @@ class KateSession /** * Save session info * @param saveGUIInfo if true, save also the information about the GUI elements + * @param setReadOnly necessary to save a session that has to be turned to read only */ - void save(bool saveGUIInfo); + void save(bool saveGUIInfo, bool setReadOnly = false); /** * Activate the session */ void activate(); + private: friend class KateViewSpace; + /** * @return the session config object */ - TDEConfig* getConfig() { return m_config; } + TDEConfig* getConfig() const { return m_config; } TQString m_sessionName; @@ -132,6 +140,12 @@ class KateSession //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. +/** + * The Kate session manager. It takes care of storing and retrieving each session object + * as well as providing methods to operate on them. + * + * @note The Kate session manager takes ownership of each session object it handles. + */ class KateSessionManager : public TQObject { Q_OBJECT @@ -174,6 +188,12 @@ class KateSessionManager : public TQObject */ KateSession* getActiveSession() { return m_sessions[m_activeSessionId]; } + /** + * @param sessionId the id of the session to return + * @return a reference to the specified session + */ + KateSession* getSessionFromId(int sessionId); + /** * Return the session id of the first session whose name matches the * provided one. In case multiple sessions share the same name, @@ -216,8 +236,16 @@ class KateSessionManager : public TQObject /** * Saves the active session + * @emit sessionSaved (through invoked "void saveSession(int)" method) */ - void saveActiveSession() { m_sessions[m_activeSessionId]->save(true); } + void saveActiveSession() { saveSession(m_activeSessionId); } + + /** + * Save the specified session + * @param sessionId the id of the session to save + * @emit sessionSaved + */ + void saveSession(int sessionId); /** * Delete the specified session @@ -246,6 +274,13 @@ class KateSessionManager : public TQObject */ void renameSession(int sessionId, const TQString &newSessionName); + /** + * Set the read only status of the specified session + * @param sessionId the id of the session to modify + * @param readOnly the new read only status + */ + void setSessionReadOnlyStatus(int sessionId, bool readOnly); + signals: /** @@ -261,6 +296,12 @@ class KateSessionManager : public TQObject */ void sessionCreated(int sessionId); + /** + * Emitted once a session has been saved + * @param sessionId the id of the saved session + */ + void sessionSaved(int sessionId); + /** * Emitted once a session has been deleted * @param sessionId the id of the deleted session diff --git a/kate/app/katesessionpanel.cpp b/kate/app/katesessionpanel.cpp index 3a579dff4..b3f7ef55b 100644 --- a/kate/app/katesessionpanel.cpp +++ b/kate/app/katesessionpanel.cpp @@ -136,8 +136,13 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager * m_listview->setSorting(-1); m_listview->setResizeMode(TQListView::LastColumn); //m_listview->setRootIsDecorated(true); // FIXME to enable after inserting doc list + + connect(m_listview, TQT_SIGNAL(selectionChanged()), + this, TQT_SLOT(slotSelectionChanged())); connect(m_listview, TQT_SIGNAL(executed(TQListViewItem*)), this, TQT_SLOT(slotItemExecuted(TQListViewItem*))); + connect(m_listview, TQT_SIGNAL(returnPressed(TQListViewItem*)), + this, TQT_SLOT(slotItemExecuted(TQListViewItem*))); connect(m_sessionManager, TQT_SIGNAL(sessionActivated(int, int)), this, TQT_SLOT(slotSessionActivated(int, int))); connect(m_sessionManager, TQT_SIGNAL(sessionCreated(int)), @@ -175,7 +180,6 @@ 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; @@ -183,7 +187,7 @@ void KateSessionPanel::setup_toolbar() TQT_TQOBJECT(this), 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(slotSaveSession()), m_actionCollection, "session_save"); a->setWhatsThis(i18n("Save the current session.")); @@ -193,7 +197,7 @@ void KateSessionPanel::setup_toolbar() TQT_TQOBJECT(this), TQT_SLOT(slotSaveSessionAs()), m_actionCollection, "session_save_as"); a->setWhatsThis(i18n("Save the current session with a different name.")); a->plug(m_toolbar); -*/ + a = new TDEAction(i18n("Rename"), SmallIcon("edit_user"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotRenameSession()), m_actionCollection, "session_rename"); a->setWhatsThis(i18n("Rename the selected session.")); @@ -210,7 +214,7 @@ void KateSessionPanel::setup_toolbar() TQT_TQOBJECT(this), TQT_SLOT(slotActivateSession()), 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(slotSessionToggleReadOnly()), m_actionCollection, "session_toggle_read_only"); tglA->setWhatsThis(i18n("Toggle read only status for the selected session.
" @@ -218,7 +222,6 @@ void KateSessionPanel::setup_toolbar() "will not be saved when you exit Kate or switch to another session.
"
"You can use this option to create template sessions that you wish to keep unchanged over time."));
tglA->plug(m_toolbar);
-*/
a = new TDEAction(i18n("Move Up"), SmallIcon("go-up"), 0,
TQT_TQOBJECT(this), TQT_SLOT(slotSessionMoveUp()), m_actionCollection, "session_move_up");
@@ -229,6 +232,8 @@ void KateSessionPanel::setup_toolbar()
TQT_TQOBJECT(this), TQT_SLOT(slotSessionMoveDown()), m_actionCollection, "session_move_down");
a->setWhatsThis(i18n("Move down the selected session."));
a->plug(m_toolbar);
+
+ //FIXME add button to restore a modified session to its original if not yet saved to disk
}
//-------------------------------------------
@@ -246,13 +251,36 @@ void KateSessionPanel::slotNewSession()
//-------------------------------------------
void KateSessionPanel::slotSaveSession()
{
-//TODO
+ KateSessionPanelItem *sessionItem = dynamic_cast