Commit 130fc518 authored by Eugene Popov's avatar Eugene Popov 🇺🇦 Committed by Christoph Cullmann
Browse files

[WelcomeView] Properly handle changes to the recent items

Since the KRecentFilesAction doesn't notify about adding or deleting items, we should use some dirty trick to find out the KRecentFilesAction has changed.
parent 7e74b0cd
Pipeline #252699 canceled with stage
in 15 seconds
......@@ -17,6 +17,7 @@
#include <KIconLoader>
#include <KRecentFilesAction>
#include <KSharedConfig>
#include <QTimer>
#include <KIO/OpenFileManagerWindowJob>
#include <QClipboard>
......@@ -70,9 +71,7 @@ WelcomeView::WelcomeView(KateViewManager *viewManager, QWidget *parent)
KRecentFilesAction *recentFilesAction = m_viewManager->mainWindow()->recentFilesAction();
m_recentItemsModel->refresh(recentFilesAction->urls());
connect(recentFilesAction, &KRecentFilesAction::recentListCleared, this, [this, recentFilesAction]() {
m_recentItemsModel->refresh(recentFilesAction->urls());
});
recentFilesAction->menu()->installEventFilter(this);
listViewRecentItems->setModel(m_recentItemsModel);
connect(listViewRecentItems, &QListView::customContextMenuRequested,
......@@ -187,6 +186,28 @@ void WelcomeView::resizeEvent(QResizeEvent *event)
updateLayout();
}
bool WelcomeView::eventFilter(QObject *watched, QEvent *event)
{
KRecentFilesAction *recentFilesAction = m_viewManager->mainWindow()->recentFilesAction();
if (watched == recentFilesAction->menu()) {
switch (event->type()) {
case QEvent::ActionAdded:
case QEvent::ActionRemoved:
// since the KRecentFilesAction doesn't notify about adding or
// deleting items, we should use this dirty trick to find out
// the KRecentFilesAction has changed
QTimer::singleShot(0, this, [this, recentFilesAction]() {
m_recentItemsModel->refresh(recentFilesAction->urls());
});
break;
default:
break;
}
}
return QScrollArea::eventFilter(watched, event);
}
void WelcomeView::onPluginViewChanged(const QString &pluginName)
{
static const QString projectPluginName = QStringLiteral("kateprojectplugin");
......
......@@ -26,6 +26,8 @@ protected:
bool event(QEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
bool eventFilter(QObject *watched, QEvent *event) override;
private Q_SLOTS:
void onPluginViewChanged(const QString &pluginName = QString());
void onRecentItemsContextMenuRequested(const QPoint &pos);
......
Supports Markdown
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