1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-10 21:18:19 +03:00

actionsdialog:fix actions sorting for operations

This commit is contained in:
Michail Vourlakos 2021-06-10 23:41:46 +03:00
parent 9be247af22
commit 078b16447f
4 changed files with 35 additions and 32 deletions

View File

@ -11,6 +11,9 @@
#include "../settingsdialog/tabpreferenceshandler.h"
#include "../../data/contextmenudata.h"
// Qt
#include <QDebug>
// KDE
#include <KLocalizedString>
@ -23,8 +26,10 @@ ActionsHandler::ActionsHandler(Dialog::ActionsDialog *dialog)
m_dialog(dialog),
m_ui(m_dialog->ui())
{
init();
initItems();
loadItems(m_dialog->preferencesHandler()->contextMenuAlwaysActions());
init();
}
ActionsHandler::~ActionsHandler()
@ -32,6 +37,14 @@ ActionsHandler::~ActionsHandler()
}
void ActionsHandler::init()
{
connect(m_ui->buttonBox->button(QDialogButtonBox::Cancel), &QPushButton::clicked, this, &ActionsHandler::onCancel);
connect(m_ui->buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &ActionsHandler::save);
connect(m_ui->buttonBox->button(QDialogButtonBox::Reset), &QPushButton::clicked, this, &ActionsHandler::reset);
connect(m_ui->buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, this, &ActionsHandler::resetDefaults);
}
void ActionsHandler::initItems()
{
o_alwaysActions = m_dialog->preferencesHandler()->contextMenuAlwaysActions();
@ -105,8 +118,8 @@ void ActionsHandler::loadItems(const QStringList &alwaysActions)
QString actionname = Latte::Data::ContextMenu::ACTIONSEDITORDER[i];
bool inalways = alwaysActions.contains(actionname);
int rowinalways = rowInAlways(m_items[actionname]);
int rowinedit = rowInEdit(m_items[actionname]);
int rowinalways = m_ui->actionsSelector->selectedListWidget()->row(m_items[actionname]);
int rowinedit = m_ui->actionsSelector->availableListWidget()->row(m_items[actionname]);
if (inalways && rowinalways == -1) {
if (rowinedit >= 0) {
@ -121,6 +134,11 @@ void ActionsHandler::loadItems(const QStringList &alwaysActions)
}
}
m_ui->actionsSelector->setAvailableInsertionPolicy(KActionSelector::Sorted);
m_ui->actionsSelector->setSelectedInsertionPolicy(KActionSelector::Sorted);
m_ui->actionsSelector->availableListWidget()->sortItems();
m_ui->actionsSelector->selectedListWidget()->sortItems();
}
bool ActionsHandler::hasChangedData() const
@ -133,28 +151,6 @@ bool ActionsHandler::inDefaultValues() const
return currentAlwaysData() == Data::ContextMenu::ACTIONSALWAYSVISIBLE;
}
int ActionsHandler::rowInAlways(const Settings::ActionsDialog::ActionListWidgetItem *item) const
{
for(int i=0; i<m_ui->actionsSelector->selectedListWidget()->count(); ++i) {
if (m_ui->actionsSelector->selectedListWidget()->item(i) == item) {
return i;
}
}
return -1;
}
int ActionsHandler::rowInEdit(const Settings::ActionsDialog::ActionListWidgetItem *item) const
{
for(int i=0; i<m_ui->actionsSelector->availableListWidget()->count(); ++i) {
if (m_ui->actionsSelector->availableListWidget()->item(i) == item) {
return i;
}
}
return -1;
}
Data::GenericTable<Data::Generic> ActionsHandler::table(const QStringList &ids)
{
Data::GenericTable<Data::Generic> bastable;
@ -189,9 +185,17 @@ void ActionsHandler::resetDefaults()
loadItems(Data::ContextMenu::ACTIONSALWAYSVISIBLE);
}
void ActionsHandler::onCancel()
{
qDebug() << Q_FUNC_INFO;
m_dialog->close();
}
void ActionsHandler::save()
{
//do nothing
qDebug() << Q_FUNC_INFO;
m_dialog->preferencesHandler()->setContextMenuAlwaysActions(currentAlwaysData());
m_dialog->close();
}
}

View File

@ -53,15 +53,14 @@ public slots:
void resetDefaults() override;
void save() override;
void onCancel();
private:
void init();
void initDefaults();
void initItems();
void loadItems(const QStringList &alwaysActions);
int rowInAlways(const Settings::ActionsDialog::ActionListWidgetItem *item) const;
int rowInEdit(const Settings::ActionsDialog::ActionListWidgetItem *item) const;
Data::GenericTable<Data::Generic> table(const QStringList &ids);
private:

View File

@ -117,7 +117,7 @@ QStringList TabPreferences::contextMenuAlwaysActions() const
return m_preferences.contextMenuAlwaysActions;
}
void TabPreferences::setContexteMenuAlwaysActions(const QStringList &actions)
void TabPreferences::setContextMenuAlwaysActions(const QStringList &actions)
{
if (m_preferences.contextMenuAlwaysActions == actions) {
return;

View File

@ -47,7 +47,7 @@ public:
bool inDefaultValues() const override;
QStringList contextMenuAlwaysActions() const;
void setContexteMenuAlwaysActions(const QStringList &actions);
void setContextMenuAlwaysActions(const QStringList &actions);
void reset() override;
void resetDefaults() override;