Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"serial": 0,
"flags": [],
"name": "Docked_Items",
"name[zh_CN]": "已固定项目",
"description": "The default apps which is docked when dock is started.",
"name[zh_CN]": "已固定项目(已弃用)",
"description": "`Docked_Items` is deprecated, please use `dockedElements` instead",
"permissions": "readwrite",
"visibility": "private"
},
Expand Down
13 changes: 4 additions & 9 deletions panels/dock/taskmanager/desktopfileabstractparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@ bool DesktopfileAbstractParser::isDocked()
return false;
}

QJsonObject desktopfile;
desktopfile["type"] = type();
desktopfile["id"] = id();
return TaskManagerSettings::instance()->dockedDesktopFiles().contains(desktopfile);
return TaskManagerSettings::instance()->isDocked(QStringLiteral("desktop/%1").arg(id()));
}

void DesktopfileAbstractParser::setDocked(bool docked)
Expand All @@ -147,14 +144,12 @@ void DesktopfileAbstractParser::setDocked(bool docked)
return;
}

QJsonObject desktopfile;
desktopfile["type"] = type();
desktopfile["id"] = id();
auto desktopElement = QStringLiteral("desktop/%1").arg(id());

if (docked) {
TaskManagerSettings::instance()->appnedDockedDesktopfiles(desktopfile);
TaskManagerSettings::instance()->appendDockedElements(desktopElement);
} else {
TaskManagerSettings::instance()->removeDockedDesktopfile(desktopfile);
TaskManagerSettings::instance()->removeDockedElements(desktopElement);
}

Q_EMIT dockedChanged();
Expand Down
23 changes: 0 additions & 23 deletions panels/dock/taskmanager/itemmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,6 @@ QVariant ItemModel::data(const QModelIndex &index, int role) const
return QVariant();
}

void ItemModel::moveTo(const QString &id, int dIndex)
{
// simply do nothing if dIndex is invalid
if (dIndex >= m_items.size() || dIndex < 0) {
return;
}

auto sItem = getItemById(id);
auto dItem = m_items.at(dIndex);

int sIndex = m_items.indexOf(sItem);
if (sIndex == dIndex) {
return;
}
beginMoveRows(QModelIndex(), sIndex, sIndex, QModelIndex(), dIndex > sIndex ? (dIndex + 1) : dIndex);
m_items.move(sIndex, dIndex);
endMoveRows();

if (sItem->isDocked() || dItem->isDocked()) {
TaskManagerSettings::instance()->setDockedDesktopFiles(dumpDockedItems());
}
}

QJsonArray ItemModel::dumpDockedItems() const
{
QJsonArray result;
Expand Down
1 change: 0 additions & 1 deletion panels/dock/taskmanager/itemmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class ItemModel : public QAbstractListModel
static ItemModel* instance();
Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
Q_INVOKABLE QVariant data(const QModelIndex &index, int role = ItemIdRole) const Q_DECL_OVERRIDE;
Q_INVOKABLE void moveTo(const QString &id, int index);

QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;

Expand Down
43 changes: 23 additions & 20 deletions panels/dock/taskmanager/package/TaskManager.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,15 @@ ContainmentItem {
implicitWidth: useColumnLayout ? Panel.rootObject.dockSize : (Math.min(remainingSpacesForTaskManager, appContainer.implicitWidth) + forceRelayoutWorkaround)
implicitHeight: useColumnLayout ? (Math.min(remainingSpacesForTaskManager, appContainer.implicitHeight) + forceRelayoutWorkaround) : Panel.rootObject.dockSize

// Find target index by position using ListView's built-in indexAt method instead of relying on fixed width
function findTargetIndexByPosition(dragPosition) {
if (!appContainer || !appContainer.model || appContainer.model.count === 0) {
return 0
}

// Use ListView's built-in indexAt method
let targetIndex = appContainer.indexAt(dragPosition.x, dragPosition.y)

// If no valid index found, return end position
if (targetIndex === -1) {
return appContainer.model.count
// Helper function to find the current index of an app by its appId in the visualModel
function findAppIndex(appId) {
for (let i = 0; i < visualModel.items.count; i++) {
const item = visualModel.items.get(i);
if (item.model.itemId === appId) {
return item.itemsIndex
}
}

return targetIndex
return -1
}

OverflowContainer {
Expand Down Expand Up @@ -174,19 +168,28 @@ ContainmentItem {

onPositionChanged: function(drag) {
if (launcherDndDesktopId === "") return
let dragPosition = Qt.point(drag.x, drag.y)
let targetIndex = taskmanager.findTargetIndexByPosition(dragPosition)
let targetIndex = appContainer.indexAt(drag.x, drag.y)
let appId = taskmanager.Applet.desktopIdToAppId(launcherDndDesktopId)
taskmanager.Applet.dataModel.moveTo(appId, targetIndex)
let currentIndex = taskmanager.findAppIndex(appId)
if (currentIndex !== -1 && targetIndex !== -1 && currentIndex !== targetIndex) {
visualModel.items.move(currentIndex, targetIndex)
}
}

onDropped: function(drop) {
Panel.contextDragging = false
if (launcherDndDesktopId === "") return
let dropPosition = Qt.point(drop.x, drop.y)
let targetIndex = taskmanager.findTargetIndexByPosition(dropPosition)
let targetIndex = appContainer.indexAt(drop.x, drop.y)
let appId = taskmanager.Applet.desktopIdToAppId(launcherDndDesktopId)
taskmanager.Applet.dataModel.moveTo(appId, targetIndex)
let currentIndex = taskmanager.findAppIndex(appId)
if (currentIndex !== -1 && targetIndex !== -1 && currentIndex !== targetIndex) {
visualModel.items.move(currentIndex, targetIndex)
}
let appIds = []
for (let i = 0; i < visualModel.items.count; i++) {
appIds.push(visualModel.items.get(i).model.itemId)
}
taskmanager.Applet.saveDockElementsOrder(appIds)
resetDndState()
}

Expand Down
30 changes: 21 additions & 9 deletions panels/dock/taskmanager/taskmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,17 @@ void TaskManager::handleWindowAdded(QPointer<AbstractWindow> window)
QString desktopId;
if (res.size() > 0) {
desktopId = res.first().data(m_activeAppModel->roleNames().key("desktopId")).toString();
qCDebug(taskManagerLog()) << "identify bt model:" << desktopId;
qCDebug(taskManagerLog()) << "identify by model:" << desktopId;
}

if (!desktopId.isEmpty()) {
desktopfile = DESKTOPFILEFACTORY::createById(desktopId, "amAPP");
qCDebug(taskManagerLog()) << "identify bt AM:" << desktopId;
qCDebug(taskManagerLog()) << "identify by AM:" << desktopId;
}

if (desktopfile.isNull() || !desktopfile->isValied().first) {
desktopfile = DESKTOPFILEFACTORY::createByWindow(window);
qCDebug(taskManagerLog()) << "identify bt Fallback:" << desktopId;
qCDebug(taskManagerLog()) << "identify by Fallback:" << desktopId;
}

auto appitem = desktopfile->getAppItem();
Expand Down Expand Up @@ -308,12 +308,11 @@ void TaskManager::setAppItemWindowIconGeometry(const QString& appid, QObject* re

void TaskManager::loadDockedAppItems()
{
// TODO: add support for group and dir type
for (const auto& appValueRef : TaskManagerSettings::instance()->dockedDesktopFiles()) {
auto app = appValueRef.toObject();
auto appid = app.value("id").toString();
auto type = app.value("type").toString();
auto desktopfile = DESKTOPFILEFACTORY::createById(appid, type);
// TODO: remove this function once migrated to DockItemModel (when dataModel() returns m_itemModel instead of ItemModel::instance())
for (const auto &apps : TaskManagerSettings::instance()->dockedElements()) {
// app names in dockedElements are in format of "desktop/<appid>"
auto appid = apps.split('/').last();
auto desktopfile = DESKTOPFILEFACTORY::createById(appid, "amAPP");
auto valid = desktopfile->isValied();

if (!valid.first) {
Expand Down Expand Up @@ -431,6 +430,19 @@ void TaskManager::activateWindow(uint32_t windowID)
#endif
}

void TaskManager::saveDockElementsOrder(const QStringList &appIds)
{
const QStringList &dockedElements = TaskManagerSettings::instance()->dockedElements();
QStringList newDockedElements;
for (const auto &appId : appIds) {
auto desktopElement = QString("desktop/%1").arg(appId);
if (dockedElements.contains(desktopElement) && !newDockedElements.contains(desktopElement)) {
newDockedElements.append(desktopElement);
}
}
TaskManagerSettings::instance()->setDockedElements(newDockedElements);
}

void TaskManager::modifyOpacityChanged()
{
DS_NAMESPACE::DAppletBridge appearanceBridge("org.deepin.ds.dde-appearance");
Expand Down
1 change: 1 addition & 0 deletions panels/dock/taskmanager/taskmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class TaskManager : public DS_NAMESPACE::DContainment, public AbstractTaskManage

Q_INVOKABLE void setAppItemWindowIconGeometry(const QString& appid, QObject* relativePositionItem, const int& x1, const int& y1, const int& x2, const int& y2);
Q_INVOKABLE void activateWindow(uint32_t windowID);
Q_INVOKABLE void saveDockElementsOrder(const QStringList &appIds);

Q_SIGNALS:
void dataModelChanged();
Expand Down
89 changes: 37 additions & 52 deletions panels/dock/taskmanager/taskmanagersettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
} else if (TASKMANAGER_WINDOWSPLIT_KEY == key) {
m_windowSplit = m_taskManagerDconfig->value(TASKMANAGER_WINDOWSPLIT_KEY).toBool();
Q_EMIT windowSplitChanged();
} else if (TASKMANAGER_DOCKEDITEMS_KEY == key) {
loadDockedItems();
Q_EMIT dockedItemsChanged();
Q_EMIT dockedElementsChanged();
} else if (TASKMANAGER_DOCKEDELEMENTS_KEY == key) {
m_dockedElements = m_taskManagerDconfig->value(TASKMANAGER_DOCKEDELEMENTS_KEY, {}).toStringList();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Appending elements without duplicate check may cause repeated entries.

This could lead to UI or logic errors if unique docked elements are expected.

Q_EMIT dockedElementsChanged();
Expand All @@ -56,10 +52,10 @@
m_allowForceQuit = enableStr2Bool(m_taskManagerDconfig->value(TASKMANAGER_ALLOWFOCEQUIT_KEY).toString());
m_windowSplit = m_taskManagerDconfig->value(TASKMANAGER_WINDOWSPLIT_KEY).toBool();
m_dockedElements = m_taskManagerDconfig->value(TASKMANAGER_DOCKEDELEMENTS_KEY, {}).toStringList();
loadDockedItems();
migrateFromDockedItems();
}

bool TaskManagerSettings::isAllowedForceQuit()

Check warning on line 58 in panels/dock/taskmanager/taskmanagersettings.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'isAllowedForceQuit' is never used.
{
return m_allowForceQuit;
}
Expand All @@ -81,34 +77,28 @@
m_taskManagerDconfig->setValue(TASKMANAGER_WINDOWSPLIT_KEY, m_windowSplit);
}

QStringList TaskManagerSettings::dockedElements()
QStringList TaskManagerSettings::dockedElements() const

Check warning on line 80 in panels/dock/taskmanager/taskmanagersettings.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'dockedElements' is never used.
{
return m_dockedElements;
}

void TaskManagerSettings::dockedItemsPersisted()
// elementId is like "desktop/sample.app.id"
bool TaskManagerSettings::isDocked(const QString &elementId) const
{
QStringList list;

for (auto dockedDesktopFile : m_dockedItems) {
if (!dockedDesktopFile.isObject()) {
continue;
}
YAML::Node node;
auto dockedDesktopFileObj = dockedDesktopFile.toObject();
for (auto key : dockedDesktopFileObj.keys()) {
node[key.toStdString()] = dockedDesktopFileObj[key].toString().toStdString();
}
auto str = QString::fromStdString(YAML::Dump(node));
list << str.replace("\n",",");
}

m_taskManagerDconfig->setValue(TASKMANAGER_DOCKEDITEMS_KEY, list);
return m_dockedElements.contains(elementId);
}

void TaskManagerSettings::loadDockedItems()
void TaskManagerSettings::migrateFromDockedItems()
{
while (!m_dockedItems.isEmpty()) m_dockedItems.removeLast();
if (m_taskManagerDconfig->isDefaultValue(TASKMANAGER_DOCKEDITEMS_KEY)) {
qDebug() << "Won't do migration since TASKMANAGER_DOCKEDITEMS_KEY is default value";
return;
} else if (!m_taskManagerDconfig->isDefaultValue(TASKMANAGER_DOCKEDELEMENTS_KEY)) {
qDebug() << "Won't do migration since TASKMANAGER_DOCKEDELEMENTS_KEY is not default value";
return;
}

QJsonArray legacyDockedItems;

auto dcokedDesktopFilesStrList = m_taskManagerDconfig->value(TASKMANAGER_DOCKEDITEMS_KEY).toStringList();
foreach(auto dcokedDesktopFilesStr, dcokedDesktopFilesStrList) {
Expand All @@ -126,49 +116,44 @@
auto value = it->second.as<std::string>();
dockedItem[QString::fromStdString(key)] = QString::fromStdString(value);
}
m_dockedItems.append(dockedItem);
legacyDockedItems.append(dockedItem);
}

// Migrate data under the new dconfig setting entry
if (!m_dockedItems.isEmpty() && m_dockedElements.isEmpty()) {
for (auto dockedDesktopFile : m_dockedItems) {
if (!dockedDesktopFile.isObject()) {
continue;
}
auto dockedDesktopFileObj = dockedDesktopFile.toObject();
if (dockedDesktopFileObj.contains(QStringLiteral("id")) && dockedDesktopFileObj.contains(QStringLiteral("type"))) {
m_dockedElements.append(QStringLiteral("desktop/%1").arg(dockedDesktopFileObj[QStringLiteral("id")].toString()));
}
for (auto dockedDesktopFile : std::as_const(legacyDockedItems)) {
if (!dockedDesktopFile.isObject()) {
continue;
}
auto dockedDesktopFileObj = dockedDesktopFile.toObject();
if (dockedDesktopFileObj.contains(QStringLiteral("id")) && dockedDesktopFileObj.contains(QStringLiteral("type"))) {
m_dockedElements.append(QStringLiteral("desktop/%1").arg(dockedDesktopFileObj[QStringLiteral("id")].toString()));
}
}
}

void TaskManagerSettings::setDockedDesktopFiles(QJsonArray items)
void TaskManagerSettings::saveDockedElements()
{
m_dockedItems = items;
dockedItemsPersisted();
m_taskManagerDconfig->setValue(TASKMANAGER_DOCKEDELEMENTS_KEY, m_dockedElements);
}

void TaskManagerSettings::appnedDockedDesktopfiles(QJsonObject item)
void TaskManagerSettings::setDockedElements(const QStringList &elements)

Check warning on line 138 in panels/dock/taskmanager/taskmanagersettings.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'setDockedElements' is never used.
{
m_dockedItems.append(item);
dockedItemsPersisted();
m_dockedElements = elements;
Q_EMIT dockedElementsChanged();
saveDockedElements();
}

void TaskManagerSettings::removeDockedDesktopfile(QJsonObject desktopfile)
void TaskManagerSettings::appendDockedElements(const QString &element)

Check warning on line 145 in panels/dock/taskmanager/taskmanagersettings.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'appendDockedElements' is never used.
{
for (int i = 0; i < m_dockedItems.count(); i++) {
if (m_dockedItems.at(i) == desktopfile) {
m_dockedItems.removeAt(i);
break;
}
}
dockedItemsPersisted();
m_dockedElements.append(element);
Q_EMIT dockedElementsChanged();
saveDockedElements();
}

QJsonArray TaskManagerSettings::dockedDesktopFiles()
void TaskManagerSettings::removeDockedElements(const QString &element)

Check warning on line 152 in panels/dock/taskmanager/taskmanagersettings.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'removeDockedElements' is never used.
{
return m_dockedItems;
m_dockedElements.removeAll(element);
Q_EMIT dockedElementsChanged();
saveDockedElements();
}

}
15 changes: 7 additions & 8 deletions panels/dock/taskmanager/taskmanagersettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ class TaskManagerSettings : public QObject
bool isWindowSplit();
void setWindowSplit(bool split);

void setDockedDesktopFiles(QJsonArray desktopfiles);
void appnedDockedDesktopfiles(QJsonObject desktopfile);
void removeDockedDesktopfile(QJsonObject desktopfile);
QJsonArray dockedDesktopFiles();
QStringList dockedElements();
void setDockedElements(const QStringList &elements);
void appendDockedElements(const QString &element);
void removeDockedElements(const QString &element);
QStringList dockedElements() const;
bool isDocked(const QString &elementId) const;

private:
explicit TaskManagerSettings(QObject *parent = nullptr);
inline void dockedItemsPersisted();
inline void loadDockedItems();
inline void migrateFromDockedItems();
inline void saveDockedElements();

Q_SIGNALS:
void allowedForceQuitChanged();
Expand All @@ -51,7 +51,6 @@ class TaskManagerSettings : public QObject

bool m_allowForceQuit;
bool m_windowSplit;
QJsonArray m_dockedItems;
QStringList m_dockedElements;
};
}