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
2 changes: 1 addition & 1 deletion panels/dock/taskmanager/dockcombinemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ QVariant DockCombineModel::data(const QModelIndex &index, int role) const
auto res = RoleCombineModel::data(index, m_roleMaps.value(TaskManager::DesktopIdRole)).toString();
if (res.isEmpty()) {
auto data = RoleCombineModel::data(index, m_roleMaps.value(TaskManager::IdentityRole)).toStringList();
res = data.value(0, "");
res = data.join("-");
}
return res;
}
Expand Down
48 changes: 39 additions & 9 deletions panels/dock/taskmanager/dockglobalelementmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,55 @@ DockGlobalElementModel::DockGlobalElementModel(QAbstractItemModel *appsModel, Do
auto index = m_activeAppModel->index(i, 0);
auto desktopId = index.data(TaskManager::DesktopIdRole).toString();

auto it = std::find_if(m_data.begin(), m_data.end(), [this, &desktopId](auto &data) {
return m_appsModel == std::get<1>(data) && desktopId == std::get<0>(data);
if (desktopId.isEmpty())
continue;
//将同一应用的窗口添加到一起
// Find the first occurrence of this app in m_data (either docked item or existing window)
auto firstIt = std::find_if(m_data.begin(), m_data.end(), [&desktopId](const auto &data) {
return std::get<0>(data) == desktopId;
});

if (it != m_data.end()) {
*it = std::make_tuple(desktopId, m_activeAppModel, i);
auto pIndex = this->index(it - m_data.begin(), 0);
Q_EMIT dataChanged(pIndex, pIndex, {TaskManager::ActiveRole, TaskManager::AttentionRole, TaskManager::WindowsRole, TaskManager::MenusRole});

} else {
if (firstIt == m_data.end()) {
// No docked item or existing window yet, append to the end
beginInsertRows(QModelIndex(), m_data.size(), m_data.size());
m_data.append(std::make_tuple(desktopId, m_activeAppModel, i));
endInsertRows();
continue;
}

// If the first occurrence still comes from m_appsModel, this is the first window:
// reuse the docked position and turn it into a running window.
if (std::get<1>(*firstIt) == m_appsModel) {
*firstIt = std::make_tuple(desktopId, m_activeAppModel, i);
auto pIndex = this->index(firstIt - m_data.begin(), 0);
Q_EMIT dataChanged(pIndex,
pIndex,
{TaskManager::ActiveRole,
TaskManager::AttentionRole,
TaskManager::WindowsRole,
TaskManager::MenusRole,
TaskManager::WinTitleRole});
continue;
}

// There are already windows for this app: insert the new window
// right after the last existing one so that all windows stay together.
auto lastIt = firstIt;
while (lastIt + 1 != m_data.end() && std::get<0>(*(lastIt + 1)) == desktopId) {
++lastIt;
}

auto insertRow = (lastIt - m_data.begin()) + 1;
beginInsertRows(QModelIndex(), insertRow, insertRow);
m_data.insert(lastIt + 1, std::make_tuple(desktopId, m_activeAppModel, i));
endInsertRows();
}

std::for_each(m_data.begin(), m_data.end(), [this, first, last](auto &data) {
if (std::get<1>(data) == m_activeAppModel && std::get<2>(data) > first) {
data = std::make_tuple(std::get<0>(data), std::get<1>(data), std::get<2>(data) + ((last - first) + 1));
data = std::make_tuple(std::get<0>(data),
std::get<1>(data),
std::get<2>(data) + ((last - first) + 1));
}
});
},
Expand Down