1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-28 19:21:50 +03:00

remember the last used activity per layout

This commit is contained in:
Michail Vourlakos 2018-01-21 13:52:33 +02:00
parent 113822f740
commit be0f9dc0ba
3 changed files with 37 additions and 5 deletions

View File

@ -26,6 +26,8 @@
#include <QFile>
#include <KSharedConfig>
#include <KActivities/Consumer>
namespace Latte {
const QString Layout::MultipleLayoutsName = ".multiple-layouts_hidden";
@ -164,7 +166,12 @@ void Layout::initToCorona(DockCorona *corona)
qDebug() << "Layout ::::: " << name() << " added contaiments ::: " << m_containments.size();
updateLastUsedActivity();
connect(m_corona, &Plasma::Corona::containmentAdded, this, &Layout::addContainment);
connect(m_corona->m_activityConsumer, &KActivities::Consumer::currentActivityChanged,
this, &Layout::updateLastUsedActivity);
}
int Layout::version() const
@ -512,6 +519,24 @@ const QStringList Layout::appliedActivities()
}
}
QString Layout::lastUsedActivityId()
{
return m_lastUsedActivityId;
}
void Layout::updateLastUsedActivity()
{
if (!m_corona) {
return;
}
QString currentId = m_corona->activitiesConsumer()->currentActivity();
if (appliedActivities().contains(currentId)) {
m_lastUsedActivityId = currentId;
}
}
void Layout::destroyedChanged(bool destroyed)
{
if (!m_corona) {

View File

@ -68,12 +68,14 @@ public:
int version() const;
void setVersion(int ver);
QString name() const;
QString file() const;
QString color() const;
void setColor(QString color);
QString lastUsedActivityId();
QString name() const;
QString file() const;
QStringList activities() const;
void setActivities(QStringList activities);
@ -124,6 +126,7 @@ private slots:
void appletCreated(Plasma::Applet *applet);
void destroyedChanged(bool destroyed);
void containmentDestroyed(QObject *cont);
void updateLastUsedActivity();
private:
void importLocalLayout(QString file);
@ -145,6 +148,7 @@ private:
int m_version{2};
QString m_color;
QString m_lastUsedActivityId{"0"}; //the last used activity for this layout
QString m_layoutFile;
QString m_layoutName;
QStringList m_activities;

View File

@ -604,10 +604,13 @@ bool LayoutManager::switchToLayout(QString layoutName, int previousMemoryUsage)
Layout *layout = activeLayout(layoutName);
if (layout) {
QStringList appliedActivities = layout->appliedActivities();
QStringList appliedActivities = layout->appliedActivities();
QString nextActivity = layout->lastUsedActivityId() != "0" ? layout->lastUsedActivityId() : appliedActivities[0];
//! it means we are at a foreign activity
if (!appliedActivities.contains(m_corona->activitiesConsumer()->currentActivity())) {
m_activitiesController->setCurrentActivity(appliedActivities[0]);
m_activitiesController->setCurrentActivity(nextActivity);
return true;
}
}