Kate session panel: added save_as and reload functionality.

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

@ -49,7 +49,8 @@
#include <time.h> #include <time.h>
// FIXME general: need to keep doc list and current session's m_documents in synchro // FIXME general: need to keep doc list and current session's m_documents in synchro
// all the time (doc open, doc closed, doc renamed) // all the time (doc open, doc closed, doc renamed).
// To be done when doc list software is developed
// FIXME add code to handle the various options in Configure Kate -> Application -> Sessions // FIXME add code to handle the various options in Configure Kate -> Application -> Sessions
// String constants // String constants
@ -63,8 +64,8 @@ namespace
const char *KS_NAME = "Name"; const char *KS_NAME = "Name";
const char *KS_OPENDOC = "Open Documents"; const char *KS_OPENDOC = "Open Documents";
const char *KS_READONLY = "ReadOnly"; const char *KS_READONLY = "ReadOnly";
const char *KS_UNNAMED = "Unnamed";
const char *KS_OPEN_MAINWINDOWS = "Open MainWindows"; const char *KS_OPEN_MAINWINDOWS = "Open MainWindows";
const char *KS_UNNAMED = "Unnamed";
// Kate session manager // Kate session manager
const char *KSM_DIR = "kate/sessions"; const char *KSM_DIR = "kate/sessions";
@ -75,21 +76,53 @@ namespace
} }
//BEGIN Kate session //BEGIN Kate session
KateSession::KateSession(const TQString &sessionName, const TQString &filename, bool isFullName) : KateSession::KateSession(const KateSessionManager &manager, const TQString &sessionName,
m_sessionName(sessionName), m_filename(filename), m_isFullName(isFullName), const TQString &fileName) :
m_manager(manager), m_sessionName(sessionName), m_filename(fileName),
m_readOnly(false), m_documents(), m_config(NULL) m_readOnly(false), m_documents(), m_config(NULL)
{ {
if (m_isFullName && TDEGlobal::dirs()->exists(m_filename)) load(false);
}
//------------------------------------
KateSession::KateSession(const KateSession &session, const TQString &newSessionName) :
m_manager(session.m_manager), m_sessionName(newSessionName), m_filename(),
m_readOnly(false), m_documents(session.m_documents), m_config(NULL)
{
createFilename();
m_config = dynamic_cast<KSimpleConfig*>(session.m_config->copyTo(m_filename));
}
//------------------------------------
KateSession::~KateSession()
{
if (m_config)
{
delete m_config;
}
}
//------------------------------------
void KateSession::setSessionName(const TQString &sessionName)
{
m_sessionName = sessionName.isEmpty() ? i18n(KS_UNNAMED) : sessionName;
}
//------------------------------------
void KateSession::load(bool includeGUIInfo)
{
if (m_config)
{
delete m_config;
}
if (TDEGlobal::dirs()->exists(m_filename))
{ {
// Create config object if the session file already exists // Create config object if the session file already exists
m_config = new KSimpleConfig(m_filename, m_readOnly); m_config = new KSimpleConfig(m_filename, m_readOnly);
m_config->setGroup(KS_GENERAL); m_config->setGroup(KS_GENERAL);
// Session name // Session general properties
if (m_sessionName.isEmpty()) m_sessionName = m_config->readEntry(KS_NAME, i18n(KS_UNNAMED));
{
m_sessionName = m_config->readEntry(KS_NAME, i18n(KS_UNNAMED));
}
// Read only
m_readOnly = m_config->readBoolEntry(KS_READONLY, false); m_readOnly = m_config->readBoolEntry(KS_READONLY, false);
// Document list // Document list
if (m_config->hasGroup(KS_DOCLIST)) if (m_config->hasGroup(KS_DOCLIST))
@ -125,28 +158,22 @@ KateSession::KateSession(const TQString &sessionName, const TQString &filename,
} }
} }
} }
else
{
m_filename = TQString::null;
}
if (m_sessionName.isEmpty()) if (m_sessionName.isEmpty())
{ {
m_sessionName = i18n(KS_UNNAMED); m_sessionName = i18n(KS_UNNAMED);
} }
// FIXME: needs to make sure doc list and m_documents are in synchro here
} // Update e all current documents if necessary
if (includeGUIInfo)
//------------------------------------
KateSession::~KateSession()
{
if (m_config)
{ {
delete m_config; activate();
} }
} }
//------------------------------------
void KateSession::setSessionName(const TQString &sessionName)
{
m_sessionName = sessionName.isEmpty() ? i18n(KS_UNNAMED) : sessionName;
}
//------------------------------------ //------------------------------------
void KateSession::save(bool saveGUIInfo, bool setReadOnly) void KateSession::save(bool saveGUIInfo, bool setReadOnly)
{ {
@ -156,23 +183,9 @@ void KateSession::save(bool saveGUIInfo, bool setReadOnly)
} }
// create a new session filename if needed // create a new session filename if needed
if (!m_isFullName) if (m_filename.isEmpty())
{ {
int s = time(0); createFilename();
TQCString tname;
TQString tmpName;
while (true)
{
tname.setNum(s++);
KMD5 md5(tname);
tmpName = m_filename + TQString("%1.katesession").arg(md5.hexDigest().data());
if (!TDEGlobal::dirs()->exists(tmpName))
{
m_filename = tmpName;
m_isFullName = true;
break;
}
}
} }
// save session config info // save session config info
@ -252,6 +265,31 @@ void KateSession::activate()
Kate::Document::setOpenErrorDialogsActivated(true); Kate::Document::setOpenErrorDialogsActivated(true);
} }
//------------------------------------
void KateSession::createFilename()
{
// create a new session filename if needed
if (!m_filename.isEmpty())
{
return;
}
int s = time(0);
TQCString tname;
TQString tmpName;
while (true)
{
tname.setNum(s++);
KMD5 md5(tname);
tmpName = m_manager.getBaseDir() + TQString("%1.katesession").arg(md5.hexDigest().data());
if (!TDEGlobal::dirs()->exists(tmpName))
{
m_filename = tmpName;
break;
}
}
}
//END Kate session //END Kate session
@ -290,7 +328,7 @@ KateSessionManager::KateSessionManager() :
if (!urlStr.isEmpty() && TDEGlobal::dirs()->exists(urlStr)) if (!urlStr.isEmpty() && TDEGlobal::dirs()->exists(urlStr))
{ {
// Filter out empty URLs or non existing sessions // Filter out empty URLs or non existing sessions
m_sessions.append(new KateSession(TQString::null, urlStr, true)); m_sessions.append(new KateSession(*this, TQString::null, urlStr));
} }
} }
} }
@ -301,13 +339,13 @@ KateSessionManager::KateSessionManager() :
TQDir sessionDir(m_baseDir, "*.katesession"); TQDir sessionDir(m_baseDir, "*.katesession");
for (unsigned int i = 0; i < sessionDir.count(); ++i) for (unsigned int i = 0; i < sessionDir.count(); ++i)
{ {
m_sessions.append(new KateSession(TQString::null, m_baseDir+sessionDir[i], true)); m_sessions.append(new KateSession(*this, TQString::null, m_baseDir+sessionDir[i]));
} }
} }
sessionsCount = (int)m_sessions.count(); sessionsCount = (int)m_sessions.count();
if (sessionsCount == 0) // In the worst case, there is no valid session at all if (sessionsCount == 0) // In the worst case, there is no valid session at all
{ {
m_sessions.append(new KateSession(TQString::null, m_baseDir, false)); m_sessions.append(new KateSession(*this, TQString::null, TQString::null));
} }
if (m_activeSessionId < 0 || m_activeSessionId >= (int)m_sessions.count()) if (m_activeSessionId < 0 || m_activeSessionId >= (int)m_sessions.count())
{ {
@ -360,6 +398,17 @@ void KateSessionManager::saveConfig()
m_config->sync(); m_config->sync();
} }
//------------------------------------
const TQString& KateSessionManager::getSessionName(int sessionId)
{
if (sessionId < 0 || sessionId >= (int)m_sessions.count())
{
return TQString::null;
}
return m_sessions[sessionId]->getSessionName();
}
//------------------------------------ //------------------------------------
KateSession* KateSessionManager::getSessionFromId(int sessionId) KateSession* KateSessionManager::getSessionFromId(int sessionId)
{ {
@ -425,9 +474,33 @@ bool KateSessionManager::activateSession(int sessionId, bool saveCurr)
//------------------------------------ //------------------------------------
int KateSessionManager::newSession(const TQString &sessionName, bool activate) int KateSessionManager::newSession(const TQString &sessionName, bool activate)
{ {
m_sessions.append(new KateSession(sessionName, m_baseDir, false)); m_sessions.append(new KateSession(*this, sessionName, TQString::null));
int newSessionId = m_sessions.count() - 1;
emit sessionCreated(newSessionId);
if (activate)
{
activateSession(newSessionId, m_activeSessionId != INVALID_SESSION);
}
return newSessionId;
}
//------------------------------------
int KateSessionManager::cloneSession(int sessionId, const TQString &sessionName, bool activate)
{
if (sessionId < 0 || sessionId >= (int)m_sessions.count())
{
return INVALID_SESSION;
}
m_sessions.append(new KateSession(*m_sessions[sessionId], sessionName));
int newSessionId = m_sessions.count() - 1; int newSessionId = m_sessions.count() - 1;
emit sessionCreated(newSessionId); emit sessionCreated(newSessionId);
// If cloning the active session, the new session will contain the current status
// and the original session will be restored to the last saved state (save as... functionality)
m_sessions[newSessionId]->save(true);
reloadActiveSession();
if (activate) if (activate)
{ {
activateSession(newSessionId, m_activeSessionId != INVALID_SESSION); activateSession(newSessionId, m_activeSessionId != INVALID_SESSION);
@ -560,6 +633,7 @@ void KateSessionManager::renameSession(int sessionId, const TQString &newSession
} }
m_sessions[sessionId]->setSessionName(newSessionName); m_sessions[sessionId]->setSessionName(newSessionName);
emit sessionRenamed(sessionId);
} }
//------------------------------------------- //-------------------------------------------

@ -39,6 +39,7 @@ class KDirWatch;
class KPushButton; class KPushButton;
class TDEListView; class TDEListView;
class TQCheckBox; class TQCheckBox;
class KateSessionManager;
//BEGIN KateSession //BEGIN KateSession
@ -51,13 +52,19 @@ class KateSession
/** /**
* create a new session and read the config from fileName if it exists * create a new session and read the config from fileName if it exists
* @param manager the session manager handling this session
* @param sessionName session name * @param sessionName session name
* @param fileName file where session config is saved to/restored from * @param fileName file where session config is saved to/restored from
* @param isFullName true -> filename is a full filename, used to load/save the session configuration
* false -> filename is a folder name. This is used for new unsaved sessions
* to inject the location where the configuration file should be saved
*/ */
KateSession(const TQString &sessionName, const TQString &fileName, bool isFullName); KateSession(const KateSessionManager &manager, const TQString &sessionName, const TQString &fileName);
/**
* duplicate an existing session into a new one with the given new name.
* If the existing session is read-only, the new one will *not* be read-only by default
* @param session the existing session
* @param newSessionName the name of the new session
*/
KateSession(const KateSession &session, const TQString &newSessionName);
/** /**
* Destructor * Destructor
@ -89,13 +96,19 @@ class KateSession
/** /**
* @return the session filename if available, otherwise the null string * @return the session filename if available, otherwise the null string
*/ */
const TQString& getSessionFilename() const { return m_isFullName ? m_filename : TQString::null; } const TQString& getSessionFilename() const { return m_filename; }
/** /**
* @return the number of documents in the session * @return the number of documents in the session
*/ */
int getDocCount() const { return m_documents.count(); } int getDocCount() const { return m_documents.count(); }
/**
* Load session info from the saved file
* @param includeGUIInfo if true, also load the information about the GUI elements
*/
void load(bool includeGUIInfo);
/** /**
* 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
@ -117,15 +130,18 @@ class KateSession
* @return the session config object * @return the session config object
*/ */
TDEConfig* getConfig() const { return m_config; } TDEConfig* getConfig() const { return m_config; }
/**
* create a new filename for a session object
*/
void createFilename();
const KateSessionManager &m_manager; // The session manager that handles this session
TQString m_sessionName; TQString m_sessionName;
TQString m_filename; TQString m_filename;
bool m_isFullName; // true -> m_filename is a full filename
// false -> m_filename is a folder name.
bool m_readOnly; bool m_readOnly;
TQStringList m_documents; // document URLs TQStringList m_documents; // document URLs
KSimpleConfig *m_config; // session config KSimpleConfig *m_config; // session config
}; };
//END KateSession //END KateSession
@ -146,6 +162,9 @@ class KateSession
* *
* @note The Kate session manager takes ownership of each session object it handles. * @note The Kate session manager takes ownership of each session object it handles.
*/ */
//FIXME update the sessions.list file when switching to another session or to a new session
//FIXME create a new unnamed session and switch to another session. The first session is saved without
//asking the user for a new session name. This is wrong.
class KateSessionManager : public TQObject class KateSessionManager : public TQObject
{ {
Q_OBJECT Q_OBJECT
@ -173,6 +192,11 @@ class KateSessionManager : public TQObject
*/ */
void saveConfig(); void saveConfig();
/**
* @return the session files folder name
*/
const TQString& getBaseDir() const { return m_baseDir; }
/** /**
* @return the active session id * @return the active session id
*/ */
@ -183,6 +207,12 @@ class KateSessionManager : public TQObject
*/ */
const TQString& getActiveSessionName() /*FIXME const*/ { return m_sessions[m_activeSessionId]->getSessionName(); } const TQString& getActiveSessionName() /*FIXME const*/ { return m_sessions[m_activeSessionId]->getSessionName(); }
/**
* @param sessionId the id of the session of interest
* @return the name of the specified session
*/
const TQString& getSessionName(int sessionId) /*FIXME const*/;
/** /**
* @return a reference to the active session * @return a reference to the active session
*/ */
@ -227,6 +257,21 @@ class KateSessionManager : public TQObject
*/ */
int newSession(const TQString &sessionName = TQString::null, bool activate = true); int newSession(const TQString &sessionName = TQString::null, bool activate = true);
/**
* Create a new session and activate it if required
* @param sessionId the id of the session to clone
* @param sessionName the new session name
* @param activate if true, activate the new session after creation
* @return the id of the newly created session
* @emit sessionCreated
*/
int cloneSession(int sessionId, const TQString &sessionName = TQString::null, bool activate = true);
/**
* Restore the current active session to the last saved state
*/
void reloadActiveSession() { m_sessions[m_activeSessionId]->load(true); }
/** /**
* Restore the last saved session. Can only be used before * Restore the last saved session. Can only be used before
* any other session has been activated, i.e. on Kate's startup * any other session has been activated, i.e. on Kate's startup
@ -271,6 +316,7 @@ class KateSessionManager : public TQObject
* Rename the specified session * Rename the specified session
* @param sessionId the id of the session to rename * @param sessionId the id of the session to rename
* @param newSessionName the new session name * @param newSessionName the new session name
* @emit sessionRenamed
*/ */
void renameSession(int sessionId, const TQString &newSessionName); void renameSession(int sessionId, const TQString &newSessionName);
@ -281,7 +327,6 @@ class KateSessionManager : public TQObject
*/ */
void setSessionReadOnlyStatus(int sessionId, bool readOnly); void setSessionReadOnlyStatus(int sessionId, bool readOnly);
signals: signals:
/** /**
* Emitted once a session has been activated * Emitted once a session has been activated
@ -315,6 +360,12 @@ class KateSessionManager : public TQObject
*/ */
void sessionsSwapped(int sessionIdMin, int sessionIdMax); void sessionsSwapped(int sessionIdMin, int sessionIdMax);
/**
* Emitted once a session has been renamed
* @param sessionId the id of the new session
*/
void sessionRenamed(int sessionId);
protected: protected:
KateSessionManager(); KateSessionManager();
@ -385,7 +436,7 @@ class KateSessionChooser : public KDialogBase
protected: protected:
TDEListView *m_listview; TDEListView *m_listview;
}; };
//BEGIN KateSessionChooser //END KateSessionChooser

@ -38,9 +38,10 @@ namespace
//BEGIN KateSessionNameChooser //BEGIN KateSessionNameChooser
//------------------------------------------- //-------------------------------------------
KateSessionNameChooser::KateSessionNameChooser(TQWidget *parent) KateSessionNameChooser::KateSessionNameChooser(TQWidget *parent, bool showSwitchTo)
: KDialogBase(parent, "", true, i18n("Session Name Chooser"), KDialogBase::User1 | KDialogBase::User2, : KDialogBase(parent, "", true, i18n("Session Name Chooser"), KDialogBase::User1 | KDialogBase::User2,
KDialogBase::User2, true, KStdGuiItem::cancel(), KGuiItem(i18n("Continue"), "document-new")) KDialogBase::User2, true, KStdGuiItem::cancel(), KGuiItem(i18n("Continue"), "document-new")),
m_showSwitchTo(showSwitchTo)
{ {
TQHBox *page = new TQHBox(this); TQHBox *page = new TQHBox(this);
//page->setMinimumSize(300, 100); //page->setMinimumSize(300, 100);
@ -53,13 +54,16 @@ KateSessionNameChooser::KateSessionNameChooser(TQWidget *parent)
label->setText("Please type the new session name:"); label->setText("Please type the new session name:");
m_sessionNameLE = new TQLineEdit(vb); m_sessionNameLE = new TQLineEdit(vb);
m_sessionNameLE->setText(KS_UNNAMED); m_sessionNameLE->setText(i18n(KS_UNNAMED));
m_sessionNameLE->setFocus(); m_sessionNameLE->setFocus();
if (m_showSwitchTo)
{
m_activateCB = new TQCheckBox(i18n("Switch to the new session"), vb, NULL);
m_activateCB->setChecked(true);
}
m_activateCB = new TQCheckBox(i18n("Switch to the new session"), vb, NULL); connect(m_sessionNameLE, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotTextChanged()));
m_activateCB->setChecked(true);
connect (m_sessionNameLE, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotTextChanged()));
slotTextChanged(); // update button status slotTextChanged(); // update button status
} }
@ -72,7 +76,11 @@ TQString KateSessionNameChooser::getSessionName()
//------------------------------------------- //-------------------------------------------
bool KateSessionNameChooser::getActivateFlag() bool KateSessionNameChooser::getActivateFlag()
{ {
return m_activateCB->isChecked(); if (m_showSwitchTo)
{
return m_activateCB->isChecked();
}
return false;
} }
//------------------------------------------- //-------------------------------------------
@ -135,7 +143,7 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager *
m_listview->setMinimumWidth(m_listview->sizeHint().width()); m_listview->setMinimumWidth(m_listview->sizeHint().width());
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 disabled until doc list software is developed
connect(m_listview, TQT_SIGNAL(selectionChanged()), connect(m_listview, TQT_SIGNAL(selectionChanged()),
this, TQT_SLOT(slotSelectionChanged())); this, TQT_SLOT(slotSelectionChanged()));
@ -151,8 +159,10 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager *
this, TQT_SLOT(slotSessionDeleted(int))); this, TQT_SLOT(slotSessionDeleted(int)));
connect(m_sessionManager, TQT_SIGNAL(sessionsSwapped(int, int)), connect(m_sessionManager, TQT_SIGNAL(sessionsSwapped(int, int)),
this, TQT_SLOT(slotSessionsSwapped(int, int))); this, TQT_SLOT(slotSessionsSwapped(int, int)));
connect(m_sessionManager, TQT_SIGNAL(sessionRenamed(int)),
this, TQT_SLOT(slotSessionRenamed(int)));
connect(m_listview, TQT_SIGNAL(itemRenamed(TQListViewItem*)), connect(m_listview, TQT_SIGNAL(itemRenamed(TQListViewItem*)),
this, TQT_SLOT(slotSessionRenamed(TQListViewItem*))); this, TQT_SLOT(slotLVSessionRenamed(TQListViewItem*)));
TQPtrList<KateSession>& sessions = m_sessionManager->getSessionsList(); TQPtrList<KateSession>& sessions = m_sessionManager->getSessionsList();
for (int idx = sessions.count()-1; idx >= 0; --idx) for (int idx = sessions.count()-1; idx >= 0; --idx)
@ -190,12 +200,13 @@ void KateSessionPanel::setup_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 selected session."));
a->plug(m_toolbar); a->plug(m_toolbar);
a = new TDEAction(i18n("Save as..."), SmallIcon("document-save-as"), 0, a = new TDEAction(i18n("Save as..."), SmallIcon("document-save-as"), 0,
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 an unsaved session with a new name or clone an already saved session "
"into a new session."));
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,
@ -208,6 +219,11 @@ void KateSessionPanel::setup_toolbar()
a->setWhatsThis(i18n("Delete the selected session.")); a->setWhatsThis(i18n("Delete the selected session."));
a->plug(m_toolbar); a->plug(m_toolbar);
a = new TDEAction(i18n("Reload"), SmallIcon("reload"), 0,
TQT_TQOBJECT(this), TQT_SLOT(slotReloadSession()), m_actionCollection, "session_reload");
a->setWhatsThis(i18n("Reload the last saved state of the selected session."));
a->plug(m_toolbar);
m_toolbar->insertLineSeparator(); m_toolbar->insertLineSeparator();
a = new TDEAction(i18n("Activate"), SmallIcon("forward"), 0, a = new TDEAction(i18n("Activate"), SmallIcon("forward"), 0,
@ -232,14 +248,12 @@ 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
} }
//------------------------------------------- //-------------------------------------------
void KateSessionPanel::slotNewSession() void KateSessionPanel::slotNewSession()
{ {
KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this); KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this, true);
int result = nameChooser->exec(); int result = nameChooser->exec();
if (result == TQDialog::Accepted) if (result == TQDialog::Accepted)
{ {
@ -264,7 +278,7 @@ void KateSessionPanel::slotSaveSession()
return; return;
} }
if (ks->getSessionFilename().isEmpty()) if (ks->getSessionFilename().isEmpty() && ks->getSessionName() == i18n(KS_UNNAMED))
{ {
// Session has never been saved before. Ask user for a session name first // Session has never been saved before. Ask user for a session name first
slotSaveSessionAs(); slotSaveSessionAs();
@ -279,7 +293,46 @@ void KateSessionPanel::slotSaveSession()
//------------------------------------------- //-------------------------------------------
void KateSessionPanel::slotSaveSessionAs() void KateSessionPanel::slotSaveSessionAs()
{ {
//TODO KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
if (!sessionItem)
{
return;
}
int sessId = sessionItem->getSessionId();
KateSession *ks = m_sessionManager->getSessionFromId(sessId);
if (!ks)
{
return;
}
// If the session was never saved before, the session will be saved with a new name.
// If the session was already saved once, it will be cloned into a new session.
bool cloneSession = true;
//FIXME replace ks->getSessionFilename().isEmpty() with a function that tests for m_fileExists
if (ks->getSessionFilename().isEmpty() && ks->getSessionName() == i18n(KS_UNNAMED))
{
// Session has never been saved before.
cloneSession = false;
}
// Get new session name
KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this, cloneSession);
int result = nameChooser->exec();
if (result == TQDialog::Accepted)
{
if (!cloneSession)
{
// Save unsaved session
m_sessionManager->renameSession(sessId, nameChooser->getSessionName());
m_sessionManager->saveSession(sessId);
}
else
{
// Clone session
m_sessionManager->cloneSession(sessId, nameChooser->getSessionName(), nameChooser->getActivateFlag());
}
}
delete nameChooser;
slotSelectionChanged(); // Update the toolbar button status slotSelectionChanged(); // Update the toolbar button status
} }
@ -313,6 +366,24 @@ void KateSessionPanel::slotDeleteSession()
} }
} }
//-------------------------------------------
void KateSessionPanel::slotReloadSession()
{
KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(m_listview->selectedItem());
if (!sessionItem)
{
return;
}
int sessId = sessionItem->getSessionId();
if (sessId != m_sessionManager->getActiveSessionId())
{
return;
}
// Restore active session to the last saved state
m_sessionManager->reloadActiveSession();
}
//------------------------------------------- //-------------------------------------------
void KateSessionPanel::slotActivateSession() void KateSessionPanel::slotActivateSession()
{ {
@ -403,6 +474,7 @@ void KateSessionPanel::slotSelectionChanged()
m_actionCollection->action("session_save_as")->setEnabled(false); m_actionCollection->action("session_save_as")->setEnabled(false);
m_actionCollection->action("session_rename")->setEnabled(false); m_actionCollection->action("session_rename")->setEnabled(false);
m_actionCollection->action("session_delete")->setEnabled(false); m_actionCollection->action("session_delete")->setEnabled(false);
m_actionCollection->action("session_reload")->setEnabled(false);
m_actionCollection->action("session_activate")->setEnabled(false); m_actionCollection->action("session_activate")->setEnabled(false);
m_actionCollection->action("session_move_up")->setEnabled(false); m_actionCollection->action("session_move_up")->setEnabled(false);
m_actionCollection->action("session_move_down")->setEnabled(false); m_actionCollection->action("session_move_down")->setEnabled(false);
@ -416,11 +488,13 @@ void KateSessionPanel::slotSelectionChanged()
// Read only sessions can not be saved or renamed // Read only sessions can not be saved or renamed
m_actionCollection->action("session_save")->setEnabled(false); m_actionCollection->action("session_save")->setEnabled(false);
m_actionCollection->action("session_rename")->setEnabled(false); m_actionCollection->action("session_rename")->setEnabled(false);
m_actionCollection->action("session_delete")->setEnabled(false);
} }
else else
{ {
m_actionCollection->action("session_save")->setEnabled(true); m_actionCollection->action("session_save")->setEnabled(true);
m_actionCollection->action("session_rename")->setEnabled(true); m_actionCollection->action("session_rename")->setEnabled(true);
m_actionCollection->action("session_delete")->setEnabled(true);
} }
if (ks->getSessionFilename().isEmpty()) if (ks->getSessionFilename().isEmpty())
{ {
@ -434,7 +508,8 @@ void KateSessionPanel::slotSelectionChanged()
readOnlyAction->setChecked(ks->isReadOnly()); readOnlyAction->setChecked(ks->isReadOnly());
} }
m_actionCollection->action("session_save_as")->setEnabled(true); m_actionCollection->action("session_save_as")->setEnabled(true);
m_actionCollection->action("session_delete")->setEnabled(true); m_actionCollection->action("session_reload")->setEnabled(
sessionItem->getSessionId() == m_sessionManager->getActiveSessionId());
m_actionCollection->action("session_activate")->setEnabled(true); m_actionCollection->action("session_activate")->setEnabled(true);
m_actionCollection->action("session_move_up")->setEnabled(true); m_actionCollection->action("session_move_up")->setEnabled(true);
m_actionCollection->action("session_move_down")->setEnabled(true); m_actionCollection->action("session_move_down")->setEnabled(true);
@ -459,6 +534,7 @@ void KateSessionPanel::slotSessionActivated(int newSessionId, int oldSessionId)
} }
item->setPixmap(m_columnPixmap, SmallIcon("ok")); item->setPixmap(m_columnPixmap, SmallIcon("ok"));
m_listview->setSelected(item, true); m_listview->setSelected(item, true);
slotSelectionChanged(); // Update the toolbar button status
} }
//------------------------------------------- //-------------------------------------------
@ -557,7 +633,18 @@ void KateSessionPanel::slotSessionsSwapped(int sessionIdMin, int sessionIdMax)
} }
//------------------------------------------- //-------------------------------------------
void KateSessionPanel::slotSessionRenamed(TQListViewItem *item) void KateSessionPanel::slotSessionRenamed(int sessionId)
{
TQListViewItem *item = m_listview->firstChild();
for (int idx = 0; idx < sessionId; ++idx)
{
item = item->nextSibling();
}
item->setText(m_columnName, m_sessionManager->getSessionName(sessionId));
}
//-------------------------------------------
void KateSessionPanel::slotLVSessionRenamed(TQListViewItem *item)
{ {
KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(item); KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(item);
if (!sessionItem) if (!sessionItem)

@ -47,7 +47,7 @@ class KateSessionNameChooser : public KDialogBase
public: public:
KateSessionNameChooser(TQWidget *parent); KateSessionNameChooser(TQWidget *parent, bool showSwitchTo);
~KateSessionNameChooser() {} ~KateSessionNameChooser() {}
TQString getSessionName(); // return the session name typed by the user TQString getSessionName(); // return the session name typed by the user
@ -62,6 +62,7 @@ class KateSessionNameChooser : public KDialogBase
protected: protected:
TQLineEdit *m_sessionNameLE; TQLineEdit *m_sessionNameLE;
TQCheckBox *m_activateCB; TQCheckBox *m_activateCB;
bool m_showSwitchTo; // if true, display the m_activateCB checkbox
}; };
//BEGIN KateSessionNameChooser //BEGIN KateSessionNameChooser
@ -121,6 +122,7 @@ class KateSessionPanel : public TQVBox
void slotSaveSessionAs(); void slotSaveSessionAs();
void slotRenameSession(); void slotRenameSession();
void slotDeleteSession(); void slotDeleteSession();
void slotReloadSession();
void slotActivateSession(); void slotActivateSession();
void slotSessionToggleReadOnly(); void slotSessionToggleReadOnly();
void slotSessionMoveUp(); void slotSessionMoveUp();
@ -132,7 +134,8 @@ class KateSessionPanel : public TQVBox
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(int sessionId);
void slotLVSessionRenamed(TQListViewItem *item);
private: private:
void setup_toolbar(); void setup_toolbar();

Loading…
Cancel
Save