1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-29 07:21:49 +03:00

MultipleLayouts:Rename layout name runtime

--In MultipleLayouts we dont need to close the
active layout to rename it. We can do it without
need to close it and reopen that layout.
This commit is contained in:
Michail Vourlakos 2018-01-15 23:04:03 +02:00
parent 1e97609067
commit 308d99e215
4 changed files with 51 additions and 15 deletions

View File

@ -40,9 +40,7 @@ Layout::Layout(QObject *parent, QString layoutFile, QString assignedName)
assignedName = layoutName(layoutFile);
}
m_filePtr = KSharedConfig::openConfig(layoutFile);
m_layoutGroup = KConfigGroup(m_filePtr, "LayoutSettings");
//!this order is important because setFile initializes also the m_layoutGroup
setFile(layoutFile);
setName(assignedName);
loadConfig();
@ -53,7 +51,6 @@ Layout::Layout(QObject *parent, QString layoutFile, QString assignedName)
Layout::~Layout()
{
if (!m_layoutFile.isEmpty()) {
//saveConfig();
m_layoutGroup.sync();
}
}
@ -64,7 +61,9 @@ void Layout::syncToLayoutFile()
return;
}
KConfigGroup oldContainments = KConfigGroup(m_filePtr, "Containments");
KSharedConfigPtr filePtr = KSharedConfig::openConfig(m_layoutFile);
KConfigGroup oldContainments = KConfigGroup(filePtr, "Containments");
oldContainments.deleteGroup();
oldContainments.sync();
@ -215,6 +214,24 @@ void Layout::setName(QString name)
emit nameChanged();
}
void Layout::renameLayout(QString newName)
{
if (m_layoutFile != Importer::layoutFilePath(newName)) {
setFile(Importer::layoutFilePath(newName));
}
if (m_layoutName != newName) {
setName(newName);
}
//! thus this is a linked file
if (m_corona) {
foreach (auto containment, m_containments) {
containment->config().writeEntry("layoutId", m_layoutName);
}
}
}
QString Layout::color() const
{
return m_color;
@ -245,6 +262,10 @@ void Layout::setFile(QString file)
qDebug() << "Layout file:" << file;
m_layoutFile = file;
KSharedConfigPtr filePtr = KSharedConfig::openConfig(m_layoutFile);
m_layoutGroup = KConfigGroup(filePtr, "LayoutSettings");
emit fileChanged();
}
@ -799,10 +820,10 @@ void Layout::importToCorona()
if (copyFile.exists())
copyFile.remove();
KSharedConfigPtr filePtr = KSharedConfig::openConfig(m_layoutFile);
KSharedConfigPtr newFile = KSharedConfig::openConfig(temp1File);
KConfigGroup copyGroup = KConfigGroup(newFile, "Containments");
KConfigGroup current_containments = KConfigGroup(m_filePtr, "Containments");
KConfigGroup current_containments = KConfigGroup(filePtr, "Containments");
current_containments.copyTo(&copyGroup);

View File

@ -82,6 +82,8 @@ public:
static QString layoutName(const QString &fileName);
void renameLayout(QString newName);
QStringList unloadedContainmentsIds();
//! this function needs the layout to have first set the corona through initToCorona() function
@ -141,7 +143,6 @@ private:
DockCorona *m_corona{nullptr};
KConfigGroup m_layoutGroup;
KSharedConfigPtr m_filePtr;
QList<Plasma::Containment *> m_containments;

View File

@ -828,6 +828,8 @@ bool LayoutConfigDialog::saveAllChanges()
QString switchToLayout;
QHash<QString, Layout *> activeLayoutsToRename;
for (int i = 0; i < m_model->rowCount(); ++i) {
QString id = m_model->data(m_model->index(i, IDCOLUMN), Qt::DisplayRole).toString();
QString color = m_model->data(m_model->index(i, COLORCOLUMN), Qt::BackgroundRole).toString();
@ -845,7 +847,7 @@ bool LayoutConfigDialog::saveAllChanges()
}
//qDebug() << i << ". " << id << " - " << color << " - " << name << " - " << menu << " - " << lActivities;
Layout *activeLayout = m_manager->activeLayout(name);
Layout *activeLayout = m_manager->activeLayout(m_layouts[id]->name());
Layout *layout = activeLayout ? activeLayout : m_layouts[id];
@ -861,14 +863,19 @@ bool LayoutConfigDialog::saveAllChanges()
layout->setActivities(cleanedActivities);
}
//!if the layout name changed or when the layout path is a temporary one
//! If the layout name changed OR the layout path is a temporary one
if (layout->name() != name || (id.startsWith("/tmp/"))) {
//! If the layout is Active in MultipleLayouts
if (m_manager->memoryUsage() == Dock::MultipleLayouts && activeLayout) {
qDebug() << " Active Layout Should Be Renamed From : " << layout->name() << " TO :: " << name;
activeLayoutsToRename[name] = layout;
}
QString tempFile = layoutTempDir.path() + "/" + QString(layout->name() + ".layout.latte");
qDebug() << "new temp file ::: " << tempFile;
if (layout->name() == m_manager->currentLayoutName()) {
if ((m_manager->memoryUsage() == Dock::SingleLayout) && (layout->name() == m_manager->currentLayoutName())) {
switchToLayout = name;
//m_manager->corona()->unload();
}
layout = m_layouts.take(id);
@ -914,6 +921,13 @@ bool LayoutConfigDialog::saveAllChanges()
}
}
if (m_manager->memoryUsage() == Dock::MultipleLayouts) {
foreach (auto newLayoutName, activeLayoutsToRename.keys()) {
qDebug() << " Active Layout Is Renamed From : " << activeLayoutsToRename[newLayoutName]->name() << " TO :: " << newLayoutName;
activeLayoutsToRename[newLayoutName]->renameLayout(newLayoutName);
}
}
m_manager->loadLayouts();
if (!switchToLayout.isNull()) {

View File

@ -669,6 +669,9 @@ bool LayoutManager::switchToLayout(QString layoutName)
void LayoutManager::syncMultipleLayoutsToActivities(QString layoutForOrphans)
{
qDebug() << " ---- --------- ------ syncMultipleLayoutsToActivities ------- ";
qDebug() << " ---- --------- ------ ------------------------------- ------- ";
QStringList layoutsToUnload;
QStringList layoutsToLoad;
layoutsToLoad << Layout::MultipleLayoutsName;
@ -704,9 +707,6 @@ void LayoutManager::syncMultipleLayoutsToActivities(QString layoutForOrphans)
}
}
qDebug() << " ---- --------- ------ syncMultipleLayoutsToActivities ------- ";
qDebug() << " ---- --------- ------ ------------------------------- ------- ";
//! Unload no needed Layouts
foreach (auto layoutName, layoutsToUnload) {
if (layoutName != Layout::MultipleLayoutsName) {