Commit aade0828 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Allow to delete groups

parent 9167a1f6
Pipeline #44981 passed with stage
in 9 minutes and 37 seconds
......@@ -46,6 +46,7 @@ GroupManagementDialog::GroupManagementDialog(QWidget *parent)
mainLayout->addWidget(mGroupManagementWidget);
mainLayout->addWidget(buttonBox);
readConfig();
connect(mGroupManagementWidget, &GroupManagementWidget::groupsChanged, this, &GroupManagementDialog::groupsChanged);
}
GroupManagementDialog::~GroupManagementDialog()
......
......@@ -31,6 +31,10 @@ class LIBKDEBUGSETTINGS_EXPORT_TEST_EXPORT GroupManagementDialog : public QDialo
public:
explicit GroupManagementDialog(QWidget *parent = nullptr);
~GroupManagementDialog() override;
Q_SIGNALS:
void groupsChanged();
private:
void writeConfig();
void readConfig();
......
......@@ -20,10 +20,14 @@
#include "groupmanagementwidget.h"
#include "loadgroupmenu.h"
#include <KLocalizedString>
#include <KMessageBox>
#include <QDir>
#include <QListWidget>
#include <QVBoxLayout>
GroupManagementWidget::GroupManagementWidget(QWidget *parent)
: QWidget(parent)
, mListWidget(new QListWidget(this))
......@@ -35,6 +39,8 @@ GroupManagementWidget::GroupManagementWidget(QWidget *parent)
mListWidget->setObjectName(QStringLiteral("mListWidget"));
mainLayout->addWidget(mListWidget);
mListWidget->setSelectionMode(QAbstractItemView::MultiSelection);
mListWidget->setContextMenuPolicy(Qt::CustomContextMenu);
connect(mListWidget, &QListWidget::customContextMenuRequested, this, &GroupManagementWidget::slotCustomContextMenu);
init();
}
......@@ -43,6 +49,26 @@ GroupManagementWidget::~GroupManagementWidget()
}
void GroupManagementWidget::slotCustomContextMenu()
{
const auto items = mListWidget->selectedItems();
if (!items.isEmpty()) {
QMenu menu(this);
menu.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), i18n("Remove Groups"), this, [this, items]() {
for (auto item : items) {
const QString fullPath = item->data(FullPathRole).toString();
QFile f(fullPath);
if (!f.remove()) {
KMessageBox::error(this, i18n("Impossible to remove \'%1\'", fullPath), i18n("Remove Group"));
}
delete item;
}
});
menu.exec(QCursor::pos());
Q_EMIT groupsChanged();
}
}
void GroupManagementWidget::init()
{
const QString groupPath = LoadGroupMenu::defaultGroupPath();
......
......@@ -31,6 +31,13 @@ class LIBKDEBUGSETTINGS_EXPORT_TEST_EXPORT GroupManagementWidget : public QWidge
public:
explicit GroupManagementWidget(QWidget *parent = nullptr);
~GroupManagementWidget() override;
private Q_SLOTS:
void slotCustomContextMenu();
Q_SIGNALS:
void groupsChanged();
private:
enum {
FullPathRole = Qt::UserRole + 1
......
......@@ -248,6 +248,7 @@ void KDebugSettingsDialog::slotRestoreDefault()
void KDebugSettingsDialog::slotManageGroup()
{
auto groupManagementDialog = new GroupManagementDialog(this);
connect(groupManagementDialog, &GroupManagementDialog::groupsChanged, this, &KDebugSettingsDialog::updateLoadGroupMenu);
groupManagementDialog->exec();
delete groupManagementDialog;
}
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