Skip to content

Conversation

@PrayagCodes
Copy link

Description

This PR adds a "Duplicate" option to the file context menu, allowing users to create a copy of a file in the same directory with automatic name deduplication.

Problem Statement

Currently, users must manually use Copy (Ctrl+C) and Paste (Ctrl+V) to duplicate files, which doesn't automatically generate unique filenames. This creates friction in the user workflow and requires manual renaming to avoid conflicts.

Solution

Added a "Duplicate" menu item to the file context menu that:

  • Creates a copy of the selected file in the same directory
  • Automatically generates unique filenames using sequential numbering
  • Only appears for files (not directories)
  • Is excluded from trash/trashed items

Changes Made

Frontend Changes

  • src/gui/src/UI/UIItem.js: Added duplicate menu item with onClick handler (lines 1250-1271)
  • src/gui/src/i18n/translations/*.js: Added 'duplicate' translation key to all 37 language files

Technical Implementation

  • Uses existing puter.fs.copy() API with dedupeName: true parameter
  • Leverages backend's automatic filename deduplication logic
  • Follows existing naming pattern: filename (1).ext, filename (2).ext, etc.
  • Includes error handling with console logging

Testing

Manual Testing Performed

  • Basic file duplication creates filename (1).ext
  • Sequential duplicates create filename (2).ext, filename (3).ext, etc.
  • Works with various file types: .txt, .html, .png, .zip
  • Handles complex filenames: spaces, multiple extensions, no extensions
  • Correctly hidden for directories
  • Correctly hidden in trash

Test Cases

  1. Right-click file → "Duplicate" appears in menu
  2. Click "Duplicate" → new file appears with unique name
  3. Duplicate again → sequential number increments
  4. Right-click folder → "Duplicate" does not appear
  5. Right-click file in trash → "Duplicate" does not appear

Add 'Duplicate' option to file context menu that creates a copy of the
selected file in the same directory with automatic name deduplication.

Changes:
- Add 'duplicate' translation key to all 37 language files
- Implement duplicate menu item in UIItem.js context menu
- Use puter.fs.copy() API with dedupeName parameter for automatic
  unique filename generation (e.g., 'file (1).txt', 'file (2).txt')
- Restrict duplicate option to files only (not directories)
- Exclude duplicate option from trash and trashed items

The feature leverages existing backend deduplication logic that
automatically handles naming conflicts by appending sequential numbers
to duplicate filenames.

Implementation details
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