diff --git a/app/lattecorona.cpp b/app/lattecorona.cpp index 681a236bc..56116042b 100644 --- a/app/lattecorona.cpp +++ b/app/lattecorona.cpp @@ -1161,9 +1161,16 @@ QStringList Corona::viewTemplatesData() void Corona::addView(const uint &containmentId, const QString &templateId) { - auto view = m_layoutsManager->synchronizer()->viewForContainment((int)containmentId); - if (view) { - view->newView(templateId); + if (containmentId <= 0) { + auto currentlayouts = m_layoutsManager->currentLayouts(); + if (currentlayouts.count() > 0) { + currentlayouts[0]->newView(templateId); + } + } else { + auto view = m_layoutsManager->synchronizer()->viewForContainment((int)containmentId); + if (view) { + view->newView(templateId); + } } } diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index ff3f521b0..13974a714 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -16,6 +16,7 @@ #include "../layouts/storage.h" #include "../layouts/synchronizer.h" #include "../shortcuts/shortcutstracker.h" +#include "../templates/templatesmanager.h" #include "../view/view.h" #include "../view/positioner.h" @@ -1538,6 +1539,35 @@ void GenericLayout::syncToLayoutFile(bool removeLayoutId) Layouts::Storage::self()->syncToLayoutFile(this, removeLayoutId); } +bool GenericLayout::newView(const QString &templateName) +{ + if (!isActive() || !m_corona->templatesManager()->hasViewTemplate(templateName)) { + return false; + } + + QString templatefilepath = m_corona->templatesManager()->viewTemplateFilePath(templateName); + Data::ViewsTable templateviews = Layouts::Storage::self()->views(templatefilepath); + + if (templateviews.rowCount() <= 0) { + return false; + } + + Data::View nextdata = templateviews[0]; + int scrId = m_corona->screenPool()->primaryScreenId(); + + QList<Plasma::Types::Location> freeedges = freeEdges(scrId); + + if (!freeedges.contains(nextdata.edge)) { + nextdata.edge = (freeedges.count() > 0 ? freeedges[0] : Plasma::Types::BottomEdge); + } + + nextdata.setState(Data::View::OriginFromViewTemplate, templatefilepath); + + newView(nextdata); + + return true; +} + Data::View GenericLayout::newView(const Latte::Data::View &nextViewData) { if (nextViewData.state() == Data::View::IsInvalid) { diff --git a/app/layout/genericlayout.h b/app/layout/genericlayout.h index 4d59a66d0..4f12b26d8 100644 --- a/app/layout/genericlayout.h +++ b/app/layout/genericlayout.h @@ -111,6 +111,7 @@ public: void recreateView(Plasma::Containment *containment, bool delayed = true); bool latteViewExists(Plasma::Containment *containment); + bool newView(const QString &templateName); Data::View newView(const Latte::Data::View &nextViewData); void removeView(const Latte::Data::View &viewData); void updateView(const Latte::Data::View &viewData); diff --git a/app/main.cpp b/app/main.cpp index 5f5d6d02c..88891bc13 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -228,8 +228,7 @@ int main(int argc, char **argv) if (iface.isValid()) { if (addview) { - //iface.call("addView", 0, parser.value(QStringLiteral("add-dock"))); - //! Enable code above when the code path is ready and works correctly + iface.call("addView", (uint)0, parser.value(QStringLiteral("add-dock"))); qGuiApp->exit(); return 0; } else { diff --git a/app/templates/templatesmanager.cpp b/app/templates/templatesmanager.cpp index fabe7a819..5c88d8b96 100644 --- a/app/templates/templatesmanager.cpp +++ b/app/templates/templatesmanager.cpp @@ -236,6 +236,15 @@ bool Manager::hasViewTemplate(const QString &templateName) const return m_viewTemplates.containsName(templateName); } +QString Manager::viewTemplateFilePath(const QString templateName) const +{ + if (m_viewTemplates.containsName(templateName)) { + return m_viewTemplates.idForName(templateName); + } + + return QString(); +} + void Manager::installCustomLayoutTemplate(const QString &templateFilePath) { if (!templateFilePath.endsWith(".layout.latte")) { diff --git a/app/templates/templatesmanager.h b/app/templates/templatesmanager.h index a94dac0fa..f68dd2b3d 100644 --- a/app/templates/templatesmanager.h +++ b/app/templates/templatesmanager.h @@ -58,6 +58,8 @@ public: QString proposedTemplateAbsolutePath(QString templateFilename); + QString viewTemplateFilePath(const QString templateName) const; + void importSystemLayouts(); void installCustomLayoutTemplate(const QString &templateFilePath);