mirror of
https://github.com/KDE/latte-dock.git
synced 2025-02-11 01:58:44 +03:00
actionsdialog:load items properly for actions
This commit is contained in:
parent
754d3c4f82
commit
3be173830e
@ -8,7 +8,7 @@
|
||||
|
||||
namespace Latte {
|
||||
namespace Settings {
|
||||
namespace Preferences {
|
||||
namespace ActionsDialog {
|
||||
|
||||
ActionListWidgetItem::ActionListWidgetItem(const QIcon &icon, const QString &text, const int &order, const QString &id, QListWidget *parent, int type)
|
||||
: QListWidgetItem(icon, text, parent, type)
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace Latte {
|
||||
namespace Settings {
|
||||
namespace Preferences {
|
||||
namespace ActionsDialog {
|
||||
|
||||
class ActionListWidgetItem : public QListWidgetItem
|
||||
{
|
||||
|
@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>681</width>
|
||||
<width>835</width>
|
||||
<height>518</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -8,6 +8,7 @@
|
||||
// local
|
||||
#include "ui_actionsdialog.h"
|
||||
#include "actionsdialog.h"
|
||||
#include "../settingsdialog/tabpreferenceshandler.h"
|
||||
#include "../../data/contextmenudata.h"
|
||||
|
||||
// KDE
|
||||
@ -23,7 +24,7 @@ ActionsHandler::ActionsHandler(Dialog::ActionsDialog *dialog)
|
||||
m_ui(m_dialog->ui())
|
||||
{
|
||||
init();
|
||||
//c_alwaysActions = table(currentActions);
|
||||
loadItems(m_dialog->preferencesHandler()->contextMenuAlwaysActions());
|
||||
}
|
||||
|
||||
ActionsHandler::~ActionsHandler()
|
||||
@ -33,6 +34,93 @@ ActionsHandler::~ActionsHandler()
|
||||
void ActionsHandler::init()
|
||||
{
|
||||
def_alwaysActions = table(Data::ContextMenu::ACTIONSALWAYSVISIBLE);
|
||||
|
||||
QString itemid = Latte::Data::ContextMenu::LAYOUTSACTION;
|
||||
int itemindex = Latte::Data::ContextMenu::ACTIONSEDITORDER.indexOf(itemid);
|
||||
m_items[itemid] = new ActionsDialog::ActionListWidgetItem(QIcon::fromTheme("user-identity"),
|
||||
i18n("Layouts"),
|
||||
itemindex,
|
||||
itemid);
|
||||
|
||||
itemid = Latte::Data::ContextMenu::PREFERENCESACTION;
|
||||
itemindex = Latte::Data::ContextMenu::ACTIONSEDITORDER.indexOf(itemid);
|
||||
m_items[itemid] = new ActionsDialog::ActionListWidgetItem(QIcon::fromTheme("configure"),
|
||||
i18nc("global settings window", "Configure Latte..."),
|
||||
itemindex,
|
||||
itemid);
|
||||
|
||||
itemid = Latte::Data::ContextMenu::QUITLATTEACTION;
|
||||
itemindex = Latte::Data::ContextMenu::ACTIONSEDITORDER.indexOf(itemid);
|
||||
m_items[itemid] = new ActionsDialog::ActionListWidgetItem(QIcon::fromTheme("application-exit"),
|
||||
i18nc("quit application", "Quit Latte"),
|
||||
itemindex,
|
||||
itemid);
|
||||
|
||||
itemid = Latte::Data::ContextMenu::SEPARATOR1ACTION;
|
||||
itemindex = Latte::Data::ContextMenu::ACTIONSEDITORDER.indexOf(itemid);
|
||||
m_items[itemid] = new ActionsDialog::ActionListWidgetItem(QIcon::fromTheme(""),
|
||||
i18n(" --- separator --- "),
|
||||
itemindex,
|
||||
itemid);
|
||||
|
||||
itemid = Latte::Data::ContextMenu::ADDWIDGETSACTION;
|
||||
itemindex = Latte::Data::ContextMenu::ACTIONSEDITORDER.indexOf(itemid);
|
||||
m_items[itemid] = new ActionsDialog::ActionListWidgetItem(QIcon::fromTheme("list-add"),
|
||||
i18n("Add Widgets..."),
|
||||
itemindex,
|
||||
itemid);
|
||||
|
||||
itemid = Latte::Data::ContextMenu::ADDVIEWACTION;
|
||||
itemindex = Latte::Data::ContextMenu::ACTIONSEDITORDER.indexOf(itemid);
|
||||
m_items[itemid] = new ActionsDialog::ActionListWidgetItem(QIcon::fromTheme("list-add"),
|
||||
i18n("Add Dock/Panel"),
|
||||
itemindex,
|
||||
itemid);
|
||||
|
||||
itemid = Latte::Data::ContextMenu::MOVEVIEWACTION;
|
||||
itemindex = Latte::Data::ContextMenu::ACTIONSEDITORDER.indexOf(itemid);
|
||||
m_items[itemid] = new ActionsDialog::ActionListWidgetItem(QIcon::fromTheme("transform-move-horizontal"),
|
||||
i18n("Move Dock/Panel To Layout"),
|
||||
itemindex,
|
||||
itemid);
|
||||
|
||||
itemid = Latte::Data::ContextMenu::EXPORTVIEWTEMPLATEACTION;
|
||||
itemindex = Latte::Data::ContextMenu::ACTIONSEDITORDER.indexOf(itemid);
|
||||
m_items[itemid] = new ActionsDialog::ActionListWidgetItem(QIcon::fromTheme("document-export"),
|
||||
i18n("Export Dock/Panel as Template..."),
|
||||
itemindex,
|
||||
itemid);
|
||||
|
||||
itemid = Latte::Data::ContextMenu::REMOVEVIEWACTION;
|
||||
itemindex = Latte::Data::ContextMenu::ACTIONSEDITORDER.indexOf(itemid);
|
||||
m_items[itemid] = new ActionsDialog::ActionListWidgetItem(QIcon::fromTheme("delete"),
|
||||
i18n("Remove Dock/Panel"),
|
||||
itemindex,
|
||||
itemid);
|
||||
}
|
||||
|
||||
void ActionsHandler::loadItems(const QStringList &alwaysActions)
|
||||
{
|
||||
for(int i=0; i<Latte::Data::ContextMenu::ACTIONSEDITORDER.count(); ++i) {
|
||||
QString actionname = Latte::Data::ContextMenu::ACTIONSEDITORDER[i];
|
||||
bool inalways = alwaysActions.contains(actionname);
|
||||
|
||||
int rowinalways = rowInAlways(m_items[actionname]);
|
||||
int rowinedit = rowInEdit(m_items[actionname]);
|
||||
|
||||
if (inalways && rowinalways == -1) {
|
||||
if (rowinedit >= 0) {
|
||||
m_ui->actionsSelector->availableListWidget()->takeItem(rowinedit);
|
||||
}
|
||||
m_ui->actionsSelector->selectedListWidget()->addItem(m_items[actionname]);
|
||||
} else if (!inalways && rowinedit == -1) {
|
||||
if (rowinalways >= 0) {
|
||||
m_ui->actionsSelector->selectedListWidget()->takeItem(rowinalways);
|
||||
}
|
||||
m_ui->actionsSelector->availableListWidget()->addItem(m_items[actionname]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool ActionsHandler::hasChangedData() const
|
||||
@ -45,6 +133,28 @@ bool ActionsHandler::inDefaultValues() const
|
||||
return c_alwaysActions == def_alwaysActions;
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -7,10 +7,12 @@
|
||||
#define ACTIONSHANDLER_H
|
||||
|
||||
// local
|
||||
#include "actionlistwidgetitem.h"
|
||||
#include "../generic/generichandler.h"
|
||||
#include "../../data/generictable.h"
|
||||
|
||||
// Qt
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
|
||||
namespace Ui {
|
||||
@ -55,6 +57,11 @@ private:
|
||||
void init();
|
||||
void initDefaults();
|
||||
|
||||
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:
|
||||
@ -63,6 +70,8 @@ private:
|
||||
Data::GenericTable<Data::Generic> c_alwaysActions;
|
||||
Data::GenericTable<Data::Generic> o_alwaysActions;
|
||||
|
||||
QHash<QString, Settings::ActionsDialog::ActionListWidgetItem *> m_items;
|
||||
|
||||
Dialog::ActionsDialog *m_dialog{nullptr};
|
||||
Ui::ActionsDialog *m_ui{nullptr};
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user