diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2016-02-22 20:25:09 +0700 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2016-02-22 20:25:09 +0700 |
commit | 93c96f301cc324ea0a38df701f70dc7bfce4b314 (patch) | |
tree | 4bc5baf3accc43153e4a2726c964902417a71747 /kate | |
parent | 127ac19145207e292e179056ab9a5956f00fac32 (diff) | |
download | tdebase-93c96f301cc324ea0a38df701f70dc7bfce4b314.tar.gz tdebase-93c96f301cc324ea0a38df701f70dc7bfce4b314.zip |
Kate session panel: some code refactoring + completed GUI for "New session" and "Delete session".
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'kate')
-rw-r--r-- | kate/app/kateapp.cpp | 1 | ||||
-rw-r--r-- | kate/app/katesession.cpp | 91 | ||||
-rw-r--r-- | kate/app/katesession.h | 40 | ||||
-rw-r--r-- | kate/app/katesessionpanel.cpp | 152 | ||||
-rw-r--r-- | kate/app/katesessionpanel.h | 70 |
5 files changed, 233 insertions, 121 deletions
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 <tdelocale.h> #include <kdebug.h> #include <kdirwatch.h> -#include <tdelistview.h> #include <kinputdialog.h> #include <kiconloader.h> #include <tdemessagebox.h> @@ -43,7 +42,6 @@ #include <tqlayout.h> #include <tqvbox.h> #include <tqhbox.h> -#include <tqcheckbox.h> #include <tqdatetime.h> #include <tqmap.h> @@ -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; i<m_docCount; ++i) + int docCount = m_config->readNumEntry(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; i<m_docCount; ++i) + int docCount = m_config->readNumEntry(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<int>(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; i<m_docCount; ++i) + m_config->writeEntry(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; i<mwCount; ++i) + for (int i = 0; i < mwCount; ++i) { m_config->setGroup(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; i<m_sessionsCount; ++i) + for (int i = 0; i < sessionsCount; ++i) { TQString urlStr = m_config->readEntry(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<sessionDir.count(); ++i) + for (unsigned int i = 0; i < sessionDir.count(); ++i) { m_sessions.append(new KateSession(TQString::null, m_baseDir+sessionDir[i], true)); } } - m_sessionsCount = static_cast<int>(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; i<m_sessionsCount; ++i) + 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); @@ -387,7 +382,7 @@ int KateSessionManager::getSessionIdFromName(const TQString &name) if (name.isEmpty()) return KateSessionManager::INVALID_SESSION; - for (int i=0; i<m_sessionsCount; ++i) + for (int i = 0; i < (int)m_sessions.count(); ++i) { if (m_sessions[i]->getSessionName() == 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) { @@ -460,17 +452,9 @@ bool KateSessionManager::restoreLastSession() } //------------------------------------------- -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<KateSession>& 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<KateSessionChooserItem*>(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 <tqptrlist.h> #include <tqvaluelist.h> #include <tqstringlist.h> +#include <tdelistview.h> 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<KateSession> 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 <kiconloader.h> #include <tdelocale.h> +#include <tdemessagebox.h> #include <tqlistview.h> +#include <tqlabel.h> + + +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<KateSession>& 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.<p>" "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.<p>" @@ -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<KateSessionPanelItem*>(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<KateSessionPanelItem*>(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<KateSession>& 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<KateSessionPanelItem*>(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 <tdetoolbar.h> #include <tdelistview.h> #include <tqframe.h> +#include <tqlineedit.h> +#include <tqcheckbox.h> +#include <kdialogbase.h> 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 |