summaryrefslogtreecommitdiffstats
path: root/kate
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2016-03-10 18:35:21 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2016-03-10 18:35:21 +0900
commite528df3eb1ee48c55535fc09e7d016a83b38b02e (patch)
treee5f5bc61231714080fc49abc0cb5409ebba41f9b /kate
parent93c96f301cc324ea0a38df701f70dc7bfce4b314 (diff)
downloadtdebase-e528df3eb1ee48c55535fc09e7d016a83b38b02e.tar.gz
tdebase-e528df3eb1ee48c55535fc09e7d016a83b38b02e.zip
Kate session panel: added move up/down and rename functionality.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'kate')
-rw-r--r--kate/app/katesession.cpp79
-rw-r--r--kate/app/katesession.h40
-rw-r--r--kate/app/katesessionpanel.cpp121
-rw-r--r--kate/app/katesessionpanel.h3
4 files changed, 225 insertions, 18 deletions
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<KateSession>& 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.<p>"
"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<KateSessionPanelItem*>(m_listview->selectedItem());
+ if (!sessionItem)
+ return;
+
+ m_sessionManager->moveSessionBackward(sessionItem->getSessionId());
}
//-------------------------------------------
void KateSessionPanel::slotSessionMoveDown()
{
-//TODO
+ KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(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<KateSessionPanelItem*>(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<KateSessionPanelItem*>(itemMax))->setSessionId(sessionIdMin);
+ (dynamic_cast<KateSessionPanelItem*>(itemMin))->setSessionId(sessionIdMax);
+
+ m_listview->setSelected(selectedItem, true);
+}
+
+//-------------------------------------------
+void KateSessionPanel::slotSessionRenamed(TQListViewItem *item)
+{
+ KateSessionPanelItem *sessionItem = dynamic_cast<KateSessionPanelItem*>(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