From 5fa77e05ebb5e2a8a520be21cb8ff74884c08a7c Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sun, 28 Feb 2021 17:35:59 +0200 Subject: [PATCH] contextmenu:add export as template --- app/dbus/org.kde.LatteDock.xml | 3 +++ app/lattecorona.cpp | 8 ++++++ app/lattecorona.h | 3 +++ containmentactions/contextmenu/menu.cpp | 25 +++++++++++++++++-- containmentactions/contextmenu/menu.h | 1 + plasmoid/package/contents/ui/ContextMenu.qml | 6 +++++ .../configuration/LatteDockConfiguration.qml | 23 ----------------- 7 files changed, 44 insertions(+), 25 deletions(-) diff --git a/app/dbus/org.kde.LatteDock.xml b/app/dbus/org.kde.LatteDock.xml index 0cc45d1f4..8fd522c3e 100644 --- a/app/dbus/org.kde.LatteDock.xml +++ b/app/dbus/org.kde.LatteDock.xml @@ -15,6 +15,9 @@ + + + diff --git a/app/lattecorona.cpp b/app/lattecorona.cpp index c9227ca9e..f8f0ecaf1 100644 --- a/app/lattecorona.cpp +++ b/app/lattecorona.cpp @@ -1174,6 +1174,14 @@ void Corona::duplicateView(const uint &containmentId) } } +void Corona::exportViewTemplate(const uint &containmentId) +{ + auto view = m_layoutsManager->synchronizer()->viewForContainment((int)containmentId); + if (view) { + view->exportTemplate(); + } +} + void Corona::removeView(const uint &containmentId) { auto view = m_layoutsManager->synchronizer()->viewForContainment((int)containmentId); diff --git a/app/lattecorona.h b/app/lattecorona.h index 00d027c44..8a134b11d 100644 --- a/app/lattecorona.h +++ b/app/lattecorona.h @@ -165,8 +165,11 @@ public slots: void aboutApplication(); void activateLauncherMenu(); void loadDefaultLayout() override; + void duplicateView(const uint &containmentId); + void exportViewTemplate(const uint &containmentId); void removeView(const uint &containmentId); + void setBackgroundFromBroadcast(QString activity, QString screenName, QString filename); void setBroadcastedBackgroundsEnabled(QString activity, QString screenName, bool enabled); void showAlternativesForApplet(Plasma::Applet *applet); diff --git a/containmentactions/contextmenu/menu.cpp b/containmentactions/contextmenu/menu.cpp index 6f076ae44..7b394567f 100644 --- a/containmentactions/contextmenu/menu.cpp +++ b/containmentactions/contextmenu/menu.cpp @@ -43,6 +43,7 @@ const char QUITLATTENAME[] = "quit latte"; const char ADDWIDGETSNAME[] = "add latte widgets"; const char DUPLICATEVIEWNAME[] = "duplicate view"; const char EDITVIEWNAME[] = "edit view"; +const char EXPORTVIEWTEMPLATENAME[] = "export view"; const char REMOVEVIEWNAME[] = "remove view"; enum ViewType @@ -144,7 +145,7 @@ void Menu::makeActions() }); //! Duplicate Action - m_duplicateAction = new QAction(QIcon::fromTheme("edit-copy"), "Duplicate Dock", this); + m_duplicateAction = new QAction(QIcon::fromTheme("edit-copy"), "Duplicate Dock as Template", this); m_duplicateAction->setVisible(containment()->isUserConfiguring()); connect(m_duplicateAction, &QAction::triggered, [=](){ QDBusInterface iface("org.kde.lattedock", "/Latte", "", QDBusConnection::sessionBus()); @@ -155,6 +156,18 @@ void Menu::makeActions() }); this->containment()->actions()->addAction(DUPLICATEVIEWNAME, m_duplicateAction); + //! Duplicate Action + m_exportViewAction = new QAction(QIcon::fromTheme("document-export"), "Export as Template...", this); + m_exportViewAction->setVisible(containment()->isUserConfiguring()); + connect(m_exportViewAction, &QAction::triggered, [=](){ + QDBusInterface iface("org.kde.lattedock", "/Latte", "", QDBusConnection::sessionBus()); + + if (iface.isValid()) { + iface.call("exportViewTemplate", containment()->id()); + } + }); + this->containment()->actions()->addAction(EXPORTVIEWTEMPLATENAME, m_exportViewAction); + //! Remove Action m_removeAction = new QAction(QIcon::fromTheme("delete"), "Remove Dock", this); m_removeAction->setVisible(containment()->isUserConfiguring()); @@ -198,6 +211,7 @@ QList Menu::contextualActions() actions << m_separator2; actions << m_addWidgetsAction; actions << m_duplicateAction; + actions << m_exportViewAction; actions << m_configureAction; actions << m_removeAction; @@ -217,12 +231,15 @@ QList Menu::contextualActions() viewType = static_cast((m_data[2]).toInt()); } - const QString configureActionText = (viewType == DockView) ? i18nc("dock settings window", "&Edit Dock...") : i18nc("panel settings window", "&Edit Panel..."); + const QString configureActionText = (viewType == DockView) ? i18n("&Edit Dock...") : i18n("&Edit Panel..."); m_configureAction->setText(configureActionText); const QString duplicateActionText = (viewType == DockView) ? i18n("&Duplicate Dock") : i18n("&Duplicate Panel"); m_duplicateAction->setText(duplicateActionText); + const QString exportTemplateText = (viewType == DockView) ? i18n("E&xport Dock as Template") : i18n("E&xport Panel as Template"); + m_exportViewAction->setText(exportTemplateText); + const QString removeActionText = (viewType == DockView) ? i18n("&Remove Dock") : i18n("&Remove Panel"); m_removeAction->setText(removeActionText); @@ -237,6 +254,8 @@ QAction *Menu::action(const QString &name) return m_duplicateAction; } else if (name == EDITVIEWNAME) { return m_configureAction; + } else if (name == EXPORTVIEWTEMPLATENAME) { + return m_exportViewAction; } else if (name == LAYOUTSNAME) { return m_layoutsAction; } else if (name == PREFERENCESNAME) { @@ -258,11 +277,13 @@ void Menu::onUserConfiguringChanged(const bool &configuring) m_configureAction->setVisible(!configuring); m_duplicateAction->setVisible(configuring); + m_exportViewAction->setVisible(configuring); m_removeAction->setVisible(configuring); // because sometimes they are disabled unexpectedly, we should reenable them m_configureAction->setEnabled(true); m_duplicateAction->setEnabled(true); + m_exportViewAction->setEnabled(true); m_removeAction->setEnabled(true); } diff --git a/containmentactions/contextmenu/menu.h b/containmentactions/contextmenu/menu.h index 1a8eada7b..b4c767964 100644 --- a/containmentactions/contextmenu/menu.h +++ b/containmentactions/contextmenu/menu.h @@ -61,6 +61,7 @@ private: QAction *m_addWidgetsAction{nullptr}; QAction *m_configureAction{nullptr}; QAction *m_duplicateAction{nullptr}; + QAction *m_exportViewAction{nullptr}; QAction *m_printAction{nullptr}; QAction *m_layoutsAction{nullptr}; QAction *m_preferenceAction{nullptr}; diff --git a/plasmoid/package/contents/ui/ContextMenu.qml b/plasmoid/package/contents/ui/ContextMenu.qml index 8498a7734..12136bb04 100644 --- a/plasmoid/package/contents/ui/ContextMenu.qml +++ b/plasmoid/package/contents/ui/ContextMenu.qml @@ -924,6 +924,12 @@ PlasmaComponents.ContextMenu { visible: appletAbilities.myView.isReady && action.visible } + PlasmaComponents.MenuItem { + id: exportItem + action: appletAbilities.myView.isReady ? appletAbilities.myView.action("export view") : plasmoid.action("configure") + visible: appletAbilities.myView.isReady && action.visible + } + PlasmaComponents.MenuItem { id: configureItem action: appletAbilities.myView.isReady ? appletAbilities.myView.action("edit view") : plasmoid.action("configure") diff --git a/shell/package/contents/configuration/LatteDockConfiguration.qml b/shell/package/contents/configuration/LatteDockConfiguration.qml index 60c28f63f..ece1bebc2 100644 --- a/shell/package/contents/configuration/LatteDockConfiguration.qml +++ b/shell/package/contents/configuration/LatteDockConfiguration.qml @@ -551,10 +551,6 @@ Loader { if (item && item.actionId === "new:") { latteView.layout.newView(item.templateId); - } else if (item && item.actionId === "export:") { - latteView.exportTemplate(); - } else if (item && item.actionId === "copy:") { - latteView.copyView(); } else if (item && item.actionId === "move:") { var layouts = actionsComboBtn.centralLayoutsNames; latteView.positioner.hideDockDuringMovingToLayout(layouts[index-1]); @@ -574,7 +570,6 @@ Loader { Connections{ target: latteView - onTypeChanged: actionsComboBtn.updateCopyText(); onLayoutChanged: actionsComboBtn.updateModel(); } @@ -617,13 +612,6 @@ Loader { } } - var exporttemplate = {actionId: 'export:', enabled: true, name: i18n("Export as Template"), icon: 'document-export'}; - actionsModel.append(exporttemplate); - - var copy = {actionId: 'copy:', enabled: true, name: '', icon: 'edit-copy'}; - actionsModel.append(copy); - updateCopyText(); - var viewTemplateIds = layoutsManager.viewTemplateIds(); var viewTemplateNames = layoutsManager.viewTemplateNames(); @@ -646,17 +634,6 @@ Loader { actionsModel.clear(); actionsComboBtn.comboBox.currentIndex = -1; } - - function updateCopyText() { - for (var i=0; i