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

expose view templates through dock settings

--the user can now add views based on view templates
found in the system through Dock Settings, New Dock
actions
This commit is contained in:
Michail Vourlakos 2021-02-06 00:14:11 +02:00
parent 390ea0596c
commit 09654e75b3
7 changed files with 37 additions and 76 deletions

View File

@ -907,6 +907,11 @@ void Corona::aboutApplication()
aboutDialog->show(); aboutDialog->show();
} }
void Corona::loadDefaultLayout()
{
//disabled
}
int Corona::screenForContainment(const Plasma::Containment *containment) const int Corona::screenForContainment(const Plasma::Containment *containment) const
{ {
//FIXME: indexOf is not a proper way to support multi-screen //FIXME: indexOf is not a proper way to support multi-screen
@ -1030,61 +1035,6 @@ void Corona::alternativesVisibilityChanged(bool visible)
} }
} }
void Corona::addViewForLayout(QString layoutName)
{
qDebug() << "loading default layout";
//! Setting mutable for create a containment
setImmutability(Plasma::Types::Mutable);
QVariantList args;
auto defaultContainment = createContainmentDelayed("org.kde.latte.containment", args);
defaultContainment->setContainmentType(Plasma::Types::PanelContainment);
defaultContainment->init();
if (!defaultContainment || !defaultContainment->kPackage().isValid()) {
qWarning() << "the requested containment plugin can not be located or loaded";
return;
}
auto config = defaultContainment->config();
defaultContainment->restore(config);
using Plasma::Types;
QList<Types::Location> edges{Types::BottomEdge, Types::LeftEdge,
Types::TopEdge, Types::RightEdge};
Layout::GenericLayout *currentLayout = m_layoutsManager->synchronizer()->layout(layoutName);
if (currentLayout) {
edges = currentLayout->freeEdges(defaultContainment->screen());
}
if ((edges.count() > 0)) {
defaultContainment->setLocation(edges.at(0));
} else {
defaultContainment->setLocation(Plasma::Types::BottomEdge);
}
if (m_layoutsManager->memoryUsage() == MemoryUsage::MultipleLayouts) {
config.writeEntry("layoutId", layoutName);
}
defaultContainment->updateConstraints(Plasma::Types::StartupCompletedConstraint);
defaultContainment->save(config);
requestConfigSync();
defaultContainment->flushPendingConstraintsEvents();
emit containmentAdded(defaultContainment);
emit containmentCreated(defaultContainment);
defaultContainment->createApplet(QStringLiteral("org.kde.latte.plasmoid"));
}
void Corona::loadDefaultLayout()
{
// addViewForLayout(m_layoutsManager->currentLayoutsNames());
}
QStringList Corona::containmentsIds() QStringList Corona::containmentsIds()
{ {
QStringList ids; QStringList ids;

View File

@ -163,7 +163,6 @@ public:
public slots: public slots:
void aboutApplication(); void aboutApplication();
void addViewForLayout(QString layoutName);
void activateLauncherMenu(); void activateLauncherMenu();
void loadDefaultLayout() override; void loadDefaultLayout() override;
void setBackgroundFromBroadcast(QString activity, QString screenName, QString filename); void setBackgroundFromBroadcast(QString activity, QString screenName, QString filename);

View File

@ -768,16 +768,6 @@ void GenericLayout::renameLayout(QString newName)
} }
} }
void GenericLayout::addNewView()
{
if (!m_corona) {
return;
}
m_corona->addViewForLayout(name());
emit viewEdgeChanged();
}
void GenericLayout::addView(Plasma::Containment *containment, bool forceOnPrimary, int explicitScreen, Layout::ViewsMap *occupied) void GenericLayout::addView(Plasma::Containment *containment, bool forceOnPrimary, int explicitScreen, Layout::ViewsMap *occupied)
{ {
qDebug() << "Layout :::: " << m_layoutName << " ::: addView was called... m_containments :: " << m_containments.size(); qDebug() << "Layout :::: " << m_layoutName << " ::: addView was called... m_containments :: " << m_containments.size();
@ -1685,6 +1675,24 @@ void GenericLayout::copyView(Plasma::Containment *containment)
emit viewEdgeChanged(); emit viewEdgeChanged();
} }
void GenericLayout::newView(const QString &templateFile)
{
//! Don't create LatteView when the containment is created because we must update its screen settings first
setBlockAutomaticLatteViewCreation(true);
Layouts::ViewDelayedCreationData result = Layouts::Storage::self()->newView(this, templateFile);
if (result.containment) {
addView(result.containment, result.forceOnPrimary, result.explicitScreen);
if (result.reactToScreenChange) {
result.containment->reactToScreenChange();
}
}
setBlockAutomaticLatteViewCreation(false);
emit viewEdgeChanged();
}
void GenericLayout::importToCorona() void GenericLayout::importToCorona()
{ {
Layouts::Storage::self()->importToCorona(this); Layouts::Storage::self()->importToCorona(this);

View File

@ -146,7 +146,7 @@ public:
QList<int> viewsScreens(); QList<int> viewsScreens();
public slots: public slots:
Q_INVOKABLE void addNewView(); Q_INVOKABLE void newView(const QString &templateFile);
Q_INVOKABLE int viewsWithTasks() const; Q_INVOKABLE int viewsWithTasks() const;
virtual Q_INVOKABLE QList<int> qmlFreeEdges(int screen) const; //change <Plasma::Types::Location> to <int> types virtual Q_INVOKABLE QList<int> qmlFreeEdges(int screen) const; //change <Plasma::Types::Location> to <int> types

View File

@ -544,19 +544,23 @@ ViewDelayedCreationData Storage::newView(const Layout::GenericLayout *destinatio
Plasma::Containment *newContainment = (importedViews.size() == 1 ? importedViews[0] : nullptr); Plasma::Containment *newContainment = (importedViews.size() == 1 ? importedViews[0] : nullptr);
if (!newContainment || !newContainment->kPackage().isValid()) { if (!newContainment || !newContainment->kPackage().isValid()) {
qWarning() << "the requested containment plugin can not be located or loaded"; qWarning() << "the requested containment plugin can not be located or loaded from:" << templateFile;
return ViewDelayedCreationData(); return ViewDelayedCreationData();
} }
auto config = newContainment->config(); auto config = newContainment->config();
int primaryScrId = destination->corona()->screenPool()->primaryScreenId(); int primaryScrId = destination->corona()->screenPool()->primaryScreenId();
QList<Plasma::Types::Location> edges = destination->freeEdges(newContainment->screen()); QList<Plasma::Types::Location> edges = destination->freeEdges(primaryScrId);
qDebug() << "org.kde.latte current template edge : " << newContainment->location() << " free edges :: " << edges;
if (edges.count() > 0) { //! if selected template screen edge is not free
newContainment->setLocation(edges.at(0)); if (!edges.contains(newContainment->location())) {
} else { if (edges.count() > 0) {
newContainment->setLocation(Plasma::Types::BottomEdge); newContainment->setLocation(edges.at(0));
} else {
newContainment->setLocation(Plasma::Types::BottomEdge);
}
} }
config.writeEntry("onPrimary", true); config.writeEntry("onPrimary", true);

View File

@ -530,7 +530,7 @@ Loader {
var item = actionsModel.get(index); var item = actionsModel.get(index);
if (item.actionId === "new:") { if (item.actionId === "new:") {
latteView.layout.newView(item.templateId);
} else if (item.actionId === "copy:") { } else if (item.actionId === "copy:") {
latteView.copyView(); latteView.copyView();
} else if (item.actionId === "move:") { } else if (item.actionId === "move:") {
@ -552,7 +552,7 @@ Loader {
Connections{ Connections{
target: actionsComboBtn.button target: actionsComboBtn.button
onClicked: latteView.layout.addNewView(); onClicked: latteView.layout.newView(layoutsManager.viewTemplateIds()[0])
} }
Connections{ Connections{

View File

@ -7,7 +7,7 @@ formfactor=2
immutability=1 immutability=1
isPreferredForShortcuts=false isPreferredForShortcuts=false
lastScreen=-1 lastScreen=-1
location=4 location=3
onPrimary=true onPrimary=true
plugin=org.kde.latte.containment plugin=org.kde.latte.containment
raiseOnActivityChange=false raiseOnActivityChange=false