1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-23 01:33:50 +03:00

cmdline:add dock/panel through --add-dock

This commit is contained in:
Michail Vourlakos 2021-06-28 17:07:53 +03:00
parent 8ec97ed6c4
commit 30de674870
6 changed files with 53 additions and 5 deletions

View File

@ -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);
}
}
}

View File

@ -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) {

View File

@ -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);

View File

@ -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 {

View File

@ -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")) {

View File

@ -58,6 +58,8 @@ public:
QString proposedTemplateAbsolutePath(QString templateFilename);
QString viewTemplateFilePath(const QString templateName) const;
void importSystemLayouts();
void installCustomLayoutTemplate(const QString &templateFilePath);