mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
save and restore app order
by default apps are in alphabetical order but the user can drag and drop them around for personalized order
This commit is contained in:
parent
d0756040ad
commit
25e1e12c4d
4 changed files with 70 additions and 3 deletions
|
|
@ -9,6 +9,9 @@
|
||||||
<entry name="AppletOrder" type="String">
|
<entry name="AppletOrder" type="String">
|
||||||
<label>encoded order of items</label>
|
<label>encoded order of items</label>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry name="AppOrder" type="StringList">
|
||||||
|
<label>order of apps</label>
|
||||||
|
</entry>
|
||||||
</group>
|
</group>
|
||||||
|
|
||||||
</kcfg>
|
</kcfg>
|
||||||
|
|
|
||||||
|
|
@ -92,10 +92,16 @@ Item {
|
||||||
LayoutManager.lastSpacer = appletsSpace.lastSpacer;
|
LayoutManager.lastSpacer = appletsSpace.lastSpacer;
|
||||||
LayoutManager.restore();
|
LayoutManager.restore();
|
||||||
applicationsView.contentY = -root.height;
|
applicationsView.contentY = -root.height;
|
||||||
|
|
||||||
|
appListModel.appOrder = plasmoid.configuration.AppOrder;
|
||||||
|
appListModel.loadApplications();
|
||||||
}
|
}
|
||||||
|
|
||||||
SatelliteComponents.ApplicationListModel {
|
SatelliteComponents.ApplicationListModel {
|
||||||
id: appListModel
|
id: appListModel
|
||||||
|
onAppOrderChanged: {
|
||||||
|
plasmoid.configuration.AppOrder = appListModel.appOrder;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@
|
||||||
ApplicationListModel::ApplicationListModel(QObject *parent)
|
ApplicationListModel::ApplicationListModel(QObject *parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
{
|
{
|
||||||
loadApplications();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationListModel::~ApplicationListModel()
|
ApplicationListModel::~ApplicationListModel()
|
||||||
|
|
@ -55,6 +54,10 @@ QHash<int, QByteArray> ApplicationListModel::roleNames() const
|
||||||
return roleNames;
|
return roleNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool appNameLessThan(const ApplicationData &a1, const ApplicationData &a2)
|
||||||
|
{
|
||||||
|
return a1.name.toLower() < a2.name.toLower();
|
||||||
|
}
|
||||||
|
|
||||||
void ApplicationListModel::loadApplications()
|
void ApplicationListModel::loadApplications()
|
||||||
{
|
{
|
||||||
|
|
@ -64,6 +67,9 @@ void ApplicationListModel::loadApplications()
|
||||||
if (!group || !group->isValid()) return;
|
if (!group || !group->isValid()) return;
|
||||||
KServiceGroup::List subGroupList = group->entries(true);
|
KServiceGroup::List subGroupList = group->entries(true);
|
||||||
|
|
||||||
|
QMap<int, ApplicationData> orderedList;
|
||||||
|
QList<ApplicationData> unorderedList;
|
||||||
|
|
||||||
// Iterate over all entries in the group
|
// Iterate over all entries in the group
|
||||||
for(KServiceGroup::List::ConstIterator it = subGroupList.begin();it != subGroupList.end(); it++) {
|
for(KServiceGroup::List::ConstIterator it = subGroupList.begin();it != subGroupList.end(); it++) {
|
||||||
KSycocaEntry::Ptr groupEntry = (*it);
|
KSycocaEntry::Ptr groupEntry = (*it);
|
||||||
|
|
@ -85,13 +91,22 @@ void ApplicationListModel::loadApplications()
|
||||||
data.icon = service->icon();
|
data.icon = service->icon();
|
||||||
data.storageId = service->storageId();
|
data.storageId = service->storageId();
|
||||||
data.entryPath = service->exec();
|
data.entryPath = service->exec();
|
||||||
m_applicationList << data;
|
|
||||||
|
if (m_appPositions.contains(service->storageId())) {
|
||||||
|
orderedList[m_appPositions.value(service->storageId())] = data;
|
||||||
|
} else {
|
||||||
|
unorderedList << data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(unorderedList.begin(), unorderedList.end(), appNameLessThan);
|
||||||
|
m_applicationList << orderedList.values();
|
||||||
|
m_applicationList << unorderedList;
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
emit countChanged();
|
emit countChanged();
|
||||||
|
|
@ -143,6 +158,19 @@ Q_INVOKABLE void ApplicationListModel::moveItem(int row, int destination)
|
||||||
beginMoveRows(QModelIndex(), row, row, QModelIndex(), destination);
|
beginMoveRows(QModelIndex(), row, row, QModelIndex(), destination);
|
||||||
ApplicationData data = m_applicationList.takeAt(row);
|
ApplicationData data = m_applicationList.takeAt(row);
|
||||||
m_applicationList.insert(destination, data);
|
m_applicationList.insert(destination, data);
|
||||||
|
|
||||||
|
|
||||||
|
m_appOrder.clear();
|
||||||
|
m_appPositions.clear();
|
||||||
|
int i = 0;
|
||||||
|
for (auto app : m_applicationList) {
|
||||||
|
m_appOrder << app.storageId;
|
||||||
|
m_appPositions[app.storageId] = i;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
emit appOrderChanged();
|
||||||
endMoveRows();
|
endMoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,4 +185,25 @@ void ApplicationListModel::runApplication(const QString &storageId)
|
||||||
QProcess::startDetached(service->exec());
|
QProcess::startDetached(service->exec());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList ApplicationListModel::appOrder() const
|
||||||
|
{
|
||||||
|
return m_appOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApplicationListModel::setAppOrder(const QStringList &order)
|
||||||
|
{
|
||||||
|
if (m_appOrder == order) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_appOrder = order;
|
||||||
|
m_appPositions.clear();
|
||||||
|
int i = 0;
|
||||||
|
for (auto app : m_appOrder) {
|
||||||
|
m_appPositions[app] = i;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
emit appOrderChanged();
|
||||||
|
}
|
||||||
|
|
||||||
#include "applicationlistmodel.moc"
|
#include "applicationlistmodel.moc"
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ class ApplicationListModel : public QAbstractListModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
||||||
|
Q_PROPERTY(QStringList appOrder READ appOrder WRITE setAppOrder NOTIFY appOrderChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ApplicationListModel(QObject *parent = 0);
|
ApplicationListModel(QObject *parent = 0);
|
||||||
|
|
@ -59,16 +60,24 @@ public:
|
||||||
ApplicationOriginalRowRole = Qt::UserRole + 6
|
ApplicationOriginalRowRole = Qt::UserRole + 6
|
||||||
};
|
};
|
||||||
|
|
||||||
|
QStringList appOrder() const;
|
||||||
|
void setAppOrder(const QStringList &order);
|
||||||
|
|
||||||
Q_INVOKABLE void moveItem(int row, int order);
|
Q_INVOKABLE void moveItem(int row, int order);
|
||||||
|
|
||||||
Q_INVOKABLE void runApplication(const QString &storageId);
|
Q_INVOKABLE void runApplication(const QString &storageId);
|
||||||
|
|
||||||
|
Q_INVOKABLE void loadApplications();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void countChanged();
|
void countChanged();
|
||||||
|
void appOrderChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<ApplicationData> m_applicationList;
|
QList<ApplicationData> m_applicationList;
|
||||||
void loadApplications();
|
|
||||||
|
QStringList m_appOrder;
|
||||||
|
QHash<QString, int> m_appPositions;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // APPLICATIONLISTMODEL_H
|
#endif // APPLICATIONLISTMODEL_H
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue