Kate session panel: added support for switch/shutdown session options and fixed up logic where required.

Fixed Kate quit process to support correct shutdown. Improved handling of configuration option changes.
Some code rework.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/2/head
Michele Calgaro 8 years ago
parent 074f8c7ccb
commit 8644afed0d

@ -83,6 +83,8 @@ KateApp::KateApp (TDECmdLineArgs *args)
kdDebug()<<"Setting KATE_PID: '"<<getpid()<<"'"<<endl; kdDebug()<<"Setting KATE_PID: '"<<getpid()<<"'"<<endl;
::setenv( "KATE_PID", TQString(TQString("%1").arg(getpid())).latin1(), 1 ); ::setenv( "KATE_PID", TQString(TQString("%1").arg(getpid())).latin1(), 1 );
connect(this, TQT_SIGNAL(aboutToQuit()), this, TQT_SLOT(slotAboutToQuit()));
// handle restore different // handle restore different
if (isRestored()) if (isRestored())
{ {
@ -178,23 +180,16 @@ bool KateApp::startupKate()
else else
{ {
// check Kate session startup options // check Kate session startup options
TDEConfig *kateCfg = KateApp::self()->config(); int startupOption = sessionManager()->getStartupOption();
kateCfg->setGroup("General"); if (startupOption == KateSessionManager::STARTUP_NEW)
if (kateCfg->hasKey("Last Session"))
{ {
// Delete no longer used entry (pre R14.1.0) sessionManager()->newSession();
kateCfg->deleteEntry("Last Session");
} }
TQString startupOption(kateCfg->readEntry("Startup Session", "manual")); else if (startupOption == KateSessionManager::STARTUP_LAST)
if (startupOption == "last")
{ {
sessionManager()->restoreLastSession(); sessionManager()->restoreLastSession();
} }
else if (startupOption == "new") else // startupOption == KateSessionManager::STARTUP_MANUAL
{
sessionManager()->newSession();
}
else // startupOption == "manual"
{ {
KateSessionChooser *chooser = new KateSessionChooser(NULL); KateSessionChooser *chooser = new KateSessionChooser(NULL);
int result = chooser->exec(); int result = chooser->exec();
@ -308,12 +303,9 @@ bool KateApp::startupKate()
void KateApp::shutdownKate(KateMainWindow *win) void KateApp::shutdownKate(KateMainWindow *win)
{ {
if (!win->queryClose_internal()) if (!win->queryClose_internal() || !query_session_close())
return; return;
// Save current session here to make sure all GUI elements are saved correctly
sessionManager()->saveActiveSession();
// detach the dcopClient // detach the dcopClient
dcopClient()->detach(); dcopClient()->detach();
@ -324,6 +316,60 @@ void KateApp::shutdownKate(KateMainWindow *win)
quit (); quit ();
} }
bool KateApp::query_session_close()
{
bool saveSessions = false;
int switchOption = m_sessionManager->getSwitchOption();
if (switchOption == KateSessionManager::SWITCH_SAVE)
{
saveSessions = true;
}
else if (switchOption == KateSessionManager::SWITCH_ASK)
{
KDialogBase *dlg = new KDialogBase(i18n("Save Sessions"),
KDialogBase::Yes | KDialogBase::No | KDialogBase::Cancel,
KDialogBase::Cancel, KDialogBase::Cancel, NULL, NULL, true, false,
KStdGuiItem::save(), KStdGuiItem::del(), KStdGuiItem::cancel());
bool dontAgain = false;
int res = KMessageBox::createKMessageBox(dlg, TQMessageBox::Warning,
i18n("<p>Do you want to save the existing sessions?<p>!!NOTE!!"
"<p>All existing sessions will be removed "
"if you choose \"Delete\""), TQStringList(),
i18n("Do not ask again"), &dontAgain, KMessageBox::Notify);
if (res == KDialogBase::Cancel)
{
return false;
}
if (dontAgain)
{
if (res == KDialogBase::No)
{
m_sessionManager->setSwitchOption(KateSessionManager::SWITCH_DISCARD);
}
else
{
m_sessionManager->setSwitchOption(KateSessionManager::SWITCH_SAVE);
}
}
if (res == KDialogBase::Yes)
{
saveSessions = true;
}
}
if (saveSessions)
{
m_sessionManager->saveActiveSession();
}
m_sessionManager->saveConfig(saveSessions);
return true;
}
void KateApp::reparse_config()
{
emit optionsChanged();
}
KatePluginManager *KateApp::pluginManager() KatePluginManager *KateApp::pluginManager()
{ {
return m_pluginManager; return m_pluginManager;

@ -100,7 +100,7 @@ class KDE_EXPORT KateApp : public TDEApplication
* shutdown kate application * shutdown kate application
* @param win mainwindow which is used for dialogs * @param win mainwindow which is used for dialogs
*/ */
void shutdownKate (KateMainWindow *win); void shutdownKate(KateMainWindow *win);
/** /**
* application should exit * application should exit
@ -108,8 +108,26 @@ class KDE_EXPORT KateApp : public TDEApplication
*/ */
bool shouldExit () { return m_shouldExit; } bool shouldExit () { return m_shouldExit; }
/**
* to be called when the application is about to quit
* @return should we exit?
*/
bool query_session_close();
/**
* called after the config dialog has been closed. The application
* can parse the new configuration and take appropriate actions if required
*/
void reparse_config();
signals:
/**
* Emitted when the configuration has or may have been changed
*/
void optionsChanged();
/** /**
* other accessors for global unique instances * other accessors for global unique instances
*/ */
public: public:
/** /**
@ -224,7 +242,6 @@ class KDE_EXPORT KateApp : public TDEApplication
*/ */
KateSessionManager *m_sessionManager; KateSessionManager *m_sessionManager;
/** /**
* known main windows * known main windows
*/ */

@ -172,7 +172,6 @@ void KateExternalToolsCommand::reload () {
config.readListEntry( "mimetypes" ), config.readListEntry( "mimetypes" ),
config.readEntry( "acname", "" ), config.readEntry( "acname", "" ),
config.readEntry( "cmdname", "" ) ); config.readEntry( "cmdname", "" ) );
// FIXME test for a command name first!
if ( t.hasexec && (!t.cmdname.isEmpty())) { if ( t.hasexec && (!t.cmdname.isEmpty())) {
m_list.append("exttool-"+t.cmdname); m_list.append("exttool-"+t.cmdname);
m_map.insert("exttool-"+t.cmdname,t.acname); m_map.insert("exttool-"+t.cmdname,t.acname);

@ -413,7 +413,6 @@ void KateFileSelector::btnFilterClick()
} }
} }
//FIXME crash on shutdown
void KateFileSelector::setActiveDocumentDir() void KateFileSelector::setActiveDocumentDir()
{ {
// kdDebug(13001)<<"KateFileSelector::setActiveDocumentDir()"<<endl; // kdDebug(13001)<<"KateFileSelector::setActiveDocumentDir()"<<endl;

@ -329,9 +329,9 @@ void KateMainWindow::slotDocumentCloseAll() {
} }
bool KateMainWindow::queryClose_internal() { bool KateMainWindow::queryClose_internal() {
uint documentCount=KateDocManager::self()->documents(); uint documentCount=KateDocManager::self()->documents();
if ( ! showModOnDiskPrompt() ) if ( !showModOnDiskPrompt() )
return false; return false;
TQPtrList<Kate::Document> modifiedDocuments=KateDocManager::self()->modifiedDocumentList(); TQPtrList<Kate::Document> modifiedDocuments=KateDocManager::self()->modifiedDocumentList();
@ -360,23 +360,22 @@ bool KateMainWindow::queryClose()
// just test, not close them actually // just test, not close them actually
if (KateApp::self()->sessionSaving()) if (KateApp::self()->sessionSaving())
{ {
return queryClose_internal (); return queryClose_internal();
} }
// normal closing of window // normal closing of window
// allow to close all windows until the last without restrictions // allow to close all windows until the last without restrictions
if ( KateApp::self()->mainWindows () > 1 ) if (KateApp::self()->mainWindows() > 1)
{
return true; return true;
}
// last one: check if we can close all documents, try run // last one: check if we can close all documents and sessions, try run
// and save docs if we really close down ! // and save docs if we really close down !
if ( queryClose_internal () ) if (queryClose_internal() && KateApp::self()->query_session_close())
{ {
KateApp::self()->sessionManager()->saveActiveSession();
// detach the dcopClient // detach the dcopClient
KateApp::self()->dcopClient()->detach(); KateApp::self()->dcopClient()->detach();
return true; return true;
} }
@ -403,7 +402,7 @@ void KateMainWindow::slotNewToolbarConfig()
void KateMainWindow::slotFileQuit() void KateMainWindow::slotFileQuit()
{ {
KateApp::self()->shutdownKate (this); KateApp::self()->shutdownKate(this);
} }
void KateMainWindow::readOptions () void KateMainWindow::readOptions ()
@ -574,6 +573,9 @@ void KateMainWindow::slotConfigure()
dlg->exec(); dlg->exec();
delete dlg; delete dlg;
// Inform Kate that options may have been changed
KateApp::self()->reparse_config();
} }
KURL KateMainWindow::activeDocumentUrl() KURL KateMainWindow::activeDocumentUrl()

@ -156,7 +156,6 @@ KateSaveModifiedDialog::KateSaveModifiedDialog(TQWidget *parent, TQPtrList<Kate:
} }
m_documentRoot->setOpen(true); m_documentRoot->setOpen(true);
} else m_documentRoot=0; } else m_documentRoot=0;
//FIXME - Is this the best way?
connect(m_list, TQT_SIGNAL(clicked(TQListViewItem *)), TQT_SLOT(slotItemSelected())); connect(m_list, TQT_SIGNAL(clicked(TQListViewItem *)), TQT_SLOT(slotItemSelected()));
connect(m_list, TQT_SIGNAL(doubleClicked(TQListViewItem *)), TQT_SLOT(slotItemSelected())); connect(m_list, TQT_SIGNAL(doubleClicked(TQListViewItem *)), TQT_SLOT(slotItemSelected()));
connect(m_list, TQT_SIGNAL(spacePressed(TQListViewItem *)), TQT_SLOT(slotItemSelected())); connect(m_list, TQT_SIGNAL(spacePressed(TQListViewItem *)), TQT_SLOT(slotItemSelected()));

@ -51,28 +51,39 @@
// 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 // To be done when doc list software is developed
// FIXME add code to handle the various options in Configure Kate -> Application -> Sessions
// String constants // String constants
namespace namespace
{ {
// Kate session // Kate session
const char *KS_COUNT = "Count"; const char *KS_COUNT = "Count";
const char *KS_DOCCOUNT = "Document count"; const char *KS_DOCCOUNT = "Document count";
const char *KS_DOCLIST = "Document list"; const char *KS_DOCLIST = "Document list";
const char *KS_GENERAL = "General"; const char *KS_GENERAL = "General";
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_OPEN_MAINWINDOWS = "Open MainWindows"; const char *KS_OPEN_MAINWINDOWS = "Open MainWindows";
const char *KS_UNNAMED = "Unnamed"; const char *KS_UNNAMED = "Unnamed";
// Kate session manager // Kate session manager
const char *KSM_DIR = "kate/sessions"; const char *KSM_DIR = "kate/sessions";
const char *KSM_FILE = "sessions.list"; const char *KSM_FILE = "sessions.list";
const char *KSM_SESSIONS_COUNT = "Sessions count"; const char *KSM_SESSIONS_COUNT = "Sessions count";
const char *KSM_LAST_SESSION_ID = "Last session id"; const char *KSM_LAST_SESSION_ID = "Last session id";
const char *KSM_SESSIONS_LIST = "Sessions list"; const char *KSM_SESSIONS_LIST = "Sessions list";
// Kate app
const char *KAPP_GENERAL = "General";
const char *KAPP_LAST_SESSION = "Last Session";
const char *KAPP_STARTUP_SESSION = "Startup Session";
const char *KAPP_NEW = "new";
const char *KAPP_LAST = "last";
const char *KAPP_MANUAL = "manual";
const char *KAPP_SESSION_EXIT = "Session Exit";
const char *KAPP_DISCARD = "discard";
const char *KAPP_SAVE = "save";
const char *KAPP_ASK = "ask";
} }
//BEGIN Kate session //BEGIN Kate session
@ -321,10 +332,14 @@ KateSessionManager* KateSessionManager::self()
//------------------------------------ //------------------------------------
KateSessionManager::KateSessionManager() : KateSessionManager::KateSessionManager() :
m_baseDir(locateLocal("data", KSM_DIR)+"/"), m_configFile(m_baseDir + KSM_FILE), m_baseDir(locateLocal("data", KSM_DIR)+"/"), m_configFile(m_baseDir + KSM_FILE),
m_activeSessionId(INVALID_SESSION), m_lastSessionId(INVALID_SESSION), m_sessions(), m_config(NULL) m_activeSessionId(INVALID_SESSION), m_lastSessionId(INVALID_SESSION), m_sessions(),
m_config(NULL), m_startupOption(STARTUP_NEW), m_switchOption(SWITCH_DISCARD)
{ {
// Session startup and switch options
updateSessionOptions(SO_ALL);
// Sessions configuration
m_sessions.setAutoDelete(true); m_sessions.setAutoDelete(true);
int sessionsCount = 0; int sessionsCount = 0;
if (TDEGlobal::dirs()->exists(m_configFile)) if (TDEGlobal::dirs()->exists(m_configFile))
{ {
@ -362,6 +377,7 @@ KateSessionManager::KateSessionManager() :
{ {
m_lastSessionId = 0; // Invalid last session was detected. Use first in the list m_lastSessionId = 0; // Invalid last session was detected. Use first in the list
} }
//NOTE do not activate any session in the KateSessionManager costructor //NOTE do not activate any session in the KateSessionManager costructor
// since Kate's main window may not be ready yet. The initial session // since Kate's main window may not be ready yet. The initial session
// will be activated by KateApp::startupKate() or KateApp::restoreKate() // will be activated by KateApp::startupKate() or KateApp::restoreKate()
@ -370,25 +386,123 @@ KateSessionManager::KateSessionManager() :
//------------------------------------ //------------------------------------
KateSessionManager::~KateSessionManager() KateSessionManager::~KateSessionManager()
{ {
saveConfig(true);
if (m_config) if (m_config)
{ {
delete m_config; delete m_config;
} }
if (!m_sessions.isEmpty()) m_sessions.clear();
}
//------------------------------------
void KateSessionManager::updateSessionOptions(int optionType)
{
// Session startup and switch options
TDEConfig *kateCfg = KateApp::self()->config();
kateCfg->setGroup(KAPP_GENERAL);
if (optionType == SO_STARTUP || optionType == SO_ALL)
{ {
m_sessions.clear(); if (kateCfg->hasKey(KAPP_LAST_SESSION))
{
// Delete no longer used entry (pre R14.1.0)
kateCfg->deleteEntry(KAPP_LAST_SESSION);
}
TQString startupOption(kateCfg->readEntry(KAPP_STARTUP_SESSION, KAPP_MANUAL));
if (startupOption == KAPP_LAST)
{
m_startupOption = STARTUP_LAST;
}
else if (startupOption == KAPP_NEW)
{
m_startupOption = STARTUP_NEW;
}
else // startupOption == "manual"
{
m_startupOption = STARTUP_MANUAL;
}
}
if (optionType == SO_SWITCH || optionType == SO_ALL)
{
TQString switchOption(kateCfg->readEntry(KAPP_SESSION_EXIT, KAPP_ASK));
if (switchOption == KAPP_DISCARD)
{
m_switchOption = SWITCH_DISCARD;
}
else if (switchOption == KAPP_SAVE)
{
m_switchOption = SWITCH_SAVE;
}
else // switchOption == "ask"
{
m_switchOption = SWITCH_ASK;
}
} }
} }
//------------------------------------ //------------------------------------
// FIXME Unnamed sessions should not be saved by default, to allow users who do not bother void KateSessionManager::saveSessionOptions(int optionType)
// 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 TDEConfig *kateCfg = KateApp::self()->config();
// saving unnamed sessions before closing the current session. Default value is off as per kateCfg->setGroup(KAPP_GENERAL);
// point above. if (optionType == SO_STARTUP || optionType == SO_ALL)
{
if (m_startupOption == STARTUP_LAST)
{
kateCfg->writeEntry(KAPP_STARTUP_SESSION, KAPP_LAST);
}
else if (m_startupOption == STARTUP_NEW)
{
kateCfg->writeEntry(KAPP_STARTUP_SESSION, KAPP_NEW);
}
else // m_startupOption == STARTUP_MANUAL
{
kateCfg->writeEntry(KAPP_STARTUP_SESSION, KAPP_MANUAL);
}
}
if (optionType == SO_SWITCH || optionType == SO_ALL)
{
if (m_switchOption == SWITCH_DISCARD)
{
kateCfg->writeEntry(KAPP_SESSION_EXIT, KAPP_DISCARD);
}
else if (m_switchOption == SWITCH_SAVE)
{
kateCfg->writeEntry(KAPP_SESSION_EXIT, KAPP_SAVE);
}
else // m_switchOption == SWITCH_ASK
{
kateCfg->writeEntry(KAPP_SESSION_EXIT, KAPP_ASK);
}
}
kateCfg->sync();
}
//------------------------------------
void KateSessionManager::saveConfig(bool saveSessions) void KateSessionManager::saveConfig(bool saveSessions)
{ {
// Session startup and switch options
updateSessionOptions(SO_ALL);
saveSessionOptions(SO_ALL);
// Sessions configuration
if (!saveSessions)
{
// delete all session files if they exist
for (int i = 0; i < (int)m_sessions.count(); ++i)
{
const TQString &filename = m_sessions[i]->getSessionFilename();
if (filename != TQString::null && TQFile::exists(filename))
{
TQFile::remove(filename);
}
}
m_sessions.clear();
m_activeSessionId = INVALID_SESSION;
}
if (!m_config) if (!m_config)
{ {
m_config = new KSimpleConfig(m_configFile); m_config = new KSimpleConfig(m_configFile);
@ -402,16 +516,34 @@ void KateSessionManager::saveConfig(bool saveSessions)
m_config->writeEntry(KSM_LAST_SESSION_ID, m_activeSessionId); m_config->writeEntry(KSM_LAST_SESSION_ID, m_activeSessionId);
for (int i = 0; i < (int)m_sessions.count(); ++i) for (int i = 0; i < (int)m_sessions.count(); ++i)
{ {
//FIXME need to consider when sessions has to be saved. saveSession(i, false, false);
if (saveSessions)
{
saveSession(i, false, false);
}
m_config->writeEntry(TQString("URL_%1").arg(i), m_sessions[i]->getSessionFilename()); m_config->writeEntry(TQString("URL_%1").arg(i), m_sessions[i]->getSessionFilename());
} }
m_config->sync(); m_config->sync();
} }
//------------------------------------
const int KateSessionManager::getStartupOption()
{
updateSessionOptions(SO_STARTUP);
return m_startupOption;
}
//------------------------------------
const int KateSessionManager::getSwitchOption()
{
updateSessionOptions(SO_SWITCH);
return m_switchOption;
}
//------------------------------------
void KateSessionManager::setSwitchOption(int option)
{
m_switchOption = (option == SWITCH_DISCARD || option == SWITCH_SAVE) ? option : SWITCH_ASK;
saveSessionOptions(SO_SWITCH);
emit switchOptionChanged();
}
//------------------------------------ //------------------------------------
const TQString& KateSessionManager::getSessionName(int sessionId) const TQString& KateSessionManager::getSessionName(int sessionId)
{ {
@ -476,9 +608,14 @@ bool KateSessionManager::activateSession(int sessionId, bool saveCurr)
{ {
saveSession(m_activeSessionId, true); saveSession(m_activeSessionId, true);
} }
else if (m_sessions[m_activeSessionId]->isStillVolatile()) else
{ {
// Automatically delete unstored and unnamed sessions when activating another one // Delete current session before activating the new one
const TQString &filename = m_sessions[m_activeSessionId]->getSessionFilename();
if (filename != TQString::null && TQFile::exists(filename))
{
TQFile::remove(filename);
}
m_sessions.remove(m_activeSessionId); // this also deletes the KateSession item since auto-deletion is enabled m_sessions.remove(m_activeSessionId); // this also deletes the KateSession item since auto-deletion is enabled
m_activeSessionId = INVALID_SESSION; m_activeSessionId = INVALID_SESSION;
if (sessionId > oldSessionId) if (sessionId > oldSessionId)
@ -508,7 +645,7 @@ int KateSessionManager::newSession(const TQString &sessionName, bool saveCurr)
} }
//------------------------------------ //------------------------------------
int KateSessionManager::cloneSession(int sessionId, const TQString &sessionName, bool activate) int KateSessionManager::cloneSession(int sessionId, const TQString &sessionName, bool activate, bool deleteCurr)
{ {
if (sessionId < 0 || sessionId >= (int)m_sessions.count()) if (sessionId < 0 || sessionId >= (int)m_sessions.count())
{ {
@ -521,15 +658,15 @@ int KateSessionManager::cloneSession(int sessionId, const TQString &sessionName,
// If cloning the active session, the new session will contain the current status // 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) // and the original session will be restored to the last saved state (save as... functionality)
/* saveSession(newSessionId, sessionId == m_activeSessionId); saveSession(newSessionId, sessionId == m_activeSessionId);
if (sessionId == m_activeSessionId) if (sessionId == m_activeSessionId)
{ {
reloadActiveSession(); reloadActiveSession();
} }
*/
if (activate) if (activate)
{ {
activateSession(newSessionId, m_activeSessionId != INVALID_SESSION); activateSession(newSessionId, m_activeSessionId != INVALID_SESSION && !deleteCurr);
} }
return newSessionId; return newSessionId;
} }

@ -154,13 +154,13 @@ class KateSession
//BEGIN KateSessionManager //BEGIN KateSessionManager
//FIXME (advanced) //FIXME (advanced - multiple main windows or multiple Kate instances)
//There should be only one session manager regardless of how many instances of Kate are running. //There should be only one session manager regardless of how many main windows of Kate are open.
//Changes should propagate to all session panels. Different Kate instances should run different //Changes should propagate to all session panels. Different Kate main windows should run different
//sessions. If the user switches to a session already opened in another Kate instance, the current //sessions. If the user switches to a session already opened in another Kate window, the other window
//session should be saved and then the focus switched to the other instance. //should be brought up to the screen (eventually ask user confirmation first).
//This would allow a safe use of multiple Kate instances without overwriting session information //This would allow a safe use of multiple Kate main windows/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/main window 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 * The Kate session manager. It takes care of storing and retrieving each session object
@ -169,6 +169,11 @@ 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 update the sessions.list file when switching to another session or to a new session
//
//FIXME create new unnamed session, choose 'save' as session switch option. Exit Kate.
// Session is saved without asking for a name
//FIXME improve getStartupOption/getSwitchOption/setSwitchOption using new signal
// KateApp::optionsChanged()
class KateSessionManager : public TQObject class KateSessionManager : public TQObject
{ {
Q_OBJECT Q_OBJECT
@ -180,6 +185,22 @@ class KateSessionManager : public TQObject
INVALID_SESSION = -1 INVALID_SESSION = -1
}; };
// Session options on Kate startup
enum
{
STARTUP_NEW = 0, // New session
STARTUP_LAST, // Use last session
STARTUP_MANUAL // Manually choose a session
};
// Session options on session switch or Kate shutdown
enum
{
SWITCH_DISCARD = 0, // Don't save current session
SWITCH_SAVE, // Save current session
SWITCH_ASK // Ask user what to do
};
/** /**
* get a pointer to the unique KateSessionManager instance. * get a pointer to the unique KateSessionManager instance.
* If the manager does not exist yet, create it. * If the manager does not exist yet, create it.
@ -191,6 +212,32 @@ class KateSessionManager : public TQObject
*/ */
~KateSessionManager(); ~KateSessionManager();
/**
* Save session manager info
* @param saveSessions true = sessions info will be saved
* false = all sessions will be discarded
*/
void saveConfig(bool saveSessions);
/**
* @return the session startup option
* The function checks the config file to see if there was any value update
*/
const int getStartupOption();
/**
* @return the session switch option
* The function checks the config file to see if there was any value update
*/
const int getSwitchOption();
/**
* Set the new session switch preference
* @param option the new option value. Defaults to SWITCH_ASK if the value is invalid.
* @emit switchOptionChanged
*/
void setSwitchOption(int option);
/** /**
* @return the session files folder name * @return the session files folder name
*/ */
@ -262,10 +309,12 @@ class KateSessionManager : public TQObject
* @param sessionId the id of the session to clone * @param sessionId the id of the session to clone
* @param sessionName the new session name * @param sessionName the new session name
* @param activate if true, activate the new session after creation * @param activate if true, activate the new session after creation
* @param deleteCurr if true, delete the current session after switching
* @return the id of the newly created session * @return the id of the newly created session
* @emit sessionCreated * @emit sessionCreated
*/ */
int cloneSession(int sessionId, const TQString &sessionName = TQString::null, bool activate = true); int cloneSession(int sessionId, const TQString &sessionName = TQString::null,
bool activate = true, bool deleteCurr = false);
/** /**
* Restore the current active session to the last saved state * Restore the current active session to the last saved state
@ -331,6 +380,11 @@ class KateSessionManager : public TQObject
void setSessionReadOnlyStatus(int sessionId, bool readOnly); void setSessionReadOnlyStatus(int sessionId, bool readOnly);
signals: signals:
/**
* Emitted when the session switch option has been set/changed
*/
void switchOptionChanged();
/** /**
* Emitted once a session has been activated * Emitted once a session has been activated
* @param newSessionId the id of the previous active session * @param newSessionId the id of the previous active session
@ -373,12 +427,26 @@ class KateSessionManager : public TQObject
protected: protected:
KateSessionManager(); KateSessionManager();
// Session options on Kate startup
enum
{
SO_STARTUP = 0, // session startup option only
SO_SWITCH, // session switch option only
SO_ALL, // session startup and switch options
};
/** /**
* Save session manager info * Updated the session startup and switch options
* @param saveSessions if true, all sessions will be saved again * @param optionType specifies which options needs to be updated
*/ */
void saveConfig(bool saveSessions); void updateSessionOptions(int optionType);
/**
* Save the session startup and switch options to the config file
* @param optionType specifies which options needs to be saved
*/
void saveSessionOptions(int optionType);
/** /**
* Swap the position of the two specified sessions in the session list * Swap the position of the two specified sessions in the session list
* @param sessionId1 the id of the first session * @param sessionId1 the id of the first session
@ -403,7 +471,9 @@ class KateSessionManager : public TQObject
int m_lastSessionId; // id of the last active session before closing Kate int m_lastSessionId; // id of the last active session before closing Kate
TQPtrList<KateSession> m_sessions; // session list TQPtrList<KateSession> m_sessions; // session list
KSimpleConfig *m_config; // session manager config KSimpleConfig *m_config; // session manager config
int m_startupOption; // session option on Kate startup
int m_switchOption; // session option on session switch or Kate shutdown
static KateSessionManager *ksm_instance; // the only KateSessionManager instance static KateSessionManager *ksm_instance; // the only KateSessionManager instance
}; };
//END KateSessionManager //END KateSessionManager

@ -146,12 +146,17 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager *
m_listview->setResizeMode(TQListView::LastColumn); m_listview->setResizeMode(TQListView::LastColumn);
//m_listview->setRootIsDecorated(true); // FIXME disabled until doc list software is developed //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()));
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*)), connect(m_listview, TQT_SIGNAL(returnPressed(TQListViewItem*)),
this, TQT_SLOT(slotItemExecuted(TQListViewItem*))); this, TQT_SLOT(slotItemExecuted(TQListViewItem*)));
connect(KateApp::self(), TQT_SIGNAL(optionsChanged()),
this, TQT_SLOT(slotSelectionChanged()));
connect(m_sessionManager, TQT_SIGNAL(switchOptionChanged()),
this, TQT_SLOT(slotSelectionChanged()));
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)),
@ -258,7 +263,7 @@ void KateSessionPanel::slotNewSession()
int result = nameChooser->exec(); int result = nameChooser->exec();
if (result == TQDialog::Accepted) if (result == TQDialog::Accepted)
{ {
int res = handleVolatileSession(); int res = handleSessionSwitch();
if (res == KMessageBox::Cancel) if (res == KMessageBox::Cancel)
{ {
return; return;
@ -312,9 +317,9 @@ void KateSessionPanel::slotSaveSessionAs()
{ {
return; return;
} }
// If the session was never saved or named before, the session will be saved with a new name. // If the session was never saved or named before, the session will be saved with a new name.
// If the session was already saved or named once, it will be cloned into a new session. // Otherwise it will be cloned into a new session.
bool cloneSession = !ks->isStillVolatile(); bool cloneSession = !ks->isStillVolatile();
// Get new session name // Get new session name
KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this, cloneSession); KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this, cloneSession);
@ -330,7 +335,20 @@ void KateSessionPanel::slotSaveSessionAs()
else else
{ {
// Clone session // Clone session
m_sessionManager->cloneSession(sessId, nameChooser->getSessionName(), nameChooser->getActivateFlag()); bool activate = nameChooser->getActivateFlag();
int activeSessionId = m_sessionManager->getActiveSessionId();
int res = KMessageBox::Yes;
if (activate && sessId != activeSessionId)
{
// Cloning another session and switching to it at the same time,
// handle session switch correctly
res = handleSessionSwitch();
if (res == KMessageBox::Cancel)
{
return;
}
}
m_sessionManager->cloneSession(sessId, nameChooser->getSessionName(), activate, res == KMessageBox::No);
} }
} }
@ -410,7 +428,7 @@ void KateSessionPanel::slotActivateSession()
int newSessionId = newSessionItem->getSessionId(); int newSessionId = newSessionItem->getSessionId();
if (newSessionId != currSessionId) if (newSessionId != currSessionId)
{ {
int res = handleVolatileSession(); int res = handleSessionSwitch();
if (res == KMessageBox::Cancel) if (res == KMessageBox::Cancel)
{ {
return; return;
@ -469,8 +487,10 @@ void KateSessionPanel::slotItemExecuted(TQListViewItem *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()) // This is only allow when the 'Activate' toolbar button is enabled
if (!item->parent() &&
m_actionCollection->action("session_activate")->isEnabled())
{ {
slotActivateSession(); slotActivateSession();
return; return;
@ -488,8 +508,9 @@ void KateSessionPanel::slotSelectionChanged()
} }
TDEToggleAction *readOnlyAction = dynamic_cast<TDEToggleAction*>( TDEToggleAction *readOnlyAction = dynamic_cast<TDEToggleAction*>(
m_actionCollection->action("session_toggle_read_only")); m_actionCollection->action("session_toggle_read_only"));
if (!sessionItem || !ks) if (!sessionItem || !ks ||
m_sessionManager->getSwitchOption() == KateSessionManager::SWITCH_DISCARD)
{ {
m_actionCollection->action("session_save")->setEnabled(false); m_actionCollection->action("session_save")->setEnabled(false);
m_actionCollection->action("session_save_as")->setEnabled(false); m_actionCollection->action("session_save_as")->setEnabled(false);
@ -683,30 +704,63 @@ void KateSessionPanel::slotLVSessionRenamed(TQListViewItem *item)
} }
//------------------------------------------- //-------------------------------------------
int KateSessionPanel::handleVolatileSession() int KateSessionPanel::handleSessionSwitch()
{ {
const KateSession *ks = m_sessionManager->getActiveSession(); const KateSession *ks = m_sessionManager->getActiveSession();
if (!ks || !ks->isStillVolatile()) int switchOption = m_sessionManager->getSwitchOption();
if (!ks || switchOption == KateSessionManager::SWITCH_DISCARD)
{ {
return (!ks ? KMessageBox::No : KMessageBox::Yes); return KMessageBox::No;
} }
int msgres = KMessageBox::warningYesNoCancel(this, i18n("<p>You are leaving a volatile session." if (switchOption == KateSessionManager::SWITCH_ASK)
"<p>Do you want to save or discard it?").arg(ks->getSessionName()), {
i18n("Close session"), KStdGuiItem::save(), KStdGuiItem::discard()); KDialogBase *dlg = new KDialogBase(i18n("Save Session"),
if (msgres == KMessageBox::Yes) KDialogBase::Yes | KDialogBase::No | KDialogBase::Cancel,
{ KDialogBase::Cancel, KDialogBase::Cancel, NULL, NULL, true, false,
KStdGuiItem::save(), KStdGuiItem::del(), KStdGuiItem::cancel());
bool dontAgain = false;
int res = KMessageBox::createKMessageBox(dlg, TQMessageBox::Warning,
i18n("<p>Do you want to save the current session?<p>!!NOTE!!"
"<p>The session will be removed if you choose \"Delete\""), TQStringList(),
i18n("Do not ask again"), &dontAgain, KMessageBox::Notify);
if (res == KDialogBase::Cancel)
{
return KMessageBox::Cancel;
}
if (dontAgain)
{
if (res == KDialogBase::No)
{
m_sessionManager->setSwitchOption(KateSessionManager::SWITCH_DISCARD);
}
else
{
m_sessionManager->setSwitchOption(KateSessionManager::SWITCH_SAVE);
}
}
if (res == KDialogBase::No)
{
return KMessageBox::No;
}
}
// At this point the session needs to be saved.
// Make sure to handle volatile sessions correctly.
if (ks->isStillVolatile())
{
KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this, false); KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this, false);
int result = nameChooser->exec(); int res = nameChooser->exec();
if (result == TQDialog::Accepted) if (res == TQDialog::Accepted)
{ {
m_sessionManager->renameSession(m_sessionManager->getActiveSessionId(), nameChooser->getSessionName()); m_sessionManager->renameSession(m_sessionManager->getActiveSessionId(), nameChooser->getSessionName());
} }
else else
{ {
msgres = KMessageBox::Cancel; return KMessageBox::Cancel;
} }
} }
return msgres;
return KMessageBox::Yes;
} }
//END KateSessionPanel //END KateSessionPanel

@ -42,6 +42,7 @@ class TDEActionCollection;
//BEGIN KateSessionNameChooser //BEGIN KateSessionNameChooser
//FIXME create one single KateSessionNameChooser and reuse it all the time //FIXME create one single KateSessionNameChooser and reuse it all the time
//FIXME improve string to distinguish between new session and saving an unnamed session
class KateSessionNameChooser : public KDialogBase class KateSessionNameChooser : public KDialogBase
{ {
Q_OBJECT Q_OBJECT
@ -141,16 +142,16 @@ class KateSessionPanel : public TQVBox
protected: protected:
void setup_toolbar(); void setup_toolbar();
/* In case the current session is still volatile, asks the user whether /* Checks the session switch option. If the choice is 'ask user',
he wants to save or discard the session. opens a dialog and asks the user what to do.
Returns one of the following: Returns one of the following:
- KMessageBox::Cancel : the user wants to abort the current operation - KMessageBox::Cancel : the user wants to abort the current operation
- KMessageBox::No : the user wants to discard the session and continue - KMessageBox::No : the user wants to discard the session and continue
- KMessageBox::Yes : the user wants to save the session and continue - KMessageBox::Yes : the user wants to save the session and continue
In case the user decides to save the session, the function also sets If the current session is volatile and the session needs to be saved,
the new session name provided in the dialog box. it will also ask the user to provide a session name.
*/ */
int handleVolatileSession(); int handleSessionSwitch();
KateMainWindow *m_mainWin; KateMainWindow *m_mainWin;
KateViewManager *m_viewManager; KateViewManager *m_viewManager;

@ -462,7 +462,6 @@ void KateViewManager::setShowFullPath( bool enable )
/** /**
* session config functions * session config functions
*/ */
// FIXME 3.0 - make those config goups more streamlined: "objN:objN..."
void KateViewManager::saveViewConfiguration(TDEConfig *config,const TQString& grp) void KateViewManager::saveViewConfiguration(TDEConfig *config,const TQString& grp)
{ {
// Use the same group name for view configuration as usual for sessions. // Use the same group name for view configuration as usual for sessions.

Loading…
Cancel
Save