Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use NSDragOperation #981

Open
onmyway133 opened this issue Sep 23, 2024 · 0 comments
Open

How to use NSDragOperation #981

onmyway133 opened this issue Sep 23, 2024 · 0 comments

Comments

@onmyway133
Copy link
Owner

NSDragOperation represent which operations the dragging source can perform on dragging items.

There are several types of drag operations, and each one has a different purpose and visual cue.

Copy Operation .copy

  • What It Does: The item you're dragging will be copied. This means the original stays in place, and a duplicate is created in the new location.
  • When to Use: Use this when you want to create a copy of a file or item, without removing it from the original spot.
    Cursor Symbol: The cursor shows a small "+" symbol to indicate that the item will be copied.
  • Example: Copying a file from one folder to another.
    swift

Move Operation .move

The item will be moved from the original location to the new one. The original item disappears from its old location.

  • When to Use: Use this when you want to move an item to a new location without keeping it in the original place.
  • Cursor Symbol: The cursor shows the normal arrow (or sometimes an open hand), which indicates that the item will be moved.
  • Example: Moving an item within the same list or from one folder to another.
    swift

Link Operation .link

A link (or alias) to the original item is created in the new location, but the actual item stays in the original place.

  • When to Use: Use this when you want to create a shortcut or link to the item without moving or copying it.
  • Cursor Symbol: The cursor shows a small arrow in the bottom corner, indicating that a link will be created.
  • Example: Creating a shortcut to a file in a different folder.
    swift
  1. Delete Operation .delete

The item will be deleted.

  • When to Use: Use this when you want to remove an item, like dragging a file to the Trash.
  • Cursor Symbol: The cursor shows a "X" symbol, indicating that the item will be deleted.
  • Example: Dragging files to the Trash to delete them.

Generic Operation .generic

This is a general-purpose operation where the action is not specifically a copy, move, or link.

  • When to Use: Use this for custom operations, like dragging a file into an app to open it without moving or copying it.
  • Cursor Symbol: This operation usually shows an app-specific cursor or no special symbol.
  • Example: Dragging a file into a photo-editing app to open it.

Every operation .every

The every operation allows all types of drag operations, such as copy, move, link, and any custom operations.

  • When to Use: Use this when you want to let the user choose any drag operation. It’s essentially a “catch-all” that means any valid drag operation is allowed at the drop target.
  • Cursor Symbol: The cursor symbol will change based on what the user chooses (for example, it could show a "+" symbol for copy or the normal arrow for move).
  • Example: You might use every in a drop area that can handle any kind of operation—copying, moving, or linking the dragged item.

None Operation []

This means no operation is allowed. The item cannot be dropped in the current location.

  • When to Use: Use this when the drop target doesn't support dragging, or the data being dragged is invalid for that area.
  • Cursor Symbol: The cursor shows a "no-entry" symbol, indicating that the item can't be dropped here.
  • Example: Trying to drag a file onto a part of an app that doesn’t accept files.

Sometimes, you might want to allow more than one operation at the same time. For example, you can allow both copy and move operations. The user can then choose which one to use by pressing special keys like the Option key.

[.copy, .move]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant