diff --git a/kate/katetabbar.h b/kate/katetabbar.h --- a/kate/katetabbar.h +++ b/kate/katetabbar.h @@ -116,6 +116,21 @@ QString tabText(int index) const; /** + * Sets the URL of the tab with ID \a id to \a url. + * \see tabUrl() + * \since 17.08 + */ + void setTabUrl(int index, const QUrl &url); + + /** + * Returns the text of the tab with ID \a id. If the button id does not + * exist \a QString() is returned. + * \see setTabUrl() + * \since 17.08 + */ + QUrl tabUrl(int index) const; + + /** * Sets the icon of the tab with ID \a id to \a icon. * \see tabIcon() */ diff --git a/kate/katetabbar.cpp b/kate/katetabbar.cpp --- a/kate/katetabbar.cpp +++ b/kate/katetabbar.cpp @@ -345,6 +345,25 @@ return QString(); } +void KateTabBar::setTabUrl(int id, const QUrl &url) +{ + Q_ASSERT(d->idToTab.contains(id)); + KateTabButton * tabButton = d->idToTab.value(id, nullptr); + if (tabButton) { + tabButton->setUrl(url); + } +} + +QUrl KateTabBar::tabUrl(int id) const +{ + Q_ASSERT(d->idToTab.contains(id)); + KateTabButton * tabButton = d->idToTab.value(id, nullptr); + if (tabButton) { + return tabButton->url(); + } + return QUrl(); +} + void KateTabBar::setTabIcon(int id, const QIcon &icon) { Q_ASSERT(d->idToTab.contains(id)); diff --git a/kate/katetabbutton.h b/kate/katetabbutton.h --- a/kate/katetabbutton.h +++ b/kate/katetabbutton.h @@ -22,6 +22,7 @@ #define KATE_TAB_BUTTON #include +#include class QPropertyAnimation; @@ -71,6 +72,18 @@ */ bool geometryAnimationRunning() const; + /** + * The URL of the document this tab represents. + * \since 17.08 + */ + QUrl url() const; + + /** + * Sets the URL of the document this tab represents. + * \since 17.08 + */ + void setUrl(const QUrl &url); + public Q_SLOTS: /** * Animate the button's geometry from @p startGeom to @p endGeom @@ -115,6 +128,7 @@ TabCloseButton * m_closeButton; QPropertyAnimation * m_geometryAnimation; QPoint m_mouseDownPosition; + QUrl m_url; }; #endif diff --git a/kate/katetabbutton.cpp b/kate/katetabbutton.cpp --- a/kate/katetabbutton.cpp +++ b/kate/katetabbutton.cpp @@ -202,6 +202,7 @@ { QMimeData *mimeData = new QMimeData; mimeData->setData(QStringLiteral("application/x-dndkatetabbutton"), QByteArray()); + mimeData->setUrls({m_url}); auto drag = new QDrag(this); drag->setMimeData(mimeData); @@ -290,3 +291,13 @@ return m_geometryAnimation && (m_geometryAnimation->state() != QAbstractAnimation::Stopped); } + +QUrl KateTabButton::url() const +{ + return m_url; +} + +void KateTabButton::setUrl(const QUrl &url) +{ + m_url = url; +} diff --git a/kate/kateviewspace.h b/kate/kateviewspace.h --- a/kate/kateviewspace.h +++ b/kate/kateviewspace.h @@ -107,6 +107,7 @@ public Q_SLOTS: void documentDestroyed(QObject *doc); void updateDocumentName(KTextEditor::Document *doc); + void updateDocumentUrl(KTextEditor::Document *doc); void updateDocumentState(KTextEditor::Document *doc); private Q_SLOTS: diff --git a/kate/kateviewspace.cpp b/kate/kateviewspace.cpp --- a/kate/kateviewspace.cpp +++ b/kate/kateviewspace.cpp @@ -359,6 +359,8 @@ connect(doc, SIGNAL(documentNameChanged(KTextEditor::Document*)), this, SLOT(updateDocumentName(KTextEditor::Document*))); + connect(doc, &KTextEditor::Document::documentUrlChanged, + this, &KateViewSpace::updateDocumentUrl); connect(doc, SIGNAL(modifiedChanged(KTextEditor::Document*)), this, SLOT(updateDocumentState(KTextEditor::Document*))); } @@ -380,6 +382,8 @@ if (!documentDestroyed) { disconnect(doc, SIGNAL(documentNameChanged(KTextEditor::Document*)), this, SLOT(updateDocumentName(KTextEditor::Document*))); + disconnect(doc, &KTextEditor::Document::documentUrlChanged, + this, &KateViewSpace::updateDocumentUrl); disconnect(doc, SIGNAL(modifiedChanged(KTextEditor::Document*)), this, SLOT(updateDocumentState(KTextEditor::Document*))); } @@ -498,6 +502,13 @@ m_tabBar->setTabToolTip(buttonId, doc->url().toDisplayString()); } +void KateViewSpace::updateDocumentUrl(KTextEditor::Document *doc) +{ + const int buttonId = m_docToTabId[doc]; + Q_ASSERT(buttonId >= 0); + m_tabBar->setTabUrl(buttonId, doc->url()); +} + void KateViewSpace::updateDocumentState(KTextEditor::Document *doc) { QIcon icon;