Commit 164a6c53 authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

cleanup KTextEditor signals

remove the emission of

aboutToCreateDocuments
documentsCreated
aboutToDeleteDocuments
documentsDeleted

use was just the filetree plugin

there the code is even easier with a singleShot timer for the update

the batched remove signals were not used correctly at all

at delete, we "connected" signals again
parent 4e8d8328
......@@ -545,26 +545,12 @@ void FileTreeModelTest::deleteDocumentBatch()
m.documentOpened(doc);
}
QList<KTextEditor::Document *> removing;
for (const int &index : remove) {
removing << documents[index];
}
m.slotAboutToDeleteDocuments(removing);
for (const int &index : remove) {
if (!fail.contains(index)) {
m.documentClosed(documents[index]);
}
}
removing.clear();
for (const int &index : fail) {
removing << documents[index];
}
m.slotDocumentsDeleted(removing);
ResultNode root;
walkTree(m, QModelIndex(), root);
......
......@@ -819,28 +819,6 @@ void KateFileTreeModel::documentEdited(const KTextEditor::Document *doc)
updateBackgrounds();
}
void KateFileTreeModel::slotAboutToDeleteDocuments(const QList<KTextEditor::Document *> &docs)
{
for (const KTextEditor::Document *doc : docs) {
disconnect(doc, &KTextEditor::Document::documentNameChanged, this, &KateFileTreeModel::documentNameChanged);
disconnect(doc, &KTextEditor::Document::documentUrlChanged, this, &KateFileTreeModel::documentNameChanged);
disconnect(doc, &KTextEditor::Document::modifiedChanged, this, &KateFileTreeModel::documentModifiedChanged);
// clang-format off
disconnect(doc,
SIGNAL(modifiedOnDisk(KTextEditor::Document*,bool,KTextEditor::ModificationInterface::ModifiedOnDiskReason)),
this,
SLOT(documentModifiedOnDisc(KTextEditor::Document*,bool,KTextEditor::ModificationInterface::ModifiedOnDiskReason)));
// clang-format on
}
}
void KateFileTreeModel::slotDocumentsDeleted(const QList<KTextEditor::Document *> &docs)
{
for (const KTextEditor::Document *doc : docs) {
connectDocument(doc);
}
}
class EditViewCount
{
public:
......@@ -941,6 +919,16 @@ void KateFileTreeModel::handleEmptyParents(ProxyItemDir *item)
void KateFileTreeModel::documentClosed(KTextEditor::Document *doc)
{
disconnect(doc, &KTextEditor::Document::documentNameChanged, this, &KateFileTreeModel::documentNameChanged);
disconnect(doc, &KTextEditor::Document::documentUrlChanged, this, &KateFileTreeModel::documentNameChanged);
disconnect(doc, &KTextEditor::Document::modifiedChanged, this, &KateFileTreeModel::documentModifiedChanged);
// clang-format off
disconnect(doc,
SIGNAL(modifiedOnDisk(KTextEditor::Document*,bool,KTextEditor::ModificationInterface::ModifiedOnDiskReason)),
this,
SLOT(documentModifiedOnDisc(KTextEditor::Document*,bool,KTextEditor::ModificationInterface::ModifiedOnDiskReason)));
// clang-format on
if (!m_docmap.contains(doc)) {
return;
}
......
......@@ -77,8 +77,6 @@ public Q_SLOTS:
void documentNameChanged(KTextEditor::Document *);
void documentModifiedChanged(KTextEditor::Document *);
void documentModifiedOnDisc(KTextEditor::Document *, bool, KTextEditor::ModificationInterface::ModifiedOnDiskReason);
void slotAboutToDeleteDocuments(const QList<KTextEditor::Document *> &);
void slotDocumentsDeleted(const QList<KTextEditor::Document *> &);
Q_SIGNALS:
void triggerViewChangeAfterNameChange();
......
......@@ -113,7 +113,6 @@ void KateFileTreePlugin::applyConfig(bool shadingEnabled, const QColor &viewShad
// BEGIN KateFileTreePluginView
KateFileTreePluginView::KateFileTreePluginView(KTextEditor::MainWindow *mainWindow, KateFileTreePlugin *plug)
: QObject(mainWindow)
, m_loadingDocuments(false)
, m_plug(plug)
, m_mainWindow(mainWindow)
{
......@@ -172,21 +171,11 @@ KateFileTreePluginView::KateFileTreePluginView(KTextEditor::MainWindow *mainWind
&KateFileTreeModel::documentClosed);
connect(KTextEditor::Editor::instance()->application(), &KTextEditor::Application::documentCreated, this, &KateFileTreePluginView::documentOpened);
connect(KTextEditor::Editor::instance()->application(), &KTextEditor::Application::documentWillBeDeleted, this, &KateFileTreePluginView::documentClosed);
connect(KTextEditor::Editor::instance()->application(),
&KTextEditor::Application::aboutToCreateDocuments,
this,
&KateFileTreePluginView::slotAboutToCreateDocuments);
connect(KTextEditor::Editor::instance()->application(), &KTextEditor::Application::documentsCreated, this, &KateFileTreePluginView::slotDocumentsCreated);
connect(KTextEditor::Editor::instance()->application(),
&KTextEditor::Application::aboutToDeleteDocuments,
m_documentModel,
&KateFileTreeModel::slotAboutToDeleteDocuments);
connect(KTextEditor::Editor::instance()->application(),
&KTextEditor::Application::documentsDeleted,
m_documentModel,
&KateFileTreeModel::slotDocumentsDeleted);
// delayed update for new documents to be more efficient if multiple ones are created at once
m_documentsCreatedTimer.setSingleShot(true);
m_documentsCreatedTimer.setInterval(0);
connect(&m_documentsCreatedTimer, &QTimer::timeout, this, &KateFileTreePluginView::slotDocumentsCreated);
connect(m_documentModel, &KateFileTreeModel::triggerViewChangeAfterNameChange, [=] {
KateFileTreePluginView::viewChanged();
......@@ -302,17 +291,14 @@ KateFileTree *KateFileTreePluginView::tree() const
void KateFileTreePluginView::documentOpened(KTextEditor::Document *doc)
{
if (m_loadingDocuments) {
return;
}
m_documentModel->documentOpened(doc);
m_proxyModel->invalidate();
// enqueue and start update timer to collapse updates
m_documentsCreatedTimer.start();
m_documentsCreated.append(doc);
}
void KateFileTreePluginView::documentClosed(KTextEditor::Document *doc)
{
Q_UNUSED(doc);
m_documentsCreated.removeAll(doc);
m_proxyModel->invalidate();
}
......@@ -433,15 +419,11 @@ void KateFileTreePluginView::writeSessionConfig(KConfigGroup &g)
g.sync();
}
void KateFileTreePluginView::slotAboutToCreateDocuments()
{
m_loadingDocuments = true;
}
void KateFileTreePluginView::slotDocumentsCreated(const QList<KTextEditor::Document *> &docs)
void KateFileTreePluginView::slotDocumentsCreated()
{
m_documentModel->documentsOpened(docs);
m_loadingDocuments = false;
// handle potential multiple new documents
m_documentModel->documentsOpened(m_documentsCreated);
m_documentsCreated.clear();
viewChanged();
}
......
......@@ -8,6 +8,7 @@
#define KATE_FILETREE_PLUGIN_H
#include <QIcon>
#include <QTimer>
#include <KTextEditor/Command>
#include <KTextEditor/Plugin>
......@@ -108,9 +109,10 @@ private:
QLineEdit *m_filter;
KateFileTreeModel *m_documentModel;
bool m_hasLocalPrefs = false;
bool m_loadingDocuments;
KateFileTreePlugin *m_plug;
KTextEditor::MainWindow *m_mainWindow;
QTimer m_documentsCreatedTimer;
QList<KTextEditor::Document *> m_documentsCreated;
private Q_SLOTS:
void showToolView();
......@@ -122,8 +124,7 @@ private Q_SLOTS:
void documentClosed(KTextEditor::Document *);
void viewModeChanged(bool);
void sortRoleChanged(int);
void slotAboutToCreateDocuments();
void slotDocumentsCreated(const QList<KTextEditor::Document *> &);
void slotDocumentsCreated();
void slotDocumentSave() const;
void slotDocumentSaveAs() const;
};
......
......@@ -61,8 +61,6 @@ KateApp::KateApp(const QCommandLineParser &args)
connect(&m_docManager, &KateDocManager::documentCreated, &m_wrapper, &KTextEditor::Application::documentCreated);
connect(&m_docManager, &KateDocManager::documentWillBeDeleted, &m_wrapper, &KTextEditor::Application::documentWillBeDeleted);
connect(&m_docManager, &KateDocManager::documentDeleted, &m_wrapper, &KTextEditor::Application::documentDeleted);
connect(&m_docManager, &KateDocManager::aboutToCreateDocuments, &m_wrapper, &KTextEditor::Application::aboutToCreateDocuments);
connect(&m_docManager, &KateDocManager::documentsCreated, &m_wrapper, &KTextEditor::Application::documentsCreated);
/**
* handle mac os x like file open request via event filter
......
......@@ -133,15 +133,9 @@ KTextEditor::Document *KateDocManager::findDocument(const QUrl &url) const
QList<KTextEditor::Document *> KateDocManager::openUrls(const QList<QUrl> &urls, const QString &encoding, bool isTempFile, const KateDocumentInfo &docInfo)
{
QList<KTextEditor::Document *> docs;
emit aboutToCreateDocuments();
for (const QUrl &url : urls) {
docs << openUrl(url, encoding, isTempFile, docInfo);
}
emit documentsCreated(docs);
return docs;
}
......
......@@ -147,20 +147,6 @@ Q_SIGNALS:
*/
void documentDeleted(KTextEditor::Document *document);
/**
* This signal is emitted before the batch of documents is being created.
*
* You can use it to pause some updates.
*/
void aboutToCreateDocuments();
/**
* This signal is emitted after the batch of documents is created.
*
* @param documents list of documents that have been created
*/
void documentsCreated(const QList<KTextEditor::Document *> &documents);
/**
* This signal is emitted before the documents batch is going to be deleted
*
......
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