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:
parent
113822f740
commit
be0f9dc0ba
@ -26,6 +26,8 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <KSharedConfig>
|
#include <KSharedConfig>
|
||||||
|
|
||||||
|
#include <KActivities/Consumer>
|
||||||
|
|
||||||
namespace Latte {
|
namespace Latte {
|
||||||
|
|
||||||
const QString Layout::MultipleLayoutsName = ".multiple-layouts_hidden";
|
const QString Layout::MultipleLayoutsName = ".multiple-layouts_hidden";
|
||||||
@ -164,7 +166,12 @@ void Layout::initToCorona(DockCorona *corona)
|
|||||||
|
|
||||||
qDebug() << "Layout ::::: " << name() << " added contaiments ::: " << m_containments.size();
|
qDebug() << "Layout ::::: " << name() << " added contaiments ::: " << m_containments.size();
|
||||||
|
|
||||||
|
updateLastUsedActivity();
|
||||||
|
|
||||||
connect(m_corona, &Plasma::Corona::containmentAdded, this, &Layout::addContainment);
|
connect(m_corona, &Plasma::Corona::containmentAdded, this, &Layout::addContainment);
|
||||||
|
|
||||||
|
connect(m_corona->m_activityConsumer, &KActivities::Consumer::currentActivityChanged,
|
||||||
|
this, &Layout::updateLastUsedActivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Layout::version() const
|
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)
|
void Layout::destroyedChanged(bool destroyed)
|
||||||
{
|
{
|
||||||
if (!m_corona) {
|
if (!m_corona) {
|
||||||
|
10
app/layout.h
10
app/layout.h
@ -68,12 +68,14 @@ public:
|
|||||||
int version() const;
|
int version() const;
|
||||||
void setVersion(int ver);
|
void setVersion(int ver);
|
||||||
|
|
||||||
QString name() const;
|
|
||||||
QString file() const;
|
|
||||||
|
|
||||||
QString color() const;
|
QString color() const;
|
||||||
void setColor(QString color);
|
void setColor(QString color);
|
||||||
|
|
||||||
|
QString lastUsedActivityId();
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
QString file() const;
|
||||||
|
|
||||||
QStringList activities() const;
|
QStringList activities() const;
|
||||||
void setActivities(QStringList activities);
|
void setActivities(QStringList activities);
|
||||||
|
|
||||||
@ -124,6 +126,7 @@ private slots:
|
|||||||
void appletCreated(Plasma::Applet *applet);
|
void appletCreated(Plasma::Applet *applet);
|
||||||
void destroyedChanged(bool destroyed);
|
void destroyedChanged(bool destroyed);
|
||||||
void containmentDestroyed(QObject *cont);
|
void containmentDestroyed(QObject *cont);
|
||||||
|
void updateLastUsedActivity();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void importLocalLayout(QString file);
|
void importLocalLayout(QString file);
|
||||||
@ -145,6 +148,7 @@ private:
|
|||||||
int m_version{2};
|
int m_version{2};
|
||||||
|
|
||||||
QString m_color;
|
QString m_color;
|
||||||
|
QString m_lastUsedActivityId{"0"}; //the last used activity for this layout
|
||||||
QString m_layoutFile;
|
QString m_layoutFile;
|
||||||
QString m_layoutName;
|
QString m_layoutName;
|
||||||
QStringList m_activities;
|
QStringList m_activities;
|
||||||
|
@ -604,10 +604,13 @@ bool LayoutManager::switchToLayout(QString layoutName, int previousMemoryUsage)
|
|||||||
Layout *layout = activeLayout(layoutName);
|
Layout *layout = activeLayout(layoutName);
|
||||||
|
|
||||||
if (layout) {
|
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())) {
|
if (!appliedActivities.contains(m_corona->activitiesConsumer()->currentActivity())) {
|
||||||
m_activitiesController->setCurrentActivity(appliedActivities[0]);
|
m_activitiesController->setCurrentActivity(nextActivity);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user