| 182 | } |
| 183 | |
| 184 | bool ResourceFolderModel::setResourceEnabled(const QModelIndexList &indexes, EnableAction action) |
| 185 | { |
| 186 | if (!m_can_interact) |
| 187 | return false; |
| 188 | |
| 189 | if (indexes.isEmpty()) |
| 190 | return true; |
| 191 | |
| 192 | bool succeeded = true; |
| 193 | for (auto const& idx : indexes) { |
| 194 | if (!validateIndex(idx) || idx.column() != 0) |
| 195 | continue; |
| 196 | |
| 197 | int row = idx.row(); |
| 198 | |
| 199 | auto& resource = m_resources[row]; |
| 200 | |
| 201 | // Preserve the row, but change its ID |
| 202 | auto old_id = resource->internal_id(); |
| 203 | if (!resource->enable(action)) { |
| 204 | succeeded = false; |
| 205 | continue; |
| 206 | } |
| 207 | |
| 208 | auto new_id = resource->internal_id(); |
| 209 | if (m_resources_index.contains(new_id)) { |
| 210 | // FIXME: https://github.com/PolyMC/PolyMC/issues/550 |
| 211 | } |
| 212 | |
| 213 | m_resources_index.remove(old_id); |
| 214 | m_resources_index[new_id] = row; |
| 215 | |
| 216 | emit dataChanged(index(row, 0), index(row, columnCount(QModelIndex()) - 1)); |
| 217 | } |
| 218 | |
| 219 | return succeeded; |
| 220 | } |
| 221 | |
| 222 | static QMutex s_update_task_mutex; |
| 223 | bool ResourceFolderModel::update() |
no test coverage detected