Commit 4c0ad7dc authored by Christoph Cullmann's avatar Christoph Cullmann 🐮

improve doc state changes

parent df7f3a3d
......@@ -22,6 +22,7 @@
#include "kateapp.h"
#include "katetabbar.h"
#include <QIcon>
#include <QMimeData>
#include <QPainter>
#include <QResizeEvent>
......@@ -34,7 +35,6 @@
#include <KTextEditor/Document>
struct KateTabButtonData {
QUrl url;
KTextEditor::Document *doc = nullptr;
};
......@@ -134,20 +134,6 @@ QVariant KateTabBar::ensureValidTabData(int idx)
return tabData(idx);
}
void KateTabBar::setTabUrl(int idx, const QUrl &url)
{
QVariant data = ensureValidTabData(idx);
KateTabButtonData buttonData = data.value<KateTabButtonData>();
buttonData.url = url;
setTabData(idx, QVariant::fromValue(buttonData));
}
QUrl KateTabBar::tabUrl(int idx)
{
QVariant data = ensureValidTabData(idx);
return data.value<KateTabButtonData>().url;
}
void KateTabBar::mouseDoubleClickEvent(QMouseEvent *event)
{
event->accept();
......@@ -201,11 +187,18 @@ void KateTabBar::setCurrentDocument(KTextEditor::Document *doc)
return;
}
// get right icon to use
QIcon icon;
if (doc->isModified()) {
icon = QIcon::fromTheme(QStringLiteral("document-save"));
}
// else: if we are still inside the allowed number of tabs or have no limit
// => create new tab and be done
if ((m_tabCountLimit == 0) || count() < m_tabCountLimit) {
m_beingAdded = doc;
insertTab(-1, doc->documentName());
int inserted = insertTab(-1, doc->documentName());
setTabIcon(inserted, icon);
return;
}
......@@ -231,6 +224,7 @@ void KateTabBar::setCurrentDocument(KTextEditor::Document *doc)
setTabText(indexToReplace, doc->documentName());
setTabDocument(indexToReplace, doc);
setTabToolTip(indexToReplace, doc->url().toDisplayString());
setTabIcon(indexToReplace, icon);
setCurrentIndex(indexToReplace);
}
......
......@@ -71,21 +71,6 @@ public:
*/
bool containsTab(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);
QVariant ensureValidTabData(int idx);
void setCurrentDocument(KTextEditor::Document *doc);
......
......@@ -326,8 +326,9 @@ void KateViewSpace::registerDocument(KTextEditor::Document *doc)
*/
m_tabBar->setCurrentDocument(doc);
updateDocumentState(doc);
/**
* handle later document state changes
*/
connect(doc, &KTextEditor::Document::documentNameChanged, this, &KateViewSpace::updateDocumentName);
connect(doc, &KTextEditor::Document::documentUrlChanged, this, &KateViewSpace::updateDocumentUrl);
connect(doc, &KTextEditor::Document::modifiedChanged, this, &KateViewSpace::updateDocumentState);
......@@ -368,7 +369,6 @@ void KateViewSpace::updateDocumentName(KTextEditor::Document *doc)
const int buttonId = m_tabBar->documentIdx(doc);
if (buttonId >= 0) {
m_tabBar->setTabText(buttonId, doc->documentName());
m_tabBar->setTabToolTip(buttonId, doc->url().toDisplayString());
}
}
......@@ -377,7 +377,7 @@ void KateViewSpace::updateDocumentUrl(KTextEditor::Document *doc)
// update tab button if available, might not be the case for tab limit set!
const int buttonId = m_tabBar->documentIdx(doc);
if (buttonId >= 0) {
m_tabBar->setTabUrl(buttonId, doc->url());
m_tabBar->setTabToolTip(buttonId, doc->url().toDisplayString());
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment