Skip to content

feat(gui): drag files out of the archive - #160

Draft
xevrion wants to merge 3 commits into
mainfrom
feat/gui-drag-out
Draft

xevrion wants to merge 3 commits into
mainfrom
feat/gui-drag-out

Conversation

@xevrion

@xevrion xevrion commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Rows of the contents tree can be dragged into Explorer (Windows) or the Finder (macOS), which extracts just those entries. The archive is always kept, as with "Extract selected…".

Design

Gesture (Slint, all systems). The row's TouchArea calls drag(index) once a press moves more than 5 px. The press is then marked as a drag, so its release is not a click and does not change the selection or open/close a folder. Rust (App::drag_out) decides what goes: the whole selection if the row is part of it (or inside a chosen folder), the row alone otherwise, which is what file managers do. The dragged rows are dimmed (opacity 0.5) until the drop. That is the only visual change; nothing moves. The gesture only works where "Extract selected…" does: a fresh archive, nothing running.

Extraction (src/drag.rs, shared). This goes through the engine, the same way "Extract selected…" does: session::open with only, then session::begin with keep_archive, then Run::execute. The archive is opened read-only. Path safety and selection checks are the engine's own, and there is no new extractor. The difference is the journal: Paths point into the drag's own work folder, never next to the archive. So a drag can't leave a journal that looks like a run to resume, and the main window's read handle stays valid on Windows. A drag is refused if a real journal exists next to the archive. The space plan is checked first, using the reserve from settings. The password is the one the window already holds.

Windows (platform/windows.rs). OLE DoDragDrop, using the shell's own data object (SHCreateDataObject, so the formats Explorer sets during a drag are handled) with a CF_HDROP of paths under %TEMP%\hatchzip-drag-<pid>\<n>\out\. Only DROPEFFECT_COPY is offered. The files are extracted in IDropSource::QueryContinueDrag when the button is released over a target whose last feedback was not DROPEFFECT_NONE. This happens before OLE tells the target about the drop, which is 7-Zip's old approach. Nothing is extracted while hovering, on Esc, or over a target that refuses.

  • OLE: winit already calls OleInitialize on the UI thread for its drop target. Before the drag the code calls OleInitialize again, which only counts up, and matches it with OleUninitialize.
  • Re-entrancy: DoDragDrop runs its own message loop. If it ran inside a Slint callback (which runs inside winit's event handler), winit would panic on the first WM_PAINT ("event handler is re-entrant"), because it does not buffer RedrawRequested. So the drag starts from a one-shot thread SetTimer callback. The message loop dispatches that between events, so the window keeps drawing during the drag.
  • Afterwards a synthetic PointerReleased at (-1, -1) gives Slint back the button-up that OLE swallowed.
  • Dropping the files back onto HatchZip's own window is ignored (drag::is_ours) instead of opening them as an archive.

macOS (platform/macos.rs). NSView beginDraggingSessionWithItems:event:source:, called synchronously from the Slint callback. At that point NSApp.currentEvent is the LeftMouseDragged being handled; for any other event type the drag doesn't start. The view comes from winit's raw window handle.

  • There is one NSFilePromiseProvider per row. Its delegate (HatchZipFilePromise, define_class!) gives the file name and serves writePromiseToURL: on a background NSOperationQueue.
  • The write extracts the entry into a hidden .hatchzip-drag-<pid>-<n> folder next to the destination (same disk), renames it into place, and removes the folder. It refuses to overwrite an existing path.
  • The source (HatchZipDragSource) offers Copy only and reports the end of the session. Delegates are kept for the life of the process, since a promise holds its delegate weakly.
  • The icon comes from NSWorkspace iconForFileType:. It is deprecated, but the replacement needs UTType bindings the app doesn't otherwise use.

Linux. winit has no drag source, so DRAG_OUT is false and the gesture does nothing. "Extract selected…" is the way there.

Cleanup. The Windows temp folder of this process is removed when the app exits. hatchzip-drag-* folders older than a day (left after a crash) are removed at startup. Temp files can't be removed right after the drop, because Explorer may still be copying from them.

Concurrency. While entries are being extracted for a drop (on macOS that happens after the drag ended, on a background thread), Extract and "Extract selected…" are refused with a notice. The drop reads the archive without a lock, so an in-place run must not shrink it underneath.

Trade-offs

  • Windows extracts on drop, then Explorer copies. That needs the temp disk to have room for the entries, and the window waits during the extraction (no progress shown). So a Windows drag is capped at 1 GB (DRAG_LIMIT, uncompressed size from the tree). Above that a notice points to "Extract selected…". Virtual files (CFSTR_FILEDESCRIPTOR/CFSTR_FILECONTENTS, what newer 7-Zip does) would avoid the double write and the cap, but need a full custom IDataObject with IStreams and much more unsafe code. That is left for later.
  • macOS has no cap. File promises are the proper delayed mechanism: the Finder picks the folder, the write runs off the main thread and needs no extra space beyond the entry.
  • Solid 7z. Each promised entry is extracted separately on macOS. Several rows from one solid block decode it more than once.
  • session::begin also records the temp output in the "chosen outputs" record for the archive, and the finished run forgets it. That is harmless, because drags are refused while a real journal exists. It does mean a second HatchZip process with a run in progress on the same archive would lose its record. That is an edge case and is not handled.

New messages

All four catalogs (es, hi, tr, zh_CN) are updated. Native speakers, please check:

  • Up to {} can be dragged out at once. Use Extract selected… for more.
  • Entries dragged out of the archive are still being extracted. Try again when they are done.

"Insufficient disk space" (already translated) is reused for a drag that doesn't fit.

Verified

Only cargo fmt ran locally. Builds, clippy and tests run on CI only.

  • Unit tests (drag.rs):
    • Extracting a file and a folder into a work folder matches byte for byte, the archive is unchanged and no journal is left beside it.
    • A promise write moves the entry into place, leaves no hidden folder and refuses an existing destination.
    • ../outside and missing entries are refused.
    • A partially extracted archive is refused.
    • Stale-folder cleanup removes only old hatchzip-drag-* folders.
    • Paths use the system's separators.
  • Unit test (entries.rs): dragging a selected row takes the selection; any other row goes alone; a row inside a chosen folder takes the selection.
  • UI test (tests/ui.rs, Slint testing backend): press plus a 30 px move on a chosen row hands the selection to the app; on another row, that row alone. The release after a drag chooses nothing and doesn't toggle the folder. A 3 px move is still a click.

Not verified (needs a real machine)

The OS drags can't run on CI: there is no display, and no Explorer or Finder. Nobody has run the Windows OLE path or the macOS AppKit path yet, beyond compiling on CI. In particular:

  • Explorer's behaviour with the shell data object plus CF_HDROP and extract-on-release.
  • That winit doesn't panic during DoDragDrop when started from the timer.
  • That the Finder calls the promise delegate on the given queue.
  • The synthetic pointer release.
  • The drag images.

Manual test plan

Use an archive with a top folder, several files and a subfolder, plus a password-protected ZIP. Check the archive's hash before and after every step.

Windows (Explorer)

  1. Open the archive. Drag a single file row onto the desktop. It appears with the right bytes, and the archive hash is unchanged.
  2. Ctrl+click two rows (a file and a folder). Drag one of them into an Explorer folder: both arrive, the folder with all its content.
  3. Drag an unselected row while others are selected: only that row arrives, and the selection is unchanged.
  4. Start a drag and press Esc, or release over the HatchZip window or over a non-folder target: nothing is extracted and nothing opens. %TEMP%\hatchzip-drag-<pid> has no new out content for that drag.
  5. While dragging, move over other windows: no crash, and HatchZip keeps repainting.
  6. After a drop, click rows normally: the click right after the drag works (no stuck press).
  7. Drag a selection over 1 GB (uncompressed): a notice appears and nothing is dragged.
  8. Password ZIP: open it with the password, then drag a file out. It extracts without asking again.
  9. Close HatchZip: %TEMP%\hatchzip-drag-<pid> is gone.
  10. Drop into a folder that already has the file: Explorer's own replace prompt appears.

macOS (Finder)

  1. Steps 1 to 3 and 8 as above, onto the desktop and into a Finder window.
  2. Drag a large file (several GB): the window stays responsive while the Finder waits, and no .hatchzip-drag-* folder is left next to it afterwards.
  3. Drop where the name already exists: the Finder reports an error, nothing is overwritten, and HatchZip shows a notice.
  4. While a large promise is still being written, choose Extract: the "still being extracted" notice appears.
  5. Release over the HatchZip window, or press Esc: nothing is extracted, and the next click on a row works.
  6. Drag icons look right for a file and a folder.

Linux: dragging a row does nothing; click, Ctrl+click and Shift+click still work.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant