diff options
Diffstat (limited to 'kate/app')
-rw-r--r-- | kate/app/kateapp.cpp | 78 | ||||
-rw-r--r-- | kate/app/kateapp.h | 23 | ||||
-rw-r--r-- | kate/app/kateexternaltools.cpp | 1 | ||||
-rw-r--r-- | kate/app/katefileselector.cpp | 1 | ||||
-rw-r--r-- | kate/app/katemainwindow.cpp | 22 | ||||
-rw-r--r-- | kate/app/katesavemodifieddialog.cpp | 1 | ||||
-rw-r--r-- | kate/app/katesession.cpp | 209 | ||||
-rw-r--r-- | kate/app/katesession.h | 98 | ||||
-rw-r--r-- | kate/app/katesessionpanel.cpp | 106 | ||||
-rw-r--r-- | kate/app/katesessionpanel.h | 11 | ||||
-rw-r--r-- | kate/app/kateviewmanager.cpp | 1 |
11 files changed, 437 insertions, 114 deletions
diff --git a/kate/app/kateapp.cpp b/kate/app/kateapp.cpp index aeecc5fac..18251ee09 100644 --- a/kate/app/kateapp.cpp +++ b/kate/app/kateapp.cpp @@ -83,6 +83,8 @@ KateApp::KateApp (TDECmdLineArgs *args) kdDebug()<<"Setting KATE_PID: '"<<getpid()<<"'"<<endl; ::setenv( "KATE_PID", TQString(TQString("%1").arg(getpid())).latin1(), 1 ); + connect(this, TQT_SIGNAL(aboutToQuit()), this, TQT_SLOT(slotAboutToQuit())); + // handle restore different if (isRestored()) { @@ -178,23 +180,16 @@ bool KateApp::startupKate() else { // check Kate session startup options - TDEConfig *kateCfg = KateApp::self()->config(); - kateCfg->setGroup("General"); - if (kateCfg->hasKey("Last Session")) + int startupOption = sessionManager()->getStartupOption(); + if (startupOption == KateSessionManager::STARTUP_NEW) { - // Delete no longer used entry (pre R14.1.0) - kateCfg->deleteEntry("Last Session"); + sessionManager()->newSession(); } - TQString startupOption(kateCfg->readEntry("Startup Session", "manual")); - if (startupOption == "last") + else if (startupOption == KateSessionManager::STARTUP_LAST) { sessionManager()->restoreLastSession(); } - else if (startupOption == "new") - { - sessionManager()->newSession(); - } - else // startupOption == "manual" + else // startupOption == KateSessionManager::STARTUP_MANUAL { KateSessionChooser *chooser = new KateSessionChooser(NULL); int result = chooser->exec(); @@ -308,12 +303,9 @@ bool KateApp::startupKate() void KateApp::shutdownKate(KateMainWindow *win) { - if (!win->queryClose_internal()) + if (!win->queryClose_internal() || !query_session_close()) return; - // Save current session here to make sure all GUI elements are saved correctly - sessionManager()->saveActiveSession(); - // detach the dcopClient dcopClient()->detach(); @@ -324,6 +316,60 @@ void KateApp::shutdownKate(KateMainWindow *win) 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() { return m_pluginManager; diff --git a/kate/app/kateapp.h b/kate/app/kateapp.h index c1c90aa46..f421df5a7 100644 --- a/kate/app/kateapp.h +++ b/kate/app/kateapp.h @@ -100,7 +100,7 @@ class KDE_EXPORT KateApp : public TDEApplication * shutdown kate application * @param win mainwindow which is used for dialogs */ - void shutdownKate (KateMainWindow *win); + void shutdownKate(KateMainWindow *win); /** * application should exit @@ -108,8 +108,26 @@ class KDE_EXPORT KateApp : public TDEApplication */ 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: /** @@ -224,7 +242,6 @@ class KDE_EXPORT KateApp : public TDEApplication */ KateSessionManager *m_sessionManager; - /** * known main windows */ diff --git a/kate/app/kateexternaltools.cpp b/kate/app/kateexternaltools.cpp index f23ef3934..3bb21c934 100644 --- a/kate/app/kateexternaltools.cpp +++ b/kate/app/kateexternaltools.cpp @@ -172,7 +172,6 @@ void KateExternalToolsCommand::reload () { config.readListEntry( "mimetypes" ), config.readEntry( "acname", "" ), config.readEntry( "cmdname", "" ) ); - // FIXME test for a command name first! if ( t.hasexec && (!t.cmdname.isEmpty())) { m_list.append("exttool-"+t.cmdname); m_map.insert("exttool-"+t.cmdname,t.acname); diff --git a/kate/app/katefileselector.cpp b/kate/app/katefileselector.cpp index c4b107912..a57115774 100644 --- a/kate/app/katefileselector.cpp +++ b/kate/app/katefileselector.cpp @@ -413,7 +413,6 @@ void KateFileSelector::btnFilterClick() } } -//FIXME crash on shutdown void KateFileSelector::setActiveDocumentDir() { // kdDebug(13001)<<"KateFileSelector::setActiveDocumentDir()"<<endl; diff --git a/kate/app/katemainwindow.cpp b/kate/app/katemainwindow.cpp index 19a76ee27..4493eae12 100644 --- a/kate/app/katemainwindow.cpp +++ b/kate/app/katemainwindow.cpp @@ -329,9 +329,9 @@ void KateMainWindow::slotDocumentCloseAll() { } bool KateMainWindow::queryClose_internal() { - uint documentCount=KateDocManager::self()->documents(); + uint documentCount=KateDocManager::self()->documents(); - if ( ! showModOnDiskPrompt() ) + if ( !showModOnDiskPrompt() ) return false; TQPtrList<Kate::Document> modifiedDocuments=KateDocManager::self()->modifiedDocumentList(); @@ -360,23 +360,22 @@ bool KateMainWindow::queryClose() // just test, not close them actually if (KateApp::self()->sessionSaving()) { - return queryClose_internal (); + return queryClose_internal(); } // normal closing of window // allow to close all windows until the last without restrictions - if ( KateApp::self()->mainWindows () > 1 ) + if (KateApp::self()->mainWindows() > 1) + { 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 ! - if ( queryClose_internal () ) + if (queryClose_internal() && KateApp::self()->query_session_close()) { - KateApp::self()->sessionManager()->saveActiveSession(); - // detach the dcopClient KateApp::self()->dcopClient()->detach(); - return true; } @@ -403,7 +402,7 @@ void KateMainWindow::slotNewToolbarConfig() void KateMainWindow::slotFileQuit() { - KateApp::self()->shutdownKate (this); + KateApp::self()->shutdownKate(this); } void KateMainWindow::readOptions () @@ -574,6 +573,9 @@ void KateMainWindow::slotConfigure() dlg->exec(); delete dlg; + + // Inform Kate that options may have been changed + KateApp::self()->reparse_config(); } KURL KateMainWindow::activeDocumentUrl() diff --git a/kate/app/katesavemodifieddialog.cpp b/kate/app/katesavemodifieddialog.cpp index a89fe57f8..9ff79dfb4 100644 --- a/kate/app/katesavemodifieddialog.cpp +++ b/kate/app/katesavemodifieddialog.cpp @@ -156,7 +156,6 @@ KateSaveModifiedDialog::KateSaveModifiedDialog(TQWidget *parent, TQPtrList<Kate: } m_documentRoot->setOpen(true); } 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(doubleClicked(TQListViewItem *)), TQT_SLOT(slotItemSelected())); connect(m_list, TQT_SIGNAL(spacePressed(TQListViewItem *)), TQT_SLOT(slotItemSelected())); diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index 91d0ad05a..91f655613 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -51,28 +51,39 @@ // FIXME general: need to keep doc list and current session's m_documents in synchro // 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 // String constants namespace { // Kate session - const char *KS_COUNT = "Count"; - const char *KS_DOCCOUNT = "Document count"; - const char *KS_DOCLIST = "Document list"; - const char *KS_GENERAL = "General"; - const char *KS_NAME = "Name"; - const char *KS_OPENDOC = "Open Documents"; - const char *KS_READONLY = "ReadOnly"; - const char *KS_OPEN_MAINWINDOWS = "Open MainWindows"; - const char *KS_UNNAMED = "Unnamed"; + const char *KS_COUNT = "Count"; + const char *KS_DOCCOUNT = "Document count"; + const char *KS_DOCLIST = "Document list"; + const char *KS_GENERAL = "General"; + const char *KS_NAME = "Name"; + const char *KS_OPENDOC = "Open Documents"; + const char *KS_READONLY = "ReadOnly"; + const char *KS_OPEN_MAINWINDOWS = "Open MainWindows"; + const char *KS_UNNAMED = "Unnamed"; // Kate session manager - const char *KSM_DIR = "kate/sessions"; - const char *KSM_FILE = "sessions.list"; - const char *KSM_SESSIONS_COUNT = "Sessions count"; - const char *KSM_LAST_SESSION_ID = "Last session id"; - const char *KSM_SESSIONS_LIST = "Sessions list"; + const char *KSM_DIR = "kate/sessions"; + const char *KSM_FILE = "sessions.list"; + const char *KSM_SESSIONS_COUNT = "Sessions count"; + const char *KSM_LAST_SESSION_ID = "Last session id"; + 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 @@ -321,10 +332,14 @@ KateSessionManager* KateSessionManager::self() //------------------------------------ KateSessionManager::KateSessionManager() : 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); - int sessionsCount = 0; 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 } + //NOTE do not activate any session in the KateSessionManager costructor // since Kate's main window may not be ready yet. The initial session // will be activated by KateApp::startupKate() or KateApp::restoreKate() @@ -370,25 +386,123 @@ KateSessionManager::KateSessionManager() : //------------------------------------ KateSessionManager::~KateSessionManager() { - saveConfig(true); if (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 -// about sessions to open-use-close Kate seemlessly. -// FIXME An option need to be added to Configure Kate -> Sessions to allow Kate to ask about -// saving unnamed sessions before closing the current session. Default value is off as per -// point above. +void KateSessionManager::saveSessionOptions(int optionType) +{ + TDEConfig *kateCfg = KateApp::self()->config(); + kateCfg->setGroup(KAPP_GENERAL); + 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) { + // 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) { m_config = new KSimpleConfig(m_configFile); @@ -402,17 +516,35 @@ void KateSessionManager::saveConfig(bool saveSessions) m_config->writeEntry(KSM_LAST_SESSION_ID, m_activeSessionId); for (int i = 0; i < (int)m_sessions.count(); ++i) { - //FIXME need to consider when sessions has to be saved. - if (saveSessions) - { - saveSession(i, false, false); - } + saveSession(i, false, false); m_config->writeEntry(TQString("URL_%1").arg(i), m_sessions[i]->getSessionFilename()); } 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) { if (sessionId < 0 || sessionId >= (int)m_sessions.count()) @@ -476,9 +608,14 @@ bool KateSessionManager::activateSession(int sessionId, bool saveCurr) { 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_activeSessionId = INVALID_SESSION; 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()) { @@ -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 // 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) { reloadActiveSession(); } -*/ + if (activate) { - activateSession(newSessionId, m_activeSessionId != INVALID_SESSION); + activateSession(newSessionId, m_activeSessionId != INVALID_SESSION && !deleteCurr); } return newSessionId; } diff --git a/kate/app/katesession.h b/kate/app/katesession.h index 4b1a63126..d073d8411 100644 --- a/kate/app/katesession.h +++ b/kate/app/katesession.h @@ -154,13 +154,13 @@ class KateSession //BEGIN KateSessionManager -//FIXME (advanced) -//There should be only one session manager regardless of how many instances of Kate are running. -//Changes should propagate to all session panels. Different Kate instances should run different -//sessions. If the user switches to a session already opened in another Kate instance, the current -//session should be saved and then the focus switched to the other instance. -//This would allow a safe use of multiple Kate instances without overwriting session information -//among them. Currently the last instance to be closed will overwrite the information previously +//FIXME (advanced - multiple main windows or multiple Kate instances) +//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 main windows should run different +//sessions. If the user switches to a session already opened in another Kate window, the other window +//should be brought up to the screen (eventually ask user confirmation first). +//This would allow a safe use of multiple Kate main windows/instances without overwriting session information +//among them. Currently the last instance/main window 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 @@ -169,6 +169,11 @@ class KateSession * @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 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 { Q_OBJECT @@ -180,6 +185,22 @@ class KateSessionManager : public TQObject 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. * If the manager does not exist yet, create it. @@ -192,6 +213,32 @@ class KateSessionManager : public TQObject ~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 */ const TQString& getBaseDir() const { return m_baseDir; } @@ -262,10 +309,12 @@ class KateSessionManager : public TQObject * @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 + * @param deleteCurr if true, delete the current session after switching * @return the id of the newly created session * @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 @@ -332,6 +381,11 @@ class KateSessionManager : public TQObject signals: /** + * Emitted when the session switch option has been set/changed + */ + void switchOptionChanged(); + + /** * Emitted once a session has been activated * @param newSessionId the id of the previous active session * @param oldSessionId the id of the new active session @@ -373,12 +427,26 @@ class KateSessionManager : public TQObject protected: 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 - * @param saveSessions if true, all sessions will be saved again - */ - void saveConfig(bool saveSessions); - + * Updated the session startup and switch options + * @param optionType specifies which options needs to be updated + */ + 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 * @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 TQPtrList<KateSession> m_sessions; // session list 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 }; //END KateSessionManager diff --git a/kate/app/katesessionpanel.cpp b/kate/app/katesessionpanel.cpp index 0c28726bd..25980dc40 100644 --- a/kate/app/katesessionpanel.cpp +++ b/kate/app/katesessionpanel.cpp @@ -146,12 +146,17 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager * m_listview->setResizeMode(TQListView::LastColumn); //m_listview->setRootIsDecorated(true); // FIXME disabled until doc list software is developed + 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(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)), this, TQT_SLOT(slotSessionActivated(int, int))); connect(m_sessionManager, TQT_SIGNAL(sessionCreated(int)), @@ -258,7 +263,7 @@ void KateSessionPanel::slotNewSession() int result = nameChooser->exec(); if (result == TQDialog::Accepted) { - int res = handleVolatileSession(); + int res = handleSessionSwitch(); if (res == KMessageBox::Cancel) { return; @@ -312,9 +317,9 @@ void KateSessionPanel::slotSaveSessionAs() { return; } - + // 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(); // Get new session name KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this, cloneSession); @@ -330,7 +335,20 @@ void KateSessionPanel::slotSaveSessionAs() else { // 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(); if (newSessionId != currSessionId) { - int res = handleVolatileSession(); + int res = handleSessionSwitch(); if (res == KMessageBox::Cancel) { return; @@ -469,8 +487,10 @@ void KateSessionPanel::slotItemExecuted(TQListViewItem *item) return; } - // First level items are sessions. Executing one, will switch to that session - if (!item->parent()) + // First level items are sessions. Executing one, will switch to that session. + // This is only allow when the 'Activate' toolbar button is enabled + if (!item->parent() && + m_actionCollection->action("session_activate")->isEnabled()) { slotActivateSession(); return; @@ -488,8 +508,9 @@ void KateSessionPanel::slotSelectionChanged() } TDEToggleAction *readOnlyAction = dynamic_cast<TDEToggleAction*>( - m_actionCollection->action("session_toggle_read_only")); - if (!sessionItem || !ks) + m_actionCollection->action("session_toggle_read_only")); + if (!sessionItem || !ks || + m_sessionManager->getSwitchOption() == KateSessionManager::SWITCH_DISCARD) { m_actionCollection->action("session_save")->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(); - 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." - "<p>Do you want to save or discard it?").arg(ks->getSessionName()), - i18n("Close session"), KStdGuiItem::save(), KStdGuiItem::discard()); - if (msgres == KMessageBox::Yes) - { + + if (switchOption == KateSessionManager::SWITCH_ASK) + { + KDialogBase *dlg = new KDialogBase(i18n("Save Session"), + 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); - int result = nameChooser->exec(); - if (result == TQDialog::Accepted) + int res = nameChooser->exec(); + if (res == TQDialog::Accepted) { - m_sessionManager->renameSession(m_sessionManager->getActiveSessionId(), nameChooser->getSessionName()); - } - else + m_sessionManager->renameSession(m_sessionManager->getActiveSessionId(), nameChooser->getSessionName()); + } + else { - msgres = KMessageBox::Cancel; - } + return KMessageBox::Cancel; + } } - return msgres; + + return KMessageBox::Yes; } //END KateSessionPanel diff --git a/kate/app/katesessionpanel.h b/kate/app/katesessionpanel.h index 6899d68e9..4b4f47236 100644 --- a/kate/app/katesessionpanel.h +++ b/kate/app/katesessionpanel.h @@ -42,6 +42,7 @@ class TDEActionCollection; //BEGIN KateSessionNameChooser //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 { Q_OBJECT @@ -141,16 +142,16 @@ class KateSessionPanel : public TQVBox protected: void setup_toolbar(); - /* In case the current session is still volatile, asks the user whether - he wants to save or discard the session. + /* Checks the session switch option. If the choice is 'ask user', + opens a dialog and asks the user what to do. Returns one of the following: - KMessageBox::Cancel : the user wants to abort the current operation - KMessageBox::No : the user wants to discard 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 - the new session name provided in the dialog box. + If the current session is volatile and the session needs to be saved, + it will also ask the user to provide a session name. */ - int handleVolatileSession(); + int handleSessionSwitch(); KateMainWindow *m_mainWin; KateViewManager *m_viewManager; diff --git a/kate/app/kateviewmanager.cpp b/kate/app/kateviewmanager.cpp index ca361232a..47ece5270 100644 --- a/kate/app/kateviewmanager.cpp +++ b/kate/app/kateviewmanager.cpp @@ -462,7 +462,6 @@ void KateViewManager::setShowFullPath( bool enable ) /** * session config functions */ -// FIXME 3.0 - make those config goups more streamlined: "objN:objN..." void KateViewManager::saveViewConfiguration(TDEConfig *config,const TQString& grp) { // Use the same group name for view configuration as usual for sessions. |