Commit 97a28438 authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

Port away from KNS3::QuickDialog::exec

Instead, we can use the KNSWidgets::Action class, which takes
care of showing the dialog when triggered without using exec.
parent 11aebe48
......@@ -12,7 +12,7 @@ target_link_libraries(
katesnippetsplugin
PRIVATE
KF5::I18n
KF5::NewStuff
KF5::NewStuffWidgets
KF5::TextEditor
)
......
......@@ -26,9 +26,6 @@
#include <QSortFilterProxyModel>
#include <QTimer>
#include <KNS3/QtQuickDialogWrapper>
#include <kns3/uploaddialog.h>
class SnippetFilterModel : public QSortFilterProxyModel
{
public:
......@@ -121,9 +118,26 @@ SnippetView::SnippetView(KateSnippetGlobal *plugin, KTextEditor::MainWindow *mai
addAction(separator);
m_getNewStuffAction = new QAction(QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")), i18n("Get New Snippets"), this);
m_getNewStuffAction = new KNSWidgets::Action(i18n("Get New Snippets"), QStringLiteral(":/katesnippets/ktexteditor_codesnippets_core.knsrc"), this);
m_getNewStuffAction->setVisible(newStuffAllowed);
connect(m_getNewStuffAction, &QAction::triggered, this, &SnippetView::slotGHNS);
connect(m_getNewStuffAction, &KNSWidgets::Action::dialogFinished, this, [this](const QList<KNSCore::Entry> &changedEntries) {
for (const auto &entry : changedEntries) {
const auto uninstalledFiles = entry.uninstalledFiles();
for (const QString &path : uninstalledFiles) {
if (path.endsWith(QLatin1String(".xml"))) {
if (SnippetRepository *repo = SnippetStore::self()->repositoryForFile(path)) {
repo->remove();
}
}
}
const auto installedFiles = entry.installedFiles();
for (const QString &path : installedFiles) {
if (path.endsWith(QLatin1String(".xml"))) {
SnippetStore::self()->appendRow(new SnippetRepository(path));
}
}
}
});
addAction(m_getNewStuffAction);
connect(snippetTree->selectionModel(), &QItemSelectionModel::selectionChanged, this, &SnippetView::validateActions);
......@@ -313,31 +327,6 @@ void SnippetView::slotRemoveRepo()
}
}
void SnippetView::slotGHNS()
{
KNS3::QtQuickDialogWrapper dialog(QStringLiteral(":/katesnippets/ktexteditor_codesnippets_core.knsrc"));
const QList<KNSCore::EntryInternal> changedEntries = dialog.exec();
if (changedEntries.isEmpty()) {
return;
}
for (const auto &entry : changedEntries) {
const auto uninstalledFiles = entry.uninstalledFiles();
for (const QString &path : uninstalledFiles) {
if (path.endsWith(QLatin1String(".xml"))) {
if (SnippetRepository *repo = SnippetStore::self()->repositoryForFile(path)) {
repo->remove();
}
}
}
const auto installedFiles = entry.installedFiles();
for (const QString &path : installedFiles) {
if (path.endsWith(QLatin1String(".xml"))) {
SnippetStore::self()->appendRow(new SnippetRepository(path));
}
}
}
}
bool SnippetView::eventFilter(QObject *obj, QEvent *e)
{
// no, listening to activated() is not enough since that would also trigger the edit mode which we _dont_ want here
......
......@@ -12,6 +12,7 @@
#ifndef SNIPPETVIEW_H
#define SNIPPETVIEW_H
#include <KNSWidgets/Action>
#include <KTextEditor/MainWindow>
#include "ui_snippetview.h"
......@@ -76,11 +77,6 @@ private Q_SLOTS:
*/
void slotAddSnippet();
/**
* Slot to get hot new stuff.
*/
void slotGHNS();
void contextMenu(const QPoint &pos);
/// disables or enables available actions based on the currently selected item
void validateActions();
......@@ -100,7 +96,7 @@ private:
QAction *m_addSnippetAction;
QAction *m_removeSnippetAction;
QAction *m_editSnippetAction;
QAction *m_getNewStuffAction;
KNSWidgets::Action *m_getNewStuffAction;
};
#endif
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