MultipleLayouts:update Layouts menu

pull/2/head
Michail Vourlakos 7 years ago
parent 60cc89d595
commit e4cd47ca3e

@ -2067,11 +2067,20 @@ void DockView::addContainmentActions(QMenu *desktopMenu, QEvent *event)
layoutsAction->setText(i18n("Layouts"));
layoutsAction->setStatusTip(i18n("Switch to another layout"));
QStringList activeLayouts = dockCorona->layoutManager()->activeLayoutsNames();
Dock::LayoutsMemoryUsage memoryUsage = dockCorona->layoutManager()->memoryUsage();
QString currentName = dockCorona->layoutManager()->currentLayoutName();
foreach (auto layout, dockCorona->layoutManager()->menuLayouts()) {
QAction *layoutAction = new QAction(layout, layoutsMenu);
QString currentText = (memoryUsage == Latte::Dock::MultipleLayouts && layout == currentName) ?
(" " + i18nc("current layout", "(Current)")) : "";
QString layoutName = layout + currentText;
QAction *layoutAction = new QAction(layoutName, layoutsMenu);
layoutAction->setCheckable(true);
if (layout == dockCorona->universalSettings()->currentLayoutName()) {
if (activeLayouts.contains(layout)) {
layoutAction->setChecked(true);
} else {
layoutAction->setChecked(false);

@ -285,6 +285,11 @@ Dock::LayoutsMemoryUsage LayoutManager::memoryUsage() const
return m_corona->universalSettings()->layoutsMemoryUsage();
}
int LayoutManager::layoutsMemoryUsage()
{
return (int)m_corona->universalSettings()->layoutsMemoryUsage();
}
void LayoutManager::setMemoryUsage(Dock::LayoutsMemoryUsage memoryUsage)
{
m_corona->universalSettings()->setLayoutsMemoryUsage(memoryUsage);
@ -356,6 +361,27 @@ QHash<const Plasma::Containment *, DockView *> *LayoutManager::layoutDockViews(c
return nullptr;
}
QStringList LayoutManager::activeLayoutsNames()
{
QStringList names;
if (memoryUsage() == Dock::SingleLayout) {
names << currentLayoutName();
} else {
for (int i = 0; i < m_activeLayouts.size(); ++i) {
Layout *layout = m_activeLayouts.at(i);
if (layout->isOriginalLayout()) {
names << layout->name();
}
}
}
return names;
}
Layout *LayoutManager::activeLayout(QString id) const
{
for (int i = 0; i < m_activeLayouts.size(); ++i) {
@ -610,7 +636,7 @@ bool LayoutManager::switchToLayout(QString layoutName)
}
}
if (toActivities.isEmpty() && activeForOrphans) {
if (toActivities.isEmpty() && activeForOrphans && (toLayout.name() != activeForOrphans->name())) {
emit currentLayoutIsSwitching(activeForOrphans->name());
}
}

@ -105,13 +105,17 @@ public:
void importPresets(bool includeDefault = false);
public slots:
Q_INVOKABLE void showLayoutConfigDialog();
//! switch to specified layout
Q_INVOKABLE bool switchToLayout(QString layoutName);
Q_INVOKABLE int layoutsMemoryUsage();
//! creates a new layout with layoutName based on the preset
Q_INVOKABLE QString newLayout(QString layoutName, QString preset = i18n("Default"));
Q_INVOKABLE void showLayoutConfigDialog();
Q_INVOKABLE QStringList activeLayoutsNames();
signals:
void activeLayoutsChanged();
@ -120,7 +124,6 @@ signals:
void currentLayoutNameChanged();
void launchersSignalsChanged();
void layoutsChanged();
void memoryUsageChanged();
void menuLayoutsChanged();
void currentLayoutIsSwitching(QString layoutName);

@ -839,15 +839,21 @@ PlasmaComponents.ContextMenu {
}
var layouts = latteDock.universalLayoutManager.menuLayouts;
var activeLayouts = latteDock.universalLayoutManager.activeLayoutsNames();
var memoryUsage = latteDock.universalLayoutManager.layoutsMemoryUsage();
var currentName = latteDock.universalLayoutManager.currentLayoutName;
for (var i = 0; i < layouts.length; ++i) {
var layout = layouts[i];
var currentText = (memoryUsage === Latte.Dock.MultipleLayouts && layout === currentName)
? " " + i18nc("current layout", "(Current)"): ""
var menuItem = menu.newMenuItem(layoutsMenu);
menuItem.text = layout;
menuItem.text = layout + currentText;
menuItem.checkable = true;
menuItem.checked = Qt.binding( (function(layout) {
return function() {
return (layout===latteDock.universalSettings.currentLayoutName);
return (activeLayouts.indexOf(layout)>=0);
};
})(layout));
menuItem.clicked.connect((function(layout) {

Loading…
Cancel
Save