From 192b7af94830ff981760570254cce1a27a81d341 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Mon, 10 Aug 2015 16:45:54 +0900 Subject: Added Kate session panel. This commit contains the GUI elements. The logic will be added in a separate commit. Signed-off-by: Michele Calgaro --- kate/app/CMakeLists.txt | 4 +- kate/app/Makefile.am | 2 +- kate/app/katemain.h | 1 + kate/app/katemainwindow.cpp | 10 ++- kate/app/katemainwindow.h | 1 + kate/app/katesessionpanel.cpp | 185 ++++++++++++++++++++++++++++++++++++++++++ kate/app/katesessionpanel.h | 92 +++++++++++++++++++++ 7 files changed, 289 insertions(+), 6 deletions(-) create mode 100644 kate/app/katesessionpanel.cpp create mode 100644 kate/app/katesessionpanel.h (limited to 'kate') diff --git a/kate/app/CMakeLists.txt b/kate/app/CMakeLists.txt index 7adea8ea3..77908ffcf 100644 --- a/kate/app/CMakeLists.txt +++ b/kate/app/CMakeLists.txt @@ -38,8 +38,8 @@ set( ${target}_SRCS kbookmarkhandler.cpp katedocmanageriface.skel kateappIface.cpp kateappIface.skel katedocmanageriface.cpp kateexternaltools.cpp katesavemodifieddialog.cpp kateviewspacecontainer.cpp - katemwmodonhddialog.cpp katesession.cpp katemdi.cpp - katetabwidget.cpp + katemwmodonhddialog.cpp katesession.cpp katesessionpanel.cpp + katemdi.cpp katetabwidget.cpp ) tde_add_library( ${target} SHARED AUTOMOC diff --git a/kate/app/Makefile.am b/kate/app/Makefile.am index de2258630..c50f68562 100644 --- a/kate/app/Makefile.am +++ b/kate/app/Makefile.am @@ -10,7 +10,7 @@ libkateinterfaces_la_SOURCES = kateapp.cpp kateconfigdialog.cpp kateconfigplugin katemailfilesdialog.cpp kbookmarkhandler.cpp \ katedocmanageriface.skel kateappIface.cpp kateappIface.skel katedocmanageriface.cpp \ kateexternaltools.cpp katesavemodifieddialog.cpp kateviewspacecontainer.cpp \ - katemwmodonhddialog.cpp katesession.cpp katemdi.cpp katetabwidget.cpp + katemwmodonhddialog.cpp katesession.cpp katesessionpanel.cpp katemdi.cpp katetabwidget.cpp libkateinterfaces_la_LIBADD = ../interfaces/libkateinterfacesprivate.la $(LIB_TDEUTILS) ../utils/libkateutils.la diff --git a/kate/app/katemain.h b/kate/app/katemain.h index 374b834cc..24663f58f 100644 --- a/kate/app/katemain.h +++ b/kate/app/katemain.h @@ -60,6 +60,7 @@ class KateConsole; class KateDocManager; class KateFileList; class KateFileSelector; +class KateSessionPanel; class KateMainWindow; class KatePluginIface; class KatePluginManager; diff --git a/kate/app/katemainwindow.cpp b/kate/app/katemainwindow.cpp index 0bcf08883..a867cb418 100644 --- a/kate/app/katemainwindow.cpp +++ b/kate/app/katemainwindow.cpp @@ -31,6 +31,7 @@ #include "kateapp.h" #include "katefileselector.h" #include "katefilelist.h" +#include "katesessionpanel.h" #include "kategrepdialog.h" #include "katemailfilesdialog.h" #include "katemainwindowiface.h" @@ -217,6 +218,9 @@ void KateMainWindow::setupMainWindow () fileselector = new KateFileSelector( this, m_viewManager, t, "operator"); connect(fileselector->dirOperator(),TQT_SIGNAL(fileSelected(const KFileItem*)),this,TQT_SLOT(fileSelected(const KFileItem*))); + KateMDI::ToolView *st = createToolView("kate_sessionpanel", KMultiTabBar::Left, SmallIcon("view_choose"), i18n("Sessions")); + sessionpanel = new KateSessionPanel( this, m_viewManager, st, "sessionpanel"); + // ONLY ALLOW SHELL ACCESS IF ALLOWED ;) if (KateApp::self()->authorize("shell_access")) { @@ -302,7 +306,7 @@ void KateMainWindow::setupActions() slotWindowActivated (); // session actions - new TDEAction(i18n("Menu entry Session->New", "&New"), "document-new", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionNew()), actionCollection(), "sessions_new"); + new TDEAction(i18n("Menu entry Session->New", "&New"), "list-add", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionNew()), actionCollection(), "sessions_new"); new TDEAction(i18n("&Open..."), "document-open", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionOpen()), actionCollection(), "sessions_open"); new TDEAction(i18n("&Save"), "document-save", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionSave()), actionCollection(), "sessions_save"); new TDEAction(i18n("Save &As..."), "document-save-as", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionSaveAs()), actionCollection(), "sessions_save_as"); @@ -434,7 +438,7 @@ void KateMainWindow::saveOptions () config->writeEntry("Show Full Path in Title", m_viewManager->getShowFullPath()); config->writeEntry("Sync Konsole", syncKonsole); config->writeEntry("UseInstance", useInstance); - + fileOpenRecent->saveEntries(config, "Recent Files"); fileselector->writeConfig(config, "fileselector"); filelist->writeConfig(config, "Filelist"); @@ -482,7 +486,7 @@ void KateMainWindow::documentMenuAboutToShow() TQListViewItem * item = filelist->firstChild(); while( item ) { // would it be saner to use the screen width as a limit that some random number?? - TQString name = KStringHandler::rsqueeze( ((KateFileListItem *)item)->document()->docName(), 150 ); + TQString name = KStringHandler::rsqueeze( ((KateFileListItem *)item)->document()->docName(), 150 ); Kate::Document* doc = ((KateFileListItem *)item)->document(); documentMenu->insertItem ( doc->isModified() ? i18n("'document name [*]', [*] means modified", "%1 [*]").arg(name) : name, diff --git a/kate/app/katemainwindow.h b/kate/app/katemainwindow.h index 157b4e57d..15b7f35c6 100644 --- a/kate/app/katemainwindow.h +++ b/kate/app/katemainwindow.h @@ -198,6 +198,7 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa KateFileList *filelist; KateFileSelector *fileselector; + KateSessionPanel *sessionpanel; TDEActionMenu* documentOpenWith; diff --git a/kate/app/katesessionpanel.cpp b/kate/app/katesessionpanel.cpp new file mode 100644 index 000000000..da595b15e --- /dev/null +++ b/kate/app/katesessionpanel.cpp @@ -0,0 +1,185 @@ +/* This file is part of the TDE project + Copyright (C) 2015 Michele Calgaro + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "katesessionpanel.h" +#include "katesessionpanel.moc" + +#include "katemainwindow.h" +#include "kateviewmanager.h" +#include "katesession.h" + +#include +#include + + +void KateSessionPanelToolBarParent::setToolBar(TDEToolBar *tbar) +{ + m_tbar = tbar; +} + +//------------------------------------------- +void KateSessionPanelToolBarParent::resizeEvent (TQResizeEvent*) +{ + if (m_tbar) + { + setMinimumHeight(m_tbar->sizeHint().height()); + m_tbar->resize(width(),height()); + } +} + +//------------------------------------------- +KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager *viewManager, + TQWidget *parent, const char *name) + : TQVBox(parent, name), m_mainWin(mainWindow), m_viewManager(viewManager), + m_sessionManager(KateSessionManager::self()), m_actionCollection(new TDEActionCollection(this)) +{ + // Toolbar + setup_toolbar(); + + // Listview + m_listview = new TDEListView(this); + m_listview->setRootIsDecorated(true); + m_listview->setSorting(-1); + m_listview->setMinimumWidth(m_listview->sizeHint().width()); +} + +//------------------------------------------- +void KateSessionPanel::setup_toolbar() +{ + // Toolbar widget and frame + KateSessionPanelToolBarParent *tbarParent=new KateSessionPanelToolBarParent(this); + m_toolbar = new TDEToolBar(tbarParent, "Kate Session Panel Toolbar", true); + tbarParent->setToolBar(m_toolbar); + m_toolbar->setMovingEnabled(false); + m_toolbar->setFlat(true); + m_toolbar->setIconText(TDEToolBar::IconOnly); + m_toolbar->setIconSize(16); + m_toolbar->setEnableContextMenu(false); + + // Toolbar actions + TDEAction *a; + a = new TDEAction(i18n("New"), SmallIcon("list-add"), 0, + TQT_TQOBJECT(m_sessionManager), TQT_SLOT(sessionNew()), m_actionCollection, "session_new"); + a->setWhatsThis(i18n("Create a new session.")); + a->plug(m_toolbar); + + a = new TDEAction(i18n("Save"), SmallIcon("document-save"), 0, + TQT_TQOBJECT(this), TQT_SLOT(saveSession()), m_actionCollection, "session_save"); + a->setWhatsThis(i18n("Save the current session.")); + a->plug(m_toolbar); + + a = new TDEAction(i18n("Save as..."), SmallIcon("document-save-as"), 0, + TQT_TQOBJECT(this), TQT_SLOT(saveSessionAs()), m_actionCollection, "session_save_as"); + a->setWhatsThis(i18n("Save the current session with a different name.")); + a->plug(m_toolbar); + + a = new TDEAction(i18n("Rename"), SmallIcon("edit_user"), 0, + TQT_TQOBJECT(this), TQT_SLOT(renameSession()), m_actionCollection, "session_rename"); + a->setWhatsThis(i18n("Rename the selected session.")); + a->plug(m_toolbar); + + a = new TDEAction(i18n("Delete"), SmallIcon("edit-delete"), 0, + TQT_TQOBJECT(this), TQT_SLOT(deleteSession()), m_actionCollection, "session_delete"); + a->setWhatsThis(i18n("Delete the selected session.")); + a->plug(m_toolbar); + + m_toolbar->insertLineSeparator(); + + a = new TDEAction(i18n("Activate"), SmallIcon("forward"), 0, + TQT_TQOBJECT(this), TQT_SLOT(sessionActivate()), m_actionCollection, "session_activate"); + a->setWhatsThis(i18n("Activate the selected session.")); + a->plug(m_toolbar); + + TDEToggleAction *tglA = new TDEToggleAction(i18n("Toggle read only"), SmallIcon("encrypted"), 0, + TQT_TQOBJECT(this), TQT_SLOT(sessionToggleReadOnly()), m_actionCollection, "session_toggle_read_only"); + tglA->setWhatsThis(i18n("Toggle read only status for the selected session.

" + "In a read only session, you can work as usual but the list of documents in the session " + "will not be saved when you exit Kate or switch to another session.

" + "You can use this option to create template sessions that you wish to keep unchanged over time.")); + tglA->plug(m_toolbar); + + a = new TDEAction(i18n("Move Up"), SmallIcon("go-up"), 0, + TQT_TQOBJECT(this), TQT_SLOT(sessionMoveUp()), m_actionCollection, "session_move_up"); + a->setWhatsThis(i18n("Move up the selected session.")); + a->plug(m_toolbar); + + a = new TDEAction(i18n("Move Down"), SmallIcon("go-down"), 0, + TQT_TQOBJECT(this), TQT_SLOT(sessionMoveDown()), m_actionCollection, "session_move_down"); + a->setWhatsThis(i18n("Move down the selected session.")); + a->plug(m_toolbar); + + m_toolbar->insertLineSeparator(); + + a = new TDEAction(i18n("Open"), SmallIcon("document-open"), 0, + TQT_TQOBJECT(m_sessionManager), TQT_SLOT(sessionOpen()), m_actionCollection, "session_open"); + a->setWhatsThis(i18n("Switch to another session chosen from a list of existing ones.")); + a->plug(m_toolbar); + + a = new TDEAction(i18n("Manage"), SmallIcon("view_choose"), 0, + TQT_TQOBJECT(m_sessionManager), TQT_SLOT(sessionManage()), m_actionCollection, "session_manage"); + a->setWhatsThis(i18n("Manage existing sessions.")); + a->plug(m_toolbar); +} + +//------------------------------------------- +void KateSessionPanel::saveSession() +{ +//TODO +} + +//------------------------------------------- +void KateSessionPanel::saveSessionAs() +{ +//TODO +} + +//------------------------------------------- +void KateSessionPanel::renameSession() +{ +//TODO +} + +//------------------------------------------- +void KateSessionPanel::deleteSession() +{ +//TODO +} + +//------------------------------------------- +void KateSessionPanel::sessionActivate() +{ +//TODO +} + +//------------------------------------------- +void KateSessionPanel::sessionToggleReadOnly() +{ +//TODO +} + +//------------------------------------------- +void KateSessionPanel::sessionMoveUp() +{ +//TODO +} + +//------------------------------------------- +void KateSessionPanel::sessionMoveDown() +{ +//TODO +} diff --git a/kate/app/katesessionpanel.h b/kate/app/katesessionpanel.h new file mode 100644 index 000000000..f110fd32b --- /dev/null +++ b/kate/app/katesessionpanel.h @@ -0,0 +1,92 @@ +/* This file is part of the TDE project + Copyright (C) 2015 Michele Calgaro + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef __KATE_SESSIONPANEL_H__ +#define __KATE_SESSIONPANEL_H__ + +/* + The kate session panel displays the available sessions (and their documents) + in a treeview list and allows for quick switching among them. + A toolbar on the top also provides quick access to actions needed + to manage sessions. +*/ + +#include +#include +#include +#include + +class KateMainWindow; +class KateViewManager; +class KateSessionManager; +class TDEActionCollection; + + +class KateSessionPanelToolBarParent: public TQFrame +{ + Q_OBJECT + + public: + KateSessionPanelToolBarParent(TQWidget *parent) : TQFrame(parent), m_tbar(0) {} + ~KateSessionPanelToolBarParent() {} + void setToolBar(TDEToolBar *tbar); + + protected: + virtual void resizeEvent (TQResizeEvent*); + + private: + TDEToolBar *m_tbar; +}; + + + +class KateSessionPanel : public TQVBox +{ + Q_OBJECT + + public: + + KateSessionPanel(KateMainWindow *mainWindow=0, KateViewManager *viewManager=0, + TQWidget *parent=0, const char *name=0); + ~KateSessionPanel() {} + + public slots: + void saveSession(); + void saveSessionAs(); + void renameSession(); + void deleteSession(); + void sessionActivate(); + void sessionToggleReadOnly(); + void sessionMoveUp(); + void sessionMoveDown(); + + private: + void setup_toolbar(); + + KateMainWindow *m_mainWin; + KateViewManager *m_viewManager; + KateSessionManager *m_sessionManager; + TDEActionCollection *m_actionCollection; + + TDEToolBar *m_toolbar; + TDEListView *m_listview; +}; + + +#endif //__KATE_SESSIONPANEL_H__ +// kate: space-indent on; indent-width 2; replace-tabs on; -- cgit v1.2.1 From 2eb61917990c77f0b67ef60a6d60a7fcab3b6ddc Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Fri, 14 Aug 2015 18:26:07 +0900 Subject: Renamed KateSession* --> OldKateSession* (except KateSessionPanel). This is to ease the development and testing of the new KateSession/KateSessionManager code while at the same time preserve session functionality. The OldKateSession* code will be removed once the new code has been fully developed and tested. Signed-off-by: Michele Calgaro --- kate/app/kateapp.cpp | 6 +- kate/app/kateapp.h | 6 +- kate/app/katemainwindow.cpp | 12 +-- kate/app/katesession.cpp | 168 +++++++++++++++++++++--------------------- kate/app/katesession.h | 66 ++++++++--------- kate/app/katesessionpanel.cpp | 2 +- kate/app/katesessionpanel.h | 4 +- kate/app/kateviewspace.cpp | 2 +- 8 files changed, 133 insertions(+), 133 deletions(-) (limited to 'kate') diff --git a/kate/app/kateapp.cpp b/kate/app/kateapp.cpp index 9cba61cc6..2f54a8e23 100644 --- a/kate/app/kateapp.cpp +++ b/kate/app/kateapp.cpp @@ -75,7 +75,7 @@ KateApp::KateApp (TDECmdLineArgs *args) m_pluginManager = new KatePluginManager (TQT_TQOBJECT(this)); // session manager up - m_sessionManager = new KateSessionManager (TQT_TQOBJECT(this)); + m_sessionManager = new OldKateSessionManager (TQT_TQOBJECT(this)); // application dcop interface m_obj = new KateAppDCOPIface (this); @@ -147,7 +147,7 @@ void KateApp::restoreKate () // activate again correct session!!! sessionConfig()->setGroup("General"); TQString lastSession (sessionConfig()->readEntry ("Last Session", "default.katesession")); - sessionManager()->activateSession (new KateSession (sessionManager(), lastSession, ""), false, false, false); + sessionManager()->activateSession (new OldKateSession (sessionManager(), lastSession, ""), false, false, false); m_docManager->restoreDocumentList (sessionConfig()); @@ -294,7 +294,7 @@ KateDocManager *KateApp::documentManager () return m_docManager; } -KateSessionManager *KateApp::sessionManager () +OldKateSessionManager *KateApp::sessionManager () { return m_sessionManager; } diff --git a/kate/app/kateapp.h b/kate/app/kateapp.h index 05d09a7fe..2b6c1e2cd 100644 --- a/kate/app/kateapp.h +++ b/kate/app/kateapp.h @@ -26,7 +26,7 @@ #include -class KateSessionManager; +class OldKateSessionManager; class KateAppDCOPIface; namespace Kate { @@ -128,7 +128,7 @@ class KDE_EXPORT KateApp : public TDEApplication * accessor to session manager * @return session manager instance */ - KateSessionManager *sessionManager (); + OldKateSessionManager *sessionManager (); /** * window management @@ -222,7 +222,7 @@ class KDE_EXPORT KateApp : public TDEApplication /** * session manager */ - KateSessionManager *m_sessionManager; + OldKateSessionManager *m_sessionManager; /** * known main windows diff --git a/kate/app/katemainwindow.cpp b/kate/app/katemainwindow.cpp index a867cb418..794e1a777 100644 --- a/kate/app/katemainwindow.cpp +++ b/kate/app/katemainwindow.cpp @@ -306,14 +306,14 @@ void KateMainWindow::setupActions() slotWindowActivated (); // session actions - new TDEAction(i18n("Menu entry Session->New", "&New"), "list-add", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionNew()), actionCollection(), "sessions_new"); - new TDEAction(i18n("&Open..."), "document-open", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionOpen()), actionCollection(), "sessions_open"); - new TDEAction(i18n("&Save"), "document-save", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionSave()), actionCollection(), "sessions_save"); - new TDEAction(i18n("Save &As..."), "document-save-as", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionSaveAs()), actionCollection(), "sessions_save_as"); - new TDEAction(i18n("&Manage..."), "view_choose", 0, TQT_TQOBJECT(KateSessionManager::self()), TQT_SLOT(sessionManage()), actionCollection(), "sessions_manage"); + new TDEAction(i18n("Menu entry Session->New", "&New"), "list-add", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionNew()), actionCollection(), "sessions_new"); + new TDEAction(i18n("&Open..."), "document-open", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionOpen()), actionCollection(), "sessions_open"); + new TDEAction(i18n("&Save"), "document-save", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionSave()), actionCollection(), "sessions_save"); + new TDEAction(i18n("Save &As..."), "document-save-as", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionSaveAs()), actionCollection(), "sessions_save_as"); + new TDEAction(i18n("&Manage..."), "view_choose", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionManage()), actionCollection(), "sessions_manage"); // quick open menu ;) - new KateSessionsAction (i18n("&Quick Open"), actionCollection(), "sessions_list"); + new OldKateSessionsAction (i18n("&Quick Open"), actionCollection(), "sessions_list"); } KateTabWidget *KateMainWindow::tabWidget () diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index 2c0057bf8..e71d383f1 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -48,12 +48,12 @@ #include #include -bool operator<( const KateSession::Ptr& a, const KateSession::Ptr& b ) +bool operator<( const OldKateSession::Ptr& a, const OldKateSession::Ptr& b ) { return a->sessionName().lower() < b->sessionName().lower(); } -KateSession::KateSession (KateSessionManager *manager, const TQString &fileName, const TQString &name) +OldKateSession::OldKateSession (OldKateSessionManager *manager, const TQString &fileName, const TQString &name) : m_sessionFileRel (fileName) , m_sessionName (name) , m_documents (0) @@ -64,7 +64,7 @@ KateSession::KateSession (KateSessionManager *manager, const TQString &fileName, init (); } -void KateSession::init () +void OldKateSession::init () { // given file exists, use it to load some stuff ;) if (!m_sessionFileRel.isEmpty() && TDEGlobal::dirs()->exists(sessionFile ())) @@ -113,18 +113,18 @@ void KateSession::init () } } -KateSession::~KateSession () +OldKateSession::~OldKateSession () { delete m_readConfig; delete m_writeConfig; } -TQString KateSession::sessionFile () const +TQString OldKateSession::sessionFile () const { return m_manager->sessionsDir() + "/" + m_sessionFileRel; } -bool KateSession::create (const TQString &name, bool force) +bool OldKateSession::create (const TQString &name, bool force) { if (!force && (name.isEmpty() || !m_sessionFileRel.isEmpty())) return false; @@ -162,7 +162,7 @@ bool KateSession::create (const TQString &name, bool force) return true; } -bool KateSession::rename (const TQString &name) +bool OldKateSession::rename (const TQString &name) { if (name.isEmpty () || m_sessionFileRel.isEmpty() || m_sessionFileRel == "default.katesession") return false; @@ -177,7 +177,7 @@ bool KateSession::rename (const TQString &name) return true; } -TDEConfig *KateSession::configRead () +TDEConfig *OldKateSession::configRead () { if (m_sessionFileRel.isEmpty()) return 0; @@ -188,7 +188,7 @@ TDEConfig *KateSession::configRead () return m_readConfig = new KSimpleConfig (sessionFile (), true); } -TDEConfig *KateSession::configWrite () +TDEConfig *OldKateSession::configWrite () { if (m_sessionFileRel.isEmpty()) return 0; @@ -203,10 +203,10 @@ TDEConfig *KateSession::configWrite () return m_writeConfig; } -KateSessionManager::KateSessionManager (TQObject *parent) +OldKateSessionManager::OldKateSessionManager (TQObject *parent) : TQObject (parent) , m_sessionsDir (locateLocal( "data", "kate/sessions")) - , m_activeSession (new KateSession (this, "", "")) + , m_activeSession (new OldKateSession (this, "", "")) { kdDebug() << "LOCAL SESSION DIR: " << m_sessionsDir << endl; @@ -214,21 +214,21 @@ KateSessionManager::KateSessionManager (TQObject *parent) TDEGlobal::dirs()->makeDir (m_sessionsDir); } -KateSessionManager::~KateSessionManager() +OldKateSessionManager::~OldKateSessionManager() { } -KateSessionManager *KateSessionManager::self() +OldKateSessionManager *OldKateSessionManager::self() { return KateApp::self()->sessionManager (); } -void KateSessionManager::dirty (const TQString &) +void OldKateSessionManager::dirty (const TQString &) { updateSessionList (); } -void KateSessionManager::updateSessionList () +void OldKateSessionManager::updateSessionList () { m_sessionList.clear (); @@ -238,7 +238,7 @@ void KateSessionManager::updateSessionList () bool foundDefault = false; for (unsigned int i=0; i < dir.count(); ++i) { - KateSession *session = new KateSession (this, dir[i], ""); + OldKateSession *session = new OldKateSession (this, dir[i], ""); m_sessionList.append (session); kdDebug () << "FOUND SESSION: " << session->sessionName() << " FILE: " << session->sessionFile() << endl; @@ -249,12 +249,12 @@ void KateSessionManager::updateSessionList () // add default session, if not there if (!foundDefault) - m_sessionList.append (new KateSession (this, "default.katesession", i18n("Default Session"))); + m_sessionList.append (new OldKateSession (this, "default.katesession", i18n("Default Session"))); qHeapSort(m_sessionList); } -void KateSessionManager::activateSession (KateSession::Ptr session, bool closeLast, bool saveLast, bool loadNew) +void OldKateSessionManager::activateSession (OldKateSession::Ptr session, bool closeLast, bool saveLast, bool loadNew) { // don't reload. // ### comparing the pointers directly is b0rk3d :( @@ -342,18 +342,18 @@ void KateSessionManager::activateSession (KateSession::Ptr session, bool closeLa } } -KateSession::Ptr KateSessionManager::createSession (const TQString &name) +OldKateSession::Ptr OldKateSessionManager::createSession (const TQString &name) { - KateSession::Ptr s = new KateSession (this, "", ""); + OldKateSession::Ptr s = new OldKateSession (this, "", ""); s->create (name); return s; } -KateSession::Ptr KateSessionManager::giveSession (const TQString &name) +OldKateSession::Ptr OldKateSessionManager::giveSession (const TQString &name) { if (name.isEmpty()) - return new KateSession (this, "", ""); + return new OldKateSession (this, "", ""); updateSessionList(); @@ -366,7 +366,7 @@ KateSession::Ptr KateSessionManager::giveSession (const TQString &name) return createSession (name); } -bool KateSessionManager::saveActiveSession (bool tryAsk, bool rememberAsLast) +bool OldKateSessionManager::saveActiveSession (bool tryAsk, bool rememberAsLast) { if (tryAsk) { @@ -437,7 +437,7 @@ bool KateSessionManager::saveActiveSession (bool tryAsk, bool rememberAsLast) return true; } -bool KateSessionManager::chooseSession () +bool OldKateSessionManager::chooseSession () { bool success = true; @@ -452,18 +452,18 @@ bool KateSessionManager::chooseSession () // uhh, just open last used session, show no chooser if (sesStart == "last") { - activateSession (new KateSession (this, lastSession, ""), false, false); + activateSession (new OldKateSession (this, lastSession, ""), false, false); return success; } // start with empty new session if (sesStart == "new") { - activateSession (new KateSession (this, "", ""), false, false); + activateSession (new OldKateSession (this, "", ""), false, false); return success; } - KateSessionChooser *chooser = new KateSessionChooser (0, lastSession); + OldKateSessionChooser *chooser = new OldKateSessionChooser (0, lastSession); bool retry = true; int res = 0; @@ -473,9 +473,9 @@ bool KateSessionManager::chooseSession () switch (res) { - case KateSessionChooser::resultOpen: + case OldKateSessionChooser::resultOpen: { - KateSession::Ptr s = chooser->selectedSession (); + OldKateSession::Ptr s = chooser->selectedSession (); if (!s) { @@ -489,13 +489,13 @@ bool KateSessionManager::chooseSession () } // exit the app lateron - case KateSessionChooser::resultQuit: + case OldKateSessionChooser::resultQuit: success = false; retry = false; break; default: - activateSession (new KateSession (this, "", ""), false, false); + activateSession (new OldKateSession (this, "", ""), false, false); retry = false; break; } @@ -506,9 +506,9 @@ bool KateSessionManager::chooseSession () { c->setGroup("General"); - if (res == KateSessionChooser::resultOpen) + if (res == OldKateSessionChooser::resultOpen) c->writeEntry ("Startup Session", "last"); - else if (res == KateSessionChooser::resultNew) + else if (res == OldKateSessionChooser::resultNew) c->writeEntry ("Startup Session", "new"); c->sync (); @@ -519,24 +519,24 @@ bool KateSessionManager::chooseSession () return success; } -void KateSessionManager::sessionNew () +void OldKateSessionManager::sessionNew () { - activateSession (new KateSession (this, "", "")); + activateSession (new OldKateSession (this, "", "")); } -void KateSessionManager::sessionOpen () +void OldKateSessionManager::sessionOpen () { - KateSessionOpenDialog *chooser = new KateSessionOpenDialog (0); + OldKateSessionOpenDialog *chooser = new OldKateSessionOpenDialog (0); int res = chooser->exec (); - if (res == KateSessionOpenDialog::resultCancel) + if (res == OldKateSessionOpenDialog::resultCancel) { delete chooser; return; } - KateSession::Ptr s = chooser->selectedSession (); + OldKateSession::Ptr s = chooser->selectedSession (); if (s) activateSession (s); @@ -544,7 +544,7 @@ void KateSessionManager::sessionOpen () delete chooser; } -void KateSessionManager::sessionSave () +void OldKateSessionManager::sessionSave () { // if the active session is valid, just save it :) if (saveActiveSession ()) @@ -566,7 +566,7 @@ void KateSessionManager::sessionSave () saveActiveSession (); } -void KateSessionManager::sessionSaveAs () +void OldKateSessionManager::sessionSaveAs () { bool ok = false; TQString name = KInputDialog::getText (i18n("Specify New Name for Current Session"), i18n("Session name:"), "", &ok); @@ -585,9 +585,9 @@ void KateSessionManager::sessionSaveAs () } -void KateSessionManager::sessionManage () +void OldKateSessionManager::sessionManage () { - KateSessionManageDialog *dlg = new KateSessionManageDialog (0); + OldKateSessionManageDialog *dlg = new OldKateSessionManageDialog (0); dlg->exec (); @@ -596,10 +596,10 @@ void KateSessionManager::sessionManage () //BEGIN CHOOSER DIALOG -class KateSessionChooserItem : public TQListViewItem +class OldKateSessionChooserItem : public TQListViewItem { public: - KateSessionChooserItem (TDEListView *lv, KateSession::Ptr s) + OldKateSessionChooserItem (TDEListView *lv, OldKateSession::Ptr s) : TQListViewItem (lv, s->sessionName()) , session (s) { @@ -608,10 +608,10 @@ class KateSessionChooserItem : public TQListViewItem setText (1, docs); } - KateSession::Ptr session; + OldKateSession::Ptr session; }; -KateSessionChooser::KateSessionChooser (TQWidget *parent, const TQString &lastSession) +OldKateSessionChooser::OldKateSessionChooser (TQWidget *parent, const TQString &lastSession) : KDialogBase ( parent , "" , true @@ -648,10 +648,10 @@ KateSessionChooser::KateSessionChooser (TQWidget *parent, const TQString &lastSe connect (m_sessions, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(selectionChanged())); connect (m_sessions, TQT_SIGNAL(doubleClicked(TQListViewItem *, const TQPoint &, int)), this, TQT_SLOT(slotUser2())); - KateSessionList &slist (KateSessionManager::self()->sessionList()); + OldKateSessionList &slist (OldKateSessionManager::self()->sessionList()); for (unsigned int i=0; i < slist.count(); ++i) { - KateSessionChooserItem *item = new KateSessionChooserItem (m_sessions, slist[i]); + OldKateSessionChooserItem *item = new OldKateSessionChooserItem (m_sessions, slist[i]); if (slist[i]->sessionFileRelative() == lastSession) m_sessions->setSelected (item, true); @@ -665,13 +665,13 @@ KateSessionChooser::KateSessionChooser (TQWidget *parent, const TQString &lastSe selectionChanged (); } -KateSessionChooser::~KateSessionChooser () +OldKateSessionChooser::~OldKateSessionChooser () { } -KateSession::Ptr KateSessionChooser::selectedSession () +OldKateSession::Ptr OldKateSessionChooser::selectedSession () { - KateSessionChooserItem *item = (KateSessionChooserItem *) m_sessions->selectedItem (); + OldKateSessionChooserItem *item = (OldKateSessionChooserItem *) m_sessions->selectedItem (); if (!item) return 0; @@ -679,27 +679,27 @@ KateSession::Ptr KateSessionChooser::selectedSession () return item->session; } -bool KateSessionChooser::reopenLastSession () +bool OldKateSessionChooser::reopenLastSession () { return m_useLast->isChecked (); } -void KateSessionChooser::slotUser2 () +void OldKateSessionChooser::slotUser2 () { done (resultOpen); } -void KateSessionChooser::slotUser3 () +void OldKateSessionChooser::slotUser3 () { done (resultNew); } -void KateSessionChooser::slotUser1 () +void OldKateSessionChooser::slotUser1 () { done (resultQuit); } -void KateSessionChooser::selectionChanged () +void OldKateSessionChooser::selectionChanged () { enableButton (KDialogBase::User2, m_sessions->selectedItem ()); } @@ -708,7 +708,7 @@ void KateSessionChooser::selectionChanged () //BEGIN OPEN DIALOG -KateSessionOpenDialog::KateSessionOpenDialog (TQWidget *parent) +OldKateSessionOpenDialog::OldKateSessionOpenDialog (TQWidget *parent) : KDialogBase ( parent , "" , true @@ -737,22 +737,22 @@ KateSessionOpenDialog::KateSessionOpenDialog (TQWidget *parent) connect (m_sessions, TQT_SIGNAL(doubleClicked(TQListViewItem *, const TQPoint &, int)), this, TQT_SLOT(slotUser2())); - KateSessionList &slist (KateSessionManager::self()->sessionList()); + OldKateSessionList &slist (OldKateSessionManager::self()->sessionList()); for (unsigned int i=0; i < slist.count(); ++i) { - new KateSessionChooserItem (m_sessions, slist[i]); + new OldKateSessionChooserItem (m_sessions, slist[i]); } setResult (resultCancel); } -KateSessionOpenDialog::~KateSessionOpenDialog () +OldKateSessionOpenDialog::~OldKateSessionOpenDialog () { } -KateSession::Ptr KateSessionOpenDialog::selectedSession () +OldKateSession::Ptr OldKateSessionOpenDialog::selectedSession () { - KateSessionChooserItem *item = (KateSessionChooserItem *) m_sessions->selectedItem (); + OldKateSessionChooserItem *item = (OldKateSessionChooserItem *) m_sessions->selectedItem (); if (!item) return 0; @@ -760,12 +760,12 @@ KateSession::Ptr KateSessionOpenDialog::selectedSession () return item->session; } -void KateSessionOpenDialog::slotUser1 () +void OldKateSessionOpenDialog::slotUser1 () { done (resultCancel); } -void KateSessionOpenDialog::slotUser2 () +void OldKateSessionOpenDialog::slotUser2 () { done (resultOk); } @@ -774,7 +774,7 @@ void KateSessionOpenDialog::slotUser2 () //BEGIN MANAGE DIALOG -KateSessionManageDialog::KateSessionManageDialog (TQWidget *parent) +OldKateSessionManageDialog::OldKateSessionManageDialog (TQWidget *parent) : KDialogBase ( parent , "" , true @@ -821,27 +821,27 @@ KateSessionManageDialog::KateSessionManageDialog (TQWidget *parent) selectionChanged (); } -KateSessionManageDialog::~KateSessionManageDialog () +OldKateSessionManageDialog::~OldKateSessionManageDialog () { } -void KateSessionManageDialog::slotUser1 () +void OldKateSessionManageDialog::slotUser1 () { done (0); } -void KateSessionManageDialog::selectionChanged () +void OldKateSessionManageDialog::selectionChanged () { - KateSessionChooserItem *item = (KateSessionChooserItem *) m_sessions->selectedItem (); + OldKateSessionChooserItem *item = (OldKateSessionChooserItem *) m_sessions->selectedItem (); m_rename->setEnabled (item && item->session->sessionFileRelative() != "default.katesession"); m_del->setEnabled (item && item->session->sessionFileRelative() != "default.katesession"); } -void KateSessionManageDialog::rename () +void OldKateSessionManageDialog::rename () { - KateSessionChooserItem *item = (KateSessionChooserItem *) m_sessions->selectedItem (); + OldKateSessionChooserItem *item = (OldKateSessionChooserItem *) m_sessions->selectedItem (); if (!item || item->session->sessionFileRelative() == "default.katesession") return; @@ -862,43 +862,43 @@ void KateSessionManageDialog::rename () updateSessionList (); } -void KateSessionManageDialog::del () +void OldKateSessionManageDialog::del () { - KateSessionChooserItem *item = (KateSessionChooserItem *) m_sessions->selectedItem (); + OldKateSessionChooserItem *item = (OldKateSessionChooserItem *) m_sessions->selectedItem (); if (!item || item->session->sessionFileRelative() == "default.katesession") return; TQFile::remove (item->session->sessionFile()); - KateSessionManager::self()->updateSessionList (); + OldKateSessionManager::self()->updateSessionList (); updateSessionList (); } -void KateSessionManageDialog::updateSessionList () +void OldKateSessionManageDialog::updateSessionList () { m_sessions->clear (); - KateSessionList &slist (KateSessionManager::self()->sessionList()); + OldKateSessionList &slist (OldKateSessionManager::self()->sessionList()); for (unsigned int i=0; i < slist.count(); ++i) { - new KateSessionChooserItem (m_sessions, slist[i]); + new OldKateSessionChooserItem (m_sessions, slist[i]); } } //END MANAGE DIALOG -KateSessionsAction::KateSessionsAction(const TQString& text, TQObject* parent, const char* name ) +OldKateSessionsAction::OldKateSessionsAction(const TQString& text, TQObject* parent, const char* name ) : TDEActionMenu(text, parent, name) { connect(popupMenu(),TQT_SIGNAL(aboutToShow()),this,TQT_SLOT(slotAboutToShow())); } -void KateSessionsAction::slotAboutToShow() +void OldKateSessionsAction::slotAboutToShow() { popupMenu()->clear (); - KateSessionList &slist (KateSessionManager::self()->sessionList()); + OldKateSessionList &slist (OldKateSessionManager::self()->sessionList()); for (unsigned int i=0; i < slist.count(); ++i) { popupMenu()->insertItem ( @@ -908,13 +908,13 @@ void KateSessionsAction::slotAboutToShow() } } -void KateSessionsAction::openSession (int i) +void OldKateSessionsAction::openSession (int i) { - KateSessionList &slist (KateSessionManager::self()->sessionList()); + OldKateSessionList &slist (OldKateSessionManager::self()->sessionList()); if ((uint)i >= slist.count()) return; - KateSessionManager::self()->activateSession(slist[(uint)i]); + OldKateSessionManager::self()->activateSession(slist[(uint)i]); } // kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off; diff --git a/kate/app/katesession.h b/kate/app/katesession.h index b62e72a48..e8038d66e 100644 --- a/kate/app/katesession.h +++ b/kate/app/katesession.h @@ -29,7 +29,7 @@ #include #include -class KateSessionManager; +class OldKateSessionManager; class KDirWatch; class TDEListView; @@ -37,13 +37,13 @@ class KPushButton; class TQCheckBox; -class KateSession : public TDEShared +class OldKateSession : public TDEShared { public: /** * Define a Shared-Pointer type */ - typedef TDESharedPtr Ptr; + typedef TDESharedPtr Ptr; public: /** @@ -52,7 +52,7 @@ class KateSession : public TDEShared * @param name session name * @param manager pointer to the manager */ - KateSession (KateSessionManager *manager, const TQString &fileName, const TQString &name); + OldKateSession (OldKateSessionManager *manager, const TQString &fileName, const TQString &name); /** * init the session object, after construction or create @@ -62,7 +62,7 @@ class KateSession : public TDEShared /** * destruct me */ - ~KateSession (); + ~OldKateSession (); /** * session filename, absolute, calculated out of relative filename + session dir @@ -143,9 +143,9 @@ class KateSession : public TDEShared unsigned int m_documents; /** - * KateSessionMananger + * OldKateSessionMananger */ - KateSessionManager *m_manager; + OldKateSessionManager *m_manager; /** * simpleconfig to read from @@ -158,27 +158,27 @@ class KateSession : public TDEShared KSimpleConfig *m_writeConfig; }; -typedef TQValueList KateSessionList; +typedef TQValueList OldKateSessionList; -class KateSessionManager : public TQObject +class OldKateSessionManager : public TQObject { Q_OBJECT public: - KateSessionManager(TQObject *parent); - ~KateSessionManager(); + OldKateSessionManager(TQObject *parent); + ~OldKateSessionManager(); /** * allow access to this :) * @return instance of the session manager */ - static KateSessionManager *self(); + static OldKateSessionManager *self(); /** * allow access to the session list * kept up to date by watching the dir */ - inline KateSessionList & sessionList () { updateSessionList (); return m_sessionList; } + inline OldKateSessionList & sessionList () { updateSessionList (); return m_sessionList; } /** * activate a session @@ -189,20 +189,20 @@ class KateSessionManager : public TQObject * @param saveLast try to save last session or not? * @param loadNew load new session stuff? */ - void activateSession (KateSession::Ptr session, bool closeLast = true, bool saveLast = true, bool loadNew = true); + void activateSession (OldKateSession::Ptr session, bool closeLast = true, bool saveLast = true, bool loadNew = true); /** * create a new session * @param name session name */ - KateSession::Ptr createSession (const TQString &name); + OldKateSession::Ptr createSession (const TQString &name); /** * return session with given name * if no existing session matches, create new one with this name * @param name session name */ - KateSession::Ptr giveSession (const TQString &name); + OldKateSession::Ptr giveSession (const TQString &name); /** * save current session @@ -218,7 +218,7 @@ class KateSessionManager : public TQObject * sessionFile == empty means we have no session around for this instance of kate * @return session active atm */ - inline KateSession::Ptr activeSession () { return m_activeSession; } + inline OldKateSession::Ptr activeSession () { return m_activeSession; } /** * session dir @@ -277,23 +277,23 @@ class KateSessionManager : public TQObject /** * list of current available sessions */ - KateSessionList m_sessionList; + OldKateSessionList m_sessionList; /** * current active session */ - KateSession::Ptr m_activeSession; + OldKateSession::Ptr m_activeSession; }; -class KateSessionChooser : public KDialogBase +class OldKateSessionChooser : public KDialogBase { Q_OBJECT public: - KateSessionChooser (TQWidget *parent, const TQString &lastSession); - ~KateSessionChooser (); + OldKateSessionChooser (TQWidget *parent, const TQString &lastSession); + ~OldKateSessionChooser (); - KateSession::Ptr selectedSession (); + OldKateSession::Ptr selectedSession (); bool reopenLastSession (); @@ -330,15 +330,15 @@ class KateSessionChooser : public KDialogBase TQCheckBox *m_useLast; }; -class KateSessionOpenDialog : public KDialogBase +class OldKateSessionOpenDialog : public KDialogBase { Q_OBJECT public: - KateSessionOpenDialog (TQWidget *parent); - ~KateSessionOpenDialog (); + OldKateSessionOpenDialog (TQWidget *parent); + ~OldKateSessionOpenDialog (); - KateSession::Ptr selectedSession (); + OldKateSession::Ptr selectedSession (); enum { resultOk, @@ -360,13 +360,13 @@ class KateSessionOpenDialog : public KDialogBase TDEListView *m_sessions; }; -class KateSessionManageDialog : public KDialogBase +class OldKateSessionManageDialog : public KDialogBase { Q_OBJECT public: - KateSessionManageDialog (TQWidget *parent); - ~KateSessionManageDialog (); + OldKateSessionManageDialog (TQWidget *parent); + ~OldKateSessionManageDialog (); protected slots: /** @@ -401,13 +401,13 @@ class KateSessionManageDialog : public KDialogBase KPushButton *m_del; }; -class KateSessionsAction : public TDEActionMenu +class OldKateSessionsAction : public TDEActionMenu { Q_OBJECT public: - KateSessionsAction(const TQString& text, TQObject* parent = 0, const char* name = 0); - ~KateSessionsAction (){;}; + OldKateSessionsAction(const TQString& text, TQObject* parent = 0, const char* name = 0); + ~OldKateSessionsAction (){;}; public slots: void slotAboutToShow(); diff --git a/kate/app/katesessionpanel.cpp b/kate/app/katesessionpanel.cpp index da595b15e..e852a9eee 100644 --- a/kate/app/katesessionpanel.cpp +++ b/kate/app/katesessionpanel.cpp @@ -46,7 +46,7 @@ void KateSessionPanelToolBarParent::resizeEvent (TQResizeEvent*) KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager *viewManager, TQWidget *parent, const char *name) : TQVBox(parent, name), m_mainWin(mainWindow), m_viewManager(viewManager), - m_sessionManager(KateSessionManager::self()), m_actionCollection(new TDEActionCollection(this)) + m_sessionManager(OldKateSessionManager::self()), m_actionCollection(new TDEActionCollection(this)) { // Toolbar setup_toolbar(); diff --git a/kate/app/katesessionpanel.h b/kate/app/katesessionpanel.h index f110fd32b..bbbba6f14 100644 --- a/kate/app/katesessionpanel.h +++ b/kate/app/katesessionpanel.h @@ -33,7 +33,7 @@ class KateMainWindow; class KateViewManager; -class KateSessionManager; +class OldKateSessionManager; class TDEActionCollection; @@ -80,7 +80,7 @@ class KateSessionPanel : public TQVBox KateMainWindow *m_mainWin; KateViewManager *m_viewManager; - KateSessionManager *m_sessionManager; + OldKateSessionManager *m_sessionManager; TDEActionCollection *m_actionCollection; TDEToolBar *m_toolbar; diff --git a/kate/app/kateviewspace.cpp b/kate/app/kateviewspace.cpp index ebc7a3b97..f53ec7468 100644 --- a/kate/app/kateviewspace.cpp +++ b/kate/app/kateviewspace.cpp @@ -114,7 +114,7 @@ void KateViewSpace::addView(Kate::View* v, bool show) { TQString vgroup = TQString("%1 %2").arg(m_group).arg(fn); - KateSession::Ptr as = KateSessionManager::self()->activeSession (); + OldKateSession::Ptr as = OldKateSessionManager::self()->activeSession (); if ( as->configRead() && as->configRead()->hasGroup( vgroup ) ) { as->configRead()->setGroup( vgroup ); -- cgit v1.2.1 From f0f642f6b23b9a38727944a6db194bf4d16f0377 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Mon, 28 Sep 2015 00:45:39 +0900 Subject: Added initial version of new KateSession and KateSessionManager. The old version of the same classes is still the default for the time being. Signed-off-by: Michele Calgaro --- kate/app/katesession.cpp | 265 +++++++++++++++++++++++++++++++++++++++++++++++ kate/app/katesession.h | 109 ++++++++++++++++++- 2 files changed, 373 insertions(+), 1 deletion(-) (limited to 'kate') diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index e71d383f1..a6547393a 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -48,6 +48,271 @@ #include #include +// 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_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_SESSIONS_LIST = "Sessions list"; +} + +KateSession::KateSession(const TQString &sessionName, const TQString &filename, bool isFullName) : + m_sessionName(sessionName), m_filename(filename), m_isFullName(isFullName), + m_readOnly(false), m_docCount(0), m_documents(), m_config(NULL) +{ + if (m_isFullName && TDEGlobal::dirs()->exists(m_filename)) + { + // Create config object if the session file already exists + m_config = new KSimpleConfig(m_filename, m_readOnly); + m_config->setGroup(KS_GENERAL); + // Session name + if (m_sessionName.isEmpty()) + { + m_sessionName = m_config->readEntry(KS_NAME, i18n(KS_UNNAMED)); + } + // Read only + m_readOnly = m_config->readBoolEntry(KS_READONLY, false); + m_config->setReadOnly(m_readOnly); + // Document list + if (m_config->hasGroup(KS_DOCLIST)) + { + // Read new style document list (from TDE R14.1.0) + m_config->setGroup(KS_DOCLIST); + m_docCount = m_config->readNumEntry(KS_DOCCOUNT, 0); + for (int i=0; ireadEntry(TQString("URL_%1").arg(i)); + if (!urlStr.isEmpty()) + { + // Filter out empty URLs + m_documents.append(urlStr); + } + } + } + else + { + // Create document list from old session configuration + // to effortlessly import existing sessions + m_config->setGroup(KS_OPENDOC); + m_docCount = m_config->readNumEntry(KS_COUNT, 0); + for (int i=0; isetGroup(TQString("Document %1").arg(i)); + TQString urlStr = m_config->readEntry("URL"); + if (!urlStr.isEmpty()) + { + // Filter out empty URLs + m_documents.append(urlStr); + } + } + } + // Update document count again, in case empty URLs were found + m_docCount = static_cast(m_documents.count()); + } + if (m_sessionName.isEmpty()) + { + m_sessionName = i18n(KS_UNNAMED); + } + if (m_docCount == 0) + { + m_documents.clear(); + } +} + +//------------------------------------ +KateSession::~KateSession() +{ + if (m_config) + { + delete m_config; + } +} + +//------------------------------------ +void KateSession::setSessionName(const TQString &sessionName) +{ + m_sessionName = sessionName; + if (m_sessionName.isEmpty()) + { + m_sessionName = i18n(KS_UNNAMED); + } +} + +//------------------------------------ +void KateSession::setReadOnly(bool readOnly) +{ + if (!m_readOnly && readOnly) + { + // When a session is turned read only, make sure the current + // status is first saved to disk + save(); + } + m_readOnly = readOnly; + if (m_config) + { + m_config->setReadOnly(m_readOnly); + } +} + +//------------------------------------ +void KateSession::save() +{ + if (m_readOnly) + return; + + if (!m_isFullName) + { + // create a new session filename + int s = time(0); + 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; + } + } + } + + if (!m_config) + { + m_config = new KSimpleConfig(m_filename); + } + if (m_config->hasGroup(KS_GENERAL)) + { + m_config->deleteGroup(KS_GENERAL); + } + m_config->setGroup(KS_GENERAL); + m_config->writeEntry(KS_NAME, m_sessionName); + m_config->writeEntry(KS_READONLY, m_readOnly); + + if (m_config->hasGroup(KS_DOCLIST)) + { + m_config->deleteGroup(KS_DOCLIST); + } + m_config->setGroup(KS_DOCLIST); + m_config->writeEntry(KS_DOCCOUNT, m_docCount); + for (int i=0; iwriteEntry(TQString("URL_%1").arg(i), m_documents[i]); + } + + m_config->sync(); +} + +//------------------------------------ +KateSessionManager *KateSessionManager::ksm_instance = NULL; + +//------------------------------------ +KateSessionManager* KateSessionManager::self() +{ + if (!KateSessionManager::ksm_instance) + { + KateSessionManager::ksm_instance = new KateSessionManager(); + } + return KateSessionManager::ksm_instance; +} + +//------------------------------------ +KateSessionManager::KateSessionManager() : + m_baseDir(locateLocal("data", KSM_DIR)+"/"), m_configFile(m_baseDir + KSM_FILE), + m_sessionsCount(0), m_sessions(), m_config(NULL) +{ + m_sessions.setAutoDelete(true); + + if (TDEGlobal::dirs()->exists(m_configFile)) + { + // Read new style configuration (from TDE R14.1.0) + m_config = new KSimpleConfig(m_configFile); + m_config->setGroup(KSM_SESSIONS_LIST); + m_sessionsCount = m_config->readNumEntry(KSM_SESSIONS_COUNT, 0); + for (int i=0; ireadEntry(TQString("URL_%1").arg(i)); + if (!urlStr.isEmpty() && TDEGlobal::dirs()->exists(urlStr)) + { + // Filter out empty URLs or non existing sessions + m_sessions.append(new KateSession(TQString::null, urlStr, true)); + } + } + } + else + { + // Create sessions list from session files + // to effortlessly import existing sessions + TQDir sessionDir(m_baseDir, "*.katesession"); + for (unsigned int i=0; i(m_sessions.count()); +} + +//------------------------------------ +KateSessionManager::~KateSessionManager() +{ + saveConfig(); + if (m_config) + { + delete m_config; + } + if (!m_sessions.isEmpty()) + { + m_sessions.clear(); + } +} + +//------------------------------------ +void KateSessionManager::saveConfig() +{ + if (!m_config) + { + m_config = new KSimpleConfig(m_configFile); + } + if (m_config->hasGroup(KSM_SESSIONS_LIST)) + { + m_config->deleteGroup(KSM_SESSIONS_LIST); + } + m_config->setGroup(KSM_SESSIONS_LIST); + m_config->writeEntry(KSM_SESSIONS_COUNT, m_sessionsCount); + for (int i=0; isave(); + m_config->writeEntry(TQString("URL_%1").arg(i), m_sessions[i]->getSessionFilename()); + } + m_config->sync(); +} + + + + + + +//------------------------------------ +//------------------------------------ +//------------------------------------ +//------------------------------------ +// Michele - to be removed with OldKateSession bool operator<( const OldKateSession::Ptr& a, const OldKateSession::Ptr& b ) { return a->sessionName().lower() < b->sessionName().lower(); diff --git a/kate/app/katesession.h b/kate/app/katesession.h index e8038d66e..81a4a77c5 100644 --- a/kate/app/katesession.h +++ b/kate/app/katesession.h @@ -27,9 +27,11 @@ #include #include +#include #include +#include -class OldKateSessionManager; +class OldKateSessionManager; // Michele - to be removed with OldKateSession class KDirWatch; class TDEListView; @@ -37,6 +39,111 @@ class KPushButton; class TQCheckBox; +class KateSession +{ + public: + + /** + * create a new session and read the config from fileName if it exists + * @param sessionName session name + * @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); + + /** + * Destructor + */ + ~KateSession(); + + /** + * Returns the session name + */ + const TQString& getSessionName() const { return m_sessionName; } + /** + * Set the new session name + * @param sessionName the new session name + */ + void setSessionName(const TQString &sessionName); + + /** + * Returns whether the session is read only or not + */ + bool isReadOnly() const { return m_readOnly; } + /** + * Set session read only status + * @param readOnly if true, the session config can not be saved to file + */ + void setReadOnly(bool readOnly); + + /** + * Returns the session filename + */ + const TQString& getSessionFilename() const { return m_filename; } + + /** + * Save session info + * @return true if the session config is saved, false otherwise + */ + void save(); + + + private: + TQString m_sessionName; + TQString m_filename; + bool m_isFullName; // true -> m_filename is a full filename + // false -> m_filename is a folder name. + bool m_readOnly; + int m_docCount; // number of documents in the session + TQStringList m_documents; // document URLs + KSimpleConfig *m_config; // session config + +}; + + +//------------------------------------ +class KateSessionManager +{ + public: + + /** + * get a pointer to the unique KateSessionManager instance. + * If the manager does not exist yet, create it. + */ + static KateSessionManager* self(); + + /** + * Destructor + */ + ~KateSessionManager(); + + /** + * Save session manager info + */ + void saveConfig(); + + + private: + KateSessionManager(); + + TQString m_baseDir; // folder where session files are stored + TQString m_configFile; // file where the session list config is stored + int m_sessionsCount; // number of sessions + TQPtrList m_sessions; // session list + KSimpleConfig *m_config; // session manager config + + static KateSessionManager *ksm_instance; // the only KateSessionManager instance +}; + + + + + +//------------------------------------ +//------------------------------------ +//------------------------------------ class OldKateSession : public TDEShared { public: -- cgit v1.2.1 From de91a161b1555bca58c4c30c6367dcc38750ca17 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Fri, 23 Oct 2015 17:59:00 +0700 Subject: Populated session panel. Now able to switch session within the new panel. *** NOTE *** In this commit both the old and new session managers are active, therefore funny things occasionally happen. Then won't be the case from the next commit since the old session manager will be disabled. Signed-off-by: Michele Calgaro --- kate/app/kateapp.cpp | 32 ++++++++++---------- kate/app/kateapp.h | 8 +++-- kate/app/kateappIface.cpp | 4 +-- kate/app/katemainwindow.cpp | 6 ++-- kate/app/katesession.cpp | 68 ++++++++++++++++++++++++++++++++++--------- kate/app/katesession.h | 37 +++++++++++++++++++---- kate/app/katesessionpanel.cpp | 65 +++++++++++++++++++++++++++++------------ kate/app/katesessionpanel.h | 9 +++--- 8 files changed, 165 insertions(+), 64 deletions(-) (limited to 'kate') diff --git a/kate/app/kateapp.cpp b/kate/app/kateapp.cpp index 2f54a8e23..2ff68ed1a 100644 --- a/kate/app/kateapp.cpp +++ b/kate/app/kateapp.cpp @@ -75,7 +75,8 @@ KateApp::KateApp (TDECmdLineArgs *args) m_pluginManager = new KatePluginManager (TQT_TQOBJECT(this)); // session manager up - m_sessionManager = new OldKateSessionManager (TQT_TQOBJECT(this)); + m_oldSessionManager = new OldKateSessionManager (TQT_TQOBJECT(this)); + m_sessionManager = KateSessionManager::self(); // application dcop interface m_obj = new KateAppDCOPIface (this); @@ -105,14 +106,11 @@ KateApp::KateApp (TDECmdLineArgs *args) KateApp::~KateApp () { - // cu dcop interface - delete m_obj; - - // cu plugin manager - delete m_pluginManager; - - // delete this now, or we crash - delete m_docManager; + delete m_obj; // cu dcop interface + delete m_pluginManager; // cu plugin manager + delete m_sessionManager; // delete session manager + delete m_oldSessionManager; // delete session manager + delete m_docManager; // delete document manager. Do this now, or we crash } KateApp *KateApp::self () @@ -147,8 +145,7 @@ void KateApp::restoreKate () // activate again correct session!!! sessionConfig()->setGroup("General"); TQString lastSession (sessionConfig()->readEntry ("Last Session", "default.katesession")); - sessionManager()->activateSession (new OldKateSession (sessionManager(), lastSession, ""), false, false, false); - + oldSessionManager()->activateSession (new OldKateSession (oldSessionManager(), lastSession, ""), false, false, false); m_docManager->restoreDocumentList (sessionConfig()); Kate::Document::setOpenErrorDialogsActivated (true); @@ -170,12 +167,12 @@ bool KateApp::startupKate () // user specified session to open if (m_args->isSet ("start")) { - sessionManager()->activateSession (sessionManager()->giveSession (TQString::fromLocal8Bit(m_args->getOption("start"))), false, false); + oldSessionManager()->activateSession (oldSessionManager()->giveSession (TQString::fromLocal8Bit(m_args->getOption("start"))), false, false); } else { // let the user choose session if possible - if (!sessionManager()->chooseSession ()) + if (!oldSessionManager()->chooseSession ()) { // we will exit kate now, notify the rest of the world we are done TDEStartupInfo::appStarted (startupId()); @@ -272,7 +269,7 @@ void KateApp::shutdownKate (KateMainWindow *win) if (!win->queryClose_internal()) return; - sessionManager()->saveActiveSession(true, true); + oldSessionManager()->saveActiveSession(true, true); // detach the dcopClient dcopClient()->detach(); @@ -294,7 +291,12 @@ KateDocManager *KateApp::documentManager () return m_docManager; } -OldKateSessionManager *KateApp::sessionManager () +OldKateSessionManager *KateApp::oldSessionManager () +{ + return m_oldSessionManager; +} + +KateSessionManager* KateApp::sessionManager() { return m_sessionManager; } diff --git a/kate/app/kateapp.h b/kate/app/kateapp.h index 2b6c1e2cd..73b9553ee 100644 --- a/kate/app/kateapp.h +++ b/kate/app/kateapp.h @@ -27,6 +27,7 @@ #include class OldKateSessionManager; +class KateSessionManager; class KateAppDCOPIface; namespace Kate { @@ -128,7 +129,8 @@ class KDE_EXPORT KateApp : public TDEApplication * accessor to session manager * @return session manager instance */ - OldKateSessionManager *sessionManager (); + OldKateSessionManager *oldSessionManager (); + KateSessionManager *sessionManager(); /** * window management @@ -222,7 +224,9 @@ class KDE_EXPORT KateApp : public TDEApplication /** * session manager */ - OldKateSessionManager *m_sessionManager; + OldKateSessionManager *m_oldSessionManager; + KateSessionManager *m_sessionManager; + /** * known main windows diff --git a/kate/app/kateappIface.cpp b/kate/app/kateappIface.cpp index 259e48b89..57f0b63d1 100644 --- a/kate/app/kateappIface.cpp +++ b/kate/app/kateappIface.cpp @@ -91,14 +91,14 @@ bool KateAppDCOPIface::openInput (TQString text) bool KateAppDCOPIface::activateSession (TQString session) { - m_app->sessionManager()->activateSession (m_app->sessionManager()->giveSession (session)); + m_app->oldSessionManager()->activateSession (m_app->oldSessionManager()->giveSession (session)); return true; } const TQString & KateAppDCOPIface::session() const { - return m_app->sessionManager()->activeSession()->sessionName(); + return m_app->oldSessionManager()->activeSession()->sessionName(); } // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/katemainwindow.cpp b/kate/app/katemainwindow.cpp index 794e1a777..1546c575b 100644 --- a/kate/app/katemainwindow.cpp +++ b/kate/app/katemainwindow.cpp @@ -370,7 +370,7 @@ bool KateMainWindow::queryClose() // and save docs if we really close down ! if ( queryClose_internal () ) { - KateApp::self()->sessionManager()->saveActiveSession(true, true); + KateApp::self()->oldSessionManager()->saveActiveSession(true, true); // detach the dcopClient KateApp::self()->dcopClient()->detach(); @@ -824,7 +824,7 @@ void KateMainWindow::updateCaption (Kate::Document *doc) c = m_viewManager->activeView()->getDoc()->url().prettyURL(); } - TQString sessName = KateApp::self()->sessionManager()->activeSession()->sessionName(); + TQString sessName = KateApp::self()->oldSessionManager()->activeSession()->sessionName(); if ( !sessName.isEmpty() ) sessName = TQString("%1: ").arg( sessName ); @@ -858,7 +858,7 @@ void KateMainWindow::saveGlobalProperties( TDEConfig* sessionConfig ) KateDocManager::self()->saveDocumentList (sessionConfig); sessionConfig->setGroup("General"); - sessionConfig->writeEntry ("Last Session", KateApp::self()->sessionManager()->activeSession()->sessionFileRelative()); + sessionConfig->writeEntry ("Last Session", KateApp::self()->oldSessionManager()->activeSession()->sessionFileRelative()); } // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index a6547393a..c66c171cf 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -48,6 +48,9 @@ #include #include +// FIXME general: need to keep doc list and current session's m_documents in synchro +// all the time (doc open, doc closed, doc renamed) + // String constants namespace { @@ -65,6 +68,7 @@ namespace const char *KSM_DIR = "kate/sessions"; const char *KSM_FILE = "sessions.list"; const char *KSM_SESSIONS_COUNT = "Sessions count"; + const char *KSM_ACTIVE_SESSION_ID = "Active session id"; const char *KSM_SESSIONS_LIST = "Sessions list"; } @@ -125,10 +129,7 @@ KateSession::KateSession(const TQString &sessionName, const TQString &filename, { m_sessionName = i18n(KS_UNNAMED); } - if (m_docCount == 0) - { - m_documents.clear(); - } + // FIXME: needs to make sure doc list and m_documents are in synchro here } //------------------------------------ @@ -153,12 +154,6 @@ void KateSession::setSessionName(const TQString &sessionName) //------------------------------------ void KateSession::setReadOnly(bool readOnly) { - if (!m_readOnly && readOnly) - { - // When a session is turned read only, make sure the current - // status is first saved to disk - save(); - } m_readOnly = readOnly; if (m_config) { @@ -167,7 +162,7 @@ void KateSession::setReadOnly(bool readOnly) } //------------------------------------ -void KateSession::save() +void KateSession::save(bool saveDocList) { if (m_readOnly) return; @@ -196,6 +191,7 @@ void KateSession::save() { m_config = new KSimpleConfig(m_filename); } + if (m_config->hasGroup(KS_GENERAL)) { m_config->deleteGroup(KS_GENERAL); @@ -214,10 +210,26 @@ void KateSession::save() { m_config->writeEntry(TQString("URL_%1").arg(i), m_documents[i]); } + if (saveDocList) + { + KateDocManager::self()->saveDocumentList(m_config); + } m_config->sync(); } +//------------------------------------ +void KateSession::activate() +{ + KateDocManager::self()->closeAllDocuments(); + Kate::Document::setOpenErrorDialogsActivated(false); + if (m_config) + { + KateApp::self()->documentManager()->restoreDocumentList(m_config); + } + Kate::Document::setOpenErrorDialogsActivated(true); +} + //------------------------------------ KateSessionManager *KateSessionManager::ksm_instance = NULL; @@ -234,7 +246,7 @@ KateSessionManager* KateSessionManager::self() //------------------------------------ KateSessionManager::KateSessionManager() : m_baseDir(locateLocal("data", KSM_DIR)+"/"), m_configFile(m_baseDir + KSM_FILE), - m_sessionsCount(0), m_sessions(), m_config(NULL) + m_sessionsCount(0), m_activeSessionId(-1), m_sessions(), m_config(NULL) { m_sessions.setAutoDelete(true); @@ -244,6 +256,7 @@ KateSessionManager::KateSessionManager() : m_config = new KSimpleConfig(m_configFile); m_config->setGroup(KSM_SESSIONS_LIST); m_sessionsCount = m_config->readNumEntry(KSM_SESSIONS_COUNT, 0); + m_activeSessionId = m_config->readNumEntry(KSM_ACTIVE_SESSION_ID, -1); for (int i=0; ireadEntry(TQString("URL_%1").arg(i)); @@ -265,6 +278,11 @@ KateSessionManager::KateSessionManager() : } } m_sessionsCount = static_cast(m_sessions.count()); + if (m_activeSessionId < 0 || m_activeSessionId >= m_sessionsCount) + { + m_activeSessionId = 0; // Invalid active session was detected. Use first in the list + } + m_sessions[m_activeSessionId]->activate(); } //------------------------------------ @@ -294,15 +312,37 @@ void KateSessionManager::saveConfig() } m_config->setGroup(KSM_SESSIONS_LIST); m_config->writeEntry(KSM_SESSIONS_COUNT, m_sessionsCount); + m_config->writeEntry(KSM_ACTIVE_SESSION_ID, m_activeSessionId); for (int i=0; isave(); + m_sessions[i]->save(i == m_activeSessionId); m_config->writeEntry(TQString("URL_%1").arg(i), m_sessions[i]->getSessionFilename()); } m_config->sync(); } +//------------------------------------ +bool KateSessionManager::activateSession(int sessionId, bool saveCurr) +{ + if (sessionId == m_activeSessionId) + { + return true; + } + + // First check if all documents can be closed safely + if (KateApp::self()->activeMainWindow()) + { + if (!KateApp::self()->activeMainWindow()->queryClose_internal()) + return false; + } + + m_sessions[m_activeSessionId]->save(true); + m_sessions[sessionId]->activate(); + m_activeSessionId = sessionId; + return true; +} + @@ -485,7 +525,7 @@ OldKateSessionManager::~OldKateSessionManager() OldKateSessionManager *OldKateSessionManager::self() { - return KateApp::self()->sessionManager (); + return KateApp::self()->oldSessionManager (); } void OldKateSessionManager::dirty (const TQString &) diff --git a/kate/app/katesession.h b/kate/app/katesession.h index 81a4a77c5..3904f9f0f 100644 --- a/kate/app/katesession.h +++ b/kate/app/katesession.h @@ -59,7 +59,7 @@ class KateSession ~KateSession(); /** - * Returns the session name + * @return the session name */ const TQString& getSessionName() const { return m_sessionName; } /** @@ -69,7 +69,7 @@ class KateSession void setSessionName(const TQString &sessionName); /** - * Returns whether the session is read only or not + * @return whether the session is read only or not */ bool isReadOnly() const { return m_readOnly; } /** @@ -79,16 +79,20 @@ class KateSession void setReadOnly(bool readOnly); /** - * Returns the session filename + * @return the session filename */ const TQString& getSessionFilename() const { return m_filename; } /** * Save session info - * @return true if the session config is saved, false otherwise + * @param saveDocList if true, save also the information about the documents currently open */ - void save(); + void save(bool saveDocList); + /** + * Activate the session + */ + void activate(); private: TQString m_sessionName; @@ -124,6 +128,28 @@ class KateSessionManager */ void saveConfig(); + /** + * @return the active session id + */ + int getActiveSessionId() const { return m_activeSessionId; } + + /** + * @return a reference to the active session + */ + KateSession* getActiveSession() { return m_sessions[m_activeSessionId]; } + + /** + * @return a reference to the sessions list + */ + TQPtrList& getSessionsList() { return m_sessions; } + + /** + * Activates the selected session. + * @param sessionId the id of the session to activate + * @param saveCurr if true, save the current session before activating the new one + * @return whether the session was activated or not + */ + bool activateSession(int sessionId, bool saveCurr = true); private: KateSessionManager(); @@ -131,6 +157,7 @@ class KateSessionManager TQString m_baseDir; // folder where session files are stored TQString m_configFile; // file where the session list config is stored int m_sessionsCount; // number of sessions + int m_activeSessionId; // index of the active session TQPtrList m_sessions; // session list KSimpleConfig *m_config; // session manager config diff --git a/kate/app/katesessionpanel.cpp b/kate/app/katesessionpanel.cpp index e852a9eee..93bca5d06 100644 --- a/kate/app/katesessionpanel.cpp +++ b/kate/app/katesessionpanel.cpp @@ -25,6 +25,7 @@ #include #include +#include void KateSessionPanelToolBarParent::setToolBar(TDEToolBar *tbar) @@ -46,23 +47,41 @@ void KateSessionPanelToolBarParent::resizeEvent (TQResizeEvent*) KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager *viewManager, TQWidget *parent, const char *name) : TQVBox(parent, name), m_mainWin(mainWindow), m_viewManager(viewManager), - m_sessionManager(OldKateSessionManager::self()), m_actionCollection(new TDEActionCollection(this)) + m_sessionManager(KateSessionManager::self()), m_actionCollection(new TDEActionCollection(this)), + m_columnSessionId(0), m_columnPixmap(0) { // Toolbar setup_toolbar(); // Listview m_listview = new TDEListView(this); - m_listview->setRootIsDecorated(true); - m_listview->setSorting(-1); + m_listview->header()->hide(); + m_listview->addColumn("Session name"); + m_columnSessionId = m_listview->addColumn("Session id", 0); + m_columnPixmap = m_listview->addColumn("Pixmap", 24); + m_listview->setColumnAlignment(2, TQt::AlignCenter); m_listview->setMinimumWidth(m_listview->sizeHint().width()); + m_listview->setSorting(-1); + //m_listview->setRootIsDecorated(true); // to enable after inserting doc list + + TQPtrList& sessions = m_sessionManager->getSessionsList(); + for (int idx = sessions.count()-1; idx >= 0; --idx) + { + new TDEListViewItem(m_listview, sessions[idx]->getSessionName(), TQString("%1").arg(idx)); + if (idx == m_sessionManager->getActiveSessionId()) + { + m_listview->setSelected(m_listview->firstChild(), true); + m_listview->firstChild()->setPixmap(m_columnPixmap, SmallIcon("ok")); + } + } + } //------------------------------------------- void KateSessionPanel::setup_toolbar() { // Toolbar widget and frame - KateSessionPanelToolBarParent *tbarParent=new KateSessionPanelToolBarParent(this); + KateSessionPanelToolBarParent *tbarParent = new KateSessionPanelToolBarParent(this); m_toolbar = new TDEToolBar(tbarParent, "Kate Session Panel Toolbar", true); tbarParent->setToolBar(m_toolbar); m_toolbar->setMovingEnabled(false); @@ -71,8 +90,10 @@ void KateSessionPanel::setup_toolbar() m_toolbar->setIconSize(16); m_toolbar->setEnableContextMenu(false); +//FIXME : uncomment and activate as long as the new session manager gets fixed // Toolbar actions TDEAction *a; +/* a = new TDEAction(i18n("New"), SmallIcon("list-add"), 0, TQT_TQOBJECT(m_sessionManager), TQT_SLOT(sessionNew()), m_actionCollection, "session_new"); a->setWhatsThis(i18n("Create a new session.")); @@ -99,12 +120,12 @@ void KateSessionPanel::setup_toolbar() a->plug(m_toolbar); m_toolbar->insertLineSeparator(); - +*/ a = new TDEAction(i18n("Activate"), SmallIcon("forward"), 0, TQT_TQOBJECT(this), TQT_SLOT(sessionActivate()), m_actionCollection, "session_activate"); a->setWhatsThis(i18n("Activate the selected session.")); a->plug(m_toolbar); - +/* TDEToggleAction *tglA = new TDEToggleAction(i18n("Toggle read only"), SmallIcon("encrypted"), 0, TQT_TQOBJECT(this), TQT_SLOT(sessionToggleReadOnly()), m_actionCollection, "session_toggle_read_only"); tglA->setWhatsThis(i18n("Toggle read only status for the selected session.

" @@ -122,18 +143,7 @@ void KateSessionPanel::setup_toolbar() TQT_TQOBJECT(this), TQT_SLOT(sessionMoveDown()), m_actionCollection, "session_move_down"); a->setWhatsThis(i18n("Move down the selected session.")); a->plug(m_toolbar); - - m_toolbar->insertLineSeparator(); - - a = new TDEAction(i18n("Open"), SmallIcon("document-open"), 0, - TQT_TQOBJECT(m_sessionManager), TQT_SLOT(sessionOpen()), m_actionCollection, "session_open"); - a->setWhatsThis(i18n("Switch to another session chosen from a list of existing ones.")); - a->plug(m_toolbar); - - a = new TDEAction(i18n("Manage"), SmallIcon("view_choose"), 0, - TQT_TQOBJECT(m_sessionManager), TQT_SLOT(sessionManage()), m_actionCollection, "session_manage"); - a->setWhatsThis(i18n("Manage existing sessions.")); - a->plug(m_toolbar); +*/ } //------------------------------------------- @@ -163,7 +173,24 @@ void KateSessionPanel::deleteSession() //------------------------------------------- void KateSessionPanel::sessionActivate() { -//TODO + TQListViewItem *newSessionItem = m_listview->selectedItem(); + int currSessionId = m_sessionManager->getActiveSessionId(); + if (!newSessionItem) + return; + int newSessionId = newSessionItem->text(m_columnSessionId).toInt(); + if (newSessionId != currSessionId) + { + if (!m_sessionManager->activateSession(newSessionId)) + return; + + TQListViewItem *item = m_listview->firstChild(); + for (int idx = 0; idx < currSessionId; ++idx) + { + item = item->nextSibling(); + } + item->setPixmap(m_columnPixmap, TQPixmap()); + newSessionItem->setPixmap(m_columnPixmap, SmallIcon("ok")); + } } //------------------------------------------- diff --git a/kate/app/katesessionpanel.h b/kate/app/katesessionpanel.h index bbbba6f14..71120b7e1 100644 --- a/kate/app/katesessionpanel.h +++ b/kate/app/katesessionpanel.h @@ -33,7 +33,7 @@ class KateMainWindow; class KateViewManager; -class OldKateSessionManager; +class KateSessionManager; class TDEActionCollection; @@ -80,11 +80,12 @@ class KateSessionPanel : public TQVBox KateMainWindow *m_mainWin; KateViewManager *m_viewManager; - OldKateSessionManager *m_sessionManager; + KateSessionManager *m_sessionManager; TDEActionCollection *m_actionCollection; - - TDEToolBar *m_toolbar; + TDEToolBar *m_toolbar; TDEListView *m_listview; + int m_columnSessionId; + int m_columnPixmap; }; -- cgit v1.2.1 From 099c8a8821e896884180f57dda94af5fdbd87aaa Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Mon, 8 Feb 2016 16:39:21 +0700 Subject: Disabled the old session manager and switched permanently to the new one. Lot of functionality still missing. It is possible to switch sessions from the session panel (either by the activate pushbutton or by executing a listview item). Kate's session settings are currently not yet supported (last session is saved and restored by default). Signed-off-by: Michele Calgaro --- kate/app/kateapp.cpp | 41 ++- kate/app/kateapp.h | 3 - kate/app/kateappIface.cpp | 9 +- kate/app/katemainwindow.cpp | 14 +- kate/app/katesession.cpp | 114 +++++- kate/app/katesession.h | 786 ++++++++++++++++++++++-------------------- kate/app/katesessionpanel.cpp | 16 +- kate/app/katesessionpanel.h | 1 + kate/app/kateviewspace.cpp | 11 +- 9 files changed, 567 insertions(+), 428 deletions(-) (limited to 'kate') diff --git a/kate/app/kateapp.cpp b/kate/app/kateapp.cpp index 2ff68ed1a..f6089cb75 100644 --- a/kate/app/kateapp.cpp +++ b/kate/app/kateapp.cpp @@ -75,7 +75,6 @@ KateApp::KateApp (TDECmdLineArgs *args) m_pluginManager = new KatePluginManager (TQT_TQOBJECT(this)); // session manager up - m_oldSessionManager = new OldKateSessionManager (TQT_TQOBJECT(this)); m_sessionManager = KateSessionManager::self(); // application dcop interface @@ -109,7 +108,6 @@ KateApp::~KateApp () delete m_obj; // cu dcop interface delete m_pluginManager; // cu plugin manager delete m_sessionManager; // delete session manager - delete m_oldSessionManager; // delete session manager delete m_docManager; // delete document manager. Do this now, or we crash } @@ -137,24 +135,22 @@ TQString KateApp::kateVersion (bool fullVersion) return fullVersion ? TQString ("2.5.%1").arg(KDE::versionMajor()) : TQString ("%1.%2").arg(2.5); } -void KateApp::restoreKate () +void KateApp::restoreKate() { // restore the nice files ;) we need it - Kate::Document::setOpenErrorDialogsActivated (false); + Kate::Document::setOpenErrorDialogsActivated(false); - // activate again correct session!!! - sessionConfig()->setGroup("General"); - TQString lastSession (sessionConfig()->readEntry ("Last Session", "default.katesession")); - oldSessionManager()->activateSession (new OldKateSession (oldSessionManager(), lastSession, ""), false, false, false); - m_docManager->restoreDocumentList (sessionConfig()); + // restore last session + sessionManager()->restoreLastSession(); + m_docManager->restoreDocumentList(sessionConfig()); - Kate::Document::setOpenErrorDialogsActivated (true); + Kate::Document::setOpenErrorDialogsActivated(true); // restore all windows ;) for (int n=1; TDEMainWindow::canBeRestored(n); n++) newMainWindow(sessionConfig(), TQString ("%1").arg(n)); - // oh, no mainwindow, create one, should not happen, but make sure ;) + // no mainwindow, create one, should not happen, but make sure ;) if (mainWindows() == 0) newMainWindow (); @@ -167,17 +163,24 @@ bool KateApp::startupKate () // user specified session to open if (m_args->isSet ("start")) { - oldSessionManager()->activateSession (oldSessionManager()->giveSession (TQString::fromLocal8Bit(m_args->getOption("start"))), false, false); + // MIKE fixme: need to handle this functionality + sessionManager()->activateSession( + sessionManager()->getSessionIdFromName(TQString::fromLocal8Bit(m_args->getOption("start")))); } else { + // MIKE: for the time being just open last session. + // FIXME: need to add support for startup session options + sessionManager()->restoreLastSession(); + + // MIKE fixme: need to handle this functionality // let the user choose session if possible - if (!oldSessionManager()->chooseSession ()) + /*if (!oldSessionManager()->chooseSession ()) { // we will exit kate now, notify the rest of the world we are done TDEStartupInfo::appStarted (startupId()); return false; - } + }*/ } // oh, no mainwindow, create one, should not happen, but make sure ;) @@ -264,12 +267,13 @@ bool KateApp::startupKate () return true; } -void KateApp::shutdownKate (KateMainWindow *win) +void KateApp::shutdownKate(KateMainWindow *win) { if (!win->queryClose_internal()) return; - oldSessionManager()->saveActiveSession(true, true); + // Save current session here to make sure all GUI elements are saved correctly + sessionManager()->saveActiveSession(); // detach the dcopClient dcopClient()->detach(); @@ -291,11 +295,6 @@ KateDocManager *KateApp::documentManager () return m_docManager; } -OldKateSessionManager *KateApp::oldSessionManager () -{ - return m_oldSessionManager; -} - KateSessionManager* KateApp::sessionManager() { return m_sessionManager; diff --git a/kate/app/kateapp.h b/kate/app/kateapp.h index 73b9553ee..c1c90aa46 100644 --- a/kate/app/kateapp.h +++ b/kate/app/kateapp.h @@ -26,7 +26,6 @@ #include -class OldKateSessionManager; class KateSessionManager; class KateAppDCOPIface; @@ -129,7 +128,6 @@ class KDE_EXPORT KateApp : public TDEApplication * accessor to session manager * @return session manager instance */ - OldKateSessionManager *oldSessionManager (); KateSessionManager *sessionManager(); /** @@ -224,7 +222,6 @@ class KDE_EXPORT KateApp : public TDEApplication /** * session manager */ - OldKateSessionManager *m_oldSessionManager; KateSessionManager *m_sessionManager; diff --git a/kate/app/kateappIface.cpp b/kate/app/kateappIface.cpp index 57f0b63d1..3ce9229b4 100644 --- a/kate/app/kateappIface.cpp +++ b/kate/app/kateappIface.cpp @@ -89,16 +89,17 @@ bool KateAppDCOPIface::openInput (TQString text) return m_app->openInput (text); } -bool KateAppDCOPIface::activateSession (TQString session) +bool KateAppDCOPIface::activateSession(TQString session) { - m_app->oldSessionManager()->activateSession (m_app->oldSessionManager()->giveSession (session)); +// MIKE: to fix +// m_app->sessionManager()->activateSession (m_app->oldSessionManager()->giveSession (session)); return true; } -const TQString & KateAppDCOPIface::session() const +const TQString& KateAppDCOPIface::session() const { - return m_app->oldSessionManager()->activeSession()->sessionName(); + return m_app->sessionManager()->getActiveSessionName(); } // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/katemainwindow.cpp b/kate/app/katemainwindow.cpp index 1546c575b..527dbdc9c 100644 --- a/kate/app/katemainwindow.cpp +++ b/kate/app/katemainwindow.cpp @@ -305,8 +305,9 @@ void KateMainWindow::setupActions() slotWindowActivated (); +// MIKE to fix and enable again // session actions - new TDEAction(i18n("Menu entry Session->New", "&New"), "list-add", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionNew()), actionCollection(), "sessions_new"); +/* new TDEAction(i18n("Menu entry Session->New", "&New"), "list-add", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionNew()), actionCollection(), "sessions_new"); new TDEAction(i18n("&Open..."), "document-open", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionOpen()), actionCollection(), "sessions_open"); new TDEAction(i18n("&Save"), "document-save", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionSave()), actionCollection(), "sessions_save"); new TDEAction(i18n("Save &As..."), "document-save-as", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionSaveAs()), actionCollection(), "sessions_save_as"); @@ -314,6 +315,7 @@ void KateMainWindow::setupActions() // quick open menu ;) new OldKateSessionsAction (i18n("&Quick Open"), actionCollection(), "sessions_list"); +*/ } KateTabWidget *KateMainWindow::tabWidget () @@ -370,7 +372,7 @@ bool KateMainWindow::queryClose() // and save docs if we really close down ! if ( queryClose_internal () ) { - KateApp::self()->oldSessionManager()->saveActiveSession(true, true); + KateApp::self()->sessionManager()->saveActiveSession(); // detach the dcopClient KateApp::self()->dcopClient()->detach(); @@ -824,7 +826,7 @@ void KateMainWindow::updateCaption (Kate::Document *doc) c = m_viewManager->activeView()->getDoc()->url().prettyURL(); } - TQString sessName = KateApp::self()->oldSessionManager()->activeSession()->sessionName(); + TQString sessName = KateApp::self()->sessionManager()->getActiveSessionName(); if ( !sessName.isEmpty() ) sessName = TQString("%1: ").arg( sessName ); @@ -855,10 +857,8 @@ void KateMainWindow::readProperties(TDEConfig *config) void KateMainWindow::saveGlobalProperties( TDEConfig* sessionConfig ) { - KateDocManager::self()->saveDocumentList (sessionConfig); - - sessionConfig->setGroup("General"); - sessionConfig->writeEntry ("Last Session", KateApp::self()->oldSessionManager()->activeSession()->sessionFileRelative()); +// MIKE do we still need this code here? +// KateDocManager::self()->saveDocumentList (sessionConfig); } // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index c66c171cf..adee747d0 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -50,6 +50,7 @@ // FIXME general: need to keep doc list and current session's m_documents in synchro // all the time (doc open, doc closed, doc renamed) +// FIXME add code to handle the various options in Configure Kate -> Application -> Sessions // String constants namespace @@ -63,6 +64,7 @@ namespace const char *KS_OPENDOC = "Open Documents"; const char *KS_READONLY = "ReadOnly"; const char *KS_UNNAMED = "Unnamed"; + const char *KS_OPEN_MAINWINDOWS = "Open MainWindows"; // Kate session manager const char *KSM_DIR = "kate/sessions"; @@ -162,14 +164,14 @@ void KateSession::setReadOnly(bool readOnly) } //------------------------------------ -void KateSession::save(bool saveDocList) +void KateSession::save(bool saveGUIInfo) { if (m_readOnly) return; + // create a new session filename if needed if (!m_isFullName) { - // create a new session filename int s = time(0); TQCString tname; TQString tmpName; @@ -187,6 +189,7 @@ void KateSession::save(bool saveDocList) } } + // save session config info if (!m_config) { m_config = new KSimpleConfig(m_filename); @@ -210,9 +213,20 @@ void KateSession::save(bool saveDocList) { m_config->writeEntry(TQString("URL_%1").arg(i), m_documents[i]); } - if (saveDocList) + + // save GUI elements info + if (saveGUIInfo) { KateDocManager::self()->saveDocumentList(m_config); + // save main windows info + int mwCount = KateApp::self()->mainWindows(); + m_config->setGroup(KS_OPEN_MAINWINDOWS); + m_config->writeEntry(KS_COUNT, mwCount); + for (int i=0; isetGroup(TQString("MainWindow%1").arg(i)); + KateApp::self()->mainWindow(i)->saveProperties(m_config); + } } m_config->sync(); @@ -221,12 +235,35 @@ void KateSession::save(bool saveDocList) //------------------------------------ void KateSession::activate() { - KateDocManager::self()->closeAllDocuments(); + if (KateDocManager::self()->documents() > 0) + { + KateDocManager::self()->closeAllDocuments(); + } Kate::Document::setOpenErrorDialogsActivated(false); if (m_config) { KateApp::self()->documentManager()->restoreDocumentList(m_config); } + + // load main windows info, if it exists + if (m_config && m_config->hasGroup(KS_OPEN_MAINWINDOWS)) + { + m_config->setGroup(KS_OPEN_MAINWINDOWS); + int mwCount = m_config->readUnsignedNumEntry(KS_COUNT, 1); + for (int i=0; i= KateApp::self()->mainWindows()) + { + KateApp::self()->newMainWindow(m_config, TQString("MainWindow%1").arg(i)); + } + else + { + m_config->setGroup(TQString("MainWindow%1").arg(i)); + KateApp::self()->mainWindow(i)->readProperties(m_config); + } + } + } + Kate::Document::setOpenErrorDialogsActivated(true); } @@ -246,7 +283,7 @@ KateSessionManager* KateSessionManager::self() //------------------------------------ KateSessionManager::KateSessionManager() : m_baseDir(locateLocal("data", KSM_DIR)+"/"), m_configFile(m_baseDir + KSM_FILE), - m_sessionsCount(0), m_activeSessionId(-1), m_sessions(), m_config(NULL) + m_sessionsCount(0), m_activeSessionId(0), m_firstActivation(true), m_sessions(), m_config(NULL) { m_sessions.setAutoDelete(true); @@ -256,7 +293,8 @@ KateSessionManager::KateSessionManager() : m_config = new KSimpleConfig(m_configFile); m_config->setGroup(KSM_SESSIONS_LIST); m_sessionsCount = m_config->readNumEntry(KSM_SESSIONS_COUNT, 0); - m_activeSessionId = m_config->readNumEntry(KSM_ACTIVE_SESSION_ID, -1); + //FIXME : if m_sessionsCount == 0, create session list from existing session files + m_activeSessionId = m_config->readNumEntry(KSM_ACTIVE_SESSION_ID, 0); for (int i=0; ireadEntry(TQString("URL_%1").arg(i)); @@ -278,11 +316,18 @@ KateSessionManager::KateSessionManager() : } } m_sessionsCount = static_cast(m_sessions.count()); + if (m_sessionsCount == 0) // In the worst case, there is no valid session at all + { + m_sessions.append(new KateSession(TQString::null, m_baseDir, false)); + ++m_sessionsCount; + } if (m_activeSessionId < 0 || m_activeSessionId >= m_sessionsCount) { m_activeSessionId = 0; // Invalid active session was detected. Use first in the list } - m_sessions[m_activeSessionId]->activate(); + //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 void KateApp::restoreKate() } //------------------------------------ @@ -316,34 +361,71 @@ void KateSessionManager::saveConfig() for (int i=0; isave(i == m_activeSessionId); + m_sessions[i]->save(false); m_config->writeEntry(TQString("URL_%1").arg(i), m_sessions[i]->getSessionFilename()); } m_config->sync(); } +//------------------------------------ +int KateSessionManager::getSessionIdFromName(const TQString &name) +{ + if (name.isEmpty()) + return KateSessionManager::INVALID_SESSION; + + for (int i=0; igetSessionName() == name) + return i; + } + + return KateSessionManager::INVALID_SESSION; +} + //------------------------------------ bool KateSessionManager::activateSession(int sessionId, bool saveCurr) { - if (sessionId == m_activeSessionId) + if (sessionId < 0) + { + return false; + } + + if (!m_firstActivation && sessionId == m_activeSessionId) { return true; } - // First check if all documents can be closed safely - if (KateApp::self()->activeMainWindow()) + if (!m_firstActivation) { - if (!KateApp::self()->activeMainWindow()->queryClose_internal()) - return false; + // Do this only if a session has already been activated earlier, + if (KateApp::self()->activeMainWindow()) + { + // First check if all documents can be closed safely + if (!KateApp::self()->activeMainWindow()->queryClose_internal()) + return false; + } + if (saveCurr) + { + m_sessions[m_activeSessionId]->save(true); + } } - m_sessions[m_activeSessionId]->save(true); m_sessions[sessionId]->activate(); m_activeSessionId = sessionId; + m_firstActivation = false; return true; } - +//------------------------------------ +bool KateSessionManager::restoreLastSession() +{ + if (!m_firstActivation) + { + return false; + } + // NOTE: m_activeSessionId contains the id of the last active session + return activateSession(m_activeSessionId, false); +} @@ -525,7 +607,7 @@ OldKateSessionManager::~OldKateSessionManager() OldKateSessionManager *OldKateSessionManager::self() { - return KateApp::self()->oldSessionManager (); + return (OldKateSessionManager*)KateApp::self()->sessionManager(); } void OldKateSessionManager::dirty (const TQString &) diff --git a/kate/app/katesession.h b/kate/app/katesession.h index 3904f9f0f..67fb6dc20 100644 --- a/kate/app/katesession.h +++ b/kate/app/katesession.h @@ -31,6 +31,8 @@ #include #include +class KateViewSpace; + class OldKateSessionManager; // Michele - to be removed with OldKateSession class KDirWatch; @@ -41,68 +43,76 @@ class TQCheckBox; class KateSession { - public: + public: - /** - * create a new session and read the config from fileName if it exists - * @param sessionName session name - * @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); + /** + * create a new session and read the config from fileName if it exists + * @param sessionName session name + * @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); - /** - * Destructor - */ - ~KateSession(); + /** + * Destructor + */ + ~KateSession(); /** - * @return the session name - */ + * @return the session name + */ const TQString& getSessionName() const { return m_sessionName; } /** - * Set the new session name - * @param sessionName the new session name - */ + * Set the new session name + * @param sessionName the new session name + */ void setSessionName(const TQString &sessionName); /** - * @return whether the session is read only or not - */ + * @return whether the session is read only or not + */ bool isReadOnly() const { return m_readOnly; } /** - * Set session read only status - * @param readOnly if true, the session config can not be saved to file - */ + * Set session read only status + * @param readOnly if true, the session config can not be saved to file + */ void setReadOnly(bool readOnly); /** - * @return the session filename - */ + * @return the session filename + */ const TQString& getSessionFilename() const { return m_filename; } - /** - * Save session info - * @param saveDocList if true, save also the information about the documents currently open - */ - void save(bool saveDocList); + /** + * Save session info + * @param saveGUIInfo if true, save also the information about the GUI elements + */ + void save(bool saveGUIInfo); - /** - * Activate the session - */ - void activate(); - - private: - TQString m_sessionName; - TQString m_filename; - bool m_isFullName; // true -> m_filename is a full filename - // false -> m_filename is a folder name. - bool m_readOnly; - int m_docCount; // number of documents in the session - TQStringList m_documents; // document URLs - KSimpleConfig *m_config; // session config + /** + * Activate the session + */ + void activate(); + + private: + + friend class KateViewSpace; + /** + * @return the session config object + */ + TDEConfig* getConfig() { return m_config; } + + + TQString m_sessionName; + TQString m_filename; + bool m_isFullName; // true -> m_filename is a full filename + // false -> m_filename is a folder name. + bool m_readOnly; + int m_docCount; // number of documents in the session + TQStringList m_documents; // document URLs + KSimpleConfig *m_config; // session config }; @@ -110,56 +120,88 @@ class KateSession //------------------------------------ class KateSessionManager { - public: + public: - /** - * get a pointer to the unique KateSessionManager instance. - * If the manager does not exist yet, create it. - */ - static KateSessionManager* self(); + enum + { + INVALID_SESSION = -1 + }; + + /** + * get a pointer to the unique KateSessionManager instance. + * If the manager does not exist yet, create it. + */ + static KateSessionManager* self(); - /** - * Destructor - */ - ~KateSessionManager(); + /** + * Destructor + */ + ~KateSessionManager(); - /** - * Save session manager info - */ - void saveConfig(); + /** + * Save session manager info + */ + void saveConfig(); - /** - * @return the active session id - */ - int getActiveSessionId() const { return m_activeSessionId; } + /** + * @return the active session id + */ + int getActiveSessionId() const { return m_activeSessionId; } - /** - * @return a reference to the active session - */ - KateSession* getActiveSession() { return m_sessions[m_activeSessionId]; } + /** + * @return the active session name + */ + const TQString& getActiveSessionName() /*FIXME const*/ { return m_sessions[m_activeSessionId]->getSessionName(); } + + /** + * @return a reference to the active session + */ + KateSession* getActiveSession() { return m_sessions[m_activeSessionId]; } + + /** + * @return a reference to the sessions list + */ + TQPtrList& getSessionsList() { return m_sessions; } /** - * @return a reference to the sessions list + * Returns the session id of the first session whose name matches the + * provided one + * @param name the session name to look for + * @return the session id of the matching session if it is found, + * otherwise KateSessionManager::INVALID_SESSION. */ - TQPtrList& getSessionsList() { return m_sessions; } + int getSessionIdFromName(const TQString &name); + + /** + * Activates the selected session. + * @param sessionId the id of the session to activate + * @param saveCurr if true, save the current session before activating the new one + * @return whether the session was activated or not + */ + bool activateSession(int sessionId, bool saveCurr = true); /** - * Activates the selected session. - * @param sessionId the id of the session to activate - * @param saveCurr if true, save the current session before activating the new one + * Restore the last saved session. Can only be used before + * any other session has been activated, i.e. on Kate's startup * @return whether the session was activated or not */ - bool activateSession(int sessionId, bool saveCurr = true); + bool restoreLastSession(); + + /** + * Saves the active session + */ + void saveActiveSession() { m_sessions[m_activeSessionId]->save(true); } - private: - KateSessionManager(); + private: + KateSessionManager(); - TQString m_baseDir; // folder where session files are stored - TQString m_configFile; // file where the session list config is stored - int m_sessionsCount; // number of sessions - int m_activeSessionId; // index of the active session - TQPtrList m_sessions; // session list - KSimpleConfig *m_config; // session manager config + TQString m_baseDir; // folder where session files are stored + TQString m_configFile; // file where the session list config is stored + int m_sessionsCount; // number of sessions + int m_activeSessionId; // index of the active session + bool m_firstActivation; // true until at least one session has been activated + TQPtrList m_sessions; // session list + KSimpleConfig *m_config; // session manager config static KateSessionManager *ksm_instance; // the only KateSessionManager instance }; @@ -173,380 +215,382 @@ class KateSessionManager //------------------------------------ class OldKateSession : public TDEShared { - public: - /** - * Define a Shared-Pointer type - */ - typedef TDESharedPtr Ptr; + public: + /** + * Define a Shared-Pointer type + */ + typedef TDESharedPtr Ptr; - public: - /** - * create a session from given file - * @param fileName session filename, relative - * @param name session name - * @param manager pointer to the manager - */ - OldKateSession (OldKateSessionManager *manager, const TQString &fileName, const TQString &name); + public: + /** + * create a session from given file + * @param fileName session filename, relative + * @param name session name + * @param manager pointer to the manager + */ + OldKateSession ( OldKateSessionManager *manager, const TQString &fileName, const TQString &name ); - /** - * init the session object, after construction or create - */ - void init (); + /** + * init the session object, after construction or create + */ + void init (); - /** - * destruct me - */ - ~OldKateSession (); + /** + * destruct me + */ + ~OldKateSession (); - /** - * session filename, absolute, calculated out of relative filename + session dir - * @return absolute path to session file - */ - TQString sessionFile () const; + /** + * session filename, absolute, calculated out of relative filename + session dir + * @return absolute path to session file + */ + TQString sessionFile () const; - /** - * relative session filename - * @return relative filename for this session - */ - const TQString &sessionFileRelative () const { return m_sessionFileRel; } + /** + * relative session filename + * @return relative filename for this session + */ + const TQString &sessionFileRelative () const { return m_sessionFileRel; } - /** - * session name - * @return name for this session - */ - const TQString &sessionName () const { return m_sessionName; } + /** + * session name + * @return name for this session + */ + const TQString &sessionName () const { return m_sessionName; } - /** - * is this a valid session? if not, don't use any session if this is - * the active one - */ - bool isNew () const { return m_sessionName.isEmpty(); } + /** + * is this a valid session? if not, don't use any session if this is + * the active one + */ + bool isNew () const { return m_sessionName.isEmpty(); } - /** - * create the session file, if not existing - * @param name name for this session - * @param force force to create new file - * @return true if created, false if no creation needed - */ - bool create (const TQString &name, bool force = false); + /** + * create the session file, if not existing + * @param name name for this session + * @param force force to create new file + * @return true if created, false if no creation needed + */ + bool create ( const TQString &name, bool force = false ); - /** - * rename this session - * @param name new name - * @return success - */ - bool rename (const TQString &name); + /** + * rename this session + * @param name new name + * @return success + */ + bool rename ( const TQString &name ); - /** - * config to read - * on first access, will create the config object, delete will be done automagic - * return 0 if we have no file to read config from atm - * @return config to read from - */ - TDEConfig *configRead (); + /** + * config to read + * on first access, will create the config object, delete will be done automagic + * return 0 if we have no file to read config from atm + * @return config to read from + */ + TDEConfig *configRead (); - /** - * config to write - * on first access, will create the config object, delete will be done automagic - * return 0 if we have no file to write config to atm - * @return config to write from - */ - TDEConfig *configWrite (); + /** + * config to write + * on first access, will create the config object, delete will be done automagic + * return 0 if we have no file to write config to atm + * @return config to write from + */ + TDEConfig *configWrite (); - /** - * count of documents in this session - * @return documents count - */ - unsigned int documents () const { return m_documents; } + /** + * count of documents in this session + * @return documents count + */ + unsigned int documents () const { return m_documents; } - private: - /** - * session filename, in local location we can write to - * relative filename to the session dirs :) - */ - TQString m_sessionFileRel; + private: + /** + * session filename, in local location we can write to + * relative filename to the session dirs :) + */ + TQString m_sessionFileRel; - /** - * session name, extracted from the file, to display to the user - */ - TQString m_sessionName; + /** + * session name, extracted from the file, to display to the user + */ + TQString m_sessionName; - /** - * number of document of this session - */ - unsigned int m_documents; + /** + * number of document of this session + */ + unsigned int m_documents; - /** - * OldKateSessionMananger - */ - OldKateSessionManager *m_manager; + /** + * OldKateSessionMananger + */ + OldKateSessionManager *m_manager; - /** - * simpleconfig to read from - */ - KSimpleConfig *m_readConfig; + /** + * simpleconfig to read from + */ + KSimpleConfig *m_readConfig; - /** - * simpleconfig to write to - */ - KSimpleConfig *m_writeConfig; + /** + * simpleconfig to write to + */ + KSimpleConfig *m_writeConfig; }; typedef TQValueList OldKateSessionList; class OldKateSessionManager : public TQObject { - Q_OBJECT + Q_OBJECT - public: - OldKateSessionManager(TQObject *parent); - ~OldKateSessionManager(); + public: + OldKateSessionManager ( TQObject *parent ); + ~OldKateSessionManager(); - /** - * allow access to this :) - * @return instance of the session manager - */ - static OldKateSessionManager *self(); + /** + * allow access to this :) + * @return instance of the session manager + */ + static OldKateSessionManager *self(); - /** - * allow access to the session list - * kept up to date by watching the dir - */ - inline OldKateSessionList & sessionList () { updateSessionList (); return m_sessionList; } + /** + * allow access to the session list + * kept up to date by watching the dir + */ + inline OldKateSessionList & sessionList () { updateSessionList (); return m_sessionList; } - /** - * activate a session - * first, it will look if a session with this name exists in list - * if yes, it will use this session, else it will create a new session file - * @param session session to activate - * @param closeLast try to close last session or not? - * @param saveLast try to save last session or not? - * @param loadNew load new session stuff? - */ - void activateSession (OldKateSession::Ptr session, bool closeLast = true, bool saveLast = true, bool loadNew = true); + /** + * activate a session + * first, it will look if a session with this name exists in list + * if yes, it will use this session, else it will create a new session file + * @param session session to activate + * @param closeLast try to close last session or not? + * @param saveLast try to save last session or not? + * @param loadNew load new session stuff? + */ + void activateSession ( OldKateSession::Ptr session, bool closeLast = true, bool saveLast = true, bool loadNew = true ); - /** - * create a new session - * @param name session name - */ - OldKateSession::Ptr createSession (const TQString &name); + /** + * create a new session + * @param name session name + */ + OldKateSession::Ptr createSession ( const TQString &name ); - /** - * return session with given name - * if no existing session matches, create new one with this name - * @param name session name - */ - OldKateSession::Ptr giveSession (const TQString &name); + /** + * return session with given name + * if no existing session matches, create new one with this name + * @param name session name + */ + OldKateSession::Ptr giveSession ( const TQString &name ); - /** - * save current session - * for sessions without filename: save nothing - * @param tryAsk should we ask user if needed? - * @param rememberAsLast remember this session as last used? - * @return success - */ - bool saveActiveSession (bool tryAsk = false, bool rememberAsLast = false); + /** + * save current session + * for sessions without filename: save nothing + * @param tryAsk should we ask user if needed? + * @param rememberAsLast remember this session as last used? + * @return success + */ + bool saveActiveSession ( bool tryAsk = false, bool rememberAsLast = false ); - /** - * return the current active session - * sessionFile == empty means we have no session around for this instance of kate - * @return session active atm - */ - inline OldKateSession::Ptr activeSession () { return m_activeSession; } + /** + * return the current active session + * sessionFile == empty means we have no session around for this instance of kate + * @return session active atm + */ + inline OldKateSession::Ptr activeSession () { return m_activeSession; } - /** - * session dir - * @return global session dir - */ - inline const TQString &sessionsDir () const { return m_sessionsDir; } + /** + * session dir + * @return global session dir + */ + inline const TQString &sessionsDir () const { return m_sessionsDir; } - /** - * initial session chooser, on app start - * @return success, if false, app should exit - */ - bool chooseSession (); + /** + * initial session chooser, on app start + * @return success, if false, app should exit + */ + bool chooseSession (); - public slots: - /** - * try to start a new session - * asks user first for name - */ - void sessionNew (); + public slots: + /** + * try to start a new session + * asks user first for name + */ + void sessionNew (); - /** - * try to open a existing session - */ - void sessionOpen (); + /** + * try to open a existing session + */ + void sessionOpen (); - /** - * try to save current session - */ - void sessionSave (); + /** + * try to save current session + */ + void sessionSave (); - /** - * try to save as current session - */ - void sessionSaveAs (); + /** + * try to save as current session + */ + void sessionSaveAs (); - /** - * show dialog to manage our sessions - */ - void sessionManage (); + /** + * show dialog to manage our sessions + */ + void sessionManage (); - private slots: - void dirty (const TQString &path); + private slots: + void dirty ( const TQString &path ); - public: - /** - * trigger update of session list - */ - void updateSessionList (); + public: + /** + * trigger update of session list + */ + void updateSessionList (); - private: - /** - * absolute path to dir in home dir where to store the sessions - */ - TQString m_sessionsDir; + private: + /** + * absolute path to dir in home dir where to store the sessions + */ + TQString m_sessionsDir; - /** - * list of current available sessions - */ - OldKateSessionList m_sessionList; + /** + * list of current available sessions + */ + OldKateSessionList m_sessionList; - /** - * current active session - */ - OldKateSession::Ptr m_activeSession; + /** + * current active session + */ + OldKateSession::Ptr m_activeSession; }; class OldKateSessionChooser : public KDialogBase { - Q_OBJECT + Q_OBJECT - public: - OldKateSessionChooser (TQWidget *parent, const TQString &lastSession); - ~OldKateSessionChooser (); + public: + OldKateSessionChooser ( TQWidget *parent, const TQString &lastSession ); + ~OldKateSessionChooser (); - OldKateSession::Ptr selectedSession (); + OldKateSession::Ptr selectedSession (); - bool reopenLastSession (); + bool reopenLastSession (); - enum { - resultQuit = TQDialog::Rejected, - resultOpen, - resultNew, - resultNone - }; + enum + { + resultQuit = TQDialog::Rejected, + resultOpen, + resultNew, + resultNone + }; - protected slots: - /** - * open session - */ - void slotUser1 (); + protected slots: + /** + * open session + */ + void slotUser1 (); - /** - * new session - */ - void slotUser2 (); + /** + * new session + */ + void slotUser2 (); - /** - * quit kate - */ - void slotUser3 (); + /** + * quit kate + */ + void slotUser3 (); - /** - * selection has changed - */ - void selectionChanged (); + /** + * selection has changed + */ + void selectionChanged (); - private: - TDEListView *m_sessions; - TQCheckBox *m_useLast; + private: + TDEListView *m_sessions; + TQCheckBox *m_useLast; }; class OldKateSessionOpenDialog : public KDialogBase { - Q_OBJECT + Q_OBJECT - public: - OldKateSessionOpenDialog (TQWidget *parent); - ~OldKateSessionOpenDialog (); + public: + OldKateSessionOpenDialog ( TQWidget *parent ); + ~OldKateSessionOpenDialog (); - OldKateSession::Ptr selectedSession (); + OldKateSession::Ptr selectedSession (); - enum { - resultOk, - resultCancel - }; + enum + { + resultOk, + resultCancel + }; - protected slots: - /** - * cancel pressed - */ - void slotUser1 (); + protected slots: + /** + * cancel pressed + */ + void slotUser1 (); - /** - * ok pressed - */ - void slotUser2 (); + /** + * ok pressed + */ + void slotUser2 (); - private: - TDEListView *m_sessions; + private: + TDEListView *m_sessions; }; class OldKateSessionManageDialog : public KDialogBase { - Q_OBJECT - - public: - OldKateSessionManageDialog (TQWidget *parent); - ~OldKateSessionManageDialog (); + Q_OBJECT - protected slots: - /** - * close pressed - */ - void slotUser1 (); + public: + OldKateSessionManageDialog ( TQWidget *parent ); + ~OldKateSessionManageDialog (); - /** - * selection has changed - */ - void selectionChanged (); + protected slots: + /** + * close pressed + */ + void slotUser1 (); - /** - * try to rename session - */ - void rename (); + /** + * selection has changed + */ + void selectionChanged (); - /** - * try to delete session - */ - void del (); + /** + * try to rename session + */ + void rename (); - private: - /** - * update our list - */ - void updateSessionList (); + /** + * try to delete session + */ + void del (); - private: - TDEListView *m_sessions; - KPushButton *m_rename; - KPushButton *m_del; + private: + /** + * update our list + */ + void updateSessionList (); + + private: + TDEListView *m_sessions; + KPushButton *m_rename; + KPushButton *m_del; }; class OldKateSessionsAction : public TDEActionMenu { - Q_OBJECT + Q_OBJECT - public: - OldKateSessionsAction(const TQString& text, TQObject* parent = 0, const char* name = 0); - ~OldKateSessionsAction (){;}; + public: + OldKateSessionsAction ( const TQString& text, TQObject* parent = 0, const char* name = 0 ); + ~OldKateSessionsAction () {;}; - public slots: - void slotAboutToShow(); + public slots: + void slotAboutToShow(); - void openSession (int i); + void openSession ( int i ); }; #endif diff --git a/kate/app/katesessionpanel.cpp b/kate/app/katesessionpanel.cpp index 93bca5d06..7bb61a308 100644 --- a/kate/app/katesessionpanel.cpp +++ b/kate/app/katesessionpanel.cpp @@ -62,7 +62,8 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager * m_listview->setColumnAlignment(2, TQt::AlignCenter); m_listview->setMinimumWidth(m_listview->sizeHint().width()); m_listview->setSorting(-1); - //m_listview->setRootIsDecorated(true); // to enable after inserting doc list + //m_listview->setRootIsDecorated(true); // MIKE to enable after inserting doc list + connect(m_listview, TQT_SIGNAL(executed(TQListViewItem*)), TQT_SLOT(itemExecuted(TQListViewItem*))); TQPtrList& sessions = m_sessionManager->getSessionsList(); for (int idx = sessions.count()-1; idx >= 0; --idx) @@ -210,3 +211,16 @@ void KateSessionPanel::sessionMoveDown() { //TODO } + +void KateSessionPanel::itemExecuted(TQListViewItem *item) +{ + if (!item) + return; + + // First level items are sessions. Executing one, will switch to that session + if (!item->parent()) + { + sessionActivate(); + return; + } +} diff --git a/kate/app/katesessionpanel.h b/kate/app/katesessionpanel.h index 71120b7e1..d3baddcb4 100644 --- a/kate/app/katesessionpanel.h +++ b/kate/app/katesessionpanel.h @@ -74,6 +74,7 @@ class KateSessionPanel : public TQVBox void sessionToggleReadOnly(); void sessionMoveUp(); void sessionMoveDown(); + void itemExecuted(TQListViewItem *item); private: void setup_toolbar(); diff --git a/kate/app/kateviewspace.cpp b/kate/app/kateviewspace.cpp index f53ec7468..7e9622b67 100644 --- a/kate/app/kateviewspace.cpp +++ b/kate/app/kateviewspace.cpp @@ -110,15 +110,16 @@ void KateViewSpace::addView(Kate::View* v, bool show) if ( !m_group.isEmpty() ) { TQString fn = v->getDoc()->url().prettyURL(); - if ( ! fn.isEmpty() ) + if (!fn.isEmpty()) { TQString vgroup = TQString("%1 %2").arg(m_group).arg(fn); - OldKateSession::Ptr as = OldKateSessionManager::self()->activeSession (); - if ( as->configRead() && as->configRead()->hasGroup( vgroup ) ) + KateSession *as = KateSessionManager::self()->getActiveSession(); + TDEConfig *asCfg = as->getConfig(); + if (asCfg && asCfg->hasGroup(vgroup)) { - as->configRead()->setGroup( vgroup ); - v->readSessionConfig ( as->configRead() ); + asCfg->setGroup(vgroup); + v->readSessionConfig(asCfg); } } } -- cgit v1.2.1 From 2675b2147b5ccc7782535e5f662847768bb8b442 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Fri, 19 Feb 2016 22:04:40 +0700 Subject: Added support for Kate startup options and for "New session" functionality. Signed-off-by: Michele Calgaro --- kate/app/kateapp.cpp | 83 ++++++++--- kate/app/kateappIface.cpp | 6 +- kate/app/katemainwindow.cpp | 4 +- kate/app/katesession.cpp | 310 ++++++++++++++++++------------------------ kate/app/katesession.h | 152 +++++++++++++-------- kate/app/katesessionpanel.cpp | 56 +++++--- kate/app/katesessionpanel.h | 3 + 7 files changed, 339 insertions(+), 275 deletions(-) (limited to 'kate') diff --git a/kate/app/kateapp.cpp b/kate/app/kateapp.cpp index f6089cb75..8793569fa 100644 --- a/kate/app/kateapp.cpp +++ b/kate/app/kateapp.cpp @@ -158,29 +158,78 @@ void KateApp::restoreKate() // TDEStartupInfo::setNewStartupId( activeMainWindow(), startupId()); } -bool KateApp::startupKate () +bool KateApp::startupKate() { - // user specified session to open - if (m_args->isSet ("start")) + if (m_args->isSet("start")) { - // MIKE fixme: need to handle this functionality - sessionManager()->activateSession( - sessionManager()->getSessionIdFromName(TQString::fromLocal8Bit(m_args->getOption("start")))); + // the user has specified the session to open + TQCString sessName = m_args->getOption("start"); + int sessId = sessionManager()->getSessionIdFromName(sessName); + if (sessId != KateSessionManager::INVALID_SESSION) + { + sessionManager()->activateSession(sessId); + } + else + { + int msgres = KMessageBox::warningYesNo(0, i18n("

The session '%1' could not be found." + "

Do you want to start a new session?").arg(sessName), + i18n("Session not found!")); + if (msgres == KMessageBox::Yes) + { + sessionManager()->newSession(TQString::null, true); + } + else + { + // Kate will exit now and notify it is done + TDEStartupInfo::appStarted(startupId()); + return false; + } + } } else { - // MIKE: for the time being just open last session. - // FIXME: need to add support for startup session options - sessionManager()->restoreLastSession(); - - // MIKE fixme: need to handle this functionality - // let the user choose session if possible - /*if (!oldSessionManager()->chooseSession ()) + // check Kate session startup options + TDEConfig *kateCfg = KateApp::self()->config(); + kateCfg->setGroup("General"); + if (kateCfg->hasKey("Last Session")) { - // we will exit kate now, notify the rest of the world we are done - TDEStartupInfo::appStarted (startupId()); - return false; - }*/ + // Delete no longer used entry (pre R14.1.0) + kateCfg->deleteEntry("Last Session"); + } + TQString startupOption(kateCfg->readEntry("Startup Session", "manual")); + if (startupOption == "last") + { + sessionManager()->restoreLastSession(); + } + else if (startupOption == "new") + { + sessionManager()->newSession(TQString::null, true); + } + else // startupOption == "manual" + { + KateSessionChooser *chooser = new KateSessionChooser(NULL); + int result = chooser->exec(); + switch (result) + { + case KateSessionChooser::RESULT_OPEN_NEW: + sessionManager()->newSession(TQString::null, true); + break; + + case KateSessionChooser::RESULT_OPEN_EXISTING: + if (!m_sessionManager->activateSession(chooser->getSelectedSessionId())) + { + // Open a new session in case of error + sessionManager()->newSession(TQString::null, true); + } + break; + + default: // KateSessionChooser::RESULT_QUIT_KATE: + // Kate will exit now and notify it is done + TDEStartupInfo::appStarted(startupId()); + return false; + break; + } + } } // oh, no mainwindow, create one, should not happen, but make sure ;) diff --git a/kate/app/kateappIface.cpp b/kate/app/kateappIface.cpp index 3ce9229b4..bc06f1b78 100644 --- a/kate/app/kateappIface.cpp +++ b/kate/app/kateappIface.cpp @@ -23,6 +23,8 @@ #include "katedocmanager.h" #include "katemainwindow.h" +// FIXME: review Kate's DCOP interface for session management when the new session code is ready + KateAppDCOPIface::KateAppDCOPIface (KateApp *app) : DCOPObject ("KateApplication") , m_app (app) { @@ -91,9 +93,7 @@ bool KateAppDCOPIface::openInput (TQString text) bool KateAppDCOPIface::activateSession(TQString session) { -// MIKE: to fix -// m_app->sessionManager()->activateSession (m_app->oldSessionManager()->giveSession (session)); - + m_app->sessionManager()->activateSession(m_app->sessionManager()->getSessionIdFromName(session)); return true; } diff --git a/kate/app/katemainwindow.cpp b/kate/app/katemainwindow.cpp index 527dbdc9c..19a76ee27 100644 --- a/kate/app/katemainwindow.cpp +++ b/kate/app/katemainwindow.cpp @@ -305,7 +305,7 @@ void KateMainWindow::setupActions() slotWindowActivated (); -// MIKE to fix and enable again +// FIXME to fix and enable again // session actions /* new TDEAction(i18n("Menu entry Session->New", "&New"), "list-add", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionNew()), actionCollection(), "sessions_new"); new TDEAction(i18n("&Open..."), "document-open", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionOpen()), actionCollection(), "sessions_open"); @@ -857,7 +857,7 @@ void KateMainWindow::readProperties(TDEConfig *config) void KateMainWindow::saveGlobalProperties( TDEConfig* sessionConfig ) { -// MIKE do we still need this code here? +// FIXME do we still need this code here? // KateDocManager::self()->saveDocumentList (sessionConfig); } diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index adee747d0..4437d7166 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -17,7 +17,6 @@ */ #include "katesession.h" -#include "katesession.moc" #include "kateapp.h" #include "katemainwindow.h" @@ -74,6 +73,7 @@ namespace const char *KSM_SESSIONS_LIST = "Sessions list"; } +//BEGIN Kate session KateSession::KateSession(const TQString &sessionName, const TQString &filename, bool isFullName) : m_sessionName(sessionName), m_filename(filename), m_isFullName(isFullName), m_readOnly(false), m_docCount(0), m_documents(), m_config(NULL) @@ -167,7 +167,9 @@ void KateSession::setReadOnly(bool readOnly) void KateSession::save(bool saveGUIInfo) { if (m_readOnly) + { return; + } // create a new session filename if needed if (!m_isFullName) @@ -252,7 +254,7 @@ void KateSession::activate() int mwCount = m_config->readUnsignedNumEntry(KS_COUNT, 1); for (int i=0; i= KateApp::self()->mainWindows()) + if (i >= (int)KateApp::self()->mainWindows()) { KateApp::self()->newMainWindow(m_config, TQString("MainWindow%1").arg(i)); } @@ -267,6 +269,9 @@ void KateSession::activate() Kate::Document::setOpenErrorDialogsActivated(true); } +//END Kate session + +//BEGIN KateSessionManager //------------------------------------ KateSessionManager *KateSessionManager::ksm_instance = NULL; @@ -345,6 +350,12 @@ KateSessionManager::~KateSessionManager() } //------------------------------------ +// 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::saveConfig() { if (!m_config) @@ -378,18 +389,20 @@ int KateSessionManager::getSessionIdFromName(const TQString &name) if (m_sessions[i]->getSessionName() == name) return i; } - + return KateSessionManager::INVALID_SESSION; } //------------------------------------ +//FIXME: after a session switch, the session name on Kate window title bar displays +//the previously activated session bool KateSessionManager::activateSession(int sessionId, bool saveCurr) { if (sessionId < 0) { return false; } - + if (!m_firstActivation && sessionId == m_activeSessionId) { return true; @@ -410,12 +423,28 @@ bool KateSessionManager::activateSession(int sessionId, bool saveCurr) } } - m_sessions[sessionId]->activate(); + int oldSessionId = m_activeSessionId; m_activeSessionId = sessionId; + m_sessions[sessionId]->activate(); m_firstActivation = false; + emit sessionActivated(m_activeSessionId, oldSessionId); return true; } +//------------------------------------ +int KateSessionManager::newSession(const TQString &sessionName, bool activate) +{ + m_sessions.append(new KateSession(sessionName, m_baseDir, false)); + ++m_sessionsCount; + int newSessionId = m_sessionsCount - 1; + emit sessionCreated(newSessionId); + if (activate) + { + activateSession(newSessionId, true); + } + return newSessionId; +} + //------------------------------------ bool KateSessionManager::restoreLastSession() { @@ -427,6 +456,99 @@ bool KateSessionManager::restoreLastSession() return activateSession(m_activeSessionId, false); } +//------------------------------------------- +void KateSessionManager::slotNewSession() +{ + // FIXME: allow the user to enter a session name first + // FIXME: allow the user to specify whether to switch to the new session or not + newSession(TQString::null, true); +} + +//END KateSessionManager + +//BEGIN KateSessionChooser +//------------------------------------------- +KateSessionChooser::KateSessionChooser(TQWidget *parent) + : KDialogBase(parent, "", true, i18n("Session Chooser"), + KDialogBase::User1 | KDialogBase::User2 | KDialogBase::User3, KDialogBase::User2, + true, KStdGuiItem::quit(), KGuiItem(i18n("Open Session"), "document-open"), + KGuiItem(i18n("New Session"), "document-new")), m_sessionList(NULL), m_columnSessionId(0) +{ + TQHBox *page = new TQHBox(this); + page->setMinimumSize(400, 200); + setMainWidget(page); + + TQHBox *hb = new TQHBox(page); + hb->setSpacing(KDialog::spacingHint()); + + TQLabel *label = new TQLabel(hb); + label->setPixmap(UserIcon("sessionchooser")); + label->setFrameStyle (TQFrame::Panel | TQFrame::Sunken); + + TQVBox *vb = new TQVBox(hb); + vb->setSpacing (KDialog::spacingHint()); + + m_sessionList = new TDEListView(vb); + m_sessionList->addColumn(i18n("Session Name")); + m_columnSessionId = m_sessionList->addColumn("Session Id", 0); // Non visible column + m_sessionList->header()->setResizeEnabled(false, m_columnSessionId); + m_sessionList->addColumn(i18n("Open Documents")); + m_sessionList->setSelectionMode(TQListView::Single); + m_sessionList->setAllColumnsShowFocus(true); + m_sessionList->setSorting(-1); + m_sessionList->setResizeMode(TQListView::LastColumn); + + connect (m_sessionList, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(slotSelectionChanged())); + connect (m_sessionList, TQT_SIGNAL(executed(TQListViewItem*)), this, TQT_SLOT(slotUser2())); + + TQPtrList& sessions = KateSessionManager::self()->getSessionsList(); + for (int idx = sessions.count()-1; idx >= 0; --idx) + { + new TDEListViewItem(m_sessionList, sessions[idx]->getSessionName(), TQString("%1").arg(idx), + TQString("%1").arg(sessions[idx]->getDocCount())); + } + + setResult(RESULT_NO_OP); + slotSelectionChanged(); // update button status +} + +//------------------------------------------- +int KateSessionChooser::getSelectedSessionId() +{ + TQListViewItem *selectedItem = m_sessionList->selectedItem(); + if (!selectedItem) + return KateSessionManager::INVALID_SESSION; + + return selectedItem->text(m_columnSessionId).toInt(); +} + +//------------------------------------------- +void KateSessionChooser::slotUser1() +{ + done(RESULT_QUIT_KATE); +} + +//------------------------------------------- +void KateSessionChooser::slotUser2() +{ + done(RESULT_OPEN_EXISTING); +} + +//------------------------------------------- +void KateSessionChooser::slotUser3() +{ + done(RESULT_OPEN_NEW); +} + +//------------------------------------------- +void KateSessionChooser::slotSelectionChanged() +{ + enableButton(KDialogBase::User2, m_sessionList->selectedItem()); +} + +//END KateSessionChooser + + @@ -817,95 +939,12 @@ bool OldKateSessionManager::saveActiveSession (bool tryAsk, bool rememberAsLast) { TDEConfig *c = KateApp::self()->config(); c->setGroup("General"); - c->writeEntry ("Last Session", activeSession()->sessionFileRelative()); c->sync (); } return true; } -bool OldKateSessionManager::chooseSession () -{ - bool success = true; - - // app config - TDEConfig *c = KateApp::self()->config(); - c->setGroup("General"); - - // get last used session, default to default session - TQString lastSession (c->readEntry ("Last Session", "default.katesession")); - TQString sesStart (c->readEntry ("Startup Session", "manual")); - - // uhh, just open last used session, show no chooser - if (sesStart == "last") - { - activateSession (new OldKateSession (this, lastSession, ""), false, false); - return success; - } - - // start with empty new session - if (sesStart == "new") - { - activateSession (new OldKateSession (this, "", ""), false, false); - return success; - } - - OldKateSessionChooser *chooser = new OldKateSessionChooser (0, lastSession); - - bool retry = true; - int res = 0; - while (retry) - { - res = chooser->exec (); - - switch (res) - { - case OldKateSessionChooser::resultOpen: - { - OldKateSession::Ptr s = chooser->selectedSession (); - - if (!s) - { - KMessageBox::error (chooser, i18n("No session selected to open."), i18n ("No Session Selected")); - break; - } - - activateSession (s, false, false); - retry = false; - break; - } - - // exit the app lateron - case OldKateSessionChooser::resultQuit: - success = false; - retry = false; - break; - - default: - activateSession (new OldKateSession (this, "", ""), false, false); - retry = false; - break; - } - } - - // write back our nice boolean :) - if (success && chooser->reopenLastSession ()) - { - c->setGroup("General"); - - if (res == OldKateSessionChooser::resultOpen) - c->writeEntry ("Startup Session", "last"); - else if (res == OldKateSessionChooser::resultNew) - c->writeEntry ("Startup Session", "new"); - - c->sync (); - } - - delete chooser; - - return success; -} - void OldKateSessionManager::sessionNew () { activateSession (new OldKateSession (this, "", "")); @@ -998,98 +1037,6 @@ class OldKateSessionChooserItem : public TQListViewItem OldKateSession::Ptr session; }; -OldKateSessionChooser::OldKateSessionChooser (TQWidget *parent, const TQString &lastSession) - : KDialogBase ( parent - , "" - , true - , i18n ("Session Chooser") - , KDialogBase::User1 | KDialogBase::User2 | KDialogBase::User3 - , KDialogBase::User2 - , true - , KStdGuiItem::quit () - , KGuiItem (i18n ("Open Session"), "document-open") - , KGuiItem (i18n ("New Session"), "document-new") - ) -{ - TQHBox *page = new TQHBox (this); - page->setMinimumSize (400, 200); - setMainWidget(page); - - TQHBox *hb = new TQHBox (page); - hb->setSpacing (KDialog::spacingHint()); - - TQLabel *label = new TQLabel (hb); - label->setPixmap (UserIcon("sessionchooser")); - label->setFrameStyle (TQFrame::Panel | TQFrame::Sunken); - - TQVBox *vb = new TQVBox (hb); - vb->setSpacing (KDialog::spacingHint()); - - m_sessions = new TDEListView (vb); - m_sessions->addColumn (i18n("Session Name")); - m_sessions->addColumn (i18n("Open Documents")); - m_sessions->setResizeMode (TQListView::AllColumns); - m_sessions->setSelectionMode (TQListView::Single); - m_sessions->setAllColumnsShowFocus (true); - - connect (m_sessions, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(selectionChanged())); - connect (m_sessions, TQT_SIGNAL(doubleClicked(TQListViewItem *, const TQPoint &, int)), this, TQT_SLOT(slotUser2())); - - OldKateSessionList &slist (OldKateSessionManager::self()->sessionList()); - for (unsigned int i=0; i < slist.count(); ++i) - { - OldKateSessionChooserItem *item = new OldKateSessionChooserItem (m_sessions, slist[i]); - - if (slist[i]->sessionFileRelative() == lastSession) - m_sessions->setSelected (item, true); - } - - m_useLast = new TQCheckBox (i18n ("&Always use this choice"), vb); - - setResult (resultNone); - - // trigger action update - selectionChanged (); -} - -OldKateSessionChooser::~OldKateSessionChooser () -{ -} - -OldKateSession::Ptr OldKateSessionChooser::selectedSession () -{ - OldKateSessionChooserItem *item = (OldKateSessionChooserItem *) m_sessions->selectedItem (); - - if (!item) - return 0; - - return item->session; -} - -bool OldKateSessionChooser::reopenLastSession () -{ - return m_useLast->isChecked (); -} - -void OldKateSessionChooser::slotUser2 () -{ - done (resultOpen); -} - -void OldKateSessionChooser::slotUser3 () -{ - done (resultNew); -} - -void OldKateSessionChooser::slotUser1 () -{ - done (resultQuit); -} - -void OldKateSessionChooser::selectionChanged () -{ - enableButton (KDialogBase::User2, m_sessions->selectedItem ()); -} //END CHOOSER DIALOG @@ -1304,4 +1251,7 @@ void OldKateSessionsAction::openSession (int i) OldKateSessionManager::self()->activateSession(slist[(uint)i]); } + +#include "katesession.moc" + // kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off; diff --git a/kate/app/katesession.h b/kate/app/katesession.h index 67fb6dc20..ff6b3c0fa 100644 --- a/kate/app/katesession.h +++ b/kate/app/katesession.h @@ -41,6 +41,7 @@ class KPushButton; class TQCheckBox; +//BEGIN KateSession class KateSession { public: @@ -85,6 +86,11 @@ class KateSession */ const TQString& getSessionFilename() const { return m_filename; } + /** + * @return the number of documents in the session + */ + int getDocCount() const { return m_docCount; } + /** * Save session info * @param saveGUIInfo if true, save also the information about the GUI elements @@ -116,17 +122,29 @@ class KateSession }; - +//END 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 +//saved by other Kate instances. //------------------------------------ -class KateSessionManager +class KateSessionManager : public TQObject { + Q_OBJECT + public: enum { INVALID_SESSION = -1 }; - + /** * get a pointer to the unique KateSessionManager instance. * If the manager does not exist yet, create it. @@ -158,14 +176,10 @@ class KateSessionManager */ KateSession* getActiveSession() { return m_sessions[m_activeSessionId]; } - /** - * @return a reference to the sessions list - */ - TQPtrList& getSessionsList() { return m_sessions; } - /** - * Returns the session id of the first session whose name matches the - * provided one + * Return the session id of the first session whose name matches the + * provided one. In case multiple sessions share the same name, + * the id of the first one found will be returned. * @param name the session name to look for * @return the session id of the matching session if it is found, * otherwise KateSessionManager::INVALID_SESSION. @@ -173,13 +187,26 @@ class KateSessionManager int getSessionIdFromName(const TQString &name); /** - * Activates the selected session. + * @return a reference to the sessions list + */ + TQPtrList& getSessionsList() { return m_sessions; } + + /** + * Activate the selected session. * @param sessionId the id of the session to activate * @param saveCurr if true, save the current session before activating the new one * @return whether the session was activated or not */ bool activateSession(int sessionId, bool saveCurr = true); + /** + * Create a new session and activate it if required + * @param sessionName new session name + * @param activate if true, activate the new session after creation + * @return the id of the newly created session + */ + int newSession(const TQString &sessionName = TQString::null, bool activate = true); + /** * Restore the last saved session. Can only be used before * any other session has been activated, i.e. on Kate's startup @@ -192,6 +219,28 @@ class KateSessionManager */ void saveActiveSession() { m_sessions[m_activeSessionId]->save(true); } + signals: + /** + * 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 + */ + void sessionActivated(int newSessionId, int oldSessionId); + + /** + * Emitted once a session has been created + * @param newSessionId the id of the new session + */ + void sessionCreated(int newSessionId); + + + public slots: + /** + * Slot to create a new session + */ + void slotNewSession(); + + private: KateSessionManager(); @@ -206,6 +255,42 @@ class KateSessionManager static KateSessionManager *ksm_instance; // the only KateSessionManager instance }; +//END KateSessionManager + +//BEGIN KateSessionChooser +//------------------------------------ +class KateSessionChooser : public KDialogBase +{ + Q_OBJECT + + public: + enum Result + { + RESULT_NO_OP = TQDialog::Rejected, + RESULT_OPEN_EXISTING, + RESULT_OPEN_NEW, + RESULT_QUIT_KATE + }; + + KateSessionChooser(TQWidget *parent); + KateSessionChooser() {} + + int getSelectedSessionId(); //return the session id of the selected session + + protected slots: + + void slotUser1(); // open existing session + void slotUser2(); // open new session + void slotUser3(); // quit kate + void slotSelectionChanged(); // list selection has changed + + protected: + TDEListView *m_sessionList; + int m_columnSessionId; +}; + +//BEGIN KateSessionChooser + @@ -461,51 +546,6 @@ class OldKateSessionManager : public TQObject OldKateSession::Ptr m_activeSession; }; -class OldKateSessionChooser : public KDialogBase -{ - Q_OBJECT - - public: - OldKateSessionChooser ( TQWidget *parent, const TQString &lastSession ); - ~OldKateSessionChooser (); - - OldKateSession::Ptr selectedSession (); - - bool reopenLastSession (); - - enum - { - resultQuit = TQDialog::Rejected, - resultOpen, - resultNew, - resultNone - }; - - protected slots: - /** - * open session - */ - void slotUser1 (); - - /** - * new session - */ - void slotUser2 (); - - /** - * quit kate - */ - void slotUser3 (); - - /** - * selection has changed - */ - void selectionChanged (); - - private: - TDEListView *m_sessions; - TQCheckBox *m_useLast; -}; class OldKateSessionOpenDialog : public KDialogBase { diff --git a/kate/app/katesessionpanel.cpp b/kate/app/katesessionpanel.cpp index 7bb61a308..2e8c12945 100644 --- a/kate/app/katesessionpanel.cpp +++ b/kate/app/katesessionpanel.cpp @@ -57,13 +57,16 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager * m_listview = new TDEListView(this); m_listview->header()->hide(); m_listview->addColumn("Session name"); - m_columnSessionId = m_listview->addColumn("Session id", 0); + m_columnSessionId = m_listview->addColumn("Session id", 50); + m_listview->header()->setResizeEnabled(false, m_columnSessionId); m_columnPixmap = m_listview->addColumn("Pixmap", 24); m_listview->setColumnAlignment(2, TQt::AlignCenter); m_listview->setMinimumWidth(m_listview->sizeHint().width()); m_listview->setSorting(-1); - //m_listview->setRootIsDecorated(true); // MIKE to enable after inserting doc list - connect(m_listview, TQT_SIGNAL(executed(TQListViewItem*)), TQT_SLOT(itemExecuted(TQListViewItem*))); + //m_listview->setRootIsDecorated(true); // FIXME to enable after inserting doc list + connect(m_listview, TQT_SIGNAL(executed(TQListViewItem*)), this, TQT_SLOT(itemExecuted(TQListViewItem*))); + connect(m_sessionManager, TQT_SIGNAL(sessionActivated(int, int)), this, TQT_SLOT(slotSessionActivated(int, int))); + connect(m_sessionManager, TQT_SIGNAL(sessionCreated(int)), this, TQT_SLOT(slotSessionCreated(int))); TQPtrList& sessions = m_sessionManager->getSessionsList(); for (int idx = sessions.count()-1; idx >= 0; --idx) @@ -94,12 +97,13 @@ void KateSessionPanel::setup_toolbar() //FIXME : uncomment and activate as long as the new session manager gets fixed // Toolbar actions TDEAction *a; -/* + a = new TDEAction(i18n("New"), SmallIcon("list-add"), 0, - TQT_TQOBJECT(m_sessionManager), TQT_SLOT(sessionNew()), m_actionCollection, "session_new"); + TQT_TQOBJECT(m_sessionManager), TQT_SLOT(slotNewSession()), + m_actionCollection, "session_new"); a->setWhatsThis(i18n("Create a new session.")); a->plug(m_toolbar); - +/* a = new TDEAction(i18n("Save"), SmallIcon("document-save"), 0, TQT_TQOBJECT(this), TQT_SLOT(saveSession()), m_actionCollection, "session_save"); a->setWhatsThis(i18n("Save the current session.")); @@ -175,22 +179,14 @@ void KateSessionPanel::deleteSession() void KateSessionPanel::sessionActivate() { TQListViewItem *newSessionItem = m_listview->selectedItem(); - int currSessionId = m_sessionManager->getActiveSessionId(); if (!newSessionItem) return; + + int currSessionId = m_sessionManager->getActiveSessionId(); int newSessionId = newSessionItem->text(m_columnSessionId).toInt(); if (newSessionId != currSessionId) { - if (!m_sessionManager->activateSession(newSessionId)) - return; - - TQListViewItem *item = m_listview->firstChild(); - for (int idx = 0; idx < currSessionId; ++idx) - { - item = item->nextSibling(); - } - item->setPixmap(m_columnPixmap, TQPixmap()); - newSessionItem->setPixmap(m_columnPixmap, SmallIcon("ok")); + m_sessionManager->activateSession(newSessionId); } } @@ -224,3 +220,29 @@ void KateSessionPanel::itemExecuted(TQListViewItem *item) return; } } + +//------------------------------------------- +void KateSessionPanel::slotSessionActivated(int newSessionId, int oldSessionId) +{ + // Move the active session marker + TQListViewItem *item = m_listview->firstChild(); + for (int idx = 0; idx < oldSessionId; ++idx) + { + item = item->nextSibling(); + } + item->setPixmap(m_columnPixmap, TQPixmap()); + + item = m_listview->firstChild(); + for (int idx = 0; idx < newSessionId; ++idx) + { + item = item->nextSibling(); + } + item->setPixmap(m_columnPixmap, SmallIcon("ok")); + m_listview->setSelected(item, true); +} + +void KateSessionPanel::slotSessionCreated(int newSessionId) +{ + TQPtrList& sessions = m_sessionManager->getSessionsList(); + new TDEListViewItem(m_listview, m_listview->lastItem(), sessions[newSessionId]->getSessionName(), TQString("%1").arg(newSessionId)); +} diff --git a/kate/app/katesessionpanel.h b/kate/app/katesessionpanel.h index d3baddcb4..a33535755 100644 --- a/kate/app/katesessionpanel.h +++ b/kate/app/katesessionpanel.h @@ -76,6 +76,9 @@ class KateSessionPanel : public TQVBox void sessionMoveDown(); void itemExecuted(TQListViewItem *item); + void slotSessionActivated(int newSessionId, int oldSessionId); + void slotSessionCreated(int newSessionId); + private: void setup_toolbar(); -- cgit v1.2.1 From 127ac19145207e292e179056ab9a5956f00fac32 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sat, 20 Feb 2016 21:43:25 +0700 Subject: Added support for "Delete session" in Kate session panel. Signed-off-by: Michele Calgaro --- kate/app/kateapp.cpp | 23 +++++-------------- kate/app/katesession.cpp | 53 +++++++++++++++++++++++++++++++++---------- kate/app/katesession.h | 47 +++++++++++++++++++++++++------------- kate/app/katesessionpanel.cpp | 52 ++++++++++++++++++++++++++++++++++-------- kate/app/katesessionpanel.h | 18 +++++++++++---- 5 files changed, 134 insertions(+), 59 deletions(-) (limited to 'kate') diff --git a/kate/app/kateapp.cpp b/kate/app/kateapp.cpp index 8793569fa..167062245 100644 --- a/kate/app/kateapp.cpp +++ b/kate/app/kateapp.cpp @@ -162,7 +162,8 @@ bool KateApp::startupKate() { if (m_args->isSet("start")) { - // the user has specified the session to open + // the user has specified the session to open. If the session does not exist, + // a new session with the specified name will be created TQCString sessName = m_args->getOption("start"); int sessId = sessionManager()->getSessionIdFromName(sessName); if (sessId != KateSessionManager::INVALID_SESSION) @@ -171,19 +172,7 @@ bool KateApp::startupKate() } else { - int msgres = KMessageBox::warningYesNo(0, i18n("

The session '%1' could not be found." - "

Do you want to start a new session?").arg(sessName), - i18n("Session not found!")); - if (msgres == KMessageBox::Yes) - { - sessionManager()->newSession(TQString::null, true); - } - else - { - // Kate will exit now and notify it is done - TDEStartupInfo::appStarted(startupId()); - return false; - } + sessionManager()->newSession(sessName, true); } } else @@ -203,7 +192,7 @@ bool KateApp::startupKate() } else if (startupOption == "new") { - sessionManager()->newSession(TQString::null, true); + sessionManager()->newSession(); } else // startupOption == "manual" { @@ -212,14 +201,14 @@ bool KateApp::startupKate() switch (result) { case KateSessionChooser::RESULT_OPEN_NEW: - sessionManager()->newSession(TQString::null, true); + sessionManager()->newSession(); break; case KateSessionChooser::RESULT_OPEN_EXISTING: if (!m_sessionManager->activateSession(chooser->getSelectedSessionId())) { // Open a new session in case of error - sessionManager()->newSession(TQString::null, true); + sessionManager()->newSession(); } break; diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index 4437d7166..0a8d0c915 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -1,4 +1,6 @@ /* This file is part of the KDE project + Copyright (C) 2015-2016 Michele Calgaro + partially based on previous work from Copyright (C) 2005 Christoph Cullmann This library is free software; you can redistribute it and/or @@ -36,6 +38,7 @@ #include #include +#include #include #include #include @@ -268,9 +271,9 @@ void KateSession::activate() Kate::Document::setOpenErrorDialogsActivated(true); } - //END Kate session + //BEGIN KateSessionManager //------------------------------------ KateSessionManager *KateSessionManager::ksm_instance = NULL; @@ -300,7 +303,7 @@ KateSessionManager::KateSessionManager() : m_sessionsCount = m_config->readNumEntry(KSM_SESSIONS_COUNT, 0); //FIXME : if m_sessionsCount == 0, create session list from existing session files m_activeSessionId = m_config->readNumEntry(KSM_ACTIVE_SESSION_ID, 0); - for (int i=0; ireadEntry(TQString("URL_%1").arg(i)); if (!urlStr.isEmpty() && TDEGlobal::dirs()->exists(urlStr)) @@ -417,7 +420,7 @@ bool KateSessionManager::activateSession(int sessionId, bool saveCurr) if (!KateApp::self()->activeMainWindow()->queryClose_internal()) return false; } - if (saveCurr) + if (saveCurr && m_activeSessionId != INVALID_SESSION) { m_sessions[m_activeSessionId]->save(true); } @@ -440,7 +443,7 @@ int KateSessionManager::newSession(const TQString &sessionName, bool activate) emit sessionCreated(newSessionId); if (activate) { - activateSession(newSessionId, true); + activateSession(newSessionId, m_activeSessionId != INVALID_SESSION); } return newSessionId; } @@ -461,11 +464,44 @@ void KateSessionManager::slotNewSession() { // FIXME: allow the user to enter a session name first // FIXME: allow the user to specify whether to switch to the new session or not - newSession(TQString::null, true); + newSession(); } +//------------------------------------------- +bool KateSessionManager::deleteSession(int sessionId) +{ + if (sessionId < 0 || sessionId >= m_sessionsCount) + return false; + + // delete session file if it exists + const TQString &filename = m_sessions[sessionId]->getSessionFilename(); + if (filename != TQString::null && TQFile::exists(filename)) + { + TQFile::remove(filename); + } + // delete session + m_sessions.remove(sessionId); // this also deletes the KateSession item since auto-deletion is enabled + --m_sessionsCount; + if (m_activeSessionId > sessionId) + { + --m_activeSessionId; + } + else if (m_activeSessionId == sessionId) + { + m_activeSessionId = INVALID_SESSION; + } + emit sessionDeleted(sessionId); + // if the active session was deleted, create a new unnamed session and activate it + if (m_activeSessionId == INVALID_SESSION) + { + newSession(); + } + + return true; +} //END KateSessionManager + //BEGIN KateSessionChooser //------------------------------------------- KateSessionChooser::KateSessionChooser(TQWidget *parent) @@ -545,7 +581,6 @@ void KateSessionChooser::slotSelectionChanged() { enableButton(KDialogBase::User2, m_sessionList->selectedItem()); } - //END KateSessionChooser @@ -556,12 +591,6 @@ void KateSessionChooser::slotSelectionChanged() //------------------------------------ //------------------------------------ //------------------------------------ -// Michele - to be removed with OldKateSession -bool operator<( const OldKateSession::Ptr& a, const OldKateSession::Ptr& b ) -{ - return a->sessionName().lower() < b->sessionName().lower(); -} - OldKateSession::OldKateSession (OldKateSessionManager *manager, const TQString &fileName, const TQString &name) : m_sessionFileRel (fileName) , m_sessionName (name) diff --git a/kate/app/katesession.h b/kate/app/katesession.h index ff6b3c0fa..831fdcf80 100644 --- a/kate/app/katesession.h +++ b/kate/app/katesession.h @@ -1,4 +1,6 @@ /* This file is part of the KDE project + Copyright (C) 2015-2016 Michele Calgaro + partially based on previous work from Copyright (C) 2005 Christoph Cullmann This library is free software; you can redistribute it and/or @@ -32,15 +34,12 @@ #include class KateViewSpace; - -class OldKateSessionManager; // Michele - to be removed with OldKateSession - class KDirWatch; -class TDEListView; class KPushButton; - +class TDEListView; class TQCheckBox; + //BEGIN KateSession class KateSession { @@ -82,9 +81,9 @@ class KateSession void setReadOnly(bool readOnly); /** - * @return the session filename + * @return the session filename if available, otherwise the null string */ - const TQString& getSessionFilename() const { return m_filename; } + const TQString& getSessionFilename() const { return m_isFullName ? m_filename : TQString::null; } /** * @return the number of documents in the session @@ -114,17 +113,18 @@ class KateSession TQString m_sessionName; TQString m_filename; bool m_isFullName; // true -> m_filename is a full filename - // false -> m_filename is a folder name. + // false -> m_filename is a folder name. bool m_readOnly; - int m_docCount; // number of documents in the session + int m_docCount; // number of documents in the session // FIXME remove and use m_documents.count() TQStringList m_documents; // document URLs KSimpleConfig *m_config; // session config }; - //END 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 @@ -133,7 +133,6 @@ class KateSession //This would allow a safe use of multiple Kate instances without overwriting session information //among them. Currently the last instance to be closed will overwrite the information previously //saved by other Kate instances. -//------------------------------------ class KateSessionManager : public TQObject { Q_OBJECT @@ -219,6 +218,14 @@ class KateSessionManager : public TQObject */ void saveActiveSession() { m_sessions[m_activeSessionId]->save(true); } + /** + * Delete the specified session + * @param sessionId the id of the session to delete + * @return whether the session has been deleted or not + */ + bool deleteSession(int sessionId); + + signals: /** * Emitted once a session has been activated @@ -229,9 +236,15 @@ class KateSessionManager : public TQObject /** * Emitted once a session has been created - * @param newSessionId the id of the new session + * @param sessionId the id of the new session + */ + void sessionCreated(int sessionId); + + /** + * Emitted once a session has been deleted + * @param sessionId the id of the deleted session */ - void sessionCreated(int newSessionId); + void sessionDeleted(int sessionId); public slots: @@ -246,7 +259,7 @@ class KateSessionManager : public TQObject TQString m_baseDir; // folder where session files are stored TQString m_configFile; // file where the session list config is stored - int m_sessionsCount; // number of sessions + int m_sessionsCount; // number of sessions // FIXME remove and use m_sessions.count() int m_activeSessionId; // index of the active session bool m_firstActivation; // true until at least one session has been activated TQPtrList m_sessions; // session list @@ -254,10 +267,12 @@ class KateSessionManager : public TQObject static KateSessionManager *ksm_instance; // the only KateSessionManager instance }; - //END KateSessionManager + //BEGIN KateSessionChooser +//FIXME subclass TQListViewItem adding a field containing the session id, +// then remove the m_columnSessionId column //------------------------------------ class KateSessionChooser : public KDialogBase { @@ -288,7 +303,6 @@ class KateSessionChooser : public KDialogBase TDEListView *m_sessionList; int m_columnSessionId; }; - //BEGIN KateSessionChooser @@ -298,6 +312,7 @@ class KateSessionChooser : public KDialogBase //------------------------------------ //------------------------------------ //------------------------------------ +class OldKateSessionManager; class OldKateSession : public TDEShared { public: diff --git a/kate/app/katesessionpanel.cpp b/kate/app/katesessionpanel.cpp index 2e8c12945..52451bb66 100644 --- a/kate/app/katesessionpanel.cpp +++ b/kate/app/katesessionpanel.cpp @@ -1,5 +1,5 @@ /* This file is part of the TDE project - Copyright (C) 2015 Michele Calgaro + Copyright (C) 2015-2016 Michele Calgaro This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -28,6 +28,7 @@ #include +//BEGIN KateSessionPanelToolBarParent void KateSessionPanelToolBarParent::setToolBar(TDEToolBar *tbar) { m_tbar = tbar; @@ -42,7 +43,10 @@ void KateSessionPanelToolBarParent::resizeEvent (TQResizeEvent*) m_tbar->resize(width(),height()); } } +//END KateSessionPanelToolBarParent + +//BEGIN KateSessionPanel //------------------------------------------- KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager *viewManager, TQWidget *parent, const char *name) @@ -67,6 +71,7 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager * connect(m_listview, TQT_SIGNAL(executed(TQListViewItem*)), this, TQT_SLOT(itemExecuted(TQListViewItem*))); connect(m_sessionManager, TQT_SIGNAL(sessionActivated(int, int)), this, TQT_SLOT(slotSessionActivated(int, int))); connect(m_sessionManager, TQT_SIGNAL(sessionCreated(int)), this, TQT_SLOT(slotSessionCreated(int))); + connect(m_sessionManager, TQT_SIGNAL(sessionDeleted(int)), this, TQT_SLOT(slotSessionDeleted(int))); TQPtrList& sessions = m_sessionManager->getSessionsList(); for (int idx = sessions.count()-1; idx >= 0; --idx) @@ -118,16 +123,16 @@ void KateSessionPanel::setup_toolbar() TQT_TQOBJECT(this), TQT_SLOT(renameSession()), m_actionCollection, "session_rename"); a->setWhatsThis(i18n("Rename the selected session.")); a->plug(m_toolbar); - +*/ a = new TDEAction(i18n("Delete"), SmallIcon("edit-delete"), 0, TQT_TQOBJECT(this), TQT_SLOT(deleteSession()), m_actionCollection, "session_delete"); a->setWhatsThis(i18n("Delete the selected session.")); a->plug(m_toolbar); m_toolbar->insertLineSeparator(); -*/ + a = new TDEAction(i18n("Activate"), SmallIcon("forward"), 0, - TQT_TQOBJECT(this), TQT_SLOT(sessionActivate()), m_actionCollection, "session_activate"); + TQT_TQOBJECT(this), TQT_SLOT(activateSession()), m_actionCollection, "session_activate"); a->setWhatsThis(i18n("Activate the selected session.")); a->plug(m_toolbar); /* @@ -172,11 +177,16 @@ void KateSessionPanel::renameSession() //------------------------------------------- void KateSessionPanel::deleteSession() { -//TODO + TQListViewItem *sessionItem = m_listview->selectedItem(); + if (!sessionItem) + return; + + //FIXME ask for user confirmation before proceeding + m_sessionManager->deleteSession(sessionItem->text(m_columnSessionId).toInt()); } //------------------------------------------- -void KateSessionPanel::sessionActivate() +void KateSessionPanel::activateSession() { TQListViewItem *newSessionItem = m_listview->selectedItem(); if (!newSessionItem) @@ -216,7 +226,7 @@ void KateSessionPanel::itemExecuted(TQListViewItem *item) // First level items are sessions. Executing one, will switch to that session if (!item->parent()) { - sessionActivate(); + activateSession(); return; } } @@ -241,8 +251,32 @@ void KateSessionPanel::slotSessionActivated(int newSessionId, int oldSessionId) m_listview->setSelected(item, true); } -void KateSessionPanel::slotSessionCreated(int newSessionId) +//------------------------------------------- +void KateSessionPanel::slotSessionCreated(int sessionId) { TQPtrList& sessions = m_sessionManager->getSessionsList(); - new TDEListViewItem(m_listview, m_listview->lastItem(), sessions[newSessionId]->getSessionName(), TQString("%1").arg(newSessionId)); + new TDEListViewItem(m_listview, m_listview->lastItem(), sessions[sessionId]->getSessionName(), + TQString("%1").arg(sessionId)); +} + +//------------------------------------------- +void KateSessionPanel::slotSessionDeleted(int sessionId) +{ + // delete item from listview + TQListViewItem *item = m_listview->firstChild(); + int idx = 0; + for (; idx < sessionId; ++idx) + { + item = item->nextSibling(); + } + TQListViewItem *nextItem = item->nextSibling(); + delete item; + // update session id of all following items + item = nextItem; + while (item) + { + item->setText(m_columnSessionId, TQString("%1").arg(idx++)); + item = item->nextSibling(); + } } +//END KateSessionPanel diff --git a/kate/app/katesessionpanel.h b/kate/app/katesessionpanel.h index a33535755..22a8d4fb9 100644 --- a/kate/app/katesessionpanel.h +++ b/kate/app/katesessionpanel.h @@ -1,5 +1,5 @@ /* This file is part of the TDE project - Copyright (C) 2015 Michele Calgaro + Copyright (C) 2015-2016 Michele Calgaro This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -37,6 +37,7 @@ class KateSessionManager; class TDEActionCollection; +//BEGIN KateSessionPanelToolBarParent class KateSessionPanelToolBarParent: public TQFrame { Q_OBJECT @@ -52,9 +53,13 @@ class KateSessionPanelToolBarParent: public TQFrame private: TDEToolBar *m_tbar; }; +//END KateSessionPanelToolBarParent - +//BEGIN KateSessionPanel +//------------------------------------ +//FIXME subclass TQListViewItem adding a field containing the session id, +// then remove the m_columnSessionId column class KateSessionPanel : public TQVBox { Q_OBJECT @@ -65,19 +70,22 @@ class KateSessionPanel : public TQVBox TQWidget *parent=0, const char *name=0); ~KateSessionPanel() {} + public slots: void saveSession(); void saveSessionAs(); void renameSession(); void deleteSession(); - void sessionActivate(); + void activateSession(); void sessionToggleReadOnly(); void sessionMoveUp(); void sessionMoveDown(); void itemExecuted(TQListViewItem *item); void slotSessionActivated(int newSessionId, int oldSessionId); - void slotSessionCreated(int newSessionId); + void slotSessionCreated(int sessionId); + void slotSessionDeleted(int sessionId); + private: void setup_toolbar(); @@ -91,7 +99,7 @@ class KateSessionPanel : public TQVBox int m_columnSessionId; int m_columnPixmap; }; +//END KateSessionPanel #endif //__KATE_SESSIONPANEL_H__ -// kate: space-indent on; indent-width 2; replace-tabs on; -- cgit v1.2.1 From 93c96f301cc324ea0a38df701f70dc7bfce4b314 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Mon, 22 Feb 2016 20:25:09 +0700 Subject: Kate session panel: some code refactoring + completed GUI for "New session" and "Delete session". Signed-off-by: Michele Calgaro --- kate/app/kateapp.cpp | 1 + kate/app/katesession.cpp | 91 ++++++++++--------------- kate/app/katesession.h | 40 +++++------ kate/app/katesessionpanel.cpp | 152 ++++++++++++++++++++++++++++++++---------- kate/app/katesessionpanel.h | 70 +++++++++++++++---- 5 files changed, 233 insertions(+), 121 deletions(-) (limited to 'kate') diff --git a/kate/app/kateapp.cpp b/kate/app/kateapp.cpp index 167062245..06b0c0ecb 100644 --- a/kate/app/kateapp.cpp +++ b/kate/app/kateapp.cpp @@ -218,6 +218,7 @@ bool KateApp::startupKate() return false; break; } + delete chooser; } } diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index 0a8d0c915..1380b19d0 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -43,7 +42,6 @@ #include #include #include -#include #include #include @@ -79,7 +77,7 @@ namespace //BEGIN Kate session KateSession::KateSession(const TQString &sessionName, const TQString &filename, bool isFullName) : m_sessionName(sessionName), m_filename(filename), m_isFullName(isFullName), - m_readOnly(false), m_docCount(0), m_documents(), m_config(NULL) + m_readOnly(false), m_documents(), m_config(NULL) { if (m_isFullName && TDEGlobal::dirs()->exists(m_filename)) { @@ -99,8 +97,8 @@ KateSession::KateSession(const TQString &sessionName, const TQString &filename, { // Read new style document list (from TDE R14.1.0) m_config->setGroup(KS_DOCLIST); - m_docCount = m_config->readNumEntry(KS_DOCCOUNT, 0); - for (int i=0; ireadNumEntry(KS_DOCCOUNT, 0); + for (int i = 0; i < docCount; ++i) { TQString urlStr = m_config->readEntry(TQString("URL_%1").arg(i)); if (!urlStr.isEmpty()) @@ -115,8 +113,8 @@ KateSession::KateSession(const TQString &sessionName, const TQString &filename, // Create document list from old session configuration // to effortlessly import existing sessions m_config->setGroup(KS_OPENDOC); - m_docCount = m_config->readNumEntry(KS_COUNT, 0); - for (int i=0; ireadNumEntry(KS_COUNT, 0); + for (int i = 0; i < docCount; ++i) { m_config->setGroup(TQString("Document %1").arg(i)); TQString urlStr = m_config->readEntry("URL"); @@ -127,8 +125,6 @@ KateSession::KateSession(const TQString &sessionName, const TQString &filename, } } } - // Update document count again, in case empty URLs were found - m_docCount = static_cast(m_documents.count()); } if (m_sessionName.isEmpty()) { @@ -213,8 +209,8 @@ void KateSession::save(bool saveGUIInfo) m_config->deleteGroup(KS_DOCLIST); } m_config->setGroup(KS_DOCLIST); - m_config->writeEntry(KS_DOCCOUNT, m_docCount); - for (int i=0; iwriteEntry(KS_DOCCOUNT, m_documents.count()); + for (int i = 0; i < (int)m_documents.count(); ++i) { m_config->writeEntry(TQString("URL_%1").arg(i), m_documents[i]); } @@ -227,7 +223,7 @@ void KateSession::save(bool saveGUIInfo) int mwCount = KateApp::self()->mainWindows(); m_config->setGroup(KS_OPEN_MAINWINDOWS); m_config->writeEntry(KS_COUNT, mwCount); - for (int i=0; isetGroup(TQString("MainWindow%1").arg(i)); KateApp::self()->mainWindow(i)->saveProperties(m_config); @@ -291,19 +287,19 @@ KateSessionManager* KateSessionManager::self() //------------------------------------ KateSessionManager::KateSessionManager() : m_baseDir(locateLocal("data", KSM_DIR)+"/"), m_configFile(m_baseDir + KSM_FILE), - m_sessionsCount(0), m_activeSessionId(0), m_firstActivation(true), m_sessions(), m_config(NULL) + m_activeSessionId(0), m_firstActivation(true), m_sessions(), m_config(NULL) { m_sessions.setAutoDelete(true); + int sessionsCount = 0; if (TDEGlobal::dirs()->exists(m_configFile)) { // Read new style configuration (from TDE R14.1.0) m_config = new KSimpleConfig(m_configFile); m_config->setGroup(KSM_SESSIONS_LIST); - m_sessionsCount = m_config->readNumEntry(KSM_SESSIONS_COUNT, 0); - //FIXME : if m_sessionsCount == 0, create session list from existing session files + sessionsCount = m_config->readNumEntry(KSM_SESSIONS_COUNT, 0); m_activeSessionId = m_config->readNumEntry(KSM_ACTIVE_SESSION_ID, 0); - for (int i=0; ireadEntry(TQString("URL_%1").arg(i)); if (!urlStr.isEmpty() && TDEGlobal::dirs()->exists(urlStr)) @@ -318,18 +314,17 @@ KateSessionManager::KateSessionManager() : // Create sessions list from session files // to effortlessly import existing sessions TQDir sessionDir(m_baseDir, "*.katesession"); - for (unsigned int i=0; i(m_sessions.count()); - if (m_sessionsCount == 0) // In the worst case, there is no valid session at all + sessionsCount = (int)m_sessions.count(); + 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_sessionsCount; } - if (m_activeSessionId < 0 || m_activeSessionId >= m_sessionsCount) + if (m_activeSessionId < 0 || m_activeSessionId >= (int)m_sessions.count()) { m_activeSessionId = 0; // Invalid active session was detected. Use first in the list } @@ -370,9 +365,9 @@ void KateSessionManager::saveConfig() m_config->deleteGroup(KSM_SESSIONS_LIST); } m_config->setGroup(KSM_SESSIONS_LIST); - m_config->writeEntry(KSM_SESSIONS_COUNT, m_sessionsCount); + m_config->writeEntry(KSM_SESSIONS_COUNT, m_sessions.count()); m_config->writeEntry(KSM_ACTIVE_SESSION_ID, m_activeSessionId); - for (int i=0; isave(false); @@ -387,7 +382,7 @@ int KateSessionManager::getSessionIdFromName(const TQString &name) if (name.isEmpty()) return KateSessionManager::INVALID_SESSION; - for (int i=0; igetSessionName() == name) return i; @@ -397,8 +392,6 @@ int KateSessionManager::getSessionIdFromName(const TQString &name) } //------------------------------------ -//FIXME: after a session switch, the session name on Kate window title bar displays -//the previously activated session bool KateSessionManager::activateSession(int sessionId, bool saveCurr) { if (sessionId < 0) @@ -438,8 +431,7 @@ bool KateSessionManager::activateSession(int sessionId, bool saveCurr) int KateSessionManager::newSession(const TQString &sessionName, bool activate) { m_sessions.append(new KateSession(sessionName, m_baseDir, false)); - ++m_sessionsCount; - int newSessionId = m_sessionsCount - 1; + int newSessionId = m_sessions.count() - 1; emit sessionCreated(newSessionId); if (activate) { @@ -459,18 +451,10 @@ bool KateSessionManager::restoreLastSession() return activateSession(m_activeSessionId, false); } -//------------------------------------------- -void KateSessionManager::slotNewSession() -{ - // FIXME: allow the user to enter a session name first - // FIXME: allow the user to specify whether to switch to the new session or not - newSession(); -} - //------------------------------------------- bool KateSessionManager::deleteSession(int sessionId) { - if (sessionId < 0 || sessionId >= m_sessionsCount) + if (sessionId < 0 || sessionId >= (int)m_sessions.count()) return false; // delete session file if it exists @@ -481,7 +465,6 @@ bool KateSessionManager::deleteSession(int sessionId) } // delete session m_sessions.remove(sessionId); // this also deletes the KateSession item since auto-deletion is enabled - --m_sessionsCount; if (m_activeSessionId > sessionId) { --m_activeSessionId; @@ -508,7 +491,7 @@ KateSessionChooser::KateSessionChooser(TQWidget *parent) : KDialogBase(parent, "", true, i18n("Session Chooser"), KDialogBase::User1 | KDialogBase::User2 | KDialogBase::User3, KDialogBase::User2, true, KStdGuiItem::quit(), KGuiItem(i18n("Open Session"), "document-open"), - KGuiItem(i18n("New Session"), "document-new")), m_sessionList(NULL), m_columnSessionId(0) + KGuiItem(i18n("New Session"), "document-new")), m_listview(NULL) { TQHBox *page = new TQHBox(this); page->setMinimumSize(400, 200); @@ -524,24 +507,22 @@ KateSessionChooser::KateSessionChooser(TQWidget *parent) TQVBox *vb = new TQVBox(hb); vb->setSpacing (KDialog::spacingHint()); - m_sessionList = new TDEListView(vb); - m_sessionList->addColumn(i18n("Session Name")); - m_columnSessionId = m_sessionList->addColumn("Session Id", 0); // Non visible column - m_sessionList->header()->setResizeEnabled(false, m_columnSessionId); - m_sessionList->addColumn(i18n("Open Documents")); - m_sessionList->setSelectionMode(TQListView::Single); - m_sessionList->setAllColumnsShowFocus(true); - m_sessionList->setSorting(-1); - m_sessionList->setResizeMode(TQListView::LastColumn); + m_listview = new TDEListView(vb); + m_listview->addColumn(i18n("Session Name")); + m_listview->addColumn(i18n("Open Documents")); + m_listview->setSelectionMode(TQListView::Single); + m_listview->setAllColumnsShowFocus(true); + m_listview->setSorting(-1); + m_listview->setResizeMode(TQListView::LastColumn); - connect (m_sessionList, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(slotSelectionChanged())); - connect (m_sessionList, TQT_SIGNAL(executed(TQListViewItem*)), this, TQT_SLOT(slotUser2())); + connect (m_listview, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(slotSelectionChanged())); + connect (m_listview, TQT_SIGNAL(executed(TQListViewItem*)), this, TQT_SLOT(slotUser2())); TQPtrList& sessions = KateSessionManager::self()->getSessionsList(); for (int idx = sessions.count()-1; idx >= 0; --idx) { - new TDEListViewItem(m_sessionList, sessions[idx]->getSessionName(), TQString("%1").arg(idx), - TQString("%1").arg(sessions[idx]->getDocCount())); + new KateSessionChooserItem(m_listview, sessions[idx]->getSessionName(), + TQString("%1").arg(sessions[idx]->getDocCount()), idx); } setResult(RESULT_NO_OP); @@ -551,11 +532,11 @@ KateSessionChooser::KateSessionChooser(TQWidget *parent) //------------------------------------------- int KateSessionChooser::getSelectedSessionId() { - TQListViewItem *selectedItem = m_sessionList->selectedItem(); + KateSessionChooserItem *selectedItem = dynamic_cast(m_listview->selectedItem()); if (!selectedItem) return KateSessionManager::INVALID_SESSION; - return selectedItem->text(m_columnSessionId).toInt(); + return selectedItem->getSessionId(); } //------------------------------------------- @@ -579,7 +560,7 @@ void KateSessionChooser::slotUser3() //------------------------------------------- void KateSessionChooser::slotSelectionChanged() { - enableButton(KDialogBase::User2, m_sessionList->selectedItem()); + enableButton(KDialogBase::User2, m_listview->selectedItem()); } //END KateSessionChooser diff --git a/kate/app/katesession.h b/kate/app/katesession.h index 831fdcf80..28cabea75 100644 --- a/kate/app/katesession.h +++ b/kate/app/katesession.h @@ -32,6 +32,7 @@ #include #include #include +#include class KateViewSpace; class KDirWatch; @@ -88,7 +89,7 @@ class KateSession /** * @return the number of documents in the session */ - int getDocCount() const { return m_docCount; } + int getDocCount() const { return m_documents.count(); } /** * Save session info @@ -115,7 +116,6 @@ class KateSession bool m_isFullName; // true -> m_filename is a full filename // false -> m_filename is a folder name. bool m_readOnly; - int m_docCount; // number of documents in the session // FIXME remove and use m_documents.count() TQStringList m_documents; // document URLs KSimpleConfig *m_config; // session config @@ -124,7 +124,6 @@ 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 @@ -247,19 +246,11 @@ class KateSessionManager : public TQObject void sessionDeleted(int sessionId); - public slots: - /** - * Slot to create a new session - */ - void slotNewSession(); - - private: KateSessionManager(); TQString m_baseDir; // folder where session files are stored TQString m_configFile; // file where the session list config is stored - int m_sessionsCount; // number of sessions // FIXME remove and use m_sessions.count() int m_activeSessionId; // index of the active session bool m_firstActivation; // true until at least one session has been activated TQPtrList m_sessions; // session list @@ -270,10 +261,23 @@ class KateSessionManager : public TQObject //END KateSessionManager +//BEGIN KateSessionChooserItem +class KateSessionChooserItem : public TDEListViewItem +{ + public: + KateSessionChooserItem(TQListView *listview, const TQString &sessionName, const TQString &nDoc, int sessionId) + : TDEListViewItem(listview, sessionName, nDoc), m_sessionId(sessionId) {} + + int getSessionId() { return m_sessionId; } + void setSessionId(int sessionId) { m_sessionId = sessionId; } + + protected: + int m_sessionId; +}; +//END KateSessionChooserItem + + //BEGIN KateSessionChooser -//FIXME subclass TQListViewItem adding a field containing the session id, -// then remove the m_columnSessionId column -//------------------------------------ class KateSessionChooser : public KDialogBase { Q_OBJECT @@ -288,9 +292,9 @@ class KateSessionChooser : public KDialogBase }; KateSessionChooser(TQWidget *parent); - KateSessionChooser() {} + ~KateSessionChooser() {} - int getSelectedSessionId(); //return the session id of the selected session + int getSelectedSessionId(); // return the session id of the selected session protected slots: @@ -300,15 +304,13 @@ class KateSessionChooser : public KDialogBase void slotSelectionChanged(); // list selection has changed protected: - TDEListView *m_sessionList; - int m_columnSessionId; + TDEListView *m_listview; }; //BEGIN KateSessionChooser - //------------------------------------ //------------------------------------ //------------------------------------ diff --git a/kate/app/katesessionpanel.cpp b/kate/app/katesessionpanel.cpp index 52451bb66..7d2433c8d 100644 --- a/kate/app/katesessionpanel.cpp +++ b/kate/app/katesessionpanel.cpp @@ -25,7 +25,74 @@ #include #include +#include #include +#include + + +namespace +{ + const char *KS_UNNAMED = "Unnamed"; +}; + + +//BEGIN KateSessionNameChooser +//------------------------------------------- +KateSessionNameChooser::KateSessionNameChooser(TQWidget *parent) + : KDialogBase(parent, "", true, i18n("Session Name Chooser"), KDialogBase::User1 | KDialogBase::User2, + KDialogBase::User2, true, KStdGuiItem::cancel(), KGuiItem(i18n("Continue"), "document-new")) +{ + TQHBox *page = new TQHBox(this); + //page->setMinimumSize(300, 100); + setMainWidget(page); + + TQVBox *vb = new TQVBox(page); + vb->setSpacing(KDialog::spacingHint()); + + TQLabel *label = new TQLabel(vb); + label->setText("Please type the new session name:"); + + m_sessionNameLE = new TQLineEdit(vb); + m_sessionNameLE->setText(KS_UNNAMED); + m_sessionNameLE->setFocus(); + + m_activateCB = new TQCheckBox(i18n("Switch to the new session"), vb, NULL); + m_activateCB->setChecked(true); + + connect (m_sessionNameLE, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotTextChanged())); + slotTextChanged(); // update button status +} + +//------------------------------------------- +TQString KateSessionNameChooser::getSessionName() +{ + return m_sessionNameLE->text(); +} + +//------------------------------------------- +bool KateSessionNameChooser::getActivateFlag() +{ + return m_activateCB->isChecked(); +} + +//------------------------------------------- +void KateSessionNameChooser::slotUser1() +{ + reject(); +} + +//------------------------------------------- +void KateSessionNameChooser::slotUser2() +{ + accept(); +} + +//------------------------------------------- +void KateSessionNameChooser::slotTextChanged() +{ + enableButton(KDialogBase::User2, !m_sessionNameLE->text().isEmpty()); +} +//END KateSessionNameChooser //BEGIN KateSessionPanelToolBarParent @@ -52,7 +119,7 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager * TQWidget *parent, const char *name) : TQVBox(parent, name), m_mainWin(mainWindow), m_viewManager(viewManager), m_sessionManager(KateSessionManager::self()), m_actionCollection(new TDEActionCollection(this)), - m_columnSessionId(0), m_columnPixmap(0) + m_columnPixmap(0) { // Toolbar setup_toolbar(); @@ -61,14 +128,15 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager * m_listview = new TDEListView(this); m_listview->header()->hide(); m_listview->addColumn("Session name"); - m_columnSessionId = m_listview->addColumn("Session id", 50); - m_listview->header()->setResizeEnabled(false, m_columnSessionId); m_columnPixmap = m_listview->addColumn("Pixmap", 24); - m_listview->setColumnAlignment(2, TQt::AlignCenter); + m_listview->addColumn("Dummy", 1); // Dummy column, only for nice resizing + m_listview->header()->setResizeEnabled(false, m_columnPixmap); + m_listview->setColumnAlignment(m_columnPixmap, TQt::AlignCenter); m_listview->setMinimumWidth(m_listview->sizeHint().width()); m_listview->setSorting(-1); + m_listview->setResizeMode(TQListView::LastColumn); //m_listview->setRootIsDecorated(true); // FIXME to enable after inserting doc list - connect(m_listview, TQT_SIGNAL(executed(TQListViewItem*)), this, TQT_SLOT(itemExecuted(TQListViewItem*))); + connect(m_listview, TQT_SIGNAL(executed(TQListViewItem*)), this, TQT_SLOT(slotItemExecuted(TQListViewItem*))); connect(m_sessionManager, TQT_SIGNAL(sessionActivated(int, int)), this, TQT_SLOT(slotSessionActivated(int, int))); connect(m_sessionManager, TQT_SIGNAL(sessionCreated(int)), this, TQT_SLOT(slotSessionCreated(int))); connect(m_sessionManager, TQT_SIGNAL(sessionDeleted(int)), this, TQT_SLOT(slotSessionDeleted(int))); @@ -76,7 +144,7 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager * TQPtrList& sessions = m_sessionManager->getSessionsList(); for (int idx = sessions.count()-1; idx >= 0; --idx) { - new TDEListViewItem(m_listview, sessions[idx]->getSessionName(), TQString("%1").arg(idx)); + new KateSessionPanelItem(m_listview, sessions[idx]->getSessionName(), idx); if (idx == m_sessionManager->getActiveSessionId()) { m_listview->setSelected(m_listview->firstChild(), true); @@ -104,40 +172,39 @@ void KateSessionPanel::setup_toolbar() TDEAction *a; a = new TDEAction(i18n("New"), SmallIcon("list-add"), 0, - TQT_TQOBJECT(m_sessionManager), TQT_SLOT(slotNewSession()), - m_actionCollection, "session_new"); + TQT_TQOBJECT(this), TQT_SLOT(slotNewSession()), m_actionCollection, "session_new"); a->setWhatsThis(i18n("Create a new session.")); a->plug(m_toolbar); /* a = new TDEAction(i18n("Save"), SmallIcon("document-save"), 0, - TQT_TQOBJECT(this), TQT_SLOT(saveSession()), m_actionCollection, "session_save"); + TQT_TQOBJECT(this), TQT_SLOT(slotSaveSession()), m_actionCollection, "session_save"); a->setWhatsThis(i18n("Save the current session.")); a->plug(m_toolbar); a = new TDEAction(i18n("Save as..."), SmallIcon("document-save-as"), 0, - TQT_TQOBJECT(this), TQT_SLOT(saveSessionAs()), 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->plug(m_toolbar); a = new TDEAction(i18n("Rename"), SmallIcon("edit_user"), 0, - TQT_TQOBJECT(this), TQT_SLOT(renameSession()), m_actionCollection, "session_rename"); + TQT_TQOBJECT(this), TQT_SLOT(slotRenameSession()), m_actionCollection, "session_rename"); a->setWhatsThis(i18n("Rename the selected session.")); a->plug(m_toolbar); */ a = new TDEAction(i18n("Delete"), SmallIcon("edit-delete"), 0, - TQT_TQOBJECT(this), TQT_SLOT(deleteSession()), m_actionCollection, "session_delete"); + TQT_TQOBJECT(this), TQT_SLOT(slotDeleteSession()), m_actionCollection, "session_delete"); a->setWhatsThis(i18n("Delete the selected session.")); a->plug(m_toolbar); m_toolbar->insertLineSeparator(); a = new TDEAction(i18n("Activate"), SmallIcon("forward"), 0, - TQT_TQOBJECT(this), TQT_SLOT(activateSession()), m_actionCollection, "session_activate"); + TQT_TQOBJECT(this), TQT_SLOT(slotActivateSession()), m_actionCollection, "session_activate"); a->setWhatsThis(i18n("Activate the selected session.")); a->plug(m_toolbar); /* TDEToggleAction *tglA = new TDEToggleAction(i18n("Toggle read only"), SmallIcon("encrypted"), 0, - TQT_TQOBJECT(this), TQT_SLOT(sessionToggleReadOnly()), m_actionCollection, "session_toggle_read_only"); + TQT_TQOBJECT(this), TQT_SLOT(slotSessionToggleReadOnly()), m_actionCollection, "session_toggle_read_only"); tglA->setWhatsThis(i18n("Toggle read only status for the selected session.

" "In a read only session, you can work as usual but the list of documents in the session " "will not be saved when you exit Kate or switch to another session.

" @@ -145,55 +212,72 @@ void KateSessionPanel::setup_toolbar() tglA->plug(m_toolbar); a = new TDEAction(i18n("Move Up"), SmallIcon("go-up"), 0, - TQT_TQOBJECT(this), TQT_SLOT(sessionMoveUp()), m_actionCollection, "session_move_up"); + TQT_TQOBJECT(this), TQT_SLOT(slotSessionMoveUp()), m_actionCollection, "session_move_up"); a->setWhatsThis(i18n("Move up the selected session.")); a->plug(m_toolbar); a = new TDEAction(i18n("Move Down"), SmallIcon("go-down"), 0, - TQT_TQOBJECT(this), TQT_SLOT(sessionMoveDown()), 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->plug(m_toolbar); */ } //------------------------------------------- -void KateSessionPanel::saveSession() +void KateSessionPanel::slotNewSession() +{ + KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this); + int result = nameChooser->exec(); + if (result == TQDialog::Accepted) + { + m_sessionManager->newSession(nameChooser->getSessionName(), nameChooser->getActivateFlag()); + } + delete nameChooser; +} + +//------------------------------------------- +void KateSessionPanel::slotSaveSession() { //TODO } //------------------------------------------- -void KateSessionPanel::saveSessionAs() +void KateSessionPanel::slotSaveSessionAs() { //TODO } //------------------------------------------- -void KateSessionPanel::renameSession() +void KateSessionPanel::slotRenameSession() { //TODO } //------------------------------------------- -void KateSessionPanel::deleteSession() +void KateSessionPanel::slotDeleteSession() { - TQListViewItem *sessionItem = m_listview->selectedItem(); + KateSessionPanelItem *sessionItem = dynamic_cast(m_listview->selectedItem()); if (!sessionItem) return; - //FIXME ask for user confirmation before proceeding - m_sessionManager->deleteSession(sessionItem->text(m_columnSessionId).toInt()); + int result = KMessageBox::warningContinueCancel(this, + i18n("Do you really want to delete the session '%1'?").arg(sessionItem->text(0)), + i18n("Delete session"), KStdGuiItem::del()); + if (result == KMessageBox::Continue) + { + m_sessionManager->deleteSession(sessionItem->getSessionId()); + } } //------------------------------------------- -void KateSessionPanel::activateSession() +void KateSessionPanel::slotActivateSession() { - TQListViewItem *newSessionItem = m_listview->selectedItem(); + KateSessionPanelItem *newSessionItem = dynamic_cast(m_listview->selectedItem()); if (!newSessionItem) return; int currSessionId = m_sessionManager->getActiveSessionId(); - int newSessionId = newSessionItem->text(m_columnSessionId).toInt(); + int newSessionId = newSessionItem->getSessionId(); if (newSessionId != currSessionId) { m_sessionManager->activateSession(newSessionId); @@ -201,24 +285,24 @@ void KateSessionPanel::activateSession() } //------------------------------------------- -void KateSessionPanel::sessionToggleReadOnly() +void KateSessionPanel::slotSessionToggleReadOnly() { //TODO } //------------------------------------------- -void KateSessionPanel::sessionMoveUp() +void KateSessionPanel::slotSessionMoveUp() { //TODO } //------------------------------------------- -void KateSessionPanel::sessionMoveDown() +void KateSessionPanel::slotSessionMoveDown() { //TODO } -void KateSessionPanel::itemExecuted(TQListViewItem *item) +void KateSessionPanel::slotItemExecuted(TQListViewItem *item) { if (!item) return; @@ -226,7 +310,7 @@ void KateSessionPanel::itemExecuted(TQListViewItem *item) // First level items are sessions. Executing one, will switch to that session if (!item->parent()) { - activateSession(); + slotActivateSession(); return; } } @@ -255,8 +339,8 @@ void KateSessionPanel::slotSessionActivated(int newSessionId, int oldSessionId) void KateSessionPanel::slotSessionCreated(int sessionId) { TQPtrList& sessions = m_sessionManager->getSessionsList(); - new TDEListViewItem(m_listview, m_listview->lastItem(), sessions[sessionId]->getSessionName(), - TQString("%1").arg(sessionId)); + new KateSessionPanelItem(m_listview, m_listview->lastItem(), sessions[sessionId]->getSessionName(), + sessionId); } //------------------------------------------- @@ -275,7 +359,7 @@ void KateSessionPanel::slotSessionDeleted(int sessionId) item = nextItem; while (item) { - item->setText(m_columnSessionId, TQString("%1").arg(idx++)); + dynamic_cast(item)->setSessionId(idx++); item = item->nextSibling(); } } diff --git a/kate/app/katesessionpanel.h b/kate/app/katesessionpanel.h index 22a8d4fb9..03f0e53dd 100644 --- a/kate/app/katesessionpanel.h +++ b/kate/app/katesessionpanel.h @@ -30,6 +30,9 @@ #include #include #include +#include +#include +#include class KateMainWindow; class KateViewManager; @@ -37,6 +40,32 @@ class KateSessionManager; class TDEActionCollection; +//BEGIN KateSessionNameChooser +class KateSessionNameChooser : public KDialogBase +{ + Q_OBJECT + + public: + + KateSessionNameChooser(TQWidget *parent); + ~KateSessionNameChooser() {} + + TQString getSessionName(); // return the session name typed by the user + bool getActivateFlag(); // return whether to switch to the new session or not + + protected slots: + + void slotUser1(); // create new session + void slotUser2(); // cancel + void slotTextChanged(); // session name has changed + + protected: + TQLineEdit *m_sessionNameLE; + TQCheckBox *m_activateCB; +}; +//BEGIN KateSessionNameChooser + + //BEGIN KateSessionPanelToolBarParent class KateSessionPanelToolBarParent: public TQFrame { @@ -56,10 +85,25 @@ class KateSessionPanelToolBarParent: public TQFrame //END KateSessionPanelToolBarParent +//BEGIN KateSessionPanelItem +class KateSessionPanelItem : public TDEListViewItem +{ + public: + KateSessionPanelItem(TQListView *listview, const TQString &sessionName, int sessionId) + : TDEListViewItem(listview, sessionName), m_sessionId(sessionId) {} + KateSessionPanelItem(TQListView *listview, TQListViewItem *after, const TQString &sessionName, int sessionId) + : TDEListViewItem(listview, after, sessionName), m_sessionId(sessionId) {} + + int getSessionId() { return m_sessionId; } + void setSessionId(int sessionId) { m_sessionId = sessionId; } + + protected: + int m_sessionId; +}; +//END KateSessionPanelItem + + //BEGIN KateSessionPanel -//------------------------------------ -//FIXME subclass TQListViewItem adding a field containing the session id, -// then remove the m_columnSessionId column class KateSessionPanel : public TQVBox { Q_OBJECT @@ -72,15 +116,16 @@ class KateSessionPanel : public TQVBox public slots: - void saveSession(); - void saveSessionAs(); - void renameSession(); - void deleteSession(); - void activateSession(); - void sessionToggleReadOnly(); - void sessionMoveUp(); - void sessionMoveDown(); - void itemExecuted(TQListViewItem *item); + void slotNewSession(); + void slotSaveSession(); + void slotSaveSessionAs(); + void slotRenameSession(); + void slotDeleteSession(); + void slotActivateSession(); + void slotSessionToggleReadOnly(); + void slotSessionMoveUp(); + void slotSessionMoveDown(); + void slotItemExecuted(TQListViewItem *item); void slotSessionActivated(int newSessionId, int oldSessionId); void slotSessionCreated(int sessionId); @@ -96,7 +141,6 @@ class KateSessionPanel : public TQVBox TDEActionCollection *m_actionCollection; TDEToolBar *m_toolbar; TDEListView *m_listview; - int m_columnSessionId; int m_columnPixmap; }; //END KateSessionPanel -- cgit v1.2.1 From e528df3eb1ee48c55535fc09e7d016a83b38b02e Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Thu, 10 Mar 2016 18:35:21 +0900 Subject: Kate session panel: added move up/down and rename functionality. Signed-off-by: Michele Calgaro --- kate/app/katesession.cpp | 79 +++++++++++++++++++++++++-- kate/app/katesession.h | 40 +++++++++++++- kate/app/katesessionpanel.cpp | 121 +++++++++++++++++++++++++++++++++++++----- kate/app/katesessionpanel.h | 3 ++ 4 files changed, 225 insertions(+), 18 deletions(-) (limited to 'kate') diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index 1380b19d0..17218d2b1 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -145,11 +145,7 @@ KateSession::~KateSession() //------------------------------------ void KateSession::setSessionName(const TQString &sessionName) { - m_sessionName = sessionName; - if (m_sessionName.isEmpty()) - { - m_sessionName = i18n(KS_UNNAMED); - } + m_sessionName = sessionName.isEmpty() ? i18n(KS_UNNAMED) : sessionName; } //------------------------------------ @@ -455,7 +451,9 @@ bool KateSessionManager::restoreLastSession() bool KateSessionManager::deleteSession(int sessionId) { if (sessionId < 0 || sessionId >= (int)m_sessions.count()) + { return false; + } // delete session file if it exists const TQString &filename = m_sessions[sessionId]->getSessionFilename(); @@ -482,6 +480,77 @@ bool KateSessionManager::deleteSession(int sessionId) return true; } + +//------------------------------------------- +void KateSessionManager::swapSessionsPosition(int sessionId1, int sessionId2) +{ + if (sessionId1 < 0 || sessionId1 >= (int)m_sessions.count() || + sessionId2 < 0 || sessionId2 >= (int)m_sessions.count() || + sessionId1 == sessionId2) + { + return; + } + + int idxMin, idxMax; + if (sessionId1 < sessionId2) + { + idxMin = sessionId1; + idxMax = sessionId2; + } + else + { + idxMin = sessionId2; + idxMax = sessionId1; + } + + KateSession *sessMax = m_sessions.take(idxMax); + KateSession *sessMin = m_sessions.take(idxMin); + m_sessions.insert(idxMin, sessMax); + m_sessions.insert(idxMax, sessMin); + if (m_activeSessionId == sessionId1) + { + m_activeSessionId = sessionId2; + } + else if (m_activeSessionId == sessionId2) + { + m_activeSessionId = sessionId1; + } + + emit sessionsSwapped(idxMin, idxMax); +} + +//------------------------------------------- +void KateSessionManager::moveSessionForward(int sessionId) +{ + if (sessionId < 0 || sessionId >= ((int)m_sessions.count() - 1)) + { + return; + } + + swapSessionsPosition(sessionId, sessionId + 1); +} + +//------------------------------------------- +void KateSessionManager::moveSessionBackward(int sessionId) +{ + if (sessionId < 1 || sessionId >= (int)m_sessions.count()) + { + return; + } + + swapSessionsPosition(sessionId, sessionId - 1); +} + +//------------------------------------------- +void KateSessionManager::renameSession(int sessionId, const TQString &newSessionName) +{ + if (sessionId < 0 || sessionId >= (int)m_sessions.count()) + { + return; + } + + m_sessions[sessionId]->setSessionName(newSessionName); +} //END KateSessionManager diff --git a/kate/app/katesession.h b/kate/app/katesession.h index 28cabea75..077ad1fda 100644 --- a/kate/app/katesession.h +++ b/kate/app/katesession.h @@ -194,6 +194,7 @@ class KateSessionManager : public TQObject * @param sessionId the id of the session to activate * @param saveCurr if true, save the current session before activating the new one * @return whether the session was activated or not + * @emit sessionActivated */ bool activateSession(int sessionId, bool saveCurr = true); @@ -202,6 +203,7 @@ class KateSessionManager : public TQObject * @param sessionName new session name * @param activate if true, activate the new session after creation * @return the id of the newly created session + * @emit sessionCreated */ int newSession(const TQString &sessionName = TQString::null, bool activate = true); @@ -221,9 +223,29 @@ class KateSessionManager : public TQObject * Delete the specified session * @param sessionId the id of the session to delete * @return whether the session has been deleted or not + * @emit sessionDeleted */ bool deleteSession(int sessionId); + /** + * Move the specified session forward in the session list (by one position) + * @param sessionId the id of the session to move + */ + void moveSessionForward(int sessionId); + + /** + * Move the specified session backward in the session list (by one position) + * @param sessionId the id of the session to move + */ + void moveSessionBackward(int sessionId); + + /** + * Rename the specified session + * @param sessionId the id of the session to rename + * @param newSessionName the new session name + */ + void renameSession(int sessionId, const TQString &newSessionName); + signals: /** @@ -245,10 +267,26 @@ class KateSessionManager : public TQObject */ void sessionDeleted(int sessionId); + /** + * Emitted once the position of the two sessions have been swapped + * @param sessionIdMin the smallest id of the session couple + * @param sessionIdMax the biggest id of the session couple + */ + void sessionsSwapped(int sessionIdMin, int sessionIdMax); - private: + + protected: KateSessionManager(); + /** + * Swap the position of the two specified sessions in the session list + * @param sessionId1 the id of the first session + * @param sessionId2 the id of the second session + * @emit sessionsSwapped + */ + void swapSessionsPosition(int sessionId1, int sessionId2); + + TQString m_baseDir; // folder where session files are stored TQString m_configFile; // file where the session list config is stored int m_activeSessionId; // index of the active session diff --git a/kate/app/katesessionpanel.cpp b/kate/app/katesessionpanel.cpp index 7d2433c8d..3a579dff4 100644 --- a/kate/app/katesessionpanel.cpp +++ b/kate/app/katesessionpanel.cpp @@ -119,7 +119,7 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager * TQWidget *parent, const char *name) : TQVBox(parent, name), m_mainWin(mainWindow), m_viewManager(viewManager), m_sessionManager(KateSessionManager::self()), m_actionCollection(new TDEActionCollection(this)), - m_columnPixmap(0) + m_columnName(-1), m_columnPixmap(-1) { // Toolbar setup_toolbar(); @@ -127,7 +127,7 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager * // Listview m_listview = new TDEListView(this); m_listview->header()->hide(); - m_listview->addColumn("Session name"); + m_columnName = m_listview->addColumn("Session name"); m_columnPixmap = m_listview->addColumn("Pixmap", 24); m_listview->addColumn("Dummy", 1); // Dummy column, only for nice resizing m_listview->header()->setResizeEnabled(false, m_columnPixmap); @@ -136,10 +136,18 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager * m_listview->setSorting(-1); m_listview->setResizeMode(TQListView::LastColumn); //m_listview->setRootIsDecorated(true); // FIXME to enable after inserting doc list - connect(m_listview, TQT_SIGNAL(executed(TQListViewItem*)), this, TQT_SLOT(slotItemExecuted(TQListViewItem*))); - connect(m_sessionManager, TQT_SIGNAL(sessionActivated(int, int)), this, TQT_SLOT(slotSessionActivated(int, int))); - connect(m_sessionManager, TQT_SIGNAL(sessionCreated(int)), this, TQT_SLOT(slotSessionCreated(int))); - connect(m_sessionManager, TQT_SIGNAL(sessionDeleted(int)), this, TQT_SLOT(slotSessionDeleted(int))); + connect(m_listview, TQT_SIGNAL(executed(TQListViewItem*)), + this, TQT_SLOT(slotItemExecuted(TQListViewItem*))); + connect(m_sessionManager, TQT_SIGNAL(sessionActivated(int, int)), + this, TQT_SLOT(slotSessionActivated(int, int))); + connect(m_sessionManager, TQT_SIGNAL(sessionCreated(int)), + this, TQT_SLOT(slotSessionCreated(int))); + connect(m_sessionManager, TQT_SIGNAL(sessionDeleted(int)), + this, TQT_SLOT(slotSessionDeleted(int))); + connect(m_sessionManager, TQT_SIGNAL(sessionsSwapped(int, int)), + this, TQT_SLOT(slotSessionsSwapped(int, int))); + connect(m_listview, TQT_SIGNAL(itemRenamed(TQListViewItem*)), + this, TQT_SLOT(slotSessionRenamed(TQListViewItem*))); TQPtrList& sessions = m_sessionManager->getSessionsList(); for (int idx = sessions.count()-1; idx >= 0; --idx) @@ -185,12 +193,12 @@ void KateSessionPanel::setup_toolbar() TQT_TQOBJECT(this), TQT_SLOT(slotSaveSessionAs()), m_actionCollection, "session_save_as"); a->setWhatsThis(i18n("Save the current session with a different name.")); a->plug(m_toolbar); - +*/ a = new TDEAction(i18n("Rename"), SmallIcon("edit_user"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotRenameSession()), m_actionCollection, "session_rename"); a->setWhatsThis(i18n("Rename the selected session.")); a->plug(m_toolbar); -*/ + a = new TDEAction(i18n("Delete"), SmallIcon("edit-delete"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotDeleteSession()), m_actionCollection, "session_delete"); a->setWhatsThis(i18n("Delete the selected session.")); @@ -210,6 +218,7 @@ void KateSessionPanel::setup_toolbar() "will not be saved when you exit Kate or switch to another session.

" "You can use this option to create template sessions that you wish to keep unchanged over time.")); tglA->plug(m_toolbar); +*/ a = new TDEAction(i18n("Move Up"), SmallIcon("go-up"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotSessionMoveUp()), m_actionCollection, "session_move_up"); @@ -220,7 +229,6 @@ void KateSessionPanel::setup_toolbar() TQT_TQOBJECT(this), TQT_SLOT(slotSessionMoveDown()), m_actionCollection, "session_move_down"); a->setWhatsThis(i18n("Move down the selected session.")); a->plug(m_toolbar); -*/ } //------------------------------------------- @@ -250,7 +258,11 @@ void KateSessionPanel::slotSaveSessionAs() //------------------------------------------- void KateSessionPanel::slotRenameSession() { -//TODO + TQListViewItem *sessionItem = m_listview->selectedItem(); + if (!sessionItem) + return; + + m_listview->rename(m_listview->selectedItem(), m_columnName); } //------------------------------------------- @@ -293,13 +305,21 @@ void KateSessionPanel::slotSessionToggleReadOnly() //------------------------------------------- void KateSessionPanel::slotSessionMoveUp() { -//TODO + KateSessionPanelItem *sessionItem = dynamic_cast(m_listview->selectedItem()); + if (!sessionItem) + return; + + m_sessionManager->moveSessionBackward(sessionItem->getSessionId()); } //------------------------------------------- void KateSessionPanel::slotSessionMoveDown() { -//TODO + KateSessionPanelItem *sessionItem = dynamic_cast(m_listview->selectedItem()); + if (!sessionItem) + return; + + m_sessionManager->moveSessionForward(sessionItem->getSessionId()); } void KateSessionPanel::slotItemExecuted(TQListViewItem *item) @@ -363,4 +383,81 @@ void KateSessionPanel::slotSessionDeleted(int sessionId) item = item->nextSibling(); } } + +//------------------------------------------- +void KateSessionPanel::slotSessionsSwapped(int sessionIdMin, int sessionIdMax) +{ + if (sessionIdMin == sessionIdMax) + { + return; + } + + if (sessionIdMin > sessionIdMax) + { + // this is not executed when the slot is connected to m_sessionManager's + // sessionsSwapped(int, int) signal + int tmp = sessionIdMin; + sessionIdMin = sessionIdMax; + sessionIdMax = tmp; + } + + TQListViewItem *selectedItem = m_listview->selectedItem(); + + // Looks for the previous siblings of the two items + TQListViewItem *siblMin(NULL), *siblMax(NULL), *itemMin(NULL), *itemMax(NULL); + TQListViewItem *currItem = m_listview->firstChild(); + TQListViewItem *nextItem(NULL); + while (currItem) + { + nextItem = currItem->nextSibling(); + KateSessionPanelItem *sessionItem = dynamic_cast(nextItem); + if (sessionItem->getSessionId() == sessionIdMin) + { + siblMin = currItem; + itemMin = nextItem; + } + else if (sessionItem->getSessionId() == sessionIdMax) + { + siblMax = currItem; + itemMax = nextItem; + break; + } + currItem = nextItem; + } + if (!itemMin) + { + // The sessionIdMin item was the first of the list + itemMin = m_listview->firstChild(); + } + // Remove the two items and place them in their new positions + m_listview->takeItem(itemMax); + m_listview->takeItem(itemMin); + m_listview->insertItem(itemMin); + m_listview->insertItem(itemMax); + itemMax->moveItem(siblMin); + if (siblMax != itemMin) + { + itemMin->moveItem(siblMax); + } + else + { + itemMin->moveItem(itemMax); + } + // Update item's session id + (dynamic_cast(itemMax))->setSessionId(sessionIdMin); + (dynamic_cast(itemMin))->setSessionId(sessionIdMax); + + m_listview->setSelected(selectedItem, true); +} + +//------------------------------------------- +void KateSessionPanel::slotSessionRenamed(TQListViewItem *item) +{ + KateSessionPanelItem *sessionItem = dynamic_cast(item); + if (!sessionItem) + { + return; + } + m_sessionManager->renameSession(sessionItem->getSessionId(), sessionItem->text(m_columnName)); +} //END KateSessionPanel diff --git a/kate/app/katesessionpanel.h b/kate/app/katesessionpanel.h index 03f0e53dd..1010a4e13 100644 --- a/kate/app/katesessionpanel.h +++ b/kate/app/katesessionpanel.h @@ -130,6 +130,8 @@ class KateSessionPanel : public TQVBox void slotSessionActivated(int newSessionId, int oldSessionId); void slotSessionCreated(int sessionId); void slotSessionDeleted(int sessionId); + void slotSessionsSwapped(int sessionIdMin, int sessionIdMax); + void slotSessionRenamed(TQListViewItem *item); private: @@ -141,6 +143,7 @@ class KateSessionPanel : public TQVBox TDEActionCollection *m_actionCollection; TDEToolBar *m_toolbar; TDEListView *m_listview; + int m_columnName; int m_columnPixmap; }; //END KateSessionPanel -- cgit v1.2.1 From 758b7bda94c4af81bbfc4e884c22db974a7c12c0 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Thu, 10 Mar 2016 15:46:16 +0100 Subject: Kate session panel: added save and read-only functionality. Fixed up toolbar buttons status update. Added ability to activate a session using the ENTER key. Some other code refactoring. Signed-off-by: Michele Calgaro --- kate/app/katesession.cpp | 51 +++++++++++++----- kate/app/katesession.h | 51 ++++++++++++++++-- kate/app/katesessionpanel.cpp | 123 +++++++++++++++++++++++++++++++++++++++--- kate/app/katesessionpanel.h | 2 +- kate/app/kateviewspace.cpp | 2 +- 5 files changed, 200 insertions(+), 29 deletions(-) (limited to 'kate') diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index 17218d2b1..1ab43c420 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -91,7 +91,6 @@ KateSession::KateSession(const TQString &sessionName, const TQString &filename, } // Read only m_readOnly = m_config->readBoolEntry(KS_READONLY, false); - m_config->setReadOnly(m_readOnly); // Document list if (m_config->hasGroup(KS_DOCLIST)) { @@ -149,19 +148,9 @@ void KateSession::setSessionName(const TQString &sessionName) } //------------------------------------ -void KateSession::setReadOnly(bool readOnly) +void KateSession::save(bool saveGUIInfo, bool setReadOnly) { - m_readOnly = readOnly; - if (m_config) - { - m_config->setReadOnly(m_readOnly); - } -} - -//------------------------------------ -void KateSession::save(bool saveGUIInfo) -{ - if (m_readOnly) + if (m_readOnly && !setReadOnly) { return; } @@ -349,7 +338,6 @@ KateSessionManager::~KateSessionManager() // FIXME An option need to be added to Configure Kate -> Sessions to allow Kate to ask about // saving unnamed sessions before closing the current session. Default value is off as per // point above. - void KateSessionManager::saveConfig() { if (!m_config) @@ -372,6 +360,17 @@ void KateSessionManager::saveConfig() m_config->sync(); } +//------------------------------------ +KateSession* KateSessionManager::getSessionFromId(int sessionId) +{ + if (sessionId < 0 || sessionId >= (int)m_sessions.count()) + { + return NULL; + } + + return m_sessions[sessionId]; +} + //------------------------------------ int KateSessionManager::getSessionIdFromName(const TQString &name) { @@ -447,6 +446,17 @@ bool KateSessionManager::restoreLastSession() return activateSession(m_activeSessionId, false); } +//------------------------------------------- +void KateSessionManager::saveSession(int sessionId) +{ + if (sessionId < 0 || sessionId >= (int)m_sessions.count()) + { + return; + } + m_sessions[sessionId]->save(sessionId == m_activeSessionId); + emit sessionSaved(sessionId); +} + //------------------------------------------- bool KateSessionManager::deleteSession(int sessionId) { @@ -551,6 +561,19 @@ void KateSessionManager::renameSession(int sessionId, const TQString &newSession m_sessions[sessionId]->setSessionName(newSessionName); } + +//------------------------------------------- +void KateSessionManager::setSessionReadOnlyStatus(int sessionId, bool readOnly) +{ + if (sessionId < 0 || sessionId >= (int)m_sessions.count()) + { + return; + } + + m_sessions[sessionId]->setReadOnly(readOnly); + // Session is saved one last time when making it read only + m_sessions[sessionId]->save(sessionId == m_activeSessionId, true); +} //END KateSessionManager diff --git a/kate/app/katesession.h b/kate/app/katesession.h index 077ad1fda..3351db150 100644 --- a/kate/app/katesession.h +++ b/kate/app/katesession.h @@ -42,6 +42,9 @@ class TQCheckBox; //BEGIN KateSession +/** + * An object representing a Kate's session. + */ class KateSession { public: @@ -65,6 +68,7 @@ class KateSession * @return the session name */ const TQString& getSessionName() const { return m_sessionName; } + /** * Set the new session name * @param sessionName the new session name @@ -75,11 +79,12 @@ class KateSession * @return whether the session is read only or not */ bool isReadOnly() const { return m_readOnly; } + /** * Set session read only status - * @param readOnly if true, the session config can not be saved to file + * @param readOnly if true, the session status can not be modified */ - void setReadOnly(bool readOnly); + void setReadOnly(bool readOnly) { m_readOnly = readOnly; } /** * @return the session filename if available, otherwise the null string @@ -94,21 +99,24 @@ class KateSession /** * Save session info * @param saveGUIInfo if true, save also the information about the GUI elements + * @param setReadOnly necessary to save a session that has to be turned to read only */ - void save(bool saveGUIInfo); + void save(bool saveGUIInfo, bool setReadOnly = false); /** * Activate the session */ void activate(); + private: friend class KateViewSpace; + /** * @return the session config object */ - TDEConfig* getConfig() { return m_config; } + TDEConfig* getConfig() const { return m_config; } TQString m_sessionName; @@ -132,6 +140,12 @@ class KateSession //This would allow a safe use of multiple Kate instances without overwriting session information //among them. Currently the last instance to be closed will overwrite the information previously //saved by other Kate instances. +/** + * The Kate session manager. It takes care of storing and retrieving each session object + * as well as providing methods to operate on them. + * + * @note The Kate session manager takes ownership of each session object it handles. + */ class KateSessionManager : public TQObject { Q_OBJECT @@ -174,6 +188,12 @@ class KateSessionManager : public TQObject */ KateSession* getActiveSession() { return m_sessions[m_activeSessionId]; } + /** + * @param sessionId the id of the session to return + * @return a reference to the specified session + */ + KateSession* getSessionFromId(int sessionId); + /** * Return the session id of the first session whose name matches the * provided one. In case multiple sessions share the same name, @@ -216,8 +236,16 @@ class KateSessionManager : public TQObject /** * Saves the active session + * @emit sessionSaved (through invoked "void saveSession(int)" method) */ - void saveActiveSession() { m_sessions[m_activeSessionId]->save(true); } + void saveActiveSession() { saveSession(m_activeSessionId); } + + /** + * Save the specified session + * @param sessionId the id of the session to save + * @emit sessionSaved + */ + void saveSession(int sessionId); /** * Delete the specified session @@ -246,6 +274,13 @@ class KateSessionManager : public TQObject */ void renameSession(int sessionId, const TQString &newSessionName); + /** + * Set the read only status of the specified session + * @param sessionId the id of the session to modify + * @param readOnly the new read only status + */ + void setSessionReadOnlyStatus(int sessionId, bool readOnly); + signals: /** @@ -261,6 +296,12 @@ class KateSessionManager : public TQObject */ void sessionCreated(int sessionId); + /** + * Emitted once a session has been saved + * @param sessionId the id of the saved session + */ + void sessionSaved(int sessionId); + /** * Emitted once a session has been deleted * @param sessionId the id of the deleted session diff --git a/kate/app/katesessionpanel.cpp b/kate/app/katesessionpanel.cpp index 3a579dff4..b3f7ef55b 100644 --- a/kate/app/katesessionpanel.cpp +++ b/kate/app/katesessionpanel.cpp @@ -136,8 +136,13 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager * m_listview->setSorting(-1); m_listview->setResizeMode(TQListView::LastColumn); //m_listview->setRootIsDecorated(true); // FIXME to enable after inserting doc list + + connect(m_listview, TQT_SIGNAL(selectionChanged()), + this, TQT_SLOT(slotSelectionChanged())); connect(m_listview, TQT_SIGNAL(executed(TQListViewItem*)), this, TQT_SLOT(slotItemExecuted(TQListViewItem*))); + connect(m_listview, TQT_SIGNAL(returnPressed(TQListViewItem*)), + this, TQT_SLOT(slotItemExecuted(TQListViewItem*))); connect(m_sessionManager, TQT_SIGNAL(sessionActivated(int, int)), this, TQT_SLOT(slotSessionActivated(int, int))); connect(m_sessionManager, TQT_SIGNAL(sessionCreated(int)), @@ -175,7 +180,6 @@ void KateSessionPanel::setup_toolbar() m_toolbar->setIconSize(16); m_toolbar->setEnableContextMenu(false); -//FIXME : uncomment and activate as long as the new session manager gets fixed // Toolbar actions TDEAction *a; @@ -183,7 +187,7 @@ void KateSessionPanel::setup_toolbar() TQT_TQOBJECT(this), TQT_SLOT(slotNewSession()), m_actionCollection, "session_new"); a->setWhatsThis(i18n("Create a new session.")); a->plug(m_toolbar); -/* + a = new TDEAction(i18n("Save"), SmallIcon("document-save"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotSaveSession()), m_actionCollection, "session_save"); a->setWhatsThis(i18n("Save the current session.")); @@ -193,7 +197,7 @@ void KateSessionPanel::setup_toolbar() TQT_TQOBJECT(this), TQT_SLOT(slotSaveSessionAs()), m_actionCollection, "session_save_as"); a->setWhatsThis(i18n("Save the current session with a different name.")); a->plug(m_toolbar); -*/ + a = new TDEAction(i18n("Rename"), SmallIcon("edit_user"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotRenameSession()), m_actionCollection, "session_rename"); a->setWhatsThis(i18n("Rename the selected session.")); @@ -210,7 +214,7 @@ void KateSessionPanel::setup_toolbar() TQT_TQOBJECT(this), TQT_SLOT(slotActivateSession()), m_actionCollection, "session_activate"); a->setWhatsThis(i18n("Activate the selected session.")); a->plug(m_toolbar); -/* + TDEToggleAction *tglA = new TDEToggleAction(i18n("Toggle read only"), SmallIcon("encrypted"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotSessionToggleReadOnly()), m_actionCollection, "session_toggle_read_only"); tglA->setWhatsThis(i18n("Toggle read only status for the selected session.

" @@ -218,7 +222,6 @@ void KateSessionPanel::setup_toolbar() "will not be saved when you exit Kate or switch to another session.

" "You can use this option to create template sessions that you wish to keep unchanged over time.")); tglA->plug(m_toolbar); -*/ a = new TDEAction(i18n("Move Up"), SmallIcon("go-up"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotSessionMoveUp()), m_actionCollection, "session_move_up"); @@ -229,6 +232,8 @@ void KateSessionPanel::setup_toolbar() TQT_TQOBJECT(this), TQT_SLOT(slotSessionMoveDown()), m_actionCollection, "session_move_down"); a->setWhatsThis(i18n("Move down the selected session.")); a->plug(m_toolbar); + + //FIXME add button to restore a modified session to its original if not yet saved to disk } //------------------------------------------- @@ -246,13 +251,36 @@ void KateSessionPanel::slotNewSession() //------------------------------------------- void KateSessionPanel::slotSaveSession() { -//TODO + KateSessionPanelItem *sessionItem = dynamic_cast(m_listview->selectedItem()); + if (!sessionItem) + { + return; + } + + int sessId = sessionItem->getSessionId(); + const KateSession *ks = m_sessionManager->getSessionFromId(sessId); + if (!ks) + { + return; + } + + if (ks->getSessionFilename().isEmpty()) + { + // Session has never been saved before. Ask user for a session name first + slotSaveSessionAs(); + } + else + { + m_sessionManager->saveSession(sessId); + slotSelectionChanged(); // Update the toolbar button status + } } //------------------------------------------- void KateSessionPanel::slotSaveSessionAs() { //TODO + slotSelectionChanged(); // Update the toolbar button status } //------------------------------------------- @@ -260,7 +288,9 @@ void KateSessionPanel::slotRenameSession() { TQListViewItem *sessionItem = m_listview->selectedItem(); if (!sessionItem) + { return; + } m_listview->rename(m_listview->selectedItem(), m_columnName); } @@ -270,7 +300,9 @@ void KateSessionPanel::slotDeleteSession() { KateSessionPanelItem *sessionItem = dynamic_cast(m_listview->selectedItem()); if (!sessionItem) + { return; + } int result = KMessageBox::warningContinueCancel(this, i18n("Do you really want to delete the session '%1'?").arg(sessionItem->text(0)), @@ -286,7 +318,9 @@ void KateSessionPanel::slotActivateSession() { KateSessionPanelItem *newSessionItem = dynamic_cast(m_listview->selectedItem()); if (!newSessionItem) + { return; + } int currSessionId = m_sessionManager->getActiveSessionId(); int newSessionId = newSessionItem->getSessionId(); @@ -299,7 +333,16 @@ void KateSessionPanel::slotActivateSession() //------------------------------------------- void KateSessionPanel::slotSessionToggleReadOnly() { -//TODO + KateSessionPanelItem *sessionItem = dynamic_cast(m_listview->selectedItem()); + if (!sessionItem) + { + return; + } + + m_sessionManager->setSessionReadOnlyStatus(sessionItem->getSessionId(), + (dynamic_cast( + m_actionCollection->action("session_toggle_read_only")))->isChecked()); + slotSelectionChanged(); // Update the toolbar button status } //------------------------------------------- @@ -307,7 +350,9 @@ void KateSessionPanel::slotSessionMoveUp() { KateSessionPanelItem *sessionItem = dynamic_cast(m_listview->selectedItem()); if (!sessionItem) + { return; + } m_sessionManager->moveSessionBackward(sessionItem->getSessionId()); } @@ -317,15 +362,20 @@ void KateSessionPanel::slotSessionMoveDown() { KateSessionPanelItem *sessionItem = dynamic_cast(m_listview->selectedItem()); if (!sessionItem) + { return; + } m_sessionManager->moveSessionForward(sessionItem->getSessionId()); } +//------------------------------------------- void KateSessionPanel::slotItemExecuted(TQListViewItem *item) { if (!item) - return; + { + return; + } // First level items are sessions. Executing one, will switch to that session if (!item->parent()) @@ -335,6 +385,62 @@ void KateSessionPanel::slotItemExecuted(TQListViewItem *item) } } +//------------------------------------------- +void KateSessionPanel::slotSelectionChanged() +{ + KateSessionPanelItem *sessionItem = dynamic_cast(m_listview->selectedItem()); + const KateSession *ks(NULL); + if (sessionItem) + { + ks = m_sessionManager->getSessionFromId(sessionItem->getSessionId()); + } + + TDEToggleAction *readOnlyAction = dynamic_cast( + m_actionCollection->action("session_toggle_read_only")); + if (!sessionItem || !ks) + { + m_actionCollection->action("session_save")->setEnabled(false); + m_actionCollection->action("session_save_as")->setEnabled(false); + m_actionCollection->action("session_rename")->setEnabled(false); + m_actionCollection->action("session_delete")->setEnabled(false); + m_actionCollection->action("session_activate")->setEnabled(false); + m_actionCollection->action("session_move_up")->setEnabled(false); + m_actionCollection->action("session_move_down")->setEnabled(false); + readOnlyAction->setEnabled(false); + readOnlyAction->setChecked(false); + } + else + { + if (ks->isReadOnly()) + { + // Read only sessions can not be saved or renamed + m_actionCollection->action("session_save")->setEnabled(false); + m_actionCollection->action("session_rename")->setEnabled(false); + } + else + { + m_actionCollection->action("session_save")->setEnabled(true); + m_actionCollection->action("session_rename")->setEnabled(true); + } + if (ks->getSessionFilename().isEmpty()) + { + // Unstored sessions can not be made readonly + readOnlyAction->setEnabled(false); + readOnlyAction->setChecked(false); + } + else + { + readOnlyAction->setEnabled(true); + readOnlyAction->setChecked(ks->isReadOnly()); + } + m_actionCollection->action("session_save_as")->setEnabled(true); + m_actionCollection->action("session_delete")->setEnabled(true); + m_actionCollection->action("session_activate")->setEnabled(true); + m_actionCollection->action("session_move_up")->setEnabled(true); + m_actionCollection->action("session_move_down")->setEnabled(true); + } +} + //------------------------------------------- void KateSessionPanel::slotSessionActivated(int newSessionId, int oldSessionId) { @@ -458,6 +564,7 @@ void KateSessionPanel::slotSessionRenamed(TQListViewItem *item) { return; } + m_sessionManager->renameSession(sessionItem->getSessionId(), sessionItem->text(m_columnName)); } //END KateSessionPanel diff --git a/kate/app/katesessionpanel.h b/kate/app/katesessionpanel.h index 1010a4e13..265d1d8e1 100644 --- a/kate/app/katesessionpanel.h +++ b/kate/app/katesessionpanel.h @@ -127,13 +127,13 @@ class KateSessionPanel : public TQVBox void slotSessionMoveDown(); void slotItemExecuted(TQListViewItem *item); + void slotSelectionChanged(); void slotSessionActivated(int newSessionId, int oldSessionId); void slotSessionCreated(int sessionId); void slotSessionDeleted(int sessionId); void slotSessionsSwapped(int sessionIdMin, int sessionIdMax); void slotSessionRenamed(TQListViewItem *item); - private: void setup_toolbar(); diff --git a/kate/app/kateviewspace.cpp b/kate/app/kateviewspace.cpp index 7e9622b67..a4066ee5a 100644 --- a/kate/app/kateviewspace.cpp +++ b/kate/app/kateviewspace.cpp @@ -114,7 +114,7 @@ void KateViewSpace::addView(Kate::View* v, bool show) { TQString vgroup = TQString("%1 %2").arg(m_group).arg(fn); - KateSession *as = KateSessionManager::self()->getActiveSession(); + const KateSession *as = KateSessionManager::self()->getActiveSession(); TDEConfig *asCfg = as->getConfig(); if (asCfg && asCfg->hasGroup(vgroup)) { -- cgit v1.2.1 From 749b05ce92c640ae42548a8929c2eb163d56d6f7 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Fri, 25 Mar 2016 23:42:53 +0900 Subject: Kate session panel: added save_as and reload functionality. Signed-off-by: Michele Calgaro --- kate/app/katesession.cpp | 164 ++++++++++++++++++++++++++++++------------ kate/app/katesession.h | 75 +++++++++++++++---- kate/app/katesessionpanel.cpp | 125 +++++++++++++++++++++++++++----- kate/app/katesessionpanel.h | 7 +- 4 files changed, 293 insertions(+), 78 deletions(-) (limited to 'kate') diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index 1ab43c420..9fc865d52 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -49,7 +49,8 @@ #include // 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 // String constants @@ -63,8 +64,8 @@ namespace const char *KS_NAME = "Name"; const char *KS_OPENDOC = "Open Documents"; const char *KS_READONLY = "ReadOnly"; - const char *KS_UNNAMED = "Unnamed"; const char *KS_OPEN_MAINWINDOWS = "Open MainWindows"; + const char *KS_UNNAMED = "Unnamed"; // Kate session manager const char *KSM_DIR = "kate/sessions"; @@ -75,21 +76,53 @@ namespace } //BEGIN Kate session -KateSession::KateSession(const TQString &sessionName, const TQString &filename, bool isFullName) : - m_sessionName(sessionName), m_filename(filename), m_isFullName(isFullName), +KateSession::KateSession(const KateSessionManager &manager, const TQString &sessionName, + const TQString &fileName) : + m_manager(manager), m_sessionName(sessionName), m_filename(fileName), 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(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 m_config = new KSimpleConfig(m_filename, m_readOnly); m_config->setGroup(KS_GENERAL); - // Session name - if (m_sessionName.isEmpty()) - { - m_sessionName = m_config->readEntry(KS_NAME, i18n(KS_UNNAMED)); - } - // Read only + // Session general properties + m_sessionName = m_config->readEntry(KS_NAME, i18n(KS_UNNAMED)); m_readOnly = m_config->readBoolEntry(KS_READONLY, false); // Document list 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()) { m_sessionName = i18n(KS_UNNAMED); } - // FIXME: needs to make sure doc list and m_documents are in synchro here -} - -//------------------------------------ -KateSession::~KateSession() -{ - if (m_config) + + // Update e all current documents if necessary + if (includeGUIInfo) { - 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) { @@ -156,23 +183,9 @@ void KateSession::save(bool saveGUIInfo, bool setReadOnly) } // create a new session filename if needed - if (!m_isFullName) + if (m_filename.isEmpty()) { - int s = time(0); - 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; - } - } + createFilename(); } // save session config info @@ -252,6 +265,31 @@ void KateSession::activate() 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 @@ -290,7 +328,7 @@ KateSessionManager::KateSessionManager() : if (!urlStr.isEmpty() && TDEGlobal::dirs()->exists(urlStr)) { // 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"); 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(); 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()) { @@ -360,6 +398,17 @@ void KateSessionManager::saveConfig() 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) { @@ -425,9 +474,33 @@ bool KateSessionManager::activateSession(int sessionId, bool saveCurr) //------------------------------------ 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; 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) { activateSession(newSessionId, m_activeSessionId != INVALID_SESSION); @@ -560,6 +633,7 @@ void KateSessionManager::renameSession(int sessionId, const TQString &newSession } m_sessions[sessionId]->setSessionName(newSessionName); + emit sessionRenamed(sessionId); } //------------------------------------------- diff --git a/kate/app/katesession.h b/kate/app/katesession.h index 3351db150..01357798b 100644 --- a/kate/app/katesession.h +++ b/kate/app/katesession.h @@ -39,6 +39,7 @@ class KDirWatch; class KPushButton; class TDEListView; class TQCheckBox; +class KateSessionManager; //BEGIN KateSession @@ -51,13 +52,19 @@ class KateSession /** * 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 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 @@ -89,13 +96,19 @@ class KateSession /** * @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 */ 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 * @param saveGUIInfo if true, save also the information about the GUI elements @@ -117,15 +130,18 @@ class KateSession * @return the session config object */ 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_filename; - bool m_isFullName; // true -> m_filename is a full filename - // false -> m_filename is a folder name. bool m_readOnly; - TQStringList m_documents; // document URLs - KSimpleConfig *m_config; // session config + TQStringList m_documents; // document URLs + KSimpleConfig *m_config; // session config }; //END KateSession @@ -146,6 +162,9 @@ 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 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 { Q_OBJECT @@ -173,6 +192,11 @@ class KateSessionManager : public TQObject */ void saveConfig(); + /** + * @return the session files folder name + */ + const TQString& getBaseDir() const { return m_baseDir; } + /** * @return the active session id */ @@ -183,6 +207,12 @@ class KateSessionManager : public TQObject */ 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 */ @@ -227,6 +257,21 @@ class KateSessionManager : public TQObject */ 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 * any other session has been activated, i.e. on Kate's startup @@ -271,6 +316,7 @@ class KateSessionManager : public TQObject * Rename the specified session * @param sessionId the id of the session to rename * @param newSessionName the new session name + * @emit sessionRenamed */ void renameSession(int sessionId, const TQString &newSessionName); @@ -281,7 +327,6 @@ class KateSessionManager : public TQObject */ void setSessionReadOnlyStatus(int sessionId, bool readOnly); - signals: /** * Emitted once a session has been activated @@ -315,6 +360,12 @@ class KateSessionManager : public TQObject */ 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: KateSessionManager(); @@ -385,7 +436,7 @@ class KateSessionChooser : public KDialogBase protected: TDEListView *m_listview; }; -//BEGIN KateSessionChooser +//END KateSessionChooser diff --git a/kate/app/katesessionpanel.cpp b/kate/app/katesessionpanel.cpp index b3f7ef55b..827dc403d 100644 --- a/kate/app/katesessionpanel.cpp +++ b/kate/app/katesessionpanel.cpp @@ -38,9 +38,10 @@ namespace //BEGIN KateSessionNameChooser //------------------------------------------- -KateSessionNameChooser::KateSessionNameChooser(TQWidget *parent) +KateSessionNameChooser::KateSessionNameChooser(TQWidget *parent, bool showSwitchTo) : 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); //page->setMinimumSize(300, 100); @@ -53,13 +54,16 @@ KateSessionNameChooser::KateSessionNameChooser(TQWidget *parent) label->setText("Please type the new session name:"); m_sessionNameLE = new TQLineEdit(vb); - m_sessionNameLE->setText(KS_UNNAMED); + m_sessionNameLE->setText(i18n(KS_UNNAMED)); 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); - m_activateCB->setChecked(true); - - connect (m_sessionNameLE, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotTextChanged())); + connect(m_sessionNameLE, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotTextChanged())); slotTextChanged(); // update button status } @@ -72,7 +76,11 @@ TQString KateSessionNameChooser::getSessionName() //------------------------------------------- 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->setSorting(-1); 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()), this, TQT_SLOT(slotSelectionChanged())); @@ -151,8 +159,10 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager * this, TQT_SLOT(slotSessionDeleted(int))); connect(m_sessionManager, TQT_SIGNAL(sessionsSwapped(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*)), - this, TQT_SLOT(slotSessionRenamed(TQListViewItem*))); + this, TQT_SLOT(slotLVSessionRenamed(TQListViewItem*))); TQPtrList& sessions = m_sessionManager->getSessionsList(); 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, 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 = new TDEAction(i18n("Save as..."), SmallIcon("document-save-as"), 0, 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 = new TDEAction(i18n("Rename"), SmallIcon("edit_user"), 0, @@ -208,6 +219,11 @@ void KateSessionPanel::setup_toolbar() a->setWhatsThis(i18n("Delete the selected session.")); 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(); 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"); a->setWhatsThis(i18n("Move down the selected session.")); a->plug(m_toolbar); - - //FIXME add button to restore a modified session to its original if not yet saved to disk } //------------------------------------------- void KateSessionPanel::slotNewSession() { - KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this); + KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this, true); int result = nameChooser->exec(); if (result == TQDialog::Accepted) { @@ -264,7 +278,7 @@ void KateSessionPanel::slotSaveSession() 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 slotSaveSessionAs(); @@ -279,7 +293,46 @@ void KateSessionPanel::slotSaveSession() //------------------------------------------- void KateSessionPanel::slotSaveSessionAs() { -//TODO + KateSessionPanelItem *sessionItem = dynamic_cast(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 } @@ -313,6 +366,24 @@ void KateSessionPanel::slotDeleteSession() } } +//------------------------------------------- +void KateSessionPanel::slotReloadSession() +{ + KateSessionPanelItem *sessionItem = dynamic_cast(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() { @@ -403,6 +474,7 @@ void KateSessionPanel::slotSelectionChanged() m_actionCollection->action("session_save_as")->setEnabled(false); m_actionCollection->action("session_rename")->setEnabled(false); m_actionCollection->action("session_delete")->setEnabled(false); + m_actionCollection->action("session_reload")->setEnabled(false); m_actionCollection->action("session_activate")->setEnabled(false); m_actionCollection->action("session_move_up")->setEnabled(false); m_actionCollection->action("session_move_down")->setEnabled(false); @@ -416,11 +488,13 @@ void KateSessionPanel::slotSelectionChanged() // Read only sessions can not be saved or renamed m_actionCollection->action("session_save")->setEnabled(false); m_actionCollection->action("session_rename")->setEnabled(false); + m_actionCollection->action("session_delete")->setEnabled(false); } else { m_actionCollection->action("session_save")->setEnabled(true); m_actionCollection->action("session_rename")->setEnabled(true); + m_actionCollection->action("session_delete")->setEnabled(true); } if (ks->getSessionFilename().isEmpty()) { @@ -434,7 +508,8 @@ void KateSessionPanel::slotSelectionChanged() readOnlyAction->setChecked(ks->isReadOnly()); } 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_move_up")->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")); 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(item); if (!sessionItem) diff --git a/kate/app/katesessionpanel.h b/kate/app/katesessionpanel.h index 265d1d8e1..2dd7347a7 100644 --- a/kate/app/katesessionpanel.h +++ b/kate/app/katesessionpanel.h @@ -47,7 +47,7 @@ class KateSessionNameChooser : public KDialogBase public: - KateSessionNameChooser(TQWidget *parent); + KateSessionNameChooser(TQWidget *parent, bool showSwitchTo); ~KateSessionNameChooser() {} TQString getSessionName(); // return the session name typed by the user @@ -62,6 +62,7 @@ class KateSessionNameChooser : public KDialogBase protected: TQLineEdit *m_sessionNameLE; TQCheckBox *m_activateCB; + bool m_showSwitchTo; // if true, display the m_activateCB checkbox }; //BEGIN KateSessionNameChooser @@ -121,6 +122,7 @@ class KateSessionPanel : public TQVBox void slotSaveSessionAs(); void slotRenameSession(); void slotDeleteSession(); + void slotReloadSession(); void slotActivateSession(); void slotSessionToggleReadOnly(); void slotSessionMoveUp(); @@ -132,7 +134,8 @@ class KateSessionPanel : public TQVBox void slotSessionCreated(int sessionId); void slotSessionDeleted(int sessionId); void slotSessionsSwapped(int sessionIdMin, int sessionIdMax); - void slotSessionRenamed(TQListViewItem *item); + void slotSessionRenamed(int sessionId); + void slotLVSessionRenamed(TQListViewItem *item); private: void setup_toolbar(); -- cgit v1.2.1 From 074f8c7ccb685fb9fa2a51dec5049637e727a9c2 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Thu, 21 Apr 2016 14:45:42 +1000 Subject: Kate session panel: fixed handling of volatile sessions. Also bug fixes and improved model-view code separation Signed-off-by: Michele Calgaro --- kate/app/kateapp.cpp | 2 +- kate/app/katesession.cpp | 141 ++++++++++++++++++++++++++---------------- kate/app/katesession.h | 47 +++++++++----- kate/app/katesessionpanel.cpp | 103 +++++++++++++++++++++++------- kate/app/katesessionpanel.h | 14 ++++- 5 files changed, 212 insertions(+), 95 deletions(-) (limited to 'kate') diff --git a/kate/app/kateapp.cpp b/kate/app/kateapp.cpp index 06b0c0ecb..aeecc5fac 100644 --- a/kate/app/kateapp.cpp +++ b/kate/app/kateapp.cpp @@ -172,7 +172,7 @@ bool KateApp::startupKate() } else { - sessionManager()->newSession(sessName, true); + sessionManager()->newSession(sessName); } } else diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index 9fc865d52..91d0ad05a 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -71,7 +71,7 @@ namespace const char *KSM_DIR = "kate/sessions"; const char *KSM_FILE = "sessions.list"; const char *KSM_SESSIONS_COUNT = "Sessions count"; - const char *KSM_ACTIVE_SESSION_ID = "Active session id"; + const char *KSM_LAST_SESSION_ID = "Last session id"; const char *KSM_SESSIONS_LIST = "Sessions list"; } @@ -90,7 +90,12 @@ KateSession::KateSession(const KateSession &session, const TQString &newSessionN m_readOnly(false), m_documents(session.m_documents), m_config(NULL) { createFilename(); - m_config = dynamic_cast(session.m_config->copyTo(m_filename)); + if (session.m_config) + { + m_config = new KSimpleConfig(m_filename); + session.m_config->copyTo(m_filename, m_config); + m_config->sync(); + } } //------------------------------------ @@ -108,6 +113,12 @@ void KateSession::setSessionName(const TQString &sessionName) m_sessionName = sessionName.isEmpty() ? i18n(KS_UNNAMED) : sessionName; } +//------------------------------------ +bool KateSession::isStillVolatile() const +{ + return m_filename.isEmpty() && m_sessionName == i18n(KS_UNNAMED); +} + //------------------------------------ void KateSession::load(bool includeGUIInfo) { @@ -167,7 +178,7 @@ void KateSession::load(bool includeGUIInfo) m_sessionName = i18n(KS_UNNAMED); } - // Update e all current documents if necessary + // Update all current documents if necessary if (includeGUIInfo) { activate(); @@ -238,31 +249,31 @@ void KateSession::activate() { KateDocManager::self()->closeAllDocuments(); } + Kate::Document::setOpenErrorDialogsActivated(false); if (m_config) { KateApp::self()->documentManager()->restoreDocumentList(m_config); - } - - // load main windows info, if it exists - if (m_config && m_config->hasGroup(KS_OPEN_MAINWINDOWS)) - { - m_config->setGroup(KS_OPEN_MAINWINDOWS); - int mwCount = m_config->readUnsignedNumEntry(KS_COUNT, 1); - for (int i=0; ihasGroup(KS_OPEN_MAINWINDOWS)) { - if (i >= (int)KateApp::self()->mainWindows()) - { - KateApp::self()->newMainWindow(m_config, TQString("MainWindow%1").arg(i)); - } - else + m_config->setGroup(KS_OPEN_MAINWINDOWS); + int mwCount = m_config->readUnsignedNumEntry(KS_COUNT, 1); + for (int i = 0; i < mwCount; ++i) { - m_config->setGroup(TQString("MainWindow%1").arg(i)); - KateApp::self()->mainWindow(i)->readProperties(m_config); + if (i >= (int)KateApp::self()->mainWindows()) + { + KateApp::self()->newMainWindow(m_config, TQString("MainWindow%1").arg(i)); + } + else + { + m_config->setGroup(TQString("MainWindow%1").arg(i)); + KateApp::self()->mainWindow(i)->readProperties(m_config); + } } } } - Kate::Document::setOpenErrorDialogsActivated(true); } @@ -310,7 +321,7 @@ KateSessionManager* KateSessionManager::self() //------------------------------------ KateSessionManager::KateSessionManager() : m_baseDir(locateLocal("data", KSM_DIR)+"/"), m_configFile(m_baseDir + KSM_FILE), - m_activeSessionId(0), m_firstActivation(true), m_sessions(), m_config(NULL) + m_activeSessionId(INVALID_SESSION), m_lastSessionId(INVALID_SESSION), m_sessions(), m_config(NULL) { m_sessions.setAutoDelete(true); @@ -321,7 +332,7 @@ KateSessionManager::KateSessionManager() : m_config = new KSimpleConfig(m_configFile); m_config->setGroup(KSM_SESSIONS_LIST); sessionsCount = m_config->readNumEntry(KSM_SESSIONS_COUNT, 0); - m_activeSessionId = m_config->readNumEntry(KSM_ACTIVE_SESSION_ID, 0); + m_lastSessionId = m_config->readNumEntry(KSM_LAST_SESSION_ID, INVALID_SESSION); for (int i = 0; i < sessionsCount; ++i) { TQString urlStr = m_config->readEntry(TQString("URL_%1").arg(i)); @@ -347,19 +358,19 @@ KateSessionManager::KateSessionManager() : { m_sessions.append(new KateSession(*this, TQString::null, TQString::null)); } - if (m_activeSessionId < 0 || m_activeSessionId >= (int)m_sessions.count()) + if (m_lastSessionId < 0 || m_lastSessionId >= (int)m_sessions.count()) { - m_activeSessionId = 0; // Invalid active 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 // since Kate's main window may not be ready yet. The initial session - // will be activated by KateApp::startupKate() or void KateApp::restoreKate() + // will be activated by KateApp::startupKate() or KateApp::restoreKate() } //------------------------------------ KateSessionManager::~KateSessionManager() { - saveConfig(); + saveConfig(true); if (m_config) { delete m_config; @@ -376,7 +387,7 @@ KateSessionManager::~KateSessionManager() // FIXME An option need to be added to Configure Kate -> Sessions to allow Kate to ask about // saving unnamed sessions before closing the current session. Default value is off as per // point above. -void KateSessionManager::saveConfig() +void KateSessionManager::saveConfig(bool saveSessions) { if (!m_config) { @@ -388,11 +399,14 @@ void KateSessionManager::saveConfig() } m_config->setGroup(KSM_SESSIONS_LIST); m_config->writeEntry(KSM_SESSIONS_COUNT, m_sessions.count()); - m_config->writeEntry(KSM_ACTIVE_SESSION_ID, m_activeSessionId); + m_config->writeEntry(KSM_LAST_SESSION_ID, m_activeSessionId); for (int i = 0; i < (int)m_sessions.count(); ++i) { - // Save the session first, to make sure a new session has an associated file - m_sessions[i]->save(false); + //FIXME need to consider when sessions has to be saved. + if (saveSessions) + { + saveSession(i, false, false); + } m_config->writeEntry(TQString("URL_%1").arg(i), m_sessions[i]->getSessionFilename()); } m_config->sync(); @@ -424,7 +438,7 @@ KateSession* KateSessionManager::getSessionFromId(int sessionId) int KateSessionManager::getSessionIdFromName(const TQString &name) { if (name.isEmpty()) - return KateSessionManager::INVALID_SESSION; + return INVALID_SESSION; for (int i = 0; i < (int)m_sessions.count(); ++i) { @@ -432,23 +446,24 @@ int KateSessionManager::getSessionIdFromName(const TQString &name) return i; } - return KateSessionManager::INVALID_SESSION; + return INVALID_SESSION; } //------------------------------------ bool KateSessionManager::activateSession(int sessionId, bool saveCurr) { - if (sessionId < 0) + if (sessionId < 0 || sessionId >= (int)m_sessions.count()) { return false; } - if (!m_firstActivation && sessionId == m_activeSessionId) + if (sessionId == m_activeSessionId) { return true; } - if (!m_firstActivation) + int oldSessionId = m_activeSessionId; + if (m_activeSessionId != INVALID_SESSION) { // Do this only if a session has already been activated earlier, if (KateApp::self()->activeMainWindow()) @@ -457,30 +472,38 @@ bool KateSessionManager::activateSession(int sessionId, bool saveCurr) if (!KateApp::self()->activeMainWindow()->queryClose_internal()) return false; } - if (saveCurr && m_activeSessionId != INVALID_SESSION) + if (saveCurr) { - m_sessions[m_activeSessionId]->save(true); + saveSession(m_activeSessionId, true); + } + else if (m_sessions[m_activeSessionId]->isStillVolatile()) + { + // Automatically delete unstored and unnamed sessions when activating another one + m_sessions.remove(m_activeSessionId); // this also deletes the KateSession item since auto-deletion is enabled + m_activeSessionId = INVALID_SESSION; + if (sessionId > oldSessionId) + { + --sessionId; + } + emit sessionDeleted(oldSessionId); + oldSessionId = INVALID_SESSION; } } - int oldSessionId = m_activeSessionId; m_activeSessionId = sessionId; m_sessions[sessionId]->activate(); - m_firstActivation = false; + m_lastSessionId = INVALID_SESSION; emit sessionActivated(m_activeSessionId, oldSessionId); return true; } //------------------------------------ -int KateSessionManager::newSession(const TQString &sessionName, bool activate) +int KateSessionManager::newSession(const TQString &sessionName, bool saveCurr) { 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); - } + activateSession(newSessionId, saveCurr); return newSessionId; } @@ -498,9 +521,12 @@ 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) - m_sessions[newSessionId]->save(true); - reloadActiveSession(); - +/* saveSession(newSessionId, sessionId == m_activeSessionId); + if (sessionId == m_activeSessionId) + { + reloadActiveSession(); + } +*/ if (activate) { activateSession(newSessionId, m_activeSessionId != INVALID_SESSION); @@ -511,27 +537,26 @@ int KateSessionManager::cloneSession(int sessionId, const TQString &sessionName, //------------------------------------ bool KateSessionManager::restoreLastSession() { - if (!m_firstActivation) + if (m_activeSessionId != INVALID_SESSION) { return false; } - // NOTE: m_activeSessionId contains the id of the last active session - return activateSession(m_activeSessionId, false); + return activateSession(m_lastSessionId, false); } //------------------------------------------- -void KateSessionManager::saveSession(int sessionId) +void KateSessionManager::saveSession(int sessionId, bool saveGUIInfo, bool setReadOnly) { if (sessionId < 0 || sessionId >= (int)m_sessions.count()) { return; } - m_sessions[sessionId]->save(sessionId == m_activeSessionId); + m_sessions[sessionId]->save(saveGUIInfo, setReadOnly); emit sessionSaved(sessionId); } //------------------------------------------- -bool KateSessionManager::deleteSession(int sessionId) +bool KateSessionManager::deleteSession(int sessionId, int actSessId) { if (sessionId < 0 || sessionId >= (int)m_sessions.count()) { @@ -555,10 +580,16 @@ bool KateSessionManager::deleteSession(int sessionId) m_activeSessionId = INVALID_SESSION; } emit sessionDeleted(sessionId); - // if the active session was deleted, create a new unnamed session and activate it if (m_activeSessionId == INVALID_SESSION) { - newSession(); + if (m_sessions.count() > 0 && actSessId >= 0 && actSessId < (int)m_sessions.count()) + { + activateSession(actSessId, false); + } + else + { + newSession(); + } } return true; @@ -646,7 +677,7 @@ void KateSessionManager::setSessionReadOnlyStatus(int sessionId, bool readOnly) m_sessions[sessionId]->setReadOnly(readOnly); // Session is saved one last time when making it read only - m_sessions[sessionId]->save(sessionId == m_activeSessionId, true); + saveSession(sessionId, sessionId == m_activeSessionId, true); } //END KateSessionManager diff --git a/kate/app/katesession.h b/kate/app/katesession.h index 01357798b..4b1a63126 100644 --- a/kate/app/katesession.h +++ b/kate/app/katesession.h @@ -98,6 +98,12 @@ class KateSession */ const TQString& getSessionFilename() const { return m_filename; } + /** + * @return whether the session is still volatile, i.e. it has never + * been saved and never been named + */ + bool isStillVolatile() const; + /** * @return the number of documents in the session */ @@ -163,8 +169,6 @@ 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 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 { Q_OBJECT @@ -187,11 +191,6 @@ class KateSessionManager : public TQObject */ ~KateSessionManager(); - /** - * Save session manager info - */ - void saveConfig(); - /** * @return the session files folder name */ @@ -249,13 +248,14 @@ class KateSessionManager : public TQObject bool activateSession(int sessionId, bool saveCurr = true); /** - * Create a new session and activate it if required + * Create a new session and activate it * @param sessionName new session name - * @param activate if true, activate the new session after creation + * @param saveCurr if true, save the current session before activating the new one * @return the id of the newly created session * @emit sessionCreated + * @emit sessionDeleted (only when leaving an unstored and unnamed session) */ - int newSession(const TQString &sessionName = TQString::null, bool activate = true); + int newSession(const TQString &sessionName = TQString::null, bool saveCurr = true); /** * Create a new session and activate it if required @@ -290,15 +290,18 @@ class KateSessionManager : public TQObject * @param sessionId the id of the session to save * @emit sessionSaved */ - void saveSession(int sessionId); + void saveSession(int sessionId) { saveSession(sessionId, sessionId == m_activeSessionId); } /** * Delete the specified session * @param sessionId the id of the session to delete + * @param actSessId the id of the next session to activate. + * If INVALID_SESSION or invalid, create a new empty session. + * This is only meaningful when deleting the current active session. * @return whether the session has been deleted or not * @emit sessionDeleted */ - bool deleteSession(int sessionId); + bool deleteSession(int sessionId, int actSessId); /** * Move the specified session forward in the session list (by one position) @@ -370,6 +373,12 @@ class KateSessionManager : public TQObject protected: KateSessionManager(); + /** + * Save session manager info + * @param saveSessions if true, all sessions will be saved again + */ + void saveConfig(bool saveSessions); + /** * Swap the position of the two specified sessions in the session list * @param sessionId1 the id of the first session @@ -378,11 +387,20 @@ class KateSessionManager : public TQObject */ void swapSessionsPosition(int sessionId1, int sessionId2); + /** + * Save the specified session + * @param sessionId the id of the session to save + * @param saveGUIInfo if true, save also the information about the GUI elements + * @param setReadOnly necessary to save a session that has to be turned to read only + * @emit sessionSaved + */ + void saveSession(int sessionId, bool saveGUIInfo, bool setReadOnly = false); + TQString m_baseDir; // folder where session files are stored TQString m_configFile; // file where the session list config is stored - int m_activeSessionId; // index of the active session - bool m_firstActivation; // true until at least one session has been activated + int m_activeSessionId; // id of the active session + int m_lastSessionId; // id of the last active session before closing Kate TQPtrList m_sessions; // session list KSimpleConfig *m_config; // session manager config @@ -408,6 +426,7 @@ class KateSessionChooserItem : public TDEListViewItem //BEGIN KateSessionChooser +//FIXME create one single KateSessionChooser and reuse it all the time class KateSessionChooser : public KDialogBase { Q_OBJECT diff --git a/kate/app/katesessionpanel.cpp b/kate/app/katesessionpanel.cpp index 827dc403d..0c28726bd 100644 --- a/kate/app/katesessionpanel.cpp +++ b/kate/app/katesessionpanel.cpp @@ -19,6 +19,7 @@ #include "katesessionpanel.h" #include "katesessionpanel.moc" +#include "kateapp.h" #include "katemainwindow.h" #include "kateviewmanager.h" #include "katesession.h" @@ -195,7 +196,7 @@ void KateSessionPanel::setup_toolbar() a = new TDEAction(i18n("New"), SmallIcon("list-add"), 0, TQT_TQOBJECT(this), TQT_SLOT(slotNewSession()), m_actionCollection, "session_new"); - a->setWhatsThis(i18n("Create a new session.")); + a->setWhatsThis(i18n("Create a new session and switch to it.")); a->plug(m_toolbar); a = new TDEAction(i18n("Save"), SmallIcon("document-save"), 0, @@ -253,13 +254,20 @@ void KateSessionPanel::setup_toolbar() //------------------------------------------- void KateSessionPanel::slotNewSession() { - KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this, true); + KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this, false); int result = nameChooser->exec(); if (result == TQDialog::Accepted) { - m_sessionManager->newSession(nameChooser->getSessionName(), nameChooser->getActivateFlag()); + int res = handleVolatileSession(); + if (res == KMessageBox::Cancel) + { + return; + } + else + { + m_sessionManager->newSession(nameChooser->getSessionName(), res == KMessageBox::Yes); + } } - delete nameChooser; } //------------------------------------------- @@ -278,7 +286,7 @@ void KateSessionPanel::slotSaveSession() return; } - if (ks->getSessionFilename().isEmpty() && ks->getSessionName() == i18n(KS_UNNAMED)) + if (ks->isStillVolatile()) { // Session has never been saved before. Ask user for a session name first slotSaveSessionAs(); @@ -305,15 +313,9 @@ void KateSessionPanel::slotSaveSessionAs() 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; - } + // 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. + bool cloneSession = !ks->isStillVolatile(); // Get new session name KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this, cloneSession); int result = nameChooser->exec(); @@ -332,7 +334,6 @@ void KateSessionPanel::slotSaveSessionAs() } } - delete nameChooser; slotSelectionChanged(); // Update the toolbar button status } @@ -358,11 +359,23 @@ void KateSessionPanel::slotDeleteSession() } int result = KMessageBox::warningContinueCancel(this, - i18n("Do you really want to delete the session '%1'?").arg(sessionItem->text(0)), + i18n("Do you really want to delete the session \"%1\"?").arg(sessionItem->text(0)), i18n("Delete session"), KStdGuiItem::del()); if (result == KMessageBox::Continue) { - m_sessionManager->deleteSession(sessionItem->getSessionId()); + int sessionId = sessionItem->getSessionId(); + if (sessionId == m_sessionManager->getActiveSessionId()) + { + // First check if all documents can be closed safely + if (KateApp::self()->activeMainWindow()) + { + if (!KateApp::self()->activeMainWindow()->queryClose_internal()) + return; + } + } + //FIXME add options to let user decide what to do when deleting the current session + //(open previous/next session, create new empty session) + m_sessionManager->deleteSession(sessionId, KateSessionManager::INVALID_SESSION); } } @@ -397,7 +410,15 @@ void KateSessionPanel::slotActivateSession() int newSessionId = newSessionItem->getSessionId(); if (newSessionId != currSessionId) { - m_sessionManager->activateSession(newSessionId); + int res = handleVolatileSession(); + if (res == KMessageBox::Cancel) + { + return; + } + else + { + m_sessionManager->activateSession(newSessionId, res == KMessageBox::Yes); + } } } @@ -520,12 +541,18 @@ void KateSessionPanel::slotSelectionChanged() void KateSessionPanel::slotSessionActivated(int newSessionId, int oldSessionId) { // Move the active session marker - TQListViewItem *item = m_listview->firstChild(); - for (int idx = 0; idx < oldSessionId; ++idx) - { - item = item->nextSibling(); - } - item->setPixmap(m_columnPixmap, TQPixmap()); + TQListViewItem *item = NULL; + if (oldSessionId != KateSessionManager::INVALID_SESSION) + { + // Old volatile sessions may have already been deleted. + // Remove the marker only for valid sessions. + item = m_listview->firstChild(); + for (int idx = 0; idx < oldSessionId; ++idx) + { + item = item->nextSibling(); + } + item->setPixmap(m_columnPixmap, TQPixmap()); + } item = m_listview->firstChild(); for (int idx = 0; idx < newSessionId; ++idx) @@ -654,4 +681,32 @@ void KateSessionPanel::slotLVSessionRenamed(TQListViewItem *item) m_sessionManager->renameSession(sessionItem->getSessionId(), sessionItem->text(m_columnName)); } + +//------------------------------------------- +int KateSessionPanel::handleVolatileSession() +{ + const KateSession *ks = m_sessionManager->getActiveSession(); + if (!ks || !ks->isStillVolatile()) + { + return (!ks ? KMessageBox::No : KMessageBox::Yes); + } + + int msgres = KMessageBox::warningYesNoCancel(this, i18n("

You are leaving a volatile session." + "

Do you want to save or discard it?").arg(ks->getSessionName()), + i18n("Close session"), KStdGuiItem::save(), KStdGuiItem::discard()); + if (msgres == KMessageBox::Yes) + { + KateSessionNameChooser *nameChooser = new KateSessionNameChooser(this, false); + int result = nameChooser->exec(); + if (result == TQDialog::Accepted) + { + m_sessionManager->renameSession(m_sessionManager->getActiveSessionId(), nameChooser->getSessionName()); + } + else + { + msgres = KMessageBox::Cancel; + } + } + return msgres; +} //END KateSessionPanel diff --git a/kate/app/katesessionpanel.h b/kate/app/katesessionpanel.h index 2dd7347a7..6899d68e9 100644 --- a/kate/app/katesessionpanel.h +++ b/kate/app/katesessionpanel.h @@ -41,6 +41,7 @@ class TDEActionCollection; //BEGIN KateSessionNameChooser +//FIXME create one single KateSessionNameChooser and reuse it all the time class KateSessionNameChooser : public KDialogBase { Q_OBJECT @@ -137,8 +138,19 @@ class KateSessionPanel : public TQVBox void slotSessionRenamed(int sessionId); void slotLVSessionRenamed(TQListViewItem *item); - private: + protected: void setup_toolbar(); + + /* In case the current session is still volatile, asks the user whether + he wants to save or discard the session. + 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. + */ + int handleVolatileSession(); KateMainWindow *m_mainWin; KateViewManager *m_viewManager; -- cgit v1.2.1 From 8644afed0d8e383cf3576c598b2ca76833a74e33 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Mon, 23 May 2016 16:17:18 +1000 Subject: 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 --- kate/app/kateapp.cpp | 78 +++++++++++--- kate/app/kateapp.h | 23 +++- kate/app/kateexternaltools.cpp | 1 - kate/app/katefileselector.cpp | 1 - kate/app/katemainwindow.cpp | 22 ++-- kate/app/katesavemodifieddialog.cpp | 1 - kate/app/katesession.cpp | 209 +++++++++++++++++++++++++++++------- kate/app/katesession.h | 98 ++++++++++++++--- kate/app/katesessionpanel.cpp | 106 +++++++++++++----- kate/app/katesessionpanel.h | 11 +- kate/app/kateviewmanager.cpp | 1 - 11 files changed, 437 insertions(+), 114 deletions(-) (limited to 'kate') 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: '"<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("

Do you want to save the existing sessions?

!!NOTE!!" + "

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()"<documents(); + uint documentCount=KateDocManager::self()->documents(); - if ( ! showModOnDiskPrompt() ) + if ( !showModOnDiskPrompt() ) return false; TQPtrList 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, TQPtrListsetOpen(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,16 +516,34 @@ 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) { @@ -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. @@ -191,6 +212,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 */ @@ -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 @@ -331,6 +380,11 @@ class KateSessionManager : public TQObject void setSessionReadOnlyStatus(int sessionId, bool readOnly); 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 @@ -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 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( - 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("

You are leaving a volatile session." - "

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("

Do you want to save the current session?

!!NOTE!!" + "

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. -- cgit v1.2.1 From 67642abd943f30babeea0c44397cc40e7c2c1b9e Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 2 Oct 2016 21:20:29 +0900 Subject: Kate session panel: removed no longer used OldKateSession and OldKateSessionManager code. Signed-off-by: Michele Calgaro --- kate/app/katesession.cpp | 698 ----------------------------------------------- kate/app/katesession.h | 343 +---------------------- 2 files changed, 1 insertion(+), 1040 deletions(-) (limited to 'kate') diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index 91f655613..1f7817f01 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -898,704 +898,6 @@ void KateSessionChooser::slotSelectionChanged() } //END KateSessionChooser - - - - -//------------------------------------ -//------------------------------------ -//------------------------------------ -//------------------------------------ -OldKateSession::OldKateSession (OldKateSessionManager *manager, const TQString &fileName, const TQString &name) - : m_sessionFileRel (fileName) - , m_sessionName (name) - , m_documents (0) - , m_manager (manager) - , m_readConfig (0) - , m_writeConfig (0) -{ - init (); -} - -void OldKateSession::init () -{ - // given file exists, use it to load some stuff ;) - if (!m_sessionFileRel.isEmpty() && TDEGlobal::dirs()->exists(sessionFile ())) - { - KSimpleConfig config (sessionFile (), true); - - if (m_sessionName.isEmpty()) - { - // get the name out of the file - if (m_sessionFileRel == "default.katesession") - m_sessionName = i18n("Default Session"); - else - { - config.setGroup ("General"); - m_sessionName = config.readEntry ("Name", i18n ("Unnamed Session")); - } - } - - // get the document count - config.setGroup ("Open Documents"); - m_documents = config.readUnsignedNumEntry("Count", 0); - - return; - } - - // filename not empty, create the file - // anders: When will this ever happen??? - if (!m_sessionFileRel.isEmpty()) - { - kdDebug(13001)<<"Kate::Session: initializing unexisting file!"<sessionsDir() + "/" + m_sessionFileRel; -} - -bool OldKateSession::create (const TQString &name, bool force) -{ - if (!force && (name.isEmpty() || !m_sessionFileRel.isEmpty())) - return false; - - delete m_writeConfig; - m_writeConfig = 0; - - delete m_readConfig; - m_readConfig = 0; - - m_sessionName = name; - - // get a usable filename - int s = time(0); - TQCString tname; - while (true) - { - tname.setNum (s++); - KMD5 md5 (tname); - m_sessionFileRel = TQString ("%1.katesession").arg (md5.hexDigest().data()); - - if (!TDEGlobal::dirs()->exists(sessionFile ())) - break; - } - - // create the file, write name to it! - KSimpleConfig config (sessionFile ()); - config.setGroup ("General"); - config.writeEntry ("Name", m_sessionName); - config.sync (); - - // reinit ourselfs ;) - init (); - - return true; -} - -bool OldKateSession::rename (const TQString &name) -{ - if (name.isEmpty () || m_sessionFileRel.isEmpty() || m_sessionFileRel == "default.katesession") - return false; - - m_sessionName = name; - - TDEConfig config (sessionFile (), false, false); - config.setGroup ("General"); - config.writeEntry ("Name", m_sessionName); - config.sync (); - - return true; -} - -TDEConfig *OldKateSession::configRead () -{ - if (m_sessionFileRel.isEmpty()) - return 0; - - if (m_readConfig) - return m_readConfig; - - return m_readConfig = new KSimpleConfig (sessionFile (), true); -} - -TDEConfig *OldKateSession::configWrite () -{ - if (m_sessionFileRel.isEmpty()) - return 0; - - if (m_writeConfig) - return m_writeConfig; - - m_writeConfig = new KSimpleConfig (sessionFile ()); - m_writeConfig->setGroup ("General"); - m_writeConfig->writeEntry ("Name", m_sessionName); - - return m_writeConfig; -} - -OldKateSessionManager::OldKateSessionManager (TQObject *parent) - : TQObject (parent) - , m_sessionsDir (locateLocal( "data", "kate/sessions")) - , m_activeSession (new OldKateSession (this, "", "")) -{ - kdDebug() << "LOCAL SESSION DIR: " << m_sessionsDir << endl; - - // create dir if needed - TDEGlobal::dirs()->makeDir (m_sessionsDir); -} - -OldKateSessionManager::~OldKateSessionManager() -{ -} - -OldKateSessionManager *OldKateSessionManager::self() -{ - return (OldKateSessionManager*)KateApp::self()->sessionManager(); -} - -void OldKateSessionManager::dirty (const TQString &) -{ - updateSessionList (); -} - -void OldKateSessionManager::updateSessionList () -{ - m_sessionList.clear (); - - // Let's get a list of all session we have atm - TQDir dir (m_sessionsDir, "*.katesession"); - - bool foundDefault = false; - for (unsigned int i=0; i < dir.count(); ++i) - { - OldKateSession *session = new OldKateSession (this, dir[i], ""); - m_sessionList.append (session); - - kdDebug () << "FOUND SESSION: " << session->sessionName() << " FILE: " << session->sessionFile() << endl; - - if (!foundDefault && (dir[i] == "default.katesession")) - foundDefault = true; - } - - // add default session, if not there - if (!foundDefault) - m_sessionList.append (new OldKateSession (this, "default.katesession", i18n("Default Session"))); - - qHeapSort(m_sessionList); -} - -void OldKateSessionManager::activateSession (OldKateSession::Ptr session, bool closeLast, bool saveLast, bool loadNew) -{ - // don't reload. - // ### comparing the pointers directly is b0rk3d :( - if ( ! session->sessionName().isEmpty() && session->sessionName() == m_activeSession->sessionName() ) - return; - // try to close last session - if (closeLast) - { - if (KateApp::self()->activeMainWindow()) - { - if (!KateApp::self()->activeMainWindow()->queryClose_internal()) - return; - } - } - - // save last session or not? - if (saveLast) - saveActiveSession (true); - - // really close last - if (closeLast) - { - KateDocManager::self()->closeAllDocuments (); - } - - // set the new session - m_activeSession = session; - - if (loadNew) - { - // open the new session - Kate::Document::setOpenErrorDialogsActivated (false); - - TDEConfig *sc = activeSession()->configRead(); - - if (sc) - KateApp::self()->documentManager()->restoreDocumentList (sc); - - // if we have no session config object, try to load the default - // (anonymous/unnamed sessions) - if ( ! sc ) - sc = new KSimpleConfig( sessionsDir() + "/default.katesession" ); - - // window config - if (sc) - { - TDEConfig *c = KateApp::self()->config(); - c->setGroup("General"); - - if (c->readBoolEntry("Restore Window Configuration", true)) - { - // a new, named session, read settings of the default session. - if ( ! sc->hasGroup("Open MainWindows") ) - sc = new KSimpleConfig( sessionsDir() + "/default.katesession" ); - - sc->setGroup ("Open MainWindows"); - unsigned int wCount = sc->readUnsignedNumEntry("Count", 1); - - for (unsigned int i=0; i < wCount; ++i) - { - if (i >= KateApp::self()->mainWindows()) - { - KateApp::self()->newMainWindow(sc, TQString ("MainWindow%1").arg(i)); - } - else - { - sc->setGroup(TQString ("MainWindow%1").arg(i)); - KateApp::self()->mainWindow(i)->readProperties (sc); - } - } - - if (wCount > 0) - { - while (wCount < KateApp::self()->mainWindows()) - { - KateMainWindow *w = KateApp::self()->mainWindow(KateApp::self()->mainWindows()-1); - KateApp::self()->removeMainWindow (w); - delete w; - } - } - } - } - - Kate::Document::setOpenErrorDialogsActivated (true); - } -} - -OldKateSession::Ptr OldKateSessionManager::createSession (const TQString &name) -{ - OldKateSession::Ptr s = new OldKateSession (this, "", ""); - s->create (name); - - return s; -} - -OldKateSession::Ptr OldKateSessionManager::giveSession (const TQString &name) -{ - if (name.isEmpty()) - return new OldKateSession (this, "", ""); - - updateSessionList(); - - for (unsigned int i=0; i < m_sessionList.count(); ++i) - { - if (m_sessionList[i]->sessionName() == name) - return m_sessionList[i]; - } - - return createSession (name); -} - -bool OldKateSessionManager::saveActiveSession (bool tryAsk, bool rememberAsLast) -{ - if (tryAsk) - { - // app config - TDEConfig *c = KateApp::self()->config(); - c->setGroup("General"); - - TQString sesExit (c->readEntry ("Session Exit", "save")); - - if (sesExit == "discard") - return true; - - if (sesExit == "ask") - { - KDialogBase* dlg = new KDialogBase(i18n ("Save Session?") - , KDialogBase::Yes | KDialogBase::No - , KDialogBase::Yes, KDialogBase::No - ); - - bool dontAgain = false; - int res = KMessageBox::createKMessageBox(dlg, TQMessageBox::Question, - i18n("Save current session?"), TQStringList(), - i18n("Do not ask again"), &dontAgain, KMessageBox::Notify); - - // remember to not ask again with right setting - if (dontAgain) - { - c->setGroup("General"); - - if (res == KDialogBase::No) - c->writeEntry ("Session Exit", "discard"); - else - c->writeEntry ("Session Exit", "save"); - } - - if (res == KDialogBase::No) - return true; - } - } - - TDEConfig *sc = activeSession()->configWrite(); - - if (!sc) - return false; - - KateDocManager::self()->saveDocumentList (sc); - - sc->setGroup ("Open MainWindows"); - sc->writeEntry ("Count", KateApp::self()->mainWindows ()); - - // save config for all windows around ;) - for (unsigned int i=0; i < KateApp::self()->mainWindows (); ++i ) - { - sc->setGroup(TQString ("MainWindow%1").arg(i)); - KateApp::self()->mainWindow(i)->saveProperties (sc); - } - - sc->sync(); - - if (rememberAsLast) - { - TDEConfig *c = KateApp::self()->config(); - c->setGroup("General"); - c->sync (); - } - - return true; -} - -void OldKateSessionManager::sessionNew () -{ - activateSession (new OldKateSession (this, "", "")); -} - -void OldKateSessionManager::sessionOpen () -{ - OldKateSessionOpenDialog *chooser = new OldKateSessionOpenDialog (0); - - int res = chooser->exec (); - - if (res == OldKateSessionOpenDialog::resultCancel) - { - delete chooser; - return; - } - - OldKateSession::Ptr s = chooser->selectedSession (); - - if (s) - activateSession (s); - - delete chooser; -} - -void OldKateSessionManager::sessionSave () -{ - // if the active session is valid, just save it :) - if (saveActiveSession ()) - return; - - bool ok = false; - TQString name = KInputDialog::getText (i18n("Specify Name for Current Session"), i18n("Session name:"), "", &ok); - - if (!ok) - return; - - if (name.isEmpty()) - { - KMessageBox::error (0, i18n("To save a new session, you must specify a name."), i18n ("Missing Session Name")); - return; - } - - activeSession()->create (name); - saveActiveSession (); -} - -void OldKateSessionManager::sessionSaveAs () -{ - bool ok = false; - TQString name = KInputDialog::getText (i18n("Specify New Name for Current Session"), i18n("Session name:"), "", &ok); - - if (!ok) - return; - - if (name.isEmpty()) - { - KMessageBox::error (0, i18n("To save a session, you must specify a name."), i18n ("Missing Session Name")); - return; - } - - activeSession()->create (name, true); - saveActiveSession (); -} - - -void OldKateSessionManager::sessionManage () -{ - OldKateSessionManageDialog *dlg = new OldKateSessionManageDialog (0); - - dlg->exec (); - - delete dlg; -} - -//BEGIN CHOOSER DIALOG - -class OldKateSessionChooserItem : public TQListViewItem -{ - public: - OldKateSessionChooserItem (TDEListView *lv, OldKateSession::Ptr s) - : TQListViewItem (lv, s->sessionName()) - , session (s) - { - TQString docs; - docs.setNum (s->documents()); - setText (1, docs); - } - - OldKateSession::Ptr session; -}; - - -//END CHOOSER DIALOG - -//BEGIN OPEN DIALOG - -OldKateSessionOpenDialog::OldKateSessionOpenDialog (TQWidget *parent) - : KDialogBase ( parent - , "" - , true - , i18n ("Open Session") - , KDialogBase::User1 | KDialogBase::User2 - , KDialogBase::User2 - , false - , KStdGuiItem::cancel () - , KGuiItem( i18n("&Open"), "document-open") - ) -{ - TQHBox *page = new TQHBox (this); - page->setMinimumSize (400, 200); - setMainWidget(page); - - TQHBox *hb = new TQHBox (page); - - TQVBox *vb = new TQVBox (hb); - - m_sessions = new TDEListView (vb); - m_sessions->addColumn (i18n("Session Name")); - m_sessions->addColumn (i18n("Open Documents")); - m_sessions->setResizeMode (TQListView::AllColumns); - m_sessions->setSelectionMode (TQListView::Single); - m_sessions->setAllColumnsShowFocus (true); - - connect (m_sessions, TQT_SIGNAL(doubleClicked(TQListViewItem *, const TQPoint &, int)), this, TQT_SLOT(slotUser2())); - - OldKateSessionList &slist (OldKateSessionManager::self()->sessionList()); - for (unsigned int i=0; i < slist.count(); ++i) - { - new OldKateSessionChooserItem (m_sessions, slist[i]); - } - - setResult (resultCancel); -} - -OldKateSessionOpenDialog::~OldKateSessionOpenDialog () -{ -} - -OldKateSession::Ptr OldKateSessionOpenDialog::selectedSession () -{ - OldKateSessionChooserItem *item = (OldKateSessionChooserItem *) m_sessions->selectedItem (); - - if (!item) - return 0; - - return item->session; -} - -void OldKateSessionOpenDialog::slotUser1 () -{ - done (resultCancel); -} - -void OldKateSessionOpenDialog::slotUser2 () -{ - done (resultOk); -} - -//END OPEN DIALOG - -//BEGIN MANAGE DIALOG - -OldKateSessionManageDialog::OldKateSessionManageDialog (TQWidget *parent) - : KDialogBase ( parent - , "" - , true - , i18n ("Manage Sessions") - , KDialogBase::User1 - , KDialogBase::User1 - , false - , KStdGuiItem::close () - ) -{ - TQHBox *page = new TQHBox (this); - page->setMinimumSize (400, 200); - setMainWidget(page); - - TQHBox *hb = new TQHBox (page); - hb->setSpacing (KDialog::spacingHint()); - - m_sessions = new TDEListView (hb); - m_sessions->addColumn (i18n("Session Name")); - m_sessions->addColumn (i18n("Open Documents")); - m_sessions->setResizeMode (TQListView::AllColumns); - m_sessions->setSelectionMode (TQListView::Single); - m_sessions->setAllColumnsShowFocus (true); - - connect (m_sessions, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(selectionChanged())); - - updateSessionList (); - - TQWidget *vb = new TQWidget (hb); - TQVBoxLayout *vbl = new TQVBoxLayout (vb); - vbl->setSpacing (KDialog::spacingHint()); - - m_rename = new KPushButton (i18n("&Rename..."), vb); - connect (m_rename, TQT_SIGNAL(clicked()), this, TQT_SLOT(rename())); - vbl->addWidget (m_rename); - - m_del = new KPushButton (KStdGuiItem::del (), vb); - connect (m_del, TQT_SIGNAL(clicked()), this, TQT_SLOT(del())); - vbl->addWidget (m_del); - - vbl->addStretch (); - - // trigger action update - selectionChanged (); -} - -OldKateSessionManageDialog::~OldKateSessionManageDialog () -{ -} - -void OldKateSessionManageDialog::slotUser1 () -{ - done (0); -} - - -void OldKateSessionManageDialog::selectionChanged () -{ - OldKateSessionChooserItem *item = (OldKateSessionChooserItem *) m_sessions->selectedItem (); - - m_rename->setEnabled (item && item->session->sessionFileRelative() != "default.katesession"); - m_del->setEnabled (item && item->session->sessionFileRelative() != "default.katesession"); -} - -void OldKateSessionManageDialog::rename () -{ - OldKateSessionChooserItem *item = (OldKateSessionChooserItem *) m_sessions->selectedItem (); - - if (!item || item->session->sessionFileRelative() == "default.katesession") - return; - - bool ok = false; - TQString name = KInputDialog::getText (i18n("Specify New Name for Session"), i18n("Session name:"), item->session->sessionName(), &ok); - - if (!ok) - return; - - if (name.isEmpty()) - { - KMessageBox::error (0, i18n("To save a session, you must specify a name."), i18n ("Missing Session Name")); - return; - } - - item->session->rename (name); - updateSessionList (); -} - -void OldKateSessionManageDialog::del () -{ - OldKateSessionChooserItem *item = (OldKateSessionChooserItem *) m_sessions->selectedItem (); - - if (!item || item->session->sessionFileRelative() == "default.katesession") - return; - - TQFile::remove (item->session->sessionFile()); - OldKateSessionManager::self()->updateSessionList (); - updateSessionList (); -} - -void OldKateSessionManageDialog::updateSessionList () -{ - m_sessions->clear (); - - OldKateSessionList &slist (OldKateSessionManager::self()->sessionList()); - for (unsigned int i=0; i < slist.count(); ++i) - { - new OldKateSessionChooserItem (m_sessions, slist[i]); - } -} - -//END MANAGE DIALOG - - -OldKateSessionsAction::OldKateSessionsAction(const TQString& text, TQObject* parent, const char* name ) - : TDEActionMenu(text, parent, name) -{ - connect(popupMenu(),TQT_SIGNAL(aboutToShow()),this,TQT_SLOT(slotAboutToShow())); -} - -void OldKateSessionsAction::slotAboutToShow() -{ - popupMenu()->clear (); - - OldKateSessionList &slist (OldKateSessionManager::self()->sessionList()); - for (unsigned int i=0; i < slist.count(); ++i) - { - popupMenu()->insertItem ( - slist[i]->sessionName(), - this, TQT_SLOT (openSession (int)), 0, - i ); - } -} - -void OldKateSessionsAction::openSession (int i) -{ - OldKateSessionList &slist (OldKateSessionManager::self()->sessionList()); - - if ((uint)i >= slist.count()) - return; - - OldKateSessionManager::self()->activateSession(slist[(uint)i]); -} - #include "katesession.moc" // kate: space-indent on; indent-width 2; replace-tabs on; mixed-indent off; diff --git a/kate/app/katesession.h b/kate/app/katesession.h index d073d8411..50db624b6 100644 --- a/kate/app/katesession.h +++ b/kate/app/katesession.h @@ -174,6 +174,7 @@ class KateSession // Session is saved without asking for a name //FIXME improve getStartupOption/getSwitchOption/setSwitchOption using new signal // KateApp::optionsChanged() +//FIXME add kdDebug statement to ease debugging class KateSessionManager : public TQObject { Q_OBJECT @@ -527,346 +528,4 @@ class KateSessionChooser : public KDialogBase }; //END KateSessionChooser - - - -//------------------------------------ -//------------------------------------ -//------------------------------------ -class OldKateSessionManager; -class OldKateSession : public TDEShared -{ - public: - /** - * Define a Shared-Pointer type - */ - typedef TDESharedPtr Ptr; - - public: - /** - * create a session from given file - * @param fileName session filename, relative - * @param name session name - * @param manager pointer to the manager - */ - OldKateSession ( OldKateSessionManager *manager, const TQString &fileName, const TQString &name ); - - /** - * init the session object, after construction or create - */ - void init (); - - /** - * destruct me - */ - ~OldKateSession (); - - /** - * session filename, absolute, calculated out of relative filename + session dir - * @return absolute path to session file - */ - TQString sessionFile () const; - - /** - * relative session filename - * @return relative filename for this session - */ - const TQString &sessionFileRelative () const { return m_sessionFileRel; } - - /** - * session name - * @return name for this session - */ - const TQString &sessionName () const { return m_sessionName; } - - /** - * is this a valid session? if not, don't use any session if this is - * the active one - */ - bool isNew () const { return m_sessionName.isEmpty(); } - - /** - * create the session file, if not existing - * @param name name for this session - * @param force force to create new file - * @return true if created, false if no creation needed - */ - bool create ( const TQString &name, bool force = false ); - - /** - * rename this session - * @param name new name - * @return success - */ - bool rename ( const TQString &name ); - - /** - * config to read - * on first access, will create the config object, delete will be done automagic - * return 0 if we have no file to read config from atm - * @return config to read from - */ - TDEConfig *configRead (); - - /** - * config to write - * on first access, will create the config object, delete will be done automagic - * return 0 if we have no file to write config to atm - * @return config to write from - */ - TDEConfig *configWrite (); - - /** - * count of documents in this session - * @return documents count - */ - unsigned int documents () const { return m_documents; } - - private: - /** - * session filename, in local location we can write to - * relative filename to the session dirs :) - */ - TQString m_sessionFileRel; - - /** - * session name, extracted from the file, to display to the user - */ - TQString m_sessionName; - - /** - * number of document of this session - */ - unsigned int m_documents; - - /** - * OldKateSessionMananger - */ - OldKateSessionManager *m_manager; - - /** - * simpleconfig to read from - */ - KSimpleConfig *m_readConfig; - - /** - * simpleconfig to write to - */ - KSimpleConfig *m_writeConfig; -}; - -typedef TQValueList OldKateSessionList; - -class OldKateSessionManager : public TQObject -{ - Q_OBJECT - - public: - OldKateSessionManager ( TQObject *parent ); - ~OldKateSessionManager(); - - /** - * allow access to this :) - * @return instance of the session manager - */ - static OldKateSessionManager *self(); - - /** - * allow access to the session list - * kept up to date by watching the dir - */ - inline OldKateSessionList & sessionList () { updateSessionList (); return m_sessionList; } - - /** - * activate a session - * first, it will look if a session with this name exists in list - * if yes, it will use this session, else it will create a new session file - * @param session session to activate - * @param closeLast try to close last session or not? - * @param saveLast try to save last session or not? - * @param loadNew load new session stuff? - */ - void activateSession ( OldKateSession::Ptr session, bool closeLast = true, bool saveLast = true, bool loadNew = true ); - - /** - * create a new session - * @param name session name - */ - OldKateSession::Ptr createSession ( const TQString &name ); - - /** - * return session with given name - * if no existing session matches, create new one with this name - * @param name session name - */ - OldKateSession::Ptr giveSession ( const TQString &name ); - - /** - * save current session - * for sessions without filename: save nothing - * @param tryAsk should we ask user if needed? - * @param rememberAsLast remember this session as last used? - * @return success - */ - bool saveActiveSession ( bool tryAsk = false, bool rememberAsLast = false ); - - /** - * return the current active session - * sessionFile == empty means we have no session around for this instance of kate - * @return session active atm - */ - inline OldKateSession::Ptr activeSession () { return m_activeSession; } - - /** - * session dir - * @return global session dir - */ - inline const TQString &sessionsDir () const { return m_sessionsDir; } - - /** - * initial session chooser, on app start - * @return success, if false, app should exit - */ - bool chooseSession (); - - public slots: - /** - * try to start a new session - * asks user first for name - */ - void sessionNew (); - - /** - * try to open a existing session - */ - void sessionOpen (); - - /** - * try to save current session - */ - void sessionSave (); - - /** - * try to save as current session - */ - void sessionSaveAs (); - - /** - * show dialog to manage our sessions - */ - void sessionManage (); - - private slots: - void dirty ( const TQString &path ); - - public: - /** - * trigger update of session list - */ - void updateSessionList (); - - private: - /** - * absolute path to dir in home dir where to store the sessions - */ - TQString m_sessionsDir; - - /** - * list of current available sessions - */ - OldKateSessionList m_sessionList; - - /** - * current active session - */ - OldKateSession::Ptr m_activeSession; -}; - - -class OldKateSessionOpenDialog : public KDialogBase -{ - Q_OBJECT - - public: - OldKateSessionOpenDialog ( TQWidget *parent ); - ~OldKateSessionOpenDialog (); - - OldKateSession::Ptr selectedSession (); - - enum - { - resultOk, - resultCancel - }; - - protected slots: - /** - * cancel pressed - */ - void slotUser1 (); - - /** - * ok pressed - */ - void slotUser2 (); - - private: - TDEListView *m_sessions; -}; - -class OldKateSessionManageDialog : public KDialogBase -{ - Q_OBJECT - - public: - OldKateSessionManageDialog ( TQWidget *parent ); - ~OldKateSessionManageDialog (); - - protected slots: - /** - * close pressed - */ - void slotUser1 (); - - /** - * selection has changed - */ - void selectionChanged (); - - /** - * try to rename session - */ - void rename (); - - /** - * try to delete session - */ - void del (); - - private: - /** - * update our list - */ - void updateSessionList (); - - private: - TDEListView *m_sessions; - KPushButton *m_rename; - KPushButton *m_del; -}; - -class OldKateSessionsAction : public TDEActionMenu -{ - Q_OBJECT - - public: - OldKateSessionsAction ( const TQString& text, TQObject* parent = 0, const char* name = 0 ); - ~OldKateSessionsAction () {;}; - - public slots: - void slotAboutToShow(); - - void openSession ( int i ); -}; - #endif -- cgit v1.2.1 From 6131095c14221ddbd16805059a9f3b3fc6c58225 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sat, 8 Oct 2016 23:57:24 +0900 Subject: Kate session panel: added "Sessions" menu support. Signed-off-by: Michele Calgaro --- kate/app/katemainwindow.cpp | 99 +++++++++++++++++++++++++++++++++++++------ kate/app/katemainwindow.h | 50 +++++++++++++++------- kate/app/katesession.cpp | 2 +- kate/app/katesession.h | 5 +++ kate/app/katesessionpanel.cpp | 33 +++++++++------ kate/app/katesessionpanel.h | 14 ++++-- kate/data/kateui.rc | 23 ++++++---- 7 files changed, 169 insertions(+), 57 deletions(-) (limited to 'kate') diff --git a/kate/app/katemainwindow.cpp b/kate/app/katemainwindow.cpp index 4493eae12..1a021beb9 100644 --- a/kate/app/katemainwindow.cpp +++ b/kate/app/katemainwindow.cpp @@ -219,7 +219,7 @@ void KateMainWindow::setupMainWindow () connect(fileselector->dirOperator(),TQT_SIGNAL(fileSelected(const KFileItem*)),this,TQT_SLOT(fileSelected(const KFileItem*))); KateMDI::ToolView *st = createToolView("kate_sessionpanel", KMultiTabBar::Left, SmallIcon("view_choose"), i18n("Sessions")); - sessionpanel = new KateSessionPanel( this, m_viewManager, st, "sessionpanel"); + m_sessionpanel = new KateSessionPanel( this, m_viewManager, st, "sessionpanel"); // ONLY ALLOW SHELL ACCESS IF ALLOWED ;) if (KateApp::self()->authorize("shell_access")) @@ -305,17 +305,30 @@ void KateMainWindow::setupActions() slotWindowActivated (); -// FIXME to fix and enable again // session actions -/* new TDEAction(i18n("Menu entry Session->New", "&New"), "list-add", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionNew()), actionCollection(), "sessions_new"); - new TDEAction(i18n("&Open..."), "document-open", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionOpen()), actionCollection(), "sessions_open"); - new TDEAction(i18n("&Save"), "document-save", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionSave()), actionCollection(), "sessions_save"); - new TDEAction(i18n("Save &As..."), "document-save-as", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionSaveAs()), actionCollection(), "sessions_save_as"); - new TDEAction(i18n("&Manage..."), "view_choose", 0, TQT_TQOBJECT(OldKateSessionManager::self()), TQT_SLOT(sessionManage()), actionCollection(), "sessions_manage"); - - // quick open menu ;) - new OldKateSessionsAction (i18n("&Quick Open"), actionCollection(), "sessions_list"); -*/ + new TDEAction(i18n("&New"), "list-add", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotNewSession()), actionCollection(), "session_new"); + new TDEAction(i18n("&Save"), "document-save", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotSaveSession()), actionCollection(), "session_save"); + new TDEAction(i18n("Save &As..."), "document-save-as", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotSaveSessionAs()), actionCollection(), "session_save_as"); + new TDEAction(i18n("&Rename"), "edit_user", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotRenameSession()), actionCollection(), "session_rename"); + new TDEAction(i18n("&Delete"), "edit-delete", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotDeleteSession()), actionCollection(), "session_delete"); + new TDEAction(i18n("Re&load"), "reload", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotReloadSession()), actionCollection(), "session_reload"); + new TDEAction(i18n("Acti&vate"), "forward", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotActivateSession()), actionCollection(), "session_activate"); + new TDEToggleAction(i18n("Toggle read &only"), "encrypted", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotSessionToggleReadOnly()), actionCollection(), "session_toggle_read_only"); + new TDEAction(i18n("Move &Up"), "go-up", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotSessionMoveUp()), actionCollection(), "session_move_up"); + new TDEAction(i18n("Move Do&wn"), "go-down", 0, + TQT_TQOBJECT(m_sessionpanel), TQT_SLOT(slotSessionMoveDown()), actionCollection(), "session_move_down"); + new KateSessionListActionMenu(this, i18n("Sele&ct session"), actionCollection(), "session_list"); + + connect(m_sessionpanel, TQT_SIGNAL(selectionChanged()), TQT_TQOBJECT(this), TQT_SLOT(slotSelectionChanged())); } KateTabWidget *KateMainWindow::tabWidget () @@ -857,10 +870,68 @@ void KateMainWindow::readProperties(TDEConfig *config) config->setGroup(grp); } -void KateMainWindow::saveGlobalProperties( TDEConfig* sessionConfig ) +//------------------------------------------- +void KateMainWindow::slotSelectionChanged() +{ + TDEActionCollection *mwac = actionCollection(); // Main Window Action Collection + TDEActionPtrList actionList = m_sessionpanel->m_actionCollection->actions(); + TDEActionPtrList::ConstIterator spa_it; + for (spa_it = actionList.begin(); spa_it != actionList.end(); ++spa_it) + { + TDEAction *a = mwac->action((*spa_it)->name()); + TDEToggleAction *ta = dynamic_cast(a); + if (ta) + { + ta->setChecked((dynamic_cast(*spa_it))->isChecked()); + } + if (a) + { + a->setEnabled((*spa_it)->isEnabled()); + } + } +} + +//------------------------------------------- +void KateMainWindow::activateSession(int sessionId) +{ + if (sessionId < 0 || sessionId == KateApp::self()->sessionManager()->getActiveSessionId()) + { + return; + } + + // Select the required session in the session panel's listview + TQListViewItem *item = m_sessionpanel->m_listview->firstChild(); + int idx = 0; + while (item && idx < sessionId) + { + item = item->nextSibling(); + ++idx; + } + if (idx == sessionId && item) + { + // Required session item found, switch session with consistent behavior + m_sessionpanel->m_listview->setSelected(item, true); + m_sessionpanel->slotActivateSession(); + } +} + +//------------------------------------------- +KateSessionListActionMenu::KateSessionListActionMenu(KateMainWindow *mw, const TQString &text, TQObject *parent, const char *name) + : TDEActionMenu(text, parent, name), m_mainWindow(mw) { -// FIXME do we still need this code here? -// KateDocManager::self()->saveDocumentList (sessionConfig); + connect(popupMenu(), TQT_SIGNAL(aboutToShow()), this, TQT_SLOT(slotAboutToShow())); +} + +//------------------------------------------- +void KateSessionListActionMenu::slotAboutToShow() +{ + popupMenu()->clear(); + + TQPtrList &sessions = KateApp::self()->sessionManager()->getSessionsList(); + for (int idx = 0; idx < (int)sessions.count(); ++idx) + { + popupMenu()->insertItem(sessions[idx]->getSessionName(), m_mainWindow, TQT_SLOT(activateSession(int)), 0, idx); + } } // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/katemainwindow.h b/kate/app/katemainwindow.h index 15b7f35c6..aa2a6cee7 100644 --- a/kate/app/katemainwindow.h +++ b/kate/app/katemainwindow.h @@ -68,7 +68,6 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa /** * Accessor methodes for interface and child objects */ - public: Kate::MainWindow *mainWindow () { return m_mainWindow; } Kate::ToolViewManager *toolViewManager () { return m_toolViewManager; } @@ -79,7 +78,6 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa /** * various methodes to get some little info out of this */ - public: /** Returns the URL of the current document. * anders: I add this for use from the file selector. */ KURL activeDocumentUrl(); @@ -101,14 +99,27 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa */ KateTabWidget *tabWidget (); - public: void readProperties(TDEConfig *config); void saveProperties(TDEConfig *config); - void saveGlobalProperties( TDEConfig* sessionConfig ); - public: bool queryClose_internal(); + void openURL (const TQString &name=0L); + + public slots: + /** + * update "Sessions" menu status when selection in session panel has changed + */ + void slotSelectionChanged(); + + /** + * activate the specified session. When there is the need to activate a session + * from the outside (for example from DCOP), using this method assures that + * the session activation is consistent with the behavior of the session panel + * @param sessionId the id of the session to activate + */ + void activateSession(int sessionId); + private: void setupMainWindow(); void setupActions(); @@ -127,11 +138,11 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa void dragEnterEvent( TQDragEnterEvent * ); void dropEvent( TQDropEvent * ); + private slots: /** * slots used for actions in the menus/toolbars * or internal signal connections */ - private slots: void newWindow (); void slotConfigure(); @@ -163,18 +174,12 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa void pluginHelp(); void slotFullScreen(bool); - public: - void openURL (const TQString &name=0L); - - private slots: void updateGrepDir (bool visible); - + void slotDocumentCloseAll(); + protected: bool event( TQEvent * ); - private slots: - void slotDocumentCloseAll(); - private: static uint uniqueID; uint myID; @@ -198,7 +203,7 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa KateFileList *filelist; KateFileSelector *fileselector; - KateSessionPanel *sessionpanel; + KateSessionPanel *m_sessionpanel; TDEActionMenu* documentOpenWith; @@ -214,6 +219,21 @@ class KateMainWindow : public KateMDI::MainWindow, virtual public KParts::PartBa KateTabWidget *m_tabWidget; }; +class KateSessionListActionMenu : public TDEActionMenu +{ + Q_OBJECT + + public: + KateSessionListActionMenu(KateMainWindow *mw, const TQString &text, TQObject *parent = NULL, const char *name = NULL); + ~KateSessionListActionMenu() {} + + public slots: + void slotAboutToShow(); + + protected: + KateMainWindow *m_mainWindow; +}; + #endif // kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/kate/app/katesession.cpp b/kate/app/katesession.cpp index 1f7817f01..4b973214b 100644 --- a/kate/app/katesession.cpp +++ b/kate/app/katesession.cpp @@ -852,7 +852,7 @@ KateSessionChooser::KateSessionChooser(TQWidget *parent) connect (m_listview, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(slotSelectionChanged())); connect (m_listview, TQT_SIGNAL(executed(TQListViewItem*)), this, TQT_SLOT(slotUser2())); - TQPtrList& sessions = KateSessionManager::self()->getSessionsList(); + TQPtrList &sessions = KateSessionManager::self()->getSessionsList(); for (int idx = sessions.count()-1; idx >= 0; --idx) { new KateSessionChooserItem(m_listview, sessions[idx]->getSessionName(), diff --git a/kate/app/katesession.h b/kate/app/katesession.h index 50db624b6..665ac867b 100644 --- a/kate/app/katesession.h +++ b/kate/app/katesession.h @@ -244,6 +244,11 @@ class KateSessionManager : public TQObject */ const TQString& getBaseDir() const { return m_baseDir; } + /** + * @return the number of existing sessions + */ + int getSessionCount() const { return m_sessions.count(); } + /** * @return the active session id */ diff --git a/kate/app/katesessionpanel.cpp b/kate/app/katesessionpanel.cpp index 25980dc40..0cf7e235b 100644 --- a/kate/app/katesessionpanel.cpp +++ b/kate/app/katesessionpanel.cpp @@ -126,9 +126,8 @@ void KateSessionPanelToolBarParent::resizeEvent (TQResizeEvent*) //------------------------------------------- KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager *viewManager, TQWidget *parent, const char *name) - : TQVBox(parent, name), m_mainWin(mainWindow), m_viewManager(viewManager), - m_sessionManager(KateSessionManager::self()), m_actionCollection(new TDEActionCollection(this)), - m_columnName(-1), m_columnPixmap(-1) + : TQVBox(parent, name), m_sessionManager(KateSessionManager::self()), + m_actionCollection(new TDEActionCollection(this)), m_columnName(-1), m_columnPixmap(-1) { // Toolbar setup_toolbar(); @@ -171,7 +170,7 @@ KateSessionPanel::KateSessionPanel(KateMainWindow *mainWindow, KateViewManager * this, TQT_SLOT(slotLVSessionRenamed(TQListViewItem*))); TQPtrList& sessions = m_sessionManager->getSessionsList(); - for (int idx = sessions.count()-1; idx >= 0; --idx) + for (int idx = sessions.count() - 1; idx >= 0; --idx) { new KateSessionPanelItem(m_listview, sessions[idx]->getSessionName(), idx); if (idx == m_sessionManager->getActiveSessionId()) @@ -444,14 +443,17 @@ void KateSessionPanel::slotActivateSession() void KateSessionPanel::slotSessionToggleReadOnly() { KateSessionPanelItem *sessionItem = dynamic_cast(m_listview->selectedItem()); - if (!sessionItem) + const KateSession *ks(NULL); + if (sessionItem) + { + ks = m_sessionManager->getSessionFromId(sessionItem->getSessionId()); + } + if (!sessionItem || !ks) { return; } - - m_sessionManager->setSessionReadOnlyStatus(sessionItem->getSessionId(), - (dynamic_cast( - m_actionCollection->action("session_toggle_read_only")))->isChecked()); + + m_sessionManager->setSessionReadOnlyStatus(sessionItem->getSessionId(), !ks->isReadOnly()); slotSelectionChanged(); // Update the toolbar button status } @@ -549,13 +551,16 @@ void KateSessionPanel::slotSelectionChanged() readOnlyAction->setEnabled(true); readOnlyAction->setChecked(ks->isReadOnly()); } + int sessId = sessionItem->getSessionId(); + int activeSessId = m_sessionManager->getActiveSessionId(); m_actionCollection->action("session_save_as")->setEnabled(true); - m_actionCollection->action("session_reload")->setEnabled( - sessionItem->getSessionId() == m_sessionManager->getActiveSessionId()); - m_actionCollection->action("session_activate")->setEnabled(true); - m_actionCollection->action("session_move_up")->setEnabled(true); - m_actionCollection->action("session_move_down")->setEnabled(true); + m_actionCollection->action("session_reload")->setEnabled(sessId == activeSessId); + m_actionCollection->action("session_activate")->setEnabled(sessId != activeSessId); + m_actionCollection->action("session_move_up")->setEnabled(sessId > 0); + m_actionCollection->action("session_move_down")->setEnabled(sessId < (m_sessionManager->getSessionCount() - 1)); } + + emit selectionChanged(); } //------------------------------------------- diff --git a/kate/app/katesessionpanel.h b/kate/app/katesessionpanel.h index 4b4f47236..acaec56cd 100644 --- a/kate/app/katesessionpanel.h +++ b/kate/app/katesessionpanel.h @@ -111,13 +111,21 @@ class KateSessionPanel : public TQVBox { Q_OBJECT + friend class KateMainWindow; + public: KateSessionPanel(KateMainWindow *mainWindow=0, KateViewManager *viewManager=0, TQWidget *parent=0, const char *name=0); ~KateSessionPanel() {} - + signals: + /** + * Emitted when the session selection in the panel has changed + */ + void selectionChanged(); + + public slots: void slotNewSession(); void slotSaveSession(); @@ -131,7 +139,7 @@ class KateSessionPanel : public TQVBox void slotSessionMoveDown(); void slotItemExecuted(TQListViewItem *item); - void slotSelectionChanged(); + void slotSelectionChanged(); /** @emit selectionChanged */ void slotSessionActivated(int newSessionId, int oldSessionId); void slotSessionCreated(int sessionId); void slotSessionDeleted(int sessionId); @@ -153,8 +161,6 @@ class KateSessionPanel : public TQVBox */ int handleSessionSwitch(); - KateMainWindow *m_mainWin; - KateViewManager *m_viewManager; KateSessionManager *m_sessionManager; TDEActionCollection *m_actionCollection; TDEToolBar *m_toolbar; diff --git a/kate/data/kateui.rc b/kate/data/kateui.rc index 5368c26c4..260b513b1 100644 --- a/kate/data/kateui.rc +++ b/kate/data/kateui.rc @@ -1,5 +1,5 @@ - +

&File @@ -60,14 +60,19 @@ Sess&ions - - - - - - - - + + + + + + + + + + + + + &Settings -- cgit v1.2.1