! * \brief Computes a diff between the present ignore patterns and staged changes. */
| 193 | * \brief Computes a diff between the present ignore patterns and staged changes. |
| 194 | */ |
| 195 | QString SyncthingFileModel::computeIgnorePatternDiff() |
| 196 | { |
| 197 | auto diff = QString(); |
| 198 | auto index = std::size_t(); |
| 199 | const auto appendNewLines = [&diff](const auto &lines) { |
| 200 | for (const auto &line : lines) { |
| 201 | diff.append(QChar('+')); |
| 202 | diff.append(line); |
| 203 | diff.append(QChar('\n')); |
| 204 | } |
| 205 | }; |
| 206 | if (const auto change = m_stagedChanges.find(beforeFirstLine); change != m_stagedChanges.end()) { |
| 207 | appendNewLines(change->prepend); |
| 208 | appendNewLines(change->append); |
| 209 | } |
| 210 | for (const auto &pattern : m_presentIgnorePatterns) { |
| 211 | auto change = m_stagedChanges.find(index++); |
| 212 | if (change != m_stagedChanges.end()) { |
| 213 | if (change->replace && !change->prepend.isEmpty() && change->prepend.back() == pattern.pattern) { |
| 214 | change->prepend.removeLast(); |
| 215 | change->replace = false; |
| 216 | } |
| 217 | appendNewLines(change->prepend); |
| 218 | } |
| 219 | diff.append(change == m_stagedChanges.end() || !change->replace ? QChar(' ') : QChar('-')); |
| 220 | diff.append(pattern.pattern); |
| 221 | diff.append(QChar('\n')); |
| 222 | if (change != m_stagedChanges.end()) { |
| 223 | appendNewLines(change->append); |
| 224 | } |
| 225 | } |
| 226 | return diff; |
| 227 | } |
| 228 | |
| 229 | QString SyncthingFileModel::availabilityNote(const SyncthingItem *item) const |
| 230 | { |