Kate session panel: added save and read-only functionality. Fixed up toolbar buttons status update.

Added ability to activate a session using the ENTER key. Some other code refactoring.

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

@ -91,7 +91,6 @@ KateSession::KateSession(const TQString &sessionName, const TQString &filename,
} }
// Read only // Read only
m_readOnly = m_config->readBoolEntry(KS_READONLY, false); m_readOnly = m_config->readBoolEntry(KS_READONLY, false);
m_config->setReadOnly(m_readOnly);
// Document list // Document list
if (m_config->hasGroup(KS_DOCLIST)) 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_readOnly && !setReadOnly)
if (m_config)
{
m_config->setReadOnly(m_readOnly);
}
}
//------------------------------------
void KateSession::save(bool saveGUIInfo)
{
if (m_readOnly)
{ {
return; return;
} }
@ -349,7 +338,6 @@ KateSessionManager::~KateSessionManager()
// FIXME An option need to be added to Configure Kate -> Sessions to allow Kate to ask about // 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 // saving unnamed sessions before closing the current session. Default value is off as per
// point above. // point above.
void KateSessionManager::saveConfig() void KateSessionManager::saveConfig()
{ {
if (!m_config) if (!m_config)
@ -372,6 +360,17 @@ void KateSessionManager::saveConfig()
m_config->sync(); 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) int KateSessionManager::getSessionIdFromName(const TQString &name)
{ {
@ -447,6 +446,17 @@ bool KateSessionManager::restoreLastSession()
return activateSession(m_activeSessionId, false); 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) bool KateSessionManager::deleteSession(int sessionId)
{ {
@ -551,6 +561,19 @@ void KateSessionManager::renameSession(int sessionId, const TQString &newSession
m_sessions[sessionId]->setSessionName(newSessionName); 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 //END KateSessionManager

@ -42,6 +42,9 @@ class TQCheckBox;
//BEGIN KateSession //BEGIN KateSession
/**
* An object representing a Kate's session.
*/
class KateSession class KateSession
{ {
public: public:
@ -65,6 +68,7 @@ class 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
@ -75,11 +79,12 @@ class KateSession
* @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 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 * @return the session filename if available, otherwise the null string
@ -94,21 +99,24 @@ class KateSession
/** /**
* Save session info * Save session info
* @param saveGUIInfo if true, save also the information about the GUI elements * @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 * Activate the session
*/ */
void activate(); void activate();
private: private:
friend class KateViewSpace; friend class KateViewSpace;
/** /**
* @return the session config object * @return the session config object
*/ */
TDEConfig* getConfig() { return m_config; } TDEConfig* getConfig() const { return m_config; }
TQString m_sessionName; TQString m_sessionName;
@ -132,6 +140,12 @@ class KateSession
//This would allow a safe use of multiple Kate instances without overwriting session information //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 //among them. Currently the last instance to be closed will overwrite the information previously
//saved by other Kate instances. //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 class KateSessionManager : public TQObject
{ {
Q_OBJECT Q_OBJECT
@ -174,6 +188,12 @@ class KateSessionManager : public TQObject
*/ */
KateSession* getActiveSession() { return m_sessions[m_activeSessionId]; } 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 * Return the session id of the first session whose name matches the
* provided one. In case multiple sessions share the same name, * provided one. In case multiple sessions share the same name,
@ -216,8 +236,16 @@ class KateSessionManager : public TQObject
/** /**
* Saves the active session * 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 * Delete the specified session
@ -246,6 +274,13 @@ class KateSessionManager : public TQObject
*/ */
void renameSession(int sessionId, const TQString &newSessionName); 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: signals:
/** /**
@ -261,6 +296,12 @@ class KateSessionManager : public TQObject
*/ */
void sessionCreated(int sessionId); 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 * Emitted once a session has been deleted
* @param sessionId the id of the deleted session * @param sessionId the id of the deleted session

@ -136,8 +136,13 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager *
m_listview->setSorting(-1); m_listview->setSorting(-1);
m_listview->setResizeMode(TQListView::LastColumn); m_listview->setResizeMode(TQListView::LastColumn);
//m_listview->setRootIsDecorated(true); // FIXME to enable after inserting doc list //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*)), connect(m_listview, TQT_SIGNAL(executed(TQListViewItem*)),
this, TQT_SLOT(slotItemExecuted(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)), connect(m_sessionManager, TQT_SIGNAL(sessionActivated(int, int)),
this, TQT_SLOT(slotSessionActivated(int, int))); this, TQT_SLOT(slotSessionActivated(int, int)));
connect(m_sessionManager, TQT_SIGNAL(sessionCreated(int)), connect(m_sessionManager, TQT_SIGNAL(sessionCreated(int)),
@ -175,7 +180,6 @@ void KateSessionPanel::setup_toolbar()
m_toolbar->setIconSize(16); m_toolbar->setIconSize(16);
m_toolbar->setEnableContextMenu(false); m_toolbar->setEnableContextMenu(false);
//FIXME : uncomment and activate as long as the new session manager gets fixed
// Toolbar actions // Toolbar actions
TDEAction *a; TDEAction *a;
@ -183,7 +187,7 @@ void KateSessionPanel::setup_toolbar()
TQT_TQOBJECT(this), TQT_SLOT(slotNewSession()), m_actionCollection, "session_new"); TQT_TQOBJECT(this), TQT_SLOT(slotNewSession()), m_actionCollection, "session_new");
a->setWhatsThis(i18n("Create a new session.")); a->setWhatsThis(i18n("Create a new session."));
a->plug(m_toolbar); a->plug(m_toolbar);
/*
a = new TDEAction(i18n("Save"), SmallIcon("document-save"), 0, a = new TDEAction(i18n("Save"), SmallIcon("document-save"), 0,
TQT_TQOBJECT(this), TQT_SLOT(slotSaveSession()), m_actionCollection, "session_save"); TQT_TQOBJECT(this), TQT_SLOT(slotSaveSession()), m_actionCollection, "session_save");
a->setWhatsThis(i18n("Save the current session.")); 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"); TQT_TQOBJECT(this), TQT_SLOT(slotSaveSessionAs()), m_actionCollection, "session_save_as");
a->setWhatsThis(i18n("Save the current session with a different name.")); a->setWhatsThis(i18n("Save the current session with a different name."));
a->plug(m_toolbar); a->plug(m_toolbar);
*/
a = new TDEAction(i18n("Rename"), SmallIcon("edit_user"), 0, a = new TDEAction(i18n("Rename"), SmallIcon("edit_user"), 0,
TQT_TQOBJECT(this), TQT_SLOT(slotRenameSession()), m_actionCollection, "session_rename"); TQT_TQOBJECT(this), TQT_SLOT(slotRenameSession()), m_actionCollection, "session_rename");
a->setWhatsThis(i18n("Rename the selected session.")); 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"); TQT_TQOBJECT(this), TQT_SLOT(slotActivateSession()), m_actionCollection, "session_activate");
a->setWhatsThis(i18n("Activate the selected session.")); a->setWhatsThis(i18n("Activate the selected session."));
a->plug(m_toolbar); a->plug(m_toolbar);
/*
TDEToggleAction *tglA = new TDEToggleAction(i18n("Toggle read only"), SmallIcon("encrypted"), 0, TDEToggleAction *tglA = new TDEToggleAction(i18n("Toggle read only"), SmallIcon("encrypted"), 0,
TQT_TQOBJECT(this), TQT_SLOT(slotSessionToggleReadOnly()), m_actionCollection, "session_toggle_read_only"); TQT_TQOBJECT(this), TQT_SLOT(slotSessionToggleReadOnly()), m_actionCollection, "session_toggle_read_only");
tglA->setWhatsThis(i18n("Toggle read only status for the selected session.<p>" tglA->setWhatsThis(i18n("Toggle read only status for the selected session.<p>"
@ -218,7 +222,6 @@ void KateSessionPanel::setup_toolbar()
"will not be saved when you exit Kate or switch to another session.<p>" "will not be saved when you exit Kate or switch to another session.<p>"
"You can use this option to create template sessions that you wish to keep unchanged over time.")); "You can use this option to create template sessions that you wish to keep unchanged over time."));
tglA->plug(m_toolbar); tglA->plug(m_toolbar);
*/
a = new TDEAction(i18n("Move Up"), SmallIcon("go-up"), 0, a = new TDEAction(i18n("Move Up"), SmallIcon("go-up"), 0,
TQT_TQOBJECT(this), TQT_SLOT(slotSessionMoveUp()), m_actionCollection, "session_move_up"); 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"); TQT_TQOBJECT(this), TQT_SLOT(slotSessionMoveDown()), m_actionCollection, "session_move_down");
a->setWhatsThis(i18n("Move down the selected session.")); a->setWhatsThis(i18n("Move down the selected session."));
a->plug(m_toolbar); 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() void KateSessionPanel::slotSaveSession()
{ {
//TODO KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
if (!sessionItem)
{
return;
}
int sessId = sessionItem->getSessionId();
const KateSession *ks = m_sessionManager->getSessionFromId(sessId);
if (!ks)
{
return;
}
if (ks->getSessionFilename().isEmpty())
{
// Session has never been saved before. Ask user for a session name first
slotSaveSessionAs();
}
else
{
m_sessionManager->saveSession(sessId);
slotSelectionChanged(); // Update the toolbar button status
}
} }
//------------------------------------------- //-------------------------------------------
void KateSessionPanel::slotSaveSessionAs() void KateSessionPanel::slotSaveSessionAs()
{ {
//TODO //TODO
slotSelectionChanged(); // Update the toolbar button status
} }
//------------------------------------------- //-------------------------------------------
@ -260,7 +288,9 @@ void KateSessionPanel::slotRenameSession()
{ {
TQListViewItem *sessionItem = m_listview->selectedItem(); TQListViewItem *sessionItem = m_listview->selectedItem();
if (!sessionItem) if (!sessionItem)
{
return; return;
}
m_listview->rename(m_listview->selectedItem(), m_columnName); m_listview->rename(m_listview->selectedItem(), m_columnName);
} }
@ -270,7 +300,9 @@ void KateSessionPanel::slotDeleteSession()
{ {
KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem()); KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
if (!sessionItem) if (!sessionItem)
{
return; return;
}
int result = KMessageBox::warningContinueCancel(this, int result = KMessageBox::warningContinueCancel(this,
i18n("Do you really want to delete the session '%1'?").arg(sessionItem->text(0)), i18n("Do you really want to delete the session '%1'?").arg(sessionItem->text(0)),
@ -286,7 +318,9 @@ void KateSessionPanel::slotActivateSession()
{ {
KateSessionPanelItem *newSessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem()); KateSessionPanelItem *newSessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
if (!newSessionItem) if (!newSessionItem)
{
return; return;
}
int currSessionId = m_sessionManager->getActiveSessionId(); int currSessionId = m_sessionManager->getActiveSessionId();
int newSessionId = newSessionItem->getSessionId(); int newSessionId = newSessionItem->getSessionId();
@ -299,7 +333,16 @@ void KateSessionPanel::slotActivateSession()
//------------------------------------------- //-------------------------------------------
void KateSessionPanel::slotSessionToggleReadOnly() void KateSessionPanel::slotSessionToggleReadOnly()
{ {
//TODO KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
if (!sessionItem)
{
return;
}
m_sessionManager->setSessionReadOnlyStatus(sessionItem->getSessionId(),
(dynamic_cast<TDEToggleAction*>(
m_actionCollection->action("session_toggle_read_only")))->isChecked());
slotSelectionChanged(); // Update the toolbar button status
} }
//------------------------------------------- //-------------------------------------------
@ -307,7 +350,9 @@ void KateSessionPanel::slotSessionMoveUp()
{ {
KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem()); KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
if (!sessionItem) if (!sessionItem)
{
return; return;
}
m_sessionManager->moveSessionBackward(sessionItem->getSessionId()); m_sessionManager->moveSessionBackward(sessionItem->getSessionId());
} }
@ -317,15 +362,20 @@ void KateSessionPanel::slotSessionMoveDown()
{ {
KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem()); KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
if (!sessionItem) if (!sessionItem)
{
return; return;
}
m_sessionManager->moveSessionForward(sessionItem->getSessionId()); m_sessionManager->moveSessionForward(sessionItem->getSessionId());
} }
//-------------------------------------------
void KateSessionPanel::slotItemExecuted(TQListViewItem *item) void KateSessionPanel::slotItemExecuted(TQListViewItem *item)
{ {
if (!item) if (!item)
return; {
return;
}
// First level items are sessions. Executing one, will switch to that session // First level items are sessions. Executing one, will switch to that session
if (!item->parent()) if (!item->parent())
@ -335,6 +385,62 @@ void KateSessionPanel::slotItemExecuted(TQListViewItem *item)
} }
} }
//-------------------------------------------
void KateSessionPanel::slotSelectionChanged()
{
KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
const KateSession *ks(NULL);
if (sessionItem)
{
ks = m_sessionManager->getSessionFromId(sessionItem->getSessionId());
}
TDEToggleAction *readOnlyAction = dynamic_cast<TDEToggleAction*>(
m_actionCollection->action("session_toggle_read_only"));
if (!sessionItem || !ks)
{
m_actionCollection->action("session_save")->setEnabled(false);
m_actionCollection->action("session_save_as")->setEnabled(false);
m_actionCollection->action("session_rename")->setEnabled(false);
m_actionCollection->action("session_delete")->setEnabled(false);
m_actionCollection->action("session_activate")->setEnabled(false);
m_actionCollection->action("session_move_up")->setEnabled(false);
m_actionCollection->action("session_move_down")->setEnabled(false);
readOnlyAction->setEnabled(false);
readOnlyAction->setChecked(false);
}
else
{
if (ks->isReadOnly())
{
// Read only sessions can not be saved or renamed
m_actionCollection->action("session_save")->setEnabled(false);
m_actionCollection->action("session_rename")->setEnabled(false);
}
else
{
m_actionCollection->action("session_save")->setEnabled(true);
m_actionCollection->action("session_rename")->setEnabled(true);
}
if (ks->getSessionFilename().isEmpty())
{
// Unstored sessions can not be made readonly
readOnlyAction->setEnabled(false);
readOnlyAction->setChecked(false);
}
else
{
readOnlyAction->setEnabled(true);
readOnlyAction->setChecked(ks->isReadOnly());
}
m_actionCollection->action("session_save_as")->setEnabled(true);
m_actionCollection->action("session_delete")->setEnabled(true);
m_actionCollection->action("session_activate")->setEnabled(true);
m_actionCollection->action("session_move_up")->setEnabled(true);
m_actionCollection->action("session_move_down")->setEnabled(true);
}
}
//------------------------------------------- //-------------------------------------------
void KateSessionPanel::slotSessionActivated(int newSessionId, int oldSessionId) void KateSessionPanel::slotSessionActivated(int newSessionId, int oldSessionId)
{ {
@ -458,6 +564,7 @@ void KateSessionPanel::slotSessionRenamed(TQListViewItem *item)
{ {
return; return;
} }
m_sessionManager->renameSession(sessionItem->getSessionId(), sessionItem->text(m_columnName)); m_sessionManager->renameSession(sessionItem->getSessionId(), sessionItem->text(m_columnName));
} }
//END KateSessionPanel //END KateSessionPanel

@ -127,13 +127,13 @@ class KateSessionPanel : public TQVBox
void slotSessionMoveDown(); void slotSessionMoveDown();
void slotItemExecuted(TQListViewItem *item); void slotItemExecuted(TQListViewItem *item);
void slotSelectionChanged();
void slotSessionActivated(int newSessionId, int oldSessionId); void slotSessionActivated(int newSessionId, int oldSessionId);
void slotSessionCreated(int sessionId); void slotSessionCreated(int sessionId);
void slotSessionDeleted(int sessionId); void slotSessionDeleted(int sessionId);
void slotSessionsSwapped(int sessionIdMin, int sessionIdMax); void slotSessionsSwapped(int sessionIdMin, int sessionIdMax);
void slotSessionRenamed(TQListViewItem *item); void slotSessionRenamed(TQListViewItem *item);
private: private:
void setup_toolbar(); void setup_toolbar();

@ -114,7 +114,7 @@ void KateViewSpace::addView(Kate::View* v, bool show)
{ {
TQString vgroup = TQString("%1 %2").arg(m_group).arg(fn); TQString vgroup = TQString("%1 %2").arg(m_group).arg(fn);
KateSession *as = KateSessionManager::self()->getActiveSession(); const KateSession *as = KateSessionManager::self()->getActiveSession();
TDEConfig *asCfg = as->getConfig(); TDEConfig *asCfg = as->getConfig();
if (asCfg && asCfg->hasGroup(vgroup)) if (asCfg && asCfg->hasGroup(vgroup))
{ {

Loading…
Cancel
Save