Skip to content

Auto-close extracted Notepad tabs after safe extraction #13

@djdarcy

Description

@djdarcy

Auto-close extracted Notepad tabs after safe extraction

Problem

After running notepad-cleanup extract, users are left with all their Notepad windows still open -- often 30+ windows with multiple tabs each. The whole point of extracting was to archive and organize that content, but the cleanup of the source windows is entirely manual: clicking through each window, closing tabs one by one, handling "save?" prompts.

Current workaround:

  • Manually close each window/tab by hand
  • Or taskkill /IM notepad.exe /F which kills everything with no selectivity

Neither is good. The first is tedious with 30+ windows. The second is dangerous -- it kills ALL Notepad instances including ones you're actively using that weren't part of the extraction.

Proposed solution

Add a close command (or --close flag on extract) that programmatically closes the tabs/windows that were successfully extracted:

# After extraction, close all extracted tabs
notepad-cleanup close --last

# Or as part of the extract workflow
notepad-cleanup extract --close

# Close with confirmation per window
notepad-cleanup close --last --confirm

# Force close (skip "save?" prompts)
notepad-cleanup close --last --force

# Dry run -- show what would be closed without doing it
notepad-cleanup close --last --dry-run

Tab closure strategy

The tool should navigate each Notepad window and close tabs that match the extraction manifest:

  1. Read the manifest from the extraction folder to know which windows/tabs were extracted
  2. For each window in the manifest:
    a. Connect via UIA (same as Phase 2 extraction)
    b. For each tab, verify content matches the extracted file (hash comparison)
    c. Close the tab using Ctrl+W or UIA close button
    d. Handle the "save?" dialog: click "Don't Save" (or "Save" if --save-first)
  3. If a window has no remaining tabs, it closes automatically
  4. If content doesn't match (user edited since extraction), skip that tab and warn

Tab identification and safety

Scenario Behavior
Tab content matches extracted file exactly Close the tab
Tab was modified since extraction Skip, warn user ("tab01.txt was modified since extraction")
Tab is a new unsaved tab not in manifest Skip (not ours to close)
Window has mix of extracted + non-extracted tabs Close only extracted tabs, leave others
"Do you want to save?" dialog appears Click "Don't Save" (or "Save" with --save-first)
Tab fails to close Warn and continue to next tab
--force flag Close without content verification

Implementation approach

Phase 1: Basic close command

  • New close command in cli.py
  • Reads manifest from --last or explicit folder
  • Connects to each window via UIA (reuses discovery.py patterns)
  • Hashes current tab content and compares to manifest
  • Closes matching tabs via Ctrl+W keystroke
  • Handles "save?" dialog via UIA button detection

Phase 2: Smart close

  • Track which tabs were already linked (from compare --link) vs genuinely new
  • Option to close only linked/duplicate tabs (safe -- the canonical copy exists elsewhere)
  • Integration with run command: notepad-cleanup run --close

Key modules affected:

  • cli.py -- new close command
  • extractor.py -- reuse UIA connection patterns, add tab close logic
  • Possibly new closer.py module to keep extraction and closing separate

Design considerations

  • UIA Ctrl+W vs close button: Ctrl+W closes the active tab in Notepad. We'd need to select the tab first (already done in Phase 2), then send Ctrl+W. The "save?" dialog appears as a UIA window we can detect and dismiss
  • Window handle stability: Notepad window handles stay stable during the session, and the manifest records them. But if the user closed/reopened Notepad since extraction, handles are stale. Need to fall back to content matching
  • Timing: After each Ctrl+W, need a brief delay for the UI to update before moving to the next tab. Similar to the 0.15s delay in Phase 2 extraction
  • All-windows kill safety: The --force flag should still only close windows that were in the extraction manifest, never arbitrary Notepad instances
  • Unsaved content: By default, choose "Don't Save" since we already have the content extracted. The --save-first flag would click "Save" instead for users who want to preserve to the original file location

Acceptance criteria

  • notepad-cleanup close --last closes tabs that match the most recent extraction
  • Content verification: tabs modified since extraction are skipped with a warning
  • "Save?" dialog handled automatically (Don't Save by default, Save with --save-first)
  • --dry-run shows which tabs would be closed without closing them
  • --confirm prompts per window before closing
  • --force skips content verification
  • Windows with no remaining tabs close automatically
  • Non-extracted tabs in mixed windows are preserved
  • --close flag on extract runs close after successful extraction
  • Stale window handles fall back to content-based matching
  • Works with --last and ... notation

Related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestextractionText extraction from NotepadfeatureNew feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions