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

fix #441,expose add widgets action in context menu

This commit is contained in:
Michail Vourlakos 2017-05-03 00:18:47 +03:00
parent 38fda1f688
commit df9edc5754
5 changed files with 49 additions and 1 deletions

View File

@ -1509,16 +1509,25 @@ void DockView::addContainmentActions(QMenu *desktopMenu, QEvent *event)
if ((this->containment()->containmentType() != Plasma::Types::PanelContainment &&
this->containment()->containmentType() != Plasma::Types::CustomPanelContainment) &&
this->containment()->actions()->action(QStringLiteral("configure"))) {
auto *dockCorona = qobject_cast<DockCorona *>(this->corona());
if (dockCorona) {
desktopMenu->addAction(dockCorona->globalSettings()->addWidgetsAction());
}
desktopMenu->addAction(this->containment()->actions()->action(QStringLiteral("configure")));
}
} else {
auto *dockCorona = qobject_cast<DockCorona *>(this->corona());
desktopMenu->addSeparator();
if (dockCorona && dockCorona->globalSettings()->exposeAltSession()) {
desktopMenu->addSeparator();
desktopMenu->addAction(dockCorona->globalSettings()->altSessionAction());
}
desktopMenu->addAction(dockCorona->globalSettings()->addWidgetsAction());
desktopMenu->addActions(actions);
}

View File

@ -9,6 +9,8 @@
#include <QMessageBox>
#include <QDesktopServices>
#include <QtDBus/QtDBus>
#include <KLocalizedString>
#include <KConfig>
#include <KArchive/KTar>
@ -33,6 +35,12 @@ GlobalSettings::GlobalSettings(QObject *parent)
connect(m_altSessionAction, &QAction::triggered, this, &GlobalSettings::enableAltSession);
connect(m_corona, &DockCorona::currentSessionChanged, this, &GlobalSettings::currentSessionChangedSlot);
//! create the add widgets action
const QIcon addWidIcon = QIcon::fromTheme("add");
m_addWidgetsAction = new QAction(addWidIcon, i18n("Add Widgets..."), this);
m_addWidgetsAction->setStatusTip(i18n("Show Plasma Widget Explorer"));
connect(m_addWidgetsAction, &QAction::triggered, this, &GlobalSettings::showWidgetsExplorer);
init();
}
}
@ -62,6 +70,15 @@ void GlobalSettings::initExtConfiguration()
m_externalGroup = KConfigGroup(extConfig, "External");
}
void GlobalSettings::showWidgetsExplorer()
{
QDBusInterface iface("org.kde.plasmashell", "/PlasmaShell", "", QDBusConnection::sessionBus());
if (iface.isValid()) {
iface.call("toggleWidgetExplorer");
}
}
void GlobalSettings::enableAltSession(bool enabled)
{
if (enabled) {
@ -102,6 +119,11 @@ QAction *GlobalSettings::altSessionAction() const
return m_altSessionAction;
}
QAction *GlobalSettings::addWidgetsAction() const
{
return m_addWidgetsAction;
}
bool GlobalSettings::autostart() const
{
QFile autostartFile(QDir::homePath() + "/.config/autostart/latte-dock.desktop");

View File

@ -42,6 +42,7 @@ class GlobalSettings : public QObject {
Q_PROPERTY(Latte::Dock::SessionType currentSession READ currentSession WRITE setCurrentSession NOTIFY currentSessionChanged)
Q_PROPERTY(QAction *altSessionAction READ altSessionAction NOTIFY altSessionActionChanged)
Q_PROPERTY(QAction *addWidgetsAction READ addWidgetsAction NOTIFY addWidgetsActionChanged)
public:
GlobalSettings(QObject *parent = nullptr);
@ -56,6 +57,8 @@ public:
void setExposeAltSession(bool state);
QAction *altSessionAction() const;
QAction *addWidgetsAction() const;
Latte::Dock::SessionType currentSession() const;
void setCurrentSession(Latte::Dock::SessionType session);
@ -66,6 +69,7 @@ public:
Q_INVOKABLE QVariantList layouts();
signals:
void addWidgetsActionChanged();
void altSessionActionChanged();
void clearLayoutSelection();
void currentSessionChanged();
@ -76,6 +80,7 @@ private slots:
void currentSessionChangedSlot(Dock::SessionType type);
void enableAltSession(bool enabled);
void importLayoutInternal(const QString &file);
void showWidgetsExplorer();
private:
void save();
@ -85,6 +90,7 @@ private:
void saveExtConfiguration();
bool m_exposeAltSession{false};
QAction *m_addWidgetsAction{nullptr};
QAction *m_altSessionAction{nullptr};
DockCorona *m_corona{nullptr};
QPointer<QFileDialog> m_fileDialog;

View File

@ -190,6 +190,7 @@ DragDrop.DropArea {
property QtObject dock
property QtObject globalSettings
property QtObject addWidgetsAction: globalSettings ? globalSettings.addWidgetsAction : 0
property QtObject altSessionAction: globalSettings ? globalSettings.altSessionAction : 0
// TO BE DELETED, if not needed: property int counter:0;

View File

@ -821,6 +821,16 @@ PlasmaComponents.ContextMenu {
onClicked: root.altSessionAction.trigger();
}
PlasmaComponents.MenuItem {
id: addWidgets
visible: latteDock.addWidgetsAction
icon: "add"
text: i18n("Add Widgets...")
onClicked: latteDock.addWidgetsAction.trigger();
}
PlasmaComponents.MenuItem {
id: containmentMenuItem