(archive: boolean)
| 473 | } |
| 474 | |
| 475 | private async batchArchive(archive: boolean): Promise<void> { |
| 476 | const { plugin, selectedPaths, onUpdate } = this.options; |
| 477 | const count = selectedPaths.length; |
| 478 | |
| 479 | try { |
| 480 | new Notice(`${archive ? "Archiving" : "Unarchiving"} ${count} tasks...`); |
| 481 | |
| 482 | let successCount = 0; |
| 483 | let failCount = 0; |
| 484 | |
| 485 | for (const path of selectedPaths) { |
| 486 | try { |
| 487 | const task = await plugin.cacheManager.getTaskInfo(path); |
| 488 | if (task && task.archived !== archive) { |
| 489 | await plugin.toggleTaskArchive(task); |
| 490 | successCount++; |
| 491 | } else if (task) { |
| 492 | // Task already in desired state |
| 493 | successCount++; |
| 494 | } else { |
| 495 | failCount++; |
| 496 | } |
| 497 | } catch (e) { |
| 498 | tasknotesLogger.error(`[BatchContextMenu] Failed to archive task ${path}:`, { |
| 499 | category: "persistence", |
| 500 | operation: "archive-task", |
| 501 | error: e, |
| 502 | }); |
| 503 | failCount++; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | if (failCount === 0) { |
| 508 | new Notice(`${archive ? "Archived" : "Unarchived"} ${successCount} tasks`); |
| 509 | } else { |
| 510 | new Notice( |
| 511 | `${archive ? "Archived" : "Unarchived"} ${successCount} tasks, ${failCount} failed` |
| 512 | ); |
| 513 | } |
| 514 | |
| 515 | // Clear selection after successful batch operation |
| 516 | plugin.taskSelectionService?.clearSelection(); |
| 517 | plugin.taskSelectionService?.exitSelectionMode(); |
| 518 | |
| 519 | onUpdate?.(); |
| 520 | } catch (error) { |
| 521 | tasknotesLogger.error("[BatchContextMenu] Batch archive failed:", { |
| 522 | category: "persistence", |
| 523 | operation: "batch-archive", |
| 524 | error: error, |
| 525 | }); |
| 526 | new Notice("Failed to archive tasks"); |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | private async batchDelete(): Promise<void> { |
| 531 | const { plugin, selectedPaths, onUpdate } = this.options; |
no test coverage detected