Commit ef0cd0dc authored by Dominik Haumann's avatar Dominik Haumann

Fix crash in tab switcher plugin when using split views

parent ad1fb0cf
......@@ -137,6 +137,10 @@ void TabSwitcherPluginView::setupModel()
void TabSwitcherPluginView::registerDocument(KTextEditor::Document * document)
{
// insert into hash
m_documents.insert(document);
// add to model
auto item = new QStandardItem(iconForDocument(document), document->documentName());
item->setData(QVariant::fromValue(document));
m_model->insertRow(0, item);
......@@ -148,6 +152,13 @@ void TabSwitcherPluginView::registerDocument(KTextEditor::Document * document)
void TabSwitcherPluginView::unregisterDocument(KTextEditor::Document * document)
{
// remove from hash
if (!m_documents.contains(document)) {
return;
}
m_documents.remove(document);
// remove from model
const auto rowCount = m_model->rowCount();
for (int i = 0; i < rowCount; ++i) {
auto doc = m_model->item(i)->data().value<KTextEditor::Document*>();
......@@ -164,6 +175,10 @@ void TabSwitcherPluginView::unregisterDocument(KTextEditor::Document * document)
void TabSwitcherPluginView::updateDocumentName(KTextEditor::Document * document)
{
if (!m_documents.contains(document)) {
return;
}
const auto rowCount = m_model->rowCount();
for (int i = 0; i < rowCount; ++i) {
auto doc = m_model->item(i)->data().value<KTextEditor::Document*>();
......@@ -176,7 +191,7 @@ void TabSwitcherPluginView::updateDocumentName(KTextEditor::Document * document)
void TabSwitcherPluginView::raiseView(KTextEditor::View * view)
{
if (!view) {
if (!view || !m_documents.contains(view->document())) {
return;
}
......
......@@ -25,6 +25,7 @@
#include <KTextEditor/MainWindow>
#include <QList>
#include <QSet>
#include <QVariant>
#include <KXMLGUIClient>
......@@ -136,6 +137,7 @@ private:
TabSwitcherPlugin *m_plugin;
KTextEditor::MainWindow *m_mainWindow;
QStandardItemModel * m_model;
QSet<KTextEditor::Document *> m_documents;
TabSwitcherTreeView * m_treeView;
};
......
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