context menu:provide Add view through templates

work/spdx
Michail Vourlakos 4 years ago
parent 5f6c0df50c
commit fe5d2d7a63

@ -18,6 +18,10 @@
<method name="exportViewTemplate">
<arg name="containmentId" type="u" direction="in"/>
</method>
<method name="addView">
<arg name="containmentId" type="u" direction="in"/>
<arg name="templateId" type="s" direction="in"/>
</method>
<method name="duplicateView">
<arg name="containmentId" type="u" direction="in"/>
</method>
@ -35,6 +39,9 @@
<arg name="data" type="as" direction="out"/>
<arg name="containmentId" type="u" direction="in"/>
</method>
<method name="viewTemplatesData">
<arg name="data" type="as" direction="out"/>
</method>
<method name="setBackgroundFromBroadcast">
<arg name="activity" type="s" direction="in"/>
<arg name="screenName" type="s" direction="in"/>

@ -26,6 +26,7 @@
#include "apptypes.h"
#include "lattedockadaptor.h"
#include "screenpool.h"
#include "data/generictable.h"
#include "declarativeimports/interfaces.h"
#include "indicator/factory.h"
#include "layout/abstractlayout.h"
@ -1163,6 +1164,28 @@ QStringList Corona::contextMenuData(const uint &containmentId)
return data;
}
QStringList Corona::viewTemplatesData()
{
QStringList data;
Latte::Data::GenericTable<Data::Generic> viewtemplates = m_templatesManager->viewTemplates();
for(int i=0; i<viewtemplates.rowCount(); ++i) {
data << viewtemplates[i].name;
data << viewtemplates[i].id;
}
return data;
}
void Corona::addView(const uint &containmentId, const QString &templateId)
{
auto view = m_layoutsManager->synchronizer()->viewForContainment((int)containmentId);
if (view && view->layout() && !templateId.isEmpty()) {
view->layout()->newView(templateId);
}
}
void Corona::duplicateView(const uint &containmentId)
{
auto view = m_layoutsManager->synchronizer()->viewForContainment((int)containmentId);

@ -160,12 +160,14 @@ public:
void showSettingsWindow(int page);
QStringList contextMenuData(const uint &containmentId);
QStringList viewTemplatesData();
public slots:
void aboutApplication();
void activateLauncherMenu();
void loadDefaultLayout() override;
void addView(const uint &containmentId, const QString &templateId);
void duplicateView(const uint &containmentId);
void exportViewTemplate(const uint &containmentId);
void moveViewToLayout(const uint &containmentId, const QString &layoutName);

@ -43,6 +43,7 @@ const int LAYOUTMENUINDEX = 3;
const int VIEWTYPEINDEX = 4;
const int VIEWLAYOUTINDEX = 5;
const char ADDVIEWNAME[] = "add view";
const char LAYOUTSNAME[] = "layouts";
const char PREFERENCESNAME[] = "preferences";
const char QUITLATTENAME[] = "quit latte";
@ -83,6 +84,7 @@ Menu::~Menu()
m_separator->deleteLater();
//! sub-menus
m_addViewMenu->deleteLater();
m_switchLayoutsMenu->deleteLater();
m_moveToLayoutMenu->deleteLater();
@ -148,6 +150,17 @@ void Menu::makeActions()
connect(m_switchLayoutsMenu, &QMenu::aboutToShow, this, &Menu::populateLayouts);
connect(m_switchLayoutsMenu, &QMenu::triggered, this, &Menu::switchToLayout);
//! Add View submenu
m_addViewMenu = new QMenu;
m_addViewAction = m_addViewMenu->menuAction();
m_addViewAction->setText(i18n("&Add Dock/Panel"));
m_addViewAction->setIcon(QIcon::fromTheme("list-add"));
m_addViewAction->setStatusTip(i18n("Add dock or panel based on specific template"));
this->containment()->actions()->addAction(ADDVIEWNAME, m_addViewAction);
connect(m_addViewMenu, &QMenu::aboutToShow, this, &Menu::populateViewTemplates);
connect(m_addViewMenu, &QMenu::triggered, this, &Menu::addView);
//! Move submenu
m_moveToLayoutMenu = new QMenu;
m_moveAction = m_moveToLayoutMenu->menuAction();
@ -237,6 +250,7 @@ QList<QAction *> Menu::contextualActions()
actions << m_separator;
actions << m_addWidgetsAction;
actions << m_addViewAction;
actions << m_duplicateAction;
actions << m_moveAction;
actions << m_exportViewAction;
@ -244,12 +258,15 @@ QList<QAction *> Menu::contextualActions()
actions << m_removeAction;
m_data.clear();
m_viewTemplates.clear();
QDBusInterface iface("org.kde.lattedock", "/Latte", "", QDBusConnection::sessionBus());
if (iface.isValid()) {
QDBusReply<QStringList> replyData = iface.call("contextMenuData", containment()->id());
QDBusReply<QStringList> contextData = iface.call("contextMenuData", containment()->id());
m_data = contextData.value();
m_data = replyData.value();
QDBusReply<QStringList> templatesData = iface.call("viewTemplatesData");
m_viewTemplates = templatesData.value();
}
ViewType viewType{static_cast<ViewType>((m_data[VIEWTYPEINDEX]).toInt())};
@ -280,7 +297,9 @@ QList<QAction *> Menu::contextualActions()
QAction *Menu::action(const QString &name)
{
if (name == ADDWIDGETSNAME) {
if (name == ADDVIEWNAME) {
return m_addViewAction;
} else if (name == ADDWIDGETSNAME) {
return m_addWidgetsAction;
} else if (name == DUPLICATEVIEWNAME) {
return m_duplicateAction;
@ -430,6 +449,34 @@ void Menu::populateMoveToLayouts()
}
}
void Menu::populateViewTemplates()
{
m_addViewMenu->clear();
for(int i=0; i<m_viewTemplates.count(); ++i) {
if (i % 2 == 1) {
//! even records are the templates ids and they have already been registered
continue;
}
QAction *templateAction = m_addViewMenu->addAction(m_viewTemplates[i]);
templateAction->setData(m_viewTemplates[i+1]);
}
}
void Menu::addView(QAction *action)
{
const QString templateId = action->data().toString();
QTimer::singleShot(400, [this, templateId]() {
QDBusInterface iface("org.kde.lattedock", "/Latte", "", QDBusConnection::sessionBus());
if (iface.isValid()) {
iface.call("addView", containment()->id(), templateId);
}
});
}
void Menu::moveToLayout(QAction *action)
{
const QString layoutName = action->data().toString();

@ -45,15 +45,18 @@ private Q_SLOTS:
void onUserConfiguringChanged(const bool &configuring);
void populateLayouts();
void populateMoveToLayouts();
void populateViewTemplates();
void quitApplication();
void requestConfiguration();
void requestWidgetExplorer();
void addView(QAction *action);
void moveToLayout(QAction *action);
void switchToLayout(QAction *action);
private:
QStringList m_data;
QStringList m_viewTemplates;
QList<QAction *>m_actions;
@ -69,6 +72,9 @@ private:
QAction *m_removeAction{nullptr};
QAction *m_quitApplication{nullptr};
QAction *m_addViewAction{nullptr};
QMenu *m_addViewMenu{nullptr};
QAction *m_layoutsAction{nullptr};
QMenu *m_switchLayoutsMenu{nullptr};

@ -519,7 +519,7 @@ Loader {
buttonEnabled: true
buttonIsTriggeringMenu: true
buttonText: i18n("New...")
buttonText: i18n("Add...")
buttonIconSource: "list-add"
buttonToolTip: i18n("Add new docks and panels from various templates")
@ -549,7 +549,7 @@ Loader {
onActivated: {
var item = actionsModel.get(index);
if (item && item.actionId === "new:") {
if (item && item.actionId === "add:") {
latteView.layout.newView(item.templateId);
}
@ -587,10 +587,10 @@ Loader {
for(var i=viewTemplateIds.length-1; i>=0; --i) {
//! add view templates on reverse
var viewtemplate = {
actionId: 'new:',
actionId: 'add:',
enabled: true,
templateId: viewTemplateIds[i],
name: i18n("New %0").arg(viewTemplateNames[i]),
name: i18n("Add %0").arg(viewTemplateNames[i]),
icon: 'list-add'
};
actionsModel.append(viewtemplate);

Loading…
Cancel
Save