diff options
author | Michele Calgaro <[email protected]> | 2016-02-22 20:25:09 +0700 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2016-02-22 20:25:09 +0700 |
commit | 93c96f301cc324ea0a38df701f70dc7bfce4b314 (patch) | |
tree | 4bc5baf3accc43153e4a2726c964902417a71747 /kate/app/katesessionpanel.cpp | |
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 <[email protected]>
Diffstat (limited to 'kate/app/katesessionpanel.cpp')
-rw-r--r-- | kate/app/katesessionpanel.cpp | 152 |
1 files changed, 118 insertions, 34 deletions
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(); } } |